Compare commits

..

No commits in common. "d60de45141b414b54aecabb7b1c87841ef72a5a2" and "4a2ed3b87b63ef4c2a0fc8f602207adfddb5a292" have entirely different histories.

5 changed files with 104 additions and 118 deletions

View file

@ -2,7 +2,7 @@
#+author: Howard X. Abrams
#+date: 2024-10-18
#+filetags: emacs hamacs
#+lastmod: [2024-11-05 Tue]
#+lastmod: [2024-10-30 Wed]
A literate programming file for creating and running demonstrations
@ -58,29 +58,6 @@ But I feel I should replace it, and this project encapsulates the following goal
* Presentations with Org
A demonstration begins with an Org file where the screen shows a /single heading/ with a larger font. Not much more. I have two projects that I like to use.
** Hiding Blocks
When showing a presentation, I never want the =#+business= to lines to completely disappear. First attempt turned the foreground color to the background color, but that still leaves a blank, but occupied line. Using the invisible overlays removes them completely:
#+BEGIN_SRC emacs-lisp
(defun ha-org-blocks-hide-headers ()
"Make the headers and other block metadata invisible.
See `ha-org-blocks-show-headers' to return their appearance."
(let ((pattern (rx bol (zero-or-more space)
(or ":" "#")
(zero-or-more any) eol)))
(save-excursion
(goto-char (point-min))
(while (re-search-forward pattern nil t)
(let* ((start (match-beginning 0)) (end (1+ (match-end 0)))
(ovlay (make-overlay start end)))
(overlay-put ovlay 'invisible t))))))
(defun ha-org-blocks-show-headers ()
"Un-invisibilize the headers and other block metadata invisible.
In other words, this undoes what `ha-org-blocks-hide-headers' did."
(delete-all-overlays))
#+END_SRC
** Org Present
Converted to use [[https://github.com/rlister/org-present][org-present]]. I love the /hooks/ as that makes it easier to handle. My problem with =org-present= is that it doesnt always display images.
@ -90,6 +67,24 @@ Converted to use [[https://github.com/rlister/org-present][org-present]]. I love
(defvar ha-org-present-mode-line mode-line-format
"Cache previous mode-line format state")
(defun ha-org-blocks-hide-headers ()
"Make the headers and other block metadata invisible.
See `ha-org-blocks-show-headers'."
(let ((pattern (rx bol (zero-or-more space)
(or ":" "#")
(zero-or-more any) eol)))
(save-excursion
(goto-char (point-min))
(while (re-search-forward pattern nil t)
(let* ((start (1+ (match-beginning 0))) (end (1+ (match-end 0)))
(ovlay (make-overlay start end)))
(overlay-put ovlay 'invisible t))))))
(defun ha-org-blocks-show-headers ()
"Un-invisibilize the headers and other block metadata invisible.
In other words, this undoes what `ha-org-blocks-hide-headers' did."
(delete-all-overlays))
(defun ha-org-present-start ()
"Hook to run when starting a presentation.
This happens _after_ `org-present' has started."
@ -122,7 +117,7 @@ Converted to use [[https://github.com/rlister/org-present][org-present]]. I love
(org-present-show-cursor))
:bind
(:map org-present-mode-keymap
(:map org-tree-slide-mode-map
("<f5>" . org-present-next)
("S-<f5>" . org-present-previous)
("C-<f5>" . org-present-quit))
@ -141,7 +136,7 @@ Converted to use [[https://github.com/rlister/org-present][org-present]]. I love
"p" #'org-present-prev
"r" #'org-present-read-only
"w" #'org-present-read-write
"Q" #'org-present-quit)
"q" #'org-present-quit)
:hook
(org-present-mode . ha-org-present-start)
@ -155,7 +150,6 @@ Ive used [[https://github.com/takaxp/org-tree-slide][org-tree-slide]] for yea
:config
(setq org-tree-slide-heading-emphasis nil
org-tree-slide-activate-message "† This demonstration is running in Emacs"
org-tree-slide-indicator '(:next nil :previous nil :content nil)
org-tree-slide-cursor-init nil)
(org-tree-slide-simple-profile)
@ -163,32 +157,33 @@ Ive used [[https://github.com/takaxp/org-tree-slide][org-tree-slide]] for yea
"Configure the presentation display.
See `ha-org-tree-slide-stop' that undoes this."
(setq org-hide-emphasis-markers t)
(ha-org-blocks-hide-headers)
(set-face-attribute 'org-quote nil
:inherit 'variable-pitch :slant 'italic)
(ha-demo-hide-cursor)
(ha-demo-hide-mode-line)
(ha-demo-presentation-frame)
;; (demo-it--presentation-display-set)
(text-scale-set 4)
(demo-it--presentation-display-set)
(ha-demo-hide-mode-line)
(git-gutter-mode -1)
(text-scale-set 4)
(flycheck-mode -1)
(jinx-mode -1))
(defun ha-org-tree-slide-stop ()
"Reset the display after a presentation.
See `ha-org-tree-slide-start' for what's set."
(demo-it--presentation-display-restore) ; Restore previous changes
(setq org-hide-emphasis-markers t)
(ha-org-blocks-show-headers)
(ha-demo-show-cursor)
(ha-demo-show-mode-line)
(ha-demo-normalize-frame)
;; (demo-it--presentation-display-restore) ; Restore previous changes
(text-scale-set 0)
(ha-demo-show-cursor)
(git-gutter-mode)
(text-scale-set 0)
(flycheck-mode)
(jinx-mode))
:bind
(:map org-tree-slide-mode-map
(("S-<f6>" . org-tree-slide-skip-done-toggle)
:map org-tree-slide-mode-map
("<f5>" . org-tree-slide-move-next-tree)
("S-<f5>" . org-tree-slide-move-previous-tree)
("M-<f5>" . org-tree-slide-content)
@ -196,10 +191,13 @@ Ive used [[https://github.com/takaxp/org-tree-slide][org-tree-slide]] for yea
:general
(:states 'normal :keymaps 'org-tree-slide-mode-map
"C" #'ha-demo-toggle-cursor
"c" #'ha-demo-hide-cursor
"C" #'ha-demo-show-cursor
"n" #'org-tree-slide-move-next-tree
"N" #'org-tree-slide-move-previous-tree
"Q" (lambda () (interactive) (org-slide-tree-mode -1)))
"j" #'org-tree-slide-move-next-tree
"k" #'org-tree-slide-move-previous-tree
"p" #'org-tree-slide-move-previous-tree
"q" (lambda () (interactive) (org-slide-tree-mode -1)))
:hook
((org-tree-slide-play . ha-org-tree-slide-start)
@ -221,18 +219,16 @@ To make the contents of the expression easier to write, the =define-ha-demo= as
#+BEGIN_SRC emacs-lisp
(defmacro define-ha-demo (demo-name &rest forms)
"Create a demonstration sequence from FORMS as DEMO-NAME function.
Call DEMO-NAME (as an interactive function), executes a function
based matching list of states at point. Where FORMS is an even
number of _matcher_ and _function_ to call.
"Create a demonstration sequence as DEMO-NAME function.
Call DEMO-NAME (as an interactive function), executes a function based matching list of states at point.
Where FORMS is an even number of _matcher_ and _function_ to call.
Probably best to explain this in an example:
\(define-demo demo1
\(:buffer \"demonstrations.py\") \(message \"In a buffer\"\)
\(:mode 'dired-mode\) \(message \"In a dired\"\)
\(:heading \"Raven Civilizations\"\) \(message \"In an org file\"\)\)
(define-demo demo1
(:buffer \"demonstrations.py\") (message \"In a buffer\")
(:mode 'dired-mode) (message \"In a dired\")
(:heading \"Raven Civilizations\" (message \"In an org file\")))
Calling `(demo1)' displays a message based on position of the
point in a particular buffer or place in a heading in an Org file.
@ -240,9 +236,9 @@ To make the contents of the expression easier to write, the =define-ha-demo= as
You can use the `:i' to specify different forms to call when
the trigger matches the first time, versus the second time, etc.
\(define-demo demo2
\(:buffer \"demonstrations.org\" :i 0\) \(message \"First time\"\)
\(:buffer \"demonstrations.org\" :i 1\) \(message \"Second time\"\)\)"
(define-demo demo2
(:buffer \"demonstrations.org\" :i 0) (message \"First time\")
(:buffer \"demonstrations.org\" :i 1) (message \"Second time\"))"
`(defun ,demo-name ()
(interactive)
(let ((state (list :buffer (buffer-name)
@ -349,54 +345,44 @@ The typical presentation software has an issue for hiding the cursor when workin
(defun ha-demo-hide-cursor ()
"Hide the cursor for the current frame."
(interactive)
(unless ha-demo-cursor
(setq ha-demo-cursor
(list cursor-type
t ; (when (boundp 'evil-default-cursor) evil-default-cursor)
(when (boundp 'evil-emacs-state-cursor) evil-emacs-state-cursor)
(when (boundp 'evil-normal-state-cursor) evil-normal-state-cursor)
(default-value blink-cursor-mode)
(when (display-graphic-p)
(frame-parameter (selected-frame) 'cursor-type))))
(setq ha-demo-cursor
(list cursor-type
t ; (when (boundp 'evil-default-cursor) evil-default-cursor)
(when (boundp 'evil-emacs-state-cursor) evil-emacs-state-cursor)
(when (boundp 'evil-normal-state-cursor) evil-normal-state-cursor)
(default-value blink-cursor-mode)
(when (display-graphic-p)
(frame-parameter (selected-frame) 'cursor-type))))
;; Turn off the cursor blinking minor mode:
(blink-cursor-mode -1)
;; Turn off the cursor blinking minor mode:
(blink-cursor-mode -1)
;; Change the cursor types for normal and Evil states:
(setq-local cursor-type nil)
(when (boundp 'evil-default-cursor)
(setq-local
evil-default-cursor nil
evil-emacs-state-cursor nil
evil-normal-state-cursor nil))
;; Change the cursor types for normal and Evil states:
(setq-local cursor-type nil)
(when (boundp 'evil-default-cursor)
(setq-local
evil-default-cursor nil
evil-emacs-state-cursor nil
evil-normal-state-cursor nil))
;; And most importantly, turn off the cursor for the selected frame:
(set-frame-parameter (selected-frame) 'cursor-type nil)))
;; And most importantly, turn off the cursor for the selected frame:
(set-frame-parameter (selected-frame) 'cursor-type nil))
(defun ha-demo-show-cursor ()
"Restore cursor properties turned off by `ha-demo-hide-cursor'."
(interactive)
(when ha-demo-cursor
(setq cursor-type (car ha-demo-cursor))
(setq cursor-type (car ha-demo-cursor))
(when (boundp 'evil-default-cursor)
(setq-local
evil-default-cursor (nth 1 ha-demo-cursor)
evil-emacs-state-cursor (nth 2 ha-demo-cursor)
evil-normal-state-cursor (nth 3 ha-demo-cursor)))
(when (boundp 'evil-default-cursor)
(setq-local
evil-default-cursor (nth 1 ha-demo-cursor)
evil-emacs-state-cursor (nth 2 ha-demo-cursor)
evil-normal-state-cursor (nth 3 ha-demo-cursor)))
(when (nth 4 ha-demo-cursor) (blink-cursor-mode 1))
(when (nth 4 ha-demo-cursor) (blink-cursor-mode 1))
(set-frame-parameter (selected-frame)
'cursor-type (nth 5 ha-demo-cursor))
(setq ha-demo-cursor nil)))
(defun ha-demo-toggle-cursor ()
"Toggles the display of the cursor."
(interactive)
(if ha-demo-cursor
(ha-demo-show-cursor)
(ha-demo-hide-cursor)))
(set-frame-parameter (selected-frame)
'cursor-type (nth 5 ha-demo-cursor)))
#+END_SRC
** Hide and Show the Modeline
@ -458,7 +444,7 @@ Displaying a File with:
All options? Should I use Common Lisps =cl-defun= for the keyword parameters?
#+BEGIN_SRC emacs-lisp :tangle no
#+BEGIN_SRC emacs-lisp
(cl-defun ha-demo-show-file (filename &key position size modeline
line heading shift commands)
"Show a file, FILENAME, in a buffer based on keyed parameters.
@ -466,7 +452,6 @@ All options? Should I use Common Lisps =cl-defun= for the keyword parameters?
SIZE is an integer for the font size based on the default size.
MODELINE is shown if non-line, default is to hide it.
LINE is either a line number or a regular expression to match.
HEADING is a headline from the currently display Org file.
SHIFT is the number of lines above the point to show, in case
the LINE shouldn't be at the top of the window.
@ -477,12 +462,10 @@ All options? Should I use Common Lisps =cl-defun= for the keyword parameters?
;; Step 1: Create a window
(pcase position
('above (progn (split-window-vertically)))
('up (progn (split-window-vertically)))
('left (progn (split-window-horizontally)))
('full )
('right (progn (split-window-horizontally) (other-window 1)))
('above (progn (split-window-vertically) (other-window 1)))
('below (progn (split-window-vertically) (other-window 1))))
;; We could do :left and :top by not doing the other window bit...
;; Step 2: Load the file or switch to the buffer:
(if (file-exists-p filename)
@ -497,7 +480,7 @@ All options? Should I use Common Lisps =cl-defun= for the keyword parameters?
(when line
(if (integerp line)
(forward-line line)
(goto-line line)
(re-search-forward line nil t)))
(when heading
@ -516,7 +499,10 @@ All options? Should I use Common Lisps =cl-defun= for the keyword parameters?
(unless modeline
(setq-local mode-line-format nil))
(when commands (funcall commands)))
(when commands (funcall commands))
)
(funcall (lambda () (message "Hello")))
#+END_SRC
Let try it all together:

View file

@ -9,7 +9,7 @@ A literate programming file for defining leaders with general
;;; ha-leader --- defining leaders with general -*- lexical-binding: t; -*-
;;
;; © 2024 Howard X. Abrams
;; Work licensed under a Creative Commons Attribution 4.0 International License.
;; This work is licensed under a Creative Commons Attribution 4.0 International License.
;; See http://creativecommons.org/licenses/by/4.0/
;;
;; Author: Howard X. Abrams <http://gitlab.com/howardabrams>

View file

@ -2,7 +2,7 @@
#+author: Howard Abrams
#+date: 2024-07-07
#+filetags: emacs hamacs
#+lastmod: [2024-10-29 Tue]
#+lastmod: [2024-10-27 Sun]
A literate programming file for literate programming in Emacs Org Files.
@ -182,7 +182,7 @@ For instance, the following function can be used to quickly select a source code
(avy-jump (rx line-start (zero-or-more blank) "#+begin_src")
:action 'goto-char)
;; Jump _into_ the block:
(forward-line))
(next-line))
#+end_src
I need to take advantage of this feature more.
@ -222,8 +222,7 @@ A trick to =org-babel-tangle=, is that it tangles /what Emacs shows/, that is, i
#+begin_src emacs-lisp :results silent
(defun org-babel-execute-subtree (prefix)
"Execute all Org source blocks in current subtree.
The PREFIX is passed to `org-babel-execute-buffer'."
"Execute all Org source blocks in current subtree."
(interactive "P")
(save-excursion
(org-narrow-to-subtree)
@ -281,7 +280,7 @@ While the goal is Emacs Lisp (and it mostly works for that), it will probably wo
(defun ha-literate-symbol-at-point ()
"Return an alphanumeric sequence at point.
Assuming the sequence can be surrounded by typical
punctuation found in `org-mode' and markdown files."
punctuation found in org-mode and markdown files."
(save-excursion
;; Position point at the first alnum character of the symbol:
(cond ((looking-at (rx (any "=~({<\"'“`") alnum))
@ -312,7 +311,7 @@ This helper function does the work of calling =ripgrep=, parsing its output, and
#+begin_src emacs-lisp
(defun ha-literate--ripgrep-matches (processor regex)
"Return list of running PROCESSOR of `rg' matches from REGEX.
"Return list of running PROCESSOR of `rg' matches from REGEXP.
PROCESSOR is called with an assoc-list of the JSON output from
the call to ripgrep."
(let* ((default-directory (if (project-current)
@ -346,8 +345,8 @@ The output from =ripgrep= goes through a couple of transformation functions list
(string-equal "match" (alist-get 'type json-data)))
#+end_src
TODO Relative Filenames
Since our =ripgrep= searches from the /project root/, but xref wants to make file references relative to the buffer that is calling it, we need to make some changes:
#+BEGIN_SRC emacs-lisp
(defun ha-literate-make-xref-file (filepath)
"Return FILEPATH relative to current buffer's file."
@ -356,7 +355,7 @@ Since our =ripgrep= searches from the /project root/, but xref wants to make fil
(project-root (project-current))
default-directory)))
(relative-to (file-name-parent-directory (buffer-file-name))))
(file-relative-name abspath relative-to)))
(file-relative-name abspath relative-to))))
#+END_SRC
Lets test this function:
@ -400,8 +399,8 @@ The work of processing a match for the =ha-literate-definition= function. It cal
#+begin_src emacs-lisp
(defun ha-literate--process-rg-line (rg-data-line)
"Return an `xref' structure based on the contents of RG-DATA-LINE.
The RG-DATA-LINE is a convert JSON data object from ripgrep.
The return data comes from `xref-make' and `xref-make-file-location'."
The RG-DATA-LINE is a convert JSON data object from ripgrep.
The return data comes from `xref-make' and `xref-make-file-location'."
(when rg-data-line
(let-alist rg-data-line
;; (message "xref-make %s" .data.path.text)
@ -485,12 +484,14 @@ And the function to process the output simply attempts to connect the =begin_src
#+begin_src emacs-lisp
(defvar ha-literate--process-src-refs
(make-hash-table :test 'equal)
"Globabl variable storing org-mode's block line numbers.
The key in this table is a file name, and the value is a list of
line numbers marking #+begin_src and #+end_src.")
"Globabl variable storing results of processing
org-mode's block line numbers. The key in this table is a file
name, and the value is a list of line numbers marking #+begin_src
and #+end_src.")
(defvar ha-literate--process-begin-src nil
"Global variable last `#+begin_src' line number.")
"Globabl variable storing the last entry of an
org-mode's `#+begin_src' line number.")
(defun ha-literate--process-src-blocks (rg-data-line)
"Return nil if RG-DATA-LINE contains a begin_src entry.
@ -550,7 +551,7 @@ Need the completion table before we can find the references. It actually doesn
(defun ha-literate-completion-table ())
#+end_src
Now we /hook this up/ to the rest of the system, and the =xref= is now complete:
Now we /hook this up/ to the rest of the system:
#+begin_src emacs-lisp
(cl-defmethod xref-backend-identifier-completion-table ((_backend (eql org)))
@ -562,7 +563,7 @@ To finish the connections, we need to create a /hook/ that I only allow to turn
#+begin_src emacs-lisp
(defun ha-literate-xref-activate ()
"Function to activate org-based literate backend.
Add this function to `xref-backend-functions' hook."
Add this function to `xref-backend-functions' hook. "
(when (eq major-mode 'org-mode)
'org))
@ -834,7 +835,8 @@ I would like to make the /filename/ more readable, I use the =s-match= again, to
(defvar ha-hamacs-edit-file-to-title
(rx (optional (or "README-" "ha-"))
(group (one-or-more any)) ".org")
"Extract the part of a file to use as a title.")
"Regular expression for extracting the interesting part of a
file to use as a title.")
#+end_src
So the following tests should pass:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

View file

@ -3,7 +3,7 @@
#+date: 2020-09-18
#+tags: emacs org
#+startup: inlineimages
#+lastmod: [2024-10-30 Wed]
#+lastmod: [2024-10-25 Fri]
A literate programming file for configuring org-mode and those files.
@ -882,11 +882,9 @@ And the Emacs interface to that:
#+begin_src emacs-lisp
(use-package jinx
:straight (:host github :repo "minad/jinx" :files (:defaults "jinx-mod.c" "emacs-module.h"))
:hook (emacs-startup . global-jinx-mode)
:bind (("M-$" . jinx-correct-nearest)
("s-;" . jinx-correct-nearest))
;; :bind (([remap ispell-word] . #'jinx-correct))
:general
(:states '(normal insert) :keymaps 'text-mode-map
"M-s M-s" 'jinx-correct)