[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/dslide 1d61b6ffc1 083/230: Codify the hooks and lifecycle
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/dslide 1d61b6ffc1 083/230: Codify the hooks and lifecycle feedback messages |
Date: |
Sun, 7 Jul 2024 19:00:18 -0400 (EDT) |
branch: elpa/dslide
commit 1d61b6ffc12a91aab175b5b4f59298c8afbafe9b
Author: Psionik K <73710933+psionic-k@users.noreply.github.com>
Commit: Psionik K <73710933+psionic-k@users.noreply.github.com>
Codify the hooks and lifecycle feedback messages
One key point: hooks on the minor mode are likely not what anyone wants
because
they run in the base buffer. `ms-start-hook' should be preferred
Signed-off-by: Psionik K <73710933+psionic-k@users.noreply.github.com>
---
README.org | 23 ++++++++++++++++++++---
macro-slides.el | 24 +++++++++++++++---------
2 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/README.org b/README.org
index c754cc14a5..6ed0c4ba8c 100644
--- a/README.org
+++ b/README.org
@@ -73,8 +73,6 @@ If you display the slideshow in one window or frame, you can
configure the point
Be sure to check =M-x= ~customize-group~ =macro-slides= to see all declared
custom variables. All of the variables are configured to recommended defaults
except hooks, which would depend on other packages usually.
Many settings can be configured at the global level through customize
variables, the document level through keywords, and the slide level through the
property drawer.
-
-There's a lot of hooks and variables. All of the variables are configured to
recommended defaults except hooks, which would depend on other packages usually.
** Binding
You likely want to start the mode via ~ms-start~. Once the mode starts, it
creates an indirect buffer to display the slides and then calls
~ms-start-function~ once the mode is active and everything is initialized, so
you can customize startup behavior.
#+begin_src elisp
@@ -83,11 +81,30 @@ You likely want to start the mode via ~ms-start~. Once the
mode starts, it crea
Once the global minor mode, ~ms-mode~ is active, additional bindings in
~ms-mode-map~ are active in every buffer so that you can integrate other
buffers into your presentation. (Tracking which buffers are part of a
presentation is still a topic under consideration 🚧)
*** Secondary Commands 🚧
Because you might want to play a video or take a branch in the presentation
and then exit that branch, the plan is to overload the ~ms-start~ binding
within presentations to enter / exit these branches.
+** Hooks
+Because slides and actions have a life-cycle and can easily find their own
heading, consider making a custom action and setting that action on slides
where it's needed.
+
+Beware of using the normal ~ms-mode-hook~ 😱 because it runs *in the base
buffer* ⚠️. If you remap faces or add a bunch of styling, it will be copied to
the indirect buffer but then linger in your base buffer. Instead, use
~ms-start-hook~. 💡
+
+- ~ms-start-hook~ Is run in the indirect buffer after it is set it. This is
what you want.
+- ~ms-stop-hook~ is run in the base buffer because the indirect buffer is
already dead.
+- ~ms-contents-hook~ is run after switching to contents. It runs in the
display buffer.
+- ~ms-narrow-hook~ is run whenever a ~ms-forward~ or ~ms-backward~ changes the
narrow state. Because this is done by watching the restriction, it might do
what you want 🤷🏻♂️
+- ~ms-after-last-slide-hook~ is run when the user tries to go forward but
there are no more slides. You can use this to implement a final feedback
before exiting the presentation or set it to just ~ms-stop~ to exit without
feedback. Another option is to use ~ms-push-step~ to push a callback that will
only run when called going forward.
+#+begin_src elisp
+ (defun my-stop-if-forward ()
+ (mc-push-step (lambda (direction)
+ (when (eq direction 'forward)
+ ;; Be sure to return t or the hook will run again.
+ (prog1 t (ms-stop))))))
+
+ (setq ms-after-last-slide-hook #'my-stop-if-forward)
+#+end_src
** Recommended MC Settings
The out-of-the-box experience can be a bit messy due to property drawers,
keywords, and babel blocks that you might include. You probably want to hide
these elements.
[[https://github.com/positron-solutions/master-of-ceremonies][Master of
Ceremonies]] contains some flexible hiding that can be updated with each slide
and turned on and off only when the slideshow is active.
#+begin_src elisp
;; Something like this should work
- (add-hook 'ms-mode-hook (lambda () (mc-hide-mode (if ms-mode 1 -1))))
+ (add-hook 'ms-start-hook mc-hide-markup-mode)
(add-hook 'ms-narrow-hook #'mc-hide-refresh)
#+end_src
** Heading Properties
diff --git a/macro-slides.el b/macro-slides.el
index 10200c4d02..13773e12e3 100644
--- a/macro-slides.el
+++ b/macro-slides.el
@@ -193,15 +193,16 @@ The current time will be used as a fallback."
:forward "Forward ➡"
:backward "⬅ Backward"
:contents "Contents ☰"
- :stop "Finished! ■" ; TODO stop is not finish
- :after-last-slide "No more slides")
+ :stop "Stop ■"
+ :after-last-slide "No more slides!")
"Feedback messages for slide controls.
Turn off by setting to nil. Plist keys:
- :start `ms-start'
- :forward `ms-forward'
- :backward `ms-backward'
- :contents `ms-contents'
-- :stop `ms-stop'"
+- :stop `ms-stop'
+ :after-last-slide: see `after-last-slide' hook"
:type 'plist
:group 'macro-slides)
@@ -263,8 +264,13 @@ affect display in another buffer will not trigger this
hook."
:group 'macro-slides
:type 'hook)
-(defcustom ms-after-last-slide-hook '(ms-stop)
- "Run when forward is called at last slide."
+(defcustom ms-after-last-slide-hook '()
+ "Run when forward is called but there is no next slide.
+This can either provide feedback or quit immediately etc.
+Consider using `ms-push-step' and writing a callback that only
+reacts to the `forward' state. This callback will then only run
+if the user immediately calls `ms-forward' again. `ms-stop' is
+another good choice."
:group 'macro-slides
:type 'hook)
@@ -2246,7 +2252,6 @@ hooks must occur in the deck's :slide-buffer."
(let* ((base-buffer (current-buffer))
(slide-buffer-name (format "*deck: %s*" (buffer-name
base-buffer))))
- (ms--feedback :start)
;; stale buffers likely indicate an issue
(when-let ((stale-buffer (get-buffer slide-buffer-name)))
@@ -2464,6 +2469,7 @@ Optional ERROR if you want to process
`wrong-type-argument'."
(define-minor-mode ms-mode
"A presentation tool for Org Mode."
:init-value nil
+ :interactive nil
:keymap ms-mode-map
:group 'macro-slides
:global t
@@ -2474,9 +2480,9 @@ Optional ERROR if you want to process
`wrong-type-argument'."
(cond (ms-mode
;; Create the indirect buffer and link it via the deck object.
(ms--ensure-deck)
- (funcall (or ms-start-function
- #'ms-display-slides))
- (run-hooks 'ms-start-hook))
+ (funcall (or ms-start-function #'ms-display-slides))
+ (run-hooks 'ms-start-hook)
+ (ms--feedback :start))
(t
(ms--stop))))
- [nongnu] elpa/dslide d0a0678463 070/230: Removed face remapping (it was sent to master-of-ceremonies), (continued)
- [nongnu] elpa/dslide d0a0678463 070/230: Removed face remapping (it was sent to master-of-ceremonies), ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide 618b803f95 067/230: !refactor Telescopio, the parents now call through their children, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide bdd5fff8d6 064/230: moving some code for packaging, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide a462b0a4ba 062/230: babel blocks should only clear results when configured to do so, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide aed4afd84a 063/230: implement hiding children, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide 199bb5b68b 079/230: Properties standardized to MS_ prefix, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide ada6553434 080/230: missed a few updates to property names, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide fca6e33a6c 060/230: Properly declare generic methods, reconcile documentation, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide 4af0c6b990 084/230: Remove vestigal push-* code, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide 0cbd0b7bab 081/230: Remove vestigal ms-slide-hook, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide 1d61b6ffc1 083/230: Codify the hooks and lifecycle feedback messages,
ELPA Syncer <=
- [nongnu] elpa/dslide 31fc027f52 057/230: !temporary basic composition support, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide 09b9e5bc63 071/230: keep-fill implementation for hiding, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide 2c515e58d0 127/230: remove redundant actions in demo, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide 5cf6e1d521 102/230: option to hide mode line when displaying images, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide 0087bce96f 082/230: Finished some incomplete parts of the README, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide 7e0cf003b0 092/230: don't log feedback messages to the message log, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide 1472ac4601 137/230: package lint, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide d33205f260 138/230: soft-require hide-mode-line, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide c131653996 139/230: Remove extraneous +1, ELPA Syncer, 2024/07/07
- [nongnu] elpa/dslide 76ff3c1b06 151/230: - dumping off some minor cleanup line noise, ELPA Syncer, 2024/07/07