org-mode,如何使用格式良好的组织链接自动生成漂亮的文件层次结构树

问题描述 投票:3回答:2

使用Org-Mode时,我正在寻找一种自动生成格式良好的组织模式链接的解决方案。

例如,要创建指向目录下所有c ++文件的链接,我需要以下内容:

enter image description here


更新:我刚刚尝试了@DamianChrzanowski的建议,org-fstree包。不过我对结果有点失望:

enter image description here

html导出结果甚至最差:

enter image description here

我的结论是包装不能满足我的需求。无论如何,感谢@DamianChrzanowski的回答。

emacs sh org-mode
2个回答
3
投票

安装了linux tree command后,我带了以下脚本来满足我的所有需求:

#+NAME: createTree
#+BEGIN_SRC sh :results drawer :var toInclude="*.org" :var toExclude="" :var directory="./" :var createLink="true" :exports none
set -e
buffer=$(mktemp /tmp/buffer.XXXXXXXXX)
current_directory=$(pwd)
cd $(eval echo "$directory")
tree -a -P "$toInclude" -I "$toExclude" -if --noreport  --prune \
    | sed "s/.//"  | sed "s/^\///"  > "$buffer"

if [ $(grep --regexp="$" --count "$buffer") -eq 0 ]; then
    echo "**ERROR empty list**"
else
    for f in $(cat "$buffer")
    do 
    filename=$(basename $f)
    ext="${filename##*.}"
    baseFilename="${filename%.*}"
    if [ -f $f ]; then
        # removes org extension (only)
        if [ "$ext" = "org" ]; then
        filename="$baseFilename"
        fi
        # creates org link (or not)
        if [ "$createLink" = true ]; then 
        echo "$(echo "$f" | tr -cd / | tr / \\t)+ [[file:"$directory/$f"][$filename]]"
        else
        echo "$(echo "$f" | tr -cd / | tr / \\t)+ $filename"
        fi
    else
        echo  "$(echo "$f" | tr -cd / | tr / \\t)+ $filename/"
    fi
    done
fi
rm "$buffer"
cd "$current_directory"
#+END_SRC

如果要创建C ++代码的文件树,只需使用以下内容:

#+CALL: createTree(toInclude="*.[hc]pp",toExclude="*test*",directory="~/MyProject")

另请注意,导出/发布组织模式文档时,可以将其用作站点地图的替代方法。只需使用:

* My site content

#+CALL: createTree(toInclude="*.org",toExclude="Setup")

以前的#+CALL命令将生成类似我在问题中发布的树。在Org HTML导出之后,你会得到类似的东西:enter image description here


命令参数/选项是:

  • toInclude =“...”:要包含的模式
  • toExclude =“...”:要排除的模式
  • directory =“...”:目录
  • createLink =“true”或“false”:如果为false,则创建没有链接的树

注意1:您可以将脚本存储在任何.org文件中并通过Library-of-Babel加载它:

在你的init.el文件中:

(org-babel-lob-ingest "~/path/to/your/scripts.org")

注2:我回答了我自己的问题,但我仍然对纯粹的Emacs-Lisp解决方案持开放态度。


1
投票

通常有一个包:-) org-fstree

© www.soinside.com 2019 - 2024. All rights reserved.