Search code examples
emacsorg-mode

org mode - clickable text jump to specific line in emacs


I have a file list and wish to jump to specific line if click the text.

#+BEGIN_SRC python :results output

for i in range(0,10):
    print "[[./test%d.txt:100]]"%i

#+END_SRC

#+RESULTS:
#+begin_example
[[./test0.txt:100]]
[[./test1.txt:100]]
[[./test2.txt:100]]
[[./test3.txt:100]]
[[./test4.txt:100]]
[[./test5.txt:100]]
[[./test6.txt:100]]
[[./test7.txt:100]]
[[./test8.txt:100]]
[[./test9.txt:100]]
#+end_example

If without the linenumber at the end, click the text line will open the file but not jump to the specific line number.

How should I change the syntax to jump to line number?


Solution

  • In your example, the only problem was the syntax for Org external links. It is

    [[./test%d.txt::100]] (and not [[./test%d.txt:100]])
    

    This will work in your Emacs Org buffer, however the link will not be exported if you publish your file (C-c C-e h o).

    If you also want to export/publish your links you can use:

    #+OPTIONS: d:t \n:t
    
    #+BEGIN_SRC python :results output drawer :exports both
    
    for i in range(0,10):
        print "[[./test%d.txt::100][test%d.txt::100]]" %(i,i)
    
    #+END_SRC
    

    The d:t option tells to export drawers, the \n:t one to preserve linebreaks.

    Putting your python code result into a drawer (the :results output drawer) allows org mode to interpret it as true org-mode code.