0

I'd like to place a link to a tag or target inside a source code block.

#+BEGIN_SRC emacs-lisp
  (use-package evil
    :ensure t
    :config
                      ; enable per default
    (evil-mode t)

                      ; <<evil-bindings>>
    :bind ("C-^" . evil-buffer)  ; Switch to another buffer quickly
#+END_SRC

*** Key bindings

See [[file:::/<<evil-bindings>>/]]

Ideally this should jump the to position of ; |<<evil-bindings>> inside the source block when followed via C-c C-o.

I've tried See [[<<evil-bindings>>]] before I tried "Method 2" in the answer from user Melioratus in How to reference source blocks in org text. My first try just prompts with No match - create this as a new heading? (yes or no) in the minibuffer. The "Method 2" just calls occur as mentioned in the answer. But there's another problem. When going from my first try and editing the link via C-c C-l and answering either just file::: or file:::/regexp/ to the Link: prompt, it errors out with org-insert-link: Args out of range: "file:::/<<evil-bindings>>/", 5, 4. (I then activated and edited the link manually.)

NB: I haven't configured anything related to org-mode yet (not even (require 'org) in my init.el). My emacs and org-mode version:

  • GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.5) of 2019-09-23, modified by Debian
  • Org mode version 9.1.9 (release_9.1.9-65-g5e4542 @ /usr/share/emacs/26.1/lisp/org/)

Greetings, AWG

2

In literal examples, Org interprets strings like (ref:name) as labels, and use them as targets for special hyperlinks like [[(name)]] (...) You can also add a -r switch which removes the labels from the source code.

See [[(jump)]].

#+begin_src emacs-lisp -r
(let ((x 1))                (ref:jump)
  (print x))
#+end_src
| improve this answer | |
  • Thank you, works like a charm. :) – AWG Mar 29 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.