Fixed issues with displaying with org-tree-slide

This commit is contained in:
Howard Abrams 2024-10-30 19:20:28 -07:00
parent 5182b352cd
commit 4a2ed3b87b

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-26 Sat] #+lastmod: [2024-10-30 Wed]
A literate programming file for creating and running demonstrations A literate programming file for creating and running demonstrations
@ -19,36 +19,57 @@ A literate programming file for creating and running demonstrations
;; ;;
;; While obvious, GNU Emacs does not include this file or project. ;; While obvious, GNU Emacs does not include this file or project.
;; ;;
;;; Commentary:
;;
;; This replaces my original demo-it project encapsulating the following goals:
;;
;; - Flexible presentation that can use either `org-present' or
;; continue to `org-tree-slide'
;;
;; - Simpler support functions for showing side windows and whatnot
;;
;; - Most importantly, a more flexible demonstration where trigger
;; events based on the current state.
;;
;; *NB:* Do not edit this file. Instead, edit the original literate file at: ;; *NB:* Do not edit this file. Instead, edit the original literate file at:
;; /Users/howard.abrams/src/hamacs/ha-demos.org ;; ~/src/hamacs/ha-demos.org
;; And tangle the file to recreate this one. ;; And tangle the file to recreate this one.
;; ;;
;;; Code: ;;; Code:
#+end_src #+end_src
* Introduction * Introduction
Once made demonstrations /within/ Emacs with my [[https://github.com/howardabrams/demo-it][demo-it]] project. While on MELPA, I wanted to use my own cloned version to make sure I can keep debugging it. Once I made demonstrations /within/ Emacs with my [[https://github.com/howardabrams/demo-it][demo-it]] project. While on MELPA, I wanted to use my own cloned version to make sure I can keep debugging it.
#+begin_src emacs-lisp :tangle no #+begin_src emacs-lisp :tangle no
(use-package demo-it (use-package demo-it
:straight (:local-repo "~/src/demo-it") :straight (:local-repo "~/src/demo-it")
;; :straight (:host github :repo "howardabrams/demo-it") ;; :straight (:host github :repo "howardabrams/demo-it")
:commands (demo-it-create demo-it-start) :commands (demo-it-create demo-it-start demo-it-hide-mode-line
:custom (demo-it--insert-test-speed :faster)) demo-it--presentation-display-set)
:custom (demo-it--insert-test-speed :faster))
#+end_src #+end_src
But I feel I should replace it. But I feel I should replace it, and this project encapsulates the following goals:
* Presentations with Org
Used to use [[https://github.com/takaxp/org-tree-slide][org-tree-slide]] for showing org files as presentations. Converted to use [[https://github.com/rlister/org-present][org-present]]. I love the /hooks/ as that makes it easier to handle. My concern with =org-present= is how it solely displays top-level headers.
#+begin_src emacs-lisp - Flexible presentation that can use either =org-present= or continue to =org-tree-slide=
- Simpler support functions for showing side windows and whatnot
- Most importantly, a more flexible demonstration where trigger events based on the current /state/.
* 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.
** 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.
#+begin_src emacs-lisp :tangle no
(use-package org-present (use-package org-present
:config :config
(defvar ha-org-present-mode-line mode-line-format "Cache previous mode-line format state") (defvar ha-org-present-mode-line mode-line-format
"Cache previous mode-line format state")
(defun ha-org-blocks-hide-headers () (defun ha-org-blocks-hide-headers ()
"Make the headers and other block metadata invisible. "Make the headers and other block metadata invisible.
See `ha-org-blocks-show-headers'." See `ha-org-blocks-show-headers'."
(let ((pattern (rx bol (zero-or-more space) (let ((pattern (rx bol (zero-or-more space)
(or ":" "#") (or ":" "#")
(zero-or-more any) eol))) (zero-or-more any) eol)))
@ -61,10 +82,12 @@ Used to use [[https://github.com/takaxp/org-tree-slide][org-tree-slide]] for sho
(defun ha-org-blocks-show-headers () (defun ha-org-blocks-show-headers ()
"Un-invisibilize the headers and other block metadata invisible. "Un-invisibilize the headers and other block metadata invisible.
In other words, this undoes what `ha-org-blocks-hide-headers' did." In other words, this undoes what `ha-org-blocks-hide-headers' did."
(delete-all-overlays)) (delete-all-overlays))
(defun ha-org-present-start () (defun ha-org-present-start ()
"Hook to run when starting a presentation.
This happens _after_ `org-present' has started."
(unless ha-org-present-mode-line (unless ha-org-present-mode-line
(setq ha-org-present-mode-line mode-line-format)) (setq ha-org-present-mode-line mode-line-format))
(goto-char (point-min)) (re-search-forward (rx bol "*")) (goto-char (point-min)) (re-search-forward (rx bol "*"))
@ -83,6 +106,9 @@ Used to use [[https://github.com/takaxp/org-tree-slide][org-tree-slide]] for sho
(org-present-hide-cursor)) (org-present-hide-cursor))
(defun ha-org-present-end () (defun ha-org-present-end ()
"Hook to run when ending a presentation.
This happens _after_ `org-present-quit' has occurred,
and attempts to _undo_ effects of `ha-org-present-start'."
(org-present-small) (org-present-small)
(org-present-read-write) (org-present-read-write)
(ha-org-blocks-show-headers) (ha-org-blocks-show-headers)
@ -90,9 +116,11 @@ Used to use [[https://github.com/takaxp/org-tree-slide][org-tree-slide]] for sho
(jinx-mode) ; Turn on spell checking (jinx-mode) ; Turn on spell checking
(org-present-show-cursor)) (org-present-show-cursor))
:hook :bind
(org-present-mode . ha-org-present-start) (:map org-tree-slide-mode-map
(org-present-mode-quit . ha-org-present-end) ("<f5>" . org-present-next)
("S-<f5>" . org-present-previous)
("C-<f5>" . org-present-quit))
:general :general
(:states 'normal :keymaps 'org-present-mode-keymap (:states 'normal :keymaps 'org-present-mode-keymap
@ -103,11 +131,78 @@ Used to use [[https://github.com/takaxp/org-tree-slide][org-tree-slide]] for sho
"c" #'org-present-hide-cursor "c" #'org-present-hide-cursor
"C" #'org-present-show-cursor "C" #'org-present-show-cursor
"n" #'org-present-next "n" #'org-present-next
"j" #'org-present-next
"k" #'org-present-prev
"p" #'org-present-prev "p" #'org-present-prev
"r" #'org-present-read-only "r" #'org-present-read-only
"w" #'org-present-read-write "w" #'org-present-read-write
"q" #'org-present-quit)) "q" #'org-present-quit)
:hook
(org-present-mode . ha-org-present-start)
(org-present-mode-quit . ha-org-present-end))
#+end_src #+end_src
** Org Tree Slide
Ive used [[https://github.com/takaxp/org-tree-slide][org-tree-slide]] for years for showing org files as presentations. I like the /simple/ presentation and it seems to shows all the images.
#+BEGIN_SRC emacs-lisp
(use-package org-tree-slide
:config
(setq org-tree-slide-heading-emphasis nil
org-tree-slide-activate-message "† This demonstration is running in Emacs"
org-tree-slide-cursor-init nil)
(org-tree-slide-simple-profile)
(defun ha-org-tree-slide-start ()
"Configure the presentation display.
See `ha-org-tree-slide-stop' that undoes this."
(setq org-hide-emphasis-markers t)
(set-face-attribute 'org-quote nil
:inherit 'variable-pitch :slant 'italic)
(ha-demo-hide-cursor)
(ha-demo-presentation-frame)
(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-demo-show-mode-line)
(ha-demo-normalize-frame)
(ha-demo-show-cursor)
(git-gutter-mode)
(text-scale-set 0)
(flycheck-mode)
(jinx-mode))
:bind
(("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)
("C-<f5>" . (lambda () (interactive) (org-tree-slide-mode -1))))
:general
(:states 'normal :keymaps 'org-tree-slide-mode-map
"c" #'ha-demo-hide-cursor
"C" #'ha-demo-show-cursor
"n" #'org-tree-slide-move-next-tree
"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)
(org-tree-slide-stop . ha-org-tree-slide-stop)))
#+END_SRC
* New Demonstration * New Demonstration
Instead of executing a sequence of demonstration steps, demonstrations key on “state”, that is, the active buffer or major-mode, or the heading of an Org file, etc. I described the [[https://howardism.org/Technical/Emacs/demonstrations-part-two.html][guts of writing this code]], but we bind a key to calling =ha-demo-step= with a list of /state matchers/ to functions to call when matched. For instance: Instead of executing a sequence of demonstration steps, demonstrations key on “state”, that is, the active buffer or major-mode, or the heading of an Org file, etc. I described the [[https://howardism.org/Technical/Emacs/demonstrations-part-two.html][guts of writing this code]], but we bind a key to calling =ha-demo-step= with a list of /state matchers/ to functions to call when matched. For instance:
@ -118,9 +213,6 @@ Instead of executing a sequence of demonstration steps, demonstrations key on
(:heading "New Demonstration" :i 1) (message "Hi there")) (:heading "New Demonstration" :i 1) (message "Hi there"))
(global-set-key (kbd "<f6>") 'ha-simple-demo) (global-set-key (kbd "<f6>") 'ha-simple-demo)
(global-set-key (kbd "<f5>") 'org-present-next)
(global-set-key (kbd "S-<f5>") 'org-present-previous)
(global-set-key (kbd "C-<f5>") 'org-present-quit)
#+END_SRC #+END_SRC
To make the contents of the expression easier to write, the =define-ha-demo= as a macro. Otherwise we write a complicated =cond= with lots of duplicated calls to =ha-demo-state-match= (defined later). This macro creates a function, so the first parameter is the name of the function: To make the contents of the expression easier to write, the =define-ha-demo= as a macro. Otherwise we write a complicated =cond= with lots of duplicated calls to =ha-demo-state-match= (defined later). This macro creates a function, so the first parameter is the name of the function:
@ -242,6 +334,106 @@ Lets create a function that could accept a list of /triggering keys/, and the
* Demonstration Support * Demonstration Support
What sort of functions will I often be doing? What sort of functions will I often be doing?
** Hide and Show the Cursor
The typical presentation software has an issue for hiding the cursor when working with Evil mode, and since setting =cursor-type= to =nil= doesnt work in a graphical display (where we typically run a presentation), the following functions turn on/off the displayed cursor.
#+BEGIN_SRC emacs-lisp
(defvar ha-demo-cursor nil
"List of cursor states stored during `ha-demo-hide-cursor' and
restored with `ha-demo-show-cursor'.")
(defun ha-demo-hide-cursor ()
"Hide the cursor for the current frame."
(interactive)
(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)
;; 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))
(defun ha-demo-show-cursor ()
"Restore cursor properties turned off by `ha-demo-hide-cursor'."
(interactive)
(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 (nth 4 ha-demo-cursor) (blink-cursor-mode 1))
(set-frame-parameter (selected-frame)
'cursor-type (nth 5 ha-demo-cursor)))
#+END_SRC
** Hide and Show the Modeline
For Org file displayed as presentations as well as images, we probably dont want the distraction associated with the modeline, but when we finish the presentation, lets turn it back on …
#+BEGIN_SRC emacs-lisp
(defvar ha-demo-mode-line nil)
(make-variable-buffer-local 'ha-demo-mode-line)
(defun ha-demo-hide-mode-line ()
"Hide mode line for a particular buffer."
(interactive)
(when mode-line-format
(setq ha-demo-mode-line mode-line-format)
(setq mode-line-format nil)))
(defun ha-demo-show-mode-line ()
"Restore mode hidden with `ha-demo-hide-mode-line'."
(interactive)
(if ha-demo-mode-line
(setq mode-line-format ha-demo-mode-line)))
#+END_SRC
** Presentation Frame Properties
Like the work Im doing to the mode-line, can we make the frame cleaner for a presentation?
#+BEGIN_SRC emacs-lisp
(defvar ha-demo-frame-state nil
"Store frame properties during `ha-demo-presentation-frame' before
altering them, and then restore them with `ha-demo-normalize-frame'.")
(defun ha-demo-presentation-frame (&optional name)
"Remove the fringe and other frame settings.
See `ha-demo-normalize-frame' for restoration.
The NAME, if given, is the name of the frame."
(interactive)
(setq ha-demo-frame-state
(list
(frame-parameter (selected-frame) 'left-fringe)
(frame-parameter (selected-frame) 'right-fringe)))
(when name
(set-frame-parameter (selected-frame) 'name name)))
(defun ha-demo-normalize-frame ()
"Restore frame state from `ha-demo-presentation-frame'."
(interactive)
(set-frame-parameter (selected-frame) 'left-fringe (nth 0 ha-demo-frame-state))
(set-frame-parameter (selected-frame) 'right-fringe (nth 1 ha-demo-frame-state)))
#+END_SRC
** Display File ** Display File
Displaying a File with: Displaying a File with:
- On the side or covering the entire frame - On the side or covering the entire frame