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?

Community
  • 1
  • 1
zeliboba7
  • 335
  • 1
  • 10

1 Answers1

3

There are no doubt different approaches available. Someone will likely describe how to use org-mode for this, which is perhaps the most common approach. Personally, I use linkd.el -- simple. You can get it here.

I use it in Emacs-Lisp files, but you can use it in any text file.

A header, or named destination looks like this as plain text:

      ;; (@* "Common helper functions")

That's for Lisp, where ; begins a comment. In your case, you would use //, I believe.

A link to it from the same file looks like this:

      ;; (@> "Common helper functions")

A link to it from a different file looks like this:

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

But they are rendered using highlighting, and without the extraneous chars.

A destination looks like this (but highlighted):

      * Common helper functions

A same-file link looks like this (but highlighted as an Emacs link, and with mouseover highlighting):

      > Common helper functions

A different-file link looks like this (but highlighted as a link, with mouseover):

      . foo.el : Common helper functions
Drew
  • 29,895
  • 7
  • 74
  • 104
  • does it support references to other files? It is not quite clear from in-package description. – zeliboba7 Oct 16 '13 at 14:23
  • Yes, and I gave an example of that above: `(@file :file-name "foo.el" :to "Common helper functions")`. – Drew Oct 16 '13 at 18:02
  • See also [LinkdMode](http://www.emacswiki.org/emacs/LinkdMode) and, for some other options, [CategoryNavigation](http://www.emacswiki.org/emacs/CategoryNavigation). The main alternative seems like WikiNav, which is distributed with [button-lock](https://github.com/rolandwalker/button-lock) – phils Oct 17 '13 at 02:21