Fix some bugs in my literate programming
Getting ready to publish an essay showcasing this.
This commit is contained in:
parent
4a8dd29d68
commit
da58857ba8
3 changed files with 40 additions and 24 deletions
|
@ -2,6 +2,7 @@
|
||||||
#+author: Howard X. Abrams
|
#+author: Howard X. Abrams
|
||||||
#+date: 2021-11-01 November
|
#+date: 2021-11-01 November
|
||||||
#+tags: emacs readme
|
#+tags: emacs readme
|
||||||
|
#+startup: inlineimages
|
||||||
|
|
||||||
** Introduction
|
** Introduction
|
||||||
I’ve crafted my Emacs configuration, I cheekily call /hamacs/, in a literate programming model, heavily inspired by my recent journey into [[https://www.youtube.com/watch?v=LKegZI9vWUU][Henrik Lissner's]] [[https://github.com/hlissner/doom-emacs][Doom Emacs]] and [[https://www.spacemacs.org/][Spacemacs]]. While I used both extensively, I decided I would /roll my own/ as Emacs people like myself, tend to be /control freaks/ (at least a little bit).
|
I’ve crafted my Emacs configuration, I cheekily call /hamacs/, in a literate programming model, heavily inspired by my recent journey into [[https://www.youtube.com/watch?v=LKegZI9vWUU][Henrik Lissner's]] [[https://github.com/hlissner/doom-emacs][Doom Emacs]] and [[https://www.spacemacs.org/][Spacemacs]]. While I used both extensively, I decided I would /roll my own/ as Emacs people like myself, tend to be /control freaks/ (at least a little bit).
|
||||||
|
|
|
@ -356,7 +356,18 @@ Since I seldom remember keybindings, or even function names, for major-modes, I
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(use-package major-mode-hydra
|
(use-package major-mode-hydra
|
||||||
:config
|
:config
|
||||||
(global-set-key (kbd "s-,") #'major-mode-hydra))
|
(global-set-key (kbd "s-,") #'major-mode-hydra)
|
||||||
|
|
||||||
|
(setq major-mode-hydra-title-generator
|
||||||
|
'(lambda (mode)
|
||||||
|
(let ((title (thread-last mode
|
||||||
|
(symbol-name)
|
||||||
|
(string-replace "-" " ")
|
||||||
|
(string-replace " mode" "")
|
||||||
|
(s-titleize))))
|
||||||
|
(s-concat ; (s-repeat 5 " ")
|
||||||
|
(all-the-icons-icon-for-mode mode :v-adjust 0.05)
|
||||||
|
" " title " Commands")))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
For this feature, I may want to pull it out into its own file, so as to keep all of its features together... however, those feature often /depend/ of the functions they are calling. If so, we would have a series like this:
|
For this feature, I may want to pull it out into its own file, so as to keep all of its features together... however, those feature often /depend/ of the functions they are calling. If so, we would have a series like this:
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#+author: Howard Abrams
|
#+author: Howard Abrams
|
||||||
#+date: 2024-07-07
|
#+date: 2024-07-07
|
||||||
#+filetags: emacs hamacs
|
#+filetags: emacs hamacs
|
||||||
#+lastmod: [2024-07-18 Thu]
|
#+lastmod: [2024-07-25 Thu]
|
||||||
|
|
||||||
A literate programming file for literate programming in Emacs Org Files.
|
A literate programming file for literate programming in Emacs Org Files.
|
||||||
|
|
||||||
|
@ -433,7 +433,7 @@ The following section shows some code to use the fuzzy matching features of [[fi
|
||||||
the heading is located."
|
the heading is located."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((default-directory (or project-root (project-root (project-current))))
|
(let* ((default-directory (or project-root (project-root (project-current))))
|
||||||
(file-headings (ha-hamacs-edit--file-heading-list project-root))
|
(file-headings (ha-hamacs-edit--file-heading-list))
|
||||||
(file-choice (completing-read "Edit Heading: " file-headings))
|
(file-choice (completing-read "Edit Heading: " file-headings))
|
||||||
(file-tuple (alist-get file-choice file-headings
|
(file-tuple (alist-get file-choice file-headings
|
||||||
nil nil 'string-equal)))
|
nil nil 'string-equal)))
|
||||||
|
@ -457,8 +457,9 @@ ha-applications.org:386:** EWW
|
||||||
We then filter out non-useful headers (with =ha-hamcs-edit—filter-heading=), and convert the headlines with =ha-hamcs-edit—process-entry= to be more presentable:
|
We then filter out non-useful headers (with =ha-hamcs-edit—filter-heading=), and convert the headlines with =ha-hamcs-edit—process-entry= to be more presentable:
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(defun ha-hamacs-edit--file-heading-list (&optional project-root)
|
(defun ha-hamacs-edit--file-heading-list ()
|
||||||
"Return list of lists of headlines and file locations.
|
"Return list of lists of headlines and file locations.
|
||||||
|
This is found by calling `ripgrep' in the `default-directory'.
|
||||||
Using the output from the shell command, `ha-hamacs-edit-ripgrep-headers',
|
Using the output from the shell command, `ha-hamacs-edit-ripgrep-headers',
|
||||||
it parses and returns something like:
|
it parses and returns something like:
|
||||||
|
|
||||||
|
@ -467,7 +468,6 @@ We then filter out non-useful headers (with =ha-hamcs-edit—filter-heading=), a
|
||||||
(\"Applications∷ Git and Magit ﹥ Git Delta\" \"ha-applications.org\" 110)
|
(\"Applications∷ Git and Magit ﹥ Git Delta\" \"ha-applications.org\" 110)
|
||||||
(\"Applications∷ Git and Magit ﹥ Time Machine\" \"ha-applications.org\" 265)
|
(\"Applications∷ Git and Magit ﹥ Time Machine\" \"ha-applications.org\" 265)
|
||||||
...)"
|
...)"
|
||||||
(let ((default-directory (or project-root (project-root (project-current)))))
|
|
||||||
(thread-last ha-hamacs-edit-ripgrep-headers
|
(thread-last ha-hamacs-edit-ripgrep-headers
|
||||||
(shell-command-to-list)
|
(shell-command-to-list)
|
||||||
;; Let's remove non-helpful, duplicate headings,
|
;; Let's remove non-helpful, duplicate headings,
|
||||||
|
@ -475,7 +475,7 @@ We then filter out non-useful headers (with =ha-hamcs-edit—filter-heading=), a
|
||||||
(seq-remove 'ha-hamacs-edit--filter-heading)
|
(seq-remove 'ha-hamacs-edit--filter-heading)
|
||||||
;; Convert the results into both a displayable
|
;; Convert the results into both a displayable
|
||||||
;; string as well as the file and line structure:
|
;; string as well as the file and line structure:
|
||||||
(seq-map 'ha-hamacs-edit--process-entry))))
|
(seq-map 'ha-hamacs-edit--process-entry)))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
As the above function’s documentation string claims, I create a list that contains the data structure necessary for =completing-read= as well as the information I need to load/jump to a position in the file. This is a three-element list of the /headline/, /filename/ and /line number/ for each entry:
|
As the above function’s documentation string claims, I create a list that contains the data structure necessary for =completing-read= as well as the information I need to load/jump to a position in the file. This is a three-element list of the /headline/, /filename/ and /line number/ for each entry:
|
||||||
|
@ -695,23 +695,27 @@ So the following tests should pass:
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:ID: 2412ef3b-b5d0-43a3-bd01-764fd92b0c3c
|
:ID: 2412ef3b-b5d0-43a3-bd01-764fd92b0c3c
|
||||||
:END:
|
:END:
|
||||||
With a lovely collection of functions, we need to have a way to easily call them. I’ve been using the =pretty-hydra= feature of major-mode-hydra:
|
With a lovely collection of functions, we need to have a way to easily call them. I’ve been using the =pretty-hydra= feature of [[https://github.com/jerrypnz/major-mode-hydra.el][major-mode-hydra]]:
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(pretty-hydra-define org-babel (:color blue)
|
(defvar org-babel--title (concat (all-the-icons-faicon "pencil-square-o")
|
||||||
("Navigate"
|
" Literate Programming Support"))
|
||||||
(("g" avy-jump-org-block "goto")
|
(pretty-hydra-define org-babel
|
||||||
("j" org-next-block "previous block" :color pink)
|
(:title org-babel--title :color blue)
|
||||||
("k" org-previous-block "next block" :color pink))
|
("Code Blocks"
|
||||||
|
(("g" avy-jump-org-block "Goto ")
|
||||||
|
("j" org-next-block "Previous" :color pink)
|
||||||
|
("k" org-previous-block "Next" :color pink))
|
||||||
"Evaluate"
|
"Evaluate"
|
||||||
(("o" avy-org-babel-execute-src-block "block")
|
(("o" avy-org-babel-execute-src-block "Block ")
|
||||||
("h" org-babel-execute-subtree "section")
|
("h" org-babel-execute-subtree "Section")
|
||||||
("b" org-babel-execute-buffer "buffer"))
|
("b" org-babel-execute-buffer "Buffer"))
|
||||||
"Tangle"
|
"Tangle"
|
||||||
(("t" org-babel-tangle "to File")
|
(("t" org-babel-tangle "to Default")
|
||||||
|
("f" org-babel-tangle-file "choose File")
|
||||||
("T" org-babel-detangle "from File"))
|
("T" org-babel-detangle "from File"))
|
||||||
"Misc"
|
"Misc"
|
||||||
(("e" avy-org-babel-edit-src-block "edit"))))
|
(("e" avy-org-babel-edit-src-block "Edit Block "))))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
And tie this hydra into the existing leader system:
|
And tie this hydra into the existing leader system:
|
||||||
|
|
Loading…
Reference in a new issue