If my cursor is on <<globals>>
, how can I open the org-src block similar to org-open-at-point
.
#+begin_src shell :noweb yes :tangle ~/file.txt
<<globals>>
<<aliases>>
#+end_src
If my cursor is on <<globals>>
, how can I open the org-src block similar to org-open-at-point
.
#+begin_src shell :noweb yes :tangle ~/file.txt
<<globals>>
<<aliases>>
#+end_src
I would recommend that you name
your source blocks with #+name: foo
e.g.:
#+name: globals
#+begin_src elisp
globals
#+end_src
#+name: aliases
#+begin_src elisp
aliases
#+end_src
#+name: bar
#+begin_src shell :noweb yes :tangle ~/file.txt
<<globals>>
<<aliases>>
#+end_src
You can then use org-babel-goto-named-source-block
, perhaps in a wrapper to implement the -at-point
functionality, although that seems to work fine out of the box: the default choice is the name that you are currently on.
org-babel-goto-named-source-block
.
@NickD's answer is more standards compliant given that it utilizes orgmode's internal mechanism. Meanwhile, I had also put together a function that will visit the noweb-ref
without the necessity of naming the src block.
(defun mb/try-open-noweb-at-point ()
"Try to visit the noweb-ref source at point."
(interactive)
(let ((thing (thing-at-point 'symbol 't))
(found nil))
(catch 'foo
(org-babel-map-src-blocks nil
(if-let* ((args (nth 2 (org-babel-get-src-block-info t)))
(noweb-ref (alist-get :noweb-ref args)))
(when (equal thing noweb-ref)
(org-show-set-visibility 'minimal)
(with-current-buffer (buffer-name)
(goto-char beg-body)
(throw 'foo (setq found t)))
t))))
(if (equal found nil)
(message "not found"))))
:noweb-ref
. That's not the purpose of the :noweb-ref
header (see Noweb reference syntax for an example of its usage). Nevertheless, +1 for the use of org-babel-map-src-blocks
and in particular for beg-body
which I had forgotten about and had to look for in the doc string of the function :-)
org-babel-get-src-block-info
: the header args are available inside org-babel-map-src-blocks
as the value of header-args
(untested).