Experimental jump to a hamacs headline

This might make it much easiler to keep code in the right place.
This commit is contained in:
Howard Abrams 2024-06-06 23:04:37 -07:00
parent 2bf50e1f78
commit 57e9fa1051
2 changed files with 56 additions and 5 deletions

View file

@ -243,6 +243,56 @@ And the ability to edit the file:
(find-file full-file))) (find-file full-file)))
#+end_src #+end_src
Why not edit a file, but select the file based on the header.
#+begin_src emacs-lisp
(defun ha-hamacs-process-heading (rg-input)
"Return list of heading, file and line number.
Parses the line entry, RG-INPUT, from a call to `rg'.
Returns something like:
(\"Some Heading\" \"some-file.org\" 42)"
(let* ((parts (string-split rg-input ":"))
(file (first parts))
(lnum (string-to-number (second parts)))
(head (thread-first parts
(third)
(substring 1)))
(disp (string-replace "*" " " head)))
(list disp file lnum)))
(defun ha-hamacs-filter-heading (rg-input)
"Return non-nil if we should remove RG-INPUT.
These are headings with typical, non-unique entries,
like Introduction and Summary."
(string-match (rx (or " Introduction"
" Install"
" Summary"
" Technical Artifacts"))
rg-input))
(defun ha-hamacs-edit-file-heading ()
"Edit a file based on a particular heading.
After presenting list of headings from all Org files,
it loads the file, and jumps to the line number where
the heading is located."
(interactive)
(let* ((default-directory hamacs-source-dir)
(file-head-list
(thread-last (concat "rg"
" --no-heading"
" --line-number"
" --max-depth 1"
" --type org"
" -e '^\\*+ '")
(shell-command-to-list)
(seq-remove 'ha-hamacs-filter-heading)
(seq-map 'ha-hamacs-process-heading)))
(file-choice (completing-read "Edit Heading: " file-head-list))
(file-tuple (alist-get file-choice file-head-list
nil nil 'string-equal)))
(find-file (first file-tuple))
(goto-line (second file-tuple))))
#+end_src
And this similar function, will /tangle/ one of my files. Notice that in order to increase the speed of the tangling process (and not wanting to pollute a project perspective), I use a /temporary buffer/ instead of =find-file=. And this similar function, will /tangle/ one of my files. Notice that in order to increase the speed of the tangling process (and not wanting to pollute a project perspective), I use a /temporary buffer/ instead of =find-file=.
#+begin_src emacs-lisp #+begin_src emacs-lisp

View file

@ -186,10 +186,11 @@ And ways to load my tangled org-files:
(ha-leader (ha-leader
"h h" '(:ignore t :which-key "hamacs") "h h" '(:ignore t :which-key "hamacs")
"h h <escape>" '(keyboard-escape-quit :which-key t) "h h <escape>" '(keyboard-escape-quit :which-key t)
"h h f" '("features" . ha-hamacs-features) "h h f" '("features" . ha-hamacs-features)
"h h e" '("edit" . ha-hamacs-find-file) "h h e" '("edit" . ha-hamacs-find-file)
"h h h" '("reload" . ha-hamacs-load) "h h j" '("heading jump" . ha-hamacs-edit-file-heading)
"h h a" '("reload all" . ha-hamacs-reload-all)) "h h h" '("reload" . ha-hamacs-load)
"h h a" '("reload all" . ha-hamacs-reload-all))
#+end_src #+end_src
* File Operations * File Operations
While =find-file= is still my bread and butter, I like getting information about the file associated with the buffer. For instance, the file path: While =find-file= is still my bread and butter, I like getting information about the file associated with the buffer. For instance, the file path:
@ -821,7 +822,7 @@ The [[https://github.com/oantolin/embark/][embark]] project offers /actions/ on
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package embark (use-package embark
:bind :bind
(("s-." . embark-act) ; Work in minibuffer and elsewhere (("s-'" . embark-act) ; Work in minibuffer and elsewhere
("s-/" . embark-dwim)) ("s-/" . embark-dwim))
:init :init