5

Sometimes when you write a program you need to refer to another part/or function in the comments. For example in the code below I could set two anchors "workaround1" and "workaround2" (in another file) in the comments, and make a note about ABC function with references to the relevant comments.

// this part does <<workaround1>>
a = 1;
a++;
...

// [[workaround1]] and [[file:c.java::workaround2][2]] can be removed once ABC is fixed
c = ABC();

I have two questions:

  1. Is there best practice for such references? How professional programmers deal with it?
  2. Is there a package for emacs which can facilitate navigation through a source code comments with such notes? I was thinking about org-mode extension with can work on top of (preferably any) language mode.

I'm aware about similar question on Redmine: Can I create a cross-project source reference in redmine?

4

1 回答 1

3

毫无疑问,有不同的方法可用。有人可能会描述如何使用org-mode它,这可能是最常见的方法。就个人而言,我使用linkd.el--简单。你可以在这里得到它。

我在 Emacs-Lisp 文件中使用它,但您可以在任何文本文件中使用它。

标头或命名目的地看起来像这样的纯文本:

      ;; (@* "常用辅助函数")

那是 Lisp 的,从哪里;开始评论。在你的情况下,你会使用//,我相信。

从同一文件到它的链接如下所示:

      ;; (@> "常用辅助函数")

从另一个文件到它的链接如下所示:

      ;; (@file :file-name "foo.el" :to "Common helper functions")

但是它们是使用突出显示的,并且没有多余的字符。

目的地看起来像这样(但突出显示):

      * 常用辅助函数

相同文件的链接看起来像这样(但突出显示为 Emacs 链接,并且鼠标悬停突出显示):

      > 常用辅助函数

不同的文件链接如下所示(但突出显示为链接,鼠标悬停):

      . foo.el : 常用辅助函数
于 2013-10-16T14:09:14.077 回答