Better hiding of Org header lines

This commit is contained in:
Howard Abrams 2024-11-05 12:07:27 -08:00
parent 029a714bd7
commit d60de45141
2 changed files with 47 additions and 40 deletions

View file

@ -2,7 +2,7 @@
#+author: Howard X. Abrams #+author: Howard X. Abrams
#+date: 2024-10-18 #+date: 2024-10-18
#+filetags: emacs hamacs #+filetags: emacs hamacs
#+lastmod: [2024-10-30 Wed] #+lastmod: [2024-11-05 Tue]
A literate programming file for creating and running demonstrations A literate programming file for creating and running demonstrations
@ -58,6 +58,29 @@ But I feel I should replace it, and this project encapsulates the following goal
* Presentations with Org * 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. 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 ** 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. 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.
@ -67,24 +90,6 @@ Converted to use [[https://github.com/rlister/org-present][org-present]]. I love
(defvar ha-org-present-mode-line mode-line-format (defvar ha-org-present-mode-line mode-line-format
"Cache previous mode-line format state") "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 () (defun ha-org-present-start ()
"Hook to run when starting a presentation. "Hook to run when starting a presentation.
This happens _after_ `org-present' has started." This happens _after_ `org-present' has started."
@ -158,33 +163,32 @@ Ive used [[https://github.com/takaxp/org-tree-slide][org-tree-slide]] for yea
"Configure the presentation display. "Configure the presentation display.
See `ha-org-tree-slide-stop' that undoes this." See `ha-org-tree-slide-stop' that undoes this."
(setq org-hide-emphasis-markers t) (setq org-hide-emphasis-markers t)
(set-face-attribute 'org-quote nil (ha-org-blocks-hide-headers)
:inherit 'variable-pitch :slant 'italic)
(ha-demo-hide-cursor) (ha-demo-hide-cursor)
(ha-demo-presentation-frame)
(demo-it--presentation-display-set)
(ha-demo-hide-mode-line) (ha-demo-hide-mode-line)
(git-gutter-mode -1) (ha-demo-presentation-frame)
;; (demo-it--presentation-display-set)
(text-scale-set 4) (text-scale-set 4)
(git-gutter-mode -1)
(flycheck-mode -1) (flycheck-mode -1)
(jinx-mode -1)) (jinx-mode -1))
(defun ha-org-tree-slide-stop () (defun ha-org-tree-slide-stop ()
"Reset the display after a presentation. "Reset the display after a presentation.
See `ha-org-tree-slide-start' for what's set." See `ha-org-tree-slide-start' for what's set."
(demo-it--presentation-display-restore) ; Restore previous changes
(setq org-hide-emphasis-markers t) (setq org-hide-emphasis-markers t)
(ha-demo-show-mode-line) (ha-org-blocks-show-headers)
(ha-demo-show-cursor) (ha-demo-show-cursor)
(ha-demo-show-mode-line)
(ha-demo-normalize-frame) (ha-demo-normalize-frame)
(git-gutter-mode) ;; (demo-it--presentation-display-restore) ; Restore previous changes
(text-scale-set 0) (text-scale-set 0)
(git-gutter-mode)
(flycheck-mode) (flycheck-mode)
(jinx-mode)) (jinx-mode))
:bind :bind
(("S-<f6>" . org-tree-slide-skip-done-toggle) (:map org-tree-slide-mode-map
:map org-tree-slide-mode-map
("<f5>" . org-tree-slide-move-next-tree) ("<f5>" . org-tree-slide-move-next-tree)
("S-<f5>" . org-tree-slide-move-previous-tree) ("S-<f5>" . org-tree-slide-move-previous-tree)
("M-<f5>" . org-tree-slide-content) ("M-<f5>" . org-tree-slide-content)
@ -192,12 +196,9 @@ Ive used [[https://github.com/takaxp/org-tree-slide][org-tree-slide]] for yea
:general :general
(:states 'normal :keymaps 'org-tree-slide-mode-map (:states 'normal :keymaps 'org-tree-slide-mode-map
"c" #'ha-demo-hide-cursor "C" #'ha-demo-toggle-cursor
"C" #'ha-demo-show-cursor
"n" #'org-tree-slide-move-next-tree "n" #'org-tree-slide-move-next-tree
"j" #'org-tree-slide-move-next-tree "N" #'org-tree-slide-move-previous-tree
"k" #'org-tree-slide-move-previous-tree
"p" #'org-tree-slide-move-previous-tree
"Q" (lambda () (interactive) (org-slide-tree-mode -1))) "Q" (lambda () (interactive) (org-slide-tree-mode -1)))
:hook :hook
@ -389,6 +390,13 @@ The typical presentation software has an issue for hiding the cursor when workin
(set-frame-parameter (selected-frame) (set-frame-parameter (selected-frame)
'cursor-type (nth 5 ha-demo-cursor)) 'cursor-type (nth 5 ha-demo-cursor))
(setq ha-demo-cursor nil))) (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)))
#+END_SRC #+END_SRC
** Hide and Show the Modeline ** Hide and Show the Modeline
@ -469,10 +477,12 @@ All options? Should I use Common Lisps =cl-defun= for the keyword parameters?
;; Step 1: Create a window ;; Step 1: Create a window
(pcase position (pcase position
('full ) ('above (progn (split-window-vertically)))
('up (progn (split-window-vertically)))
('left (progn (split-window-horizontally)))
('right (progn (split-window-horizontally) (other-window 1))) ('right (progn (split-window-horizontally) (other-window 1)))
('above (progn (split-window-vertically) (other-window 1)))
('below (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: ;; Step 2: Load the file or switch to the buffer:
(if (file-exists-p filename) (if (file-exists-p filename)
@ -506,10 +516,7 @@ All options? Should I use Common Lisps =cl-defun= for the keyword parameters?
(unless modeline (unless modeline
(setq-local mode-line-format nil)) (setq-local mode-line-format nil))
(when commands (funcall commands)) (when commands (funcall commands)))
)
(funcall (lambda () (message "Hello")))
#+END_SRC #+END_SRC
Let try it all together: Let try it all together:

BIN
ha-org-mermaid.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB