org mode 能创建 ctags 的链接么?

比如我想在笔记中引用一个函数, 希望能快速跳转到这个位置. 比如 [[file:test_rotate.py::rotate]] 就能跳转到 test_rotate.py 中 rotate 对应的 tag. org mode 支持行号链接, 但这样很不方便. 因为如果注释或者修改就可能改变行号. 也可以用 text search 的方法, 写成 [[file:test_rotate.py::def rotate]], 这种方法也不错, 不过还是想问问有没有通过 ctags 的 tag 跳转的方法. 似乎 org-ctags.el 可以做到这件事, 有用过的朋友么? 正准备尝试 org-ctags.el.

我可以考虑在counsel-etags中添加支持,不过需要明确一下test_rotate.py是相对路径还是绝对路径还是路径部分匹配?

是绝对路径, 访问文件系统任意文件比较方便

应该不难,设置一下org-open-link-functions就可以了,(add-hook 'org-open-link-functions fn t), 我明天看一下。

你提到的场景是文件级别的引用,直接用 org 的 link 就挺好,比如可以在 org 里先写以下形式的 Link Abbreviations (The Org Manual)

#+LINK: test_def file:~/codes/project/test_rotate.py::def %s

然后用 [[test_def:rotate]] 就可以跳转了

python 里 tag 基本就是 class 和 def, 因此可以再写以下的模版来链接类

#+LINK: test_cls file:~/codes/project/test_rotate.py::class %s

但如果是项目级别去找 tag,那 ctags 可能方便(或许也可扩展 open-link 去 grep 项目里的 def rotate,从而不依赖 ctags 缓存)