If my cursor is on
<<globals>>, how can I open the org-src block similar to
#+begin_src shell :noweb yes :tangle ~/file.txt <<globals>> <<aliases>> #+end_src
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
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.
@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"))))