Definition jump to a <<noweb>> in literate org files

This commit is contained in:
Howard Abrams 2023-06-14 17:35:08 -07:00
parent b948a940a4
commit b8df072250
2 changed files with 35 additions and 0 deletions

View file

@ -357,6 +357,38 @@ And turn on ALL the languages:
(css . t) (css . t)
(plantuml . t))) (plantuml . t)))
#+end_src #+end_src
*** Searching Literate Files
A noweb definition, e.g. =<<something-something>>= could /jump/ to the =#name= definition.
Since [[https://github.com/BurntSushi/ripgrep][ripgrep]] is pretty fast, Ill call it instead of attempting to build a [[https://stackoverflow.com/questions/41933837/understanding-the-ctags-file-format][CTAGS]] table. Oooh, the =rg= takes a =—json= option, which makes it easier to parse.
#+begin_src emacs-lisp
(defun ha-org-noweb-block-jump (str pos)
"Go to a literate org file containing a symbol, STR.
The POS is ignored."
;; Sometimes I wrap a function name in `=' characters, and these should be removed:
(when (string-match (rx "<<" (group (one-or-more any)) ">>") str)
(setq str (match-string 1 str)))
(ignore-errors
(let* ((default-directory (projectile-project-root))
(command (format "rg --ignore-case --json '#\\+name: +%s' *.org" str))
(results (thread-last command
shell-command-to-list
second
json-parse-string))
(file (thread-last results
(gethash "data")
(gethash "path")
(gethash "text")))
(line (thread-last results
(gethash "data")
(gethash "line_number"))))
(find-file file)
(goto-line line))))
(add-to-list 'evil-goto-definition-functions 'ha-org-noweb-block-jump)
#+end_src
*** REST Web Services *** REST Web Services
Emacs has two ways to query and investigate REST-oriented web services. The [[https://github.com/zweifisch/ob-http][ob-http]] adds HTTP calls to standard org blocks. Emacs has two ways to query and investigate REST-oriented web services. The [[https://github.com/zweifisch/ob-http][ob-http]] adds HTTP calls to standard org blocks.
#+begin_src emacs-lisp #+begin_src emacs-lisp

View file

@ -83,6 +83,9 @@ While I love packages that add functionality and I dont have to learn anythin
;; Sometimes I wrap a function name in `=' characters, and these should be removed: ;; Sometimes I wrap a function name in `=' characters, and these should be removed:
(when (string-match (rx "=" (group (one-or-more any)) "=") str) (when (string-match (rx "=" (group (one-or-more any)) "=") str)
(setq str (match-string 1 str))) (setq str (match-string 1 str)))
;; In an org-file, a function may pick up the initial #'
(when (string-match (rx (optional "#") "'" (group (one-or-more any))) str)
(setq str (match-string 1 str)))
(ignore-errors (ignore-errors
(let* ((default-directory (projectile-project-root)) (let* ((default-directory (projectile-project-root))
(command (format "rg --json '\\(def[^ ]+ %s ' *.org" str)) (command (format "rg --json '\\(def[^ ]+ %s ' *.org" str))