ffs

Form feed-separated plain text presentations with Emacs

git clone https://www.shemshak.org/~amin/ffs


main/tree/ffs.el (-rw-r--r--, 22.1 KiB, raw)

  1 ;;; ffs.el --- Form feed-separated plain text presentations -*- lexical-binding: t; -*-
  2 
  3 ;; Copyright (c) 2022-2026 Free Software Foundation, Inc.
  4 
  5 ;; Author: Amin Bandali <bandali@gnu.org>
  6 ;; Maintainer: Amin Bandali <bandali@gnu.org>
  7 ;; URL: https://www.shemshak.org/~amin/ffs
  8 ;; Version: 0.2.3
  9 ;; Package-Requires: ((emacs "27.1"))
 10 ;; Keywords: convenience, focus, narrowing, outlines, presentation, text
 11 
 12 ;; This program is free software; you can redistribute it and/or modify
 13 ;; it under the terms of the GNU General Public License as published by
 14 ;; the Free Software Foundation, either version 3 of the License, or
 15 ;; (at your option) any later version.
 16 
 17 ;; This program is distributed in the hope that it will be useful,
 18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 20 ;; GNU General Public License for more details.
 21 
 22 ;; You should have received a copy of the GNU General Public License
 23 ;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
 24 
 25 ;;; Commentary:
 26 
 27 ;; A simple mode for simple plain text presentations where the slides
 28 ;; are separated using the `page-delimiter', by default the form feed
 29 ;; character (^L).
 30 ;;
 31 ;; After installing `ffs', open a text file/buffer containing your
 32 ;; slides and do `M-x ffs-mode RET'.  You can add a key binding for
 33 ;; `ffs-mode' to your init file for convenience:
 34 ;;
 35 ;;     (global-set-key (kbd "C-c f s") #'ffs-mode)
 36 ;;
 37 ;; You should then see "ffs" appear as one of the currently enabled
 38 ;; minor modes in your mode line.  Once `ffs-mode' is enabled, it puts
 39 ;; the buffer in read-only mode, and provides convenient key bindings
 40 ;; for moving between, editing, and inserting slides.  To see a list
 41 ;; of available commands, you can type `?' or `C-h m' to invoke
 42 ;; `describe-mode' which will include a list of the key bindings in
 43 ;; the `ffs-mode-map' keymap, or type `M-x ffs- TAB' to get a
 44 ;; completion of commands starting with the "ffs-" prefix.
 45 ;;
 46 ;; There are other packages with similar or related functionality to
 47 ;; `ffs' that you might also want to look into.  The excellent `logos'
 48 ;; by Proteilaos is the one most similar to `ffs'.  Though envisioned
 49 ;; primarily as a "focus mode" for disctraction-free reading and
 50 ;; writing, it can also be well-suited for minimalist presentations.
 51 ;; A potential benefit of `ffs' over `logos' is that it provides
 52 ;; convenience commands and out-of-the-box key bindings for writing
 53 ;; and editing slides and presenting them.  On the other hand, `logos'
 54 ;; has a few more user options and may be more flexible than `ffs'.
 55 ;; For instance, `logos-outlines-are-pages' and its accompanying
 56 ;; `logos-outline-regexp-alist' allow treating each outline heading
 57 ;; as a page delimiter, a feature currently not provided by `ffs'.
 58 ;;
 59 ;; `org-present', `org-tree-slide', and `dslide' are meant for use
 60 ;; with Org mode files specifically, in contrast to `ffs' and `logos'
 61 ;; which may be used with any major mode.
 62 ;;
 63 ;; The feature that to my knowledge is unique to `ffs' is built-in
 64 ;; support for speaker notes: `ffs-find-speaker-notes-file' prompts
 65 ;; the user for a speaker notes file, and by default displays it in
 66 ;; a new frame.  Then, slide motions (e.g. going to the previous or
 67 ;; next slide) will affect both the speaker notes buffer and the main
 68 ;; slides buffer.
 69 ;;
 70 ;;
 71 ;; Refer to the manual for more details on ffs's user options and
 72 ;; usage, a sample configuration, and other pieces of information:
 73 ;; <https://www.shemshak.org/~amin/ffs/ffs.html>.
 74 
 75 ;;; Code:
 76 
 77 (require 'map)
 78 (require 'page)
 79 (require 'format-spec)
 80 
 81 ␌
 82 ;;;; User options and variables
 83 
 84 (defgroup ffs nil
 85   "Minor mode for form feed-separated plain text presentations."
 86   :group 'editing)
 87 
 88 (defcustom ffs-page-delimiter "␌"
 89   "The default page delimiter for ffs, the form feed character.
 90 If you use a custom `page-delimiter' regexp, be sure to customize this
 91 as well."
 92   :type 'string
 93   :package-version '(ffs . "0.2.0"))
 94 
 95 (defcustom ffs-echo-progress nil
 96   "Whether to display in echo area the progress through the slides.
 97 When non-nil, changing slides will also display the progress through
 98 the slides in the echo area."
 99   :type 'boolean
100   :local t
101   :package-version '(ffs . "0.2.0"))
102 
103 (defcustom ffs-echo-progress-format "Slide %c of %t"
104   "The format spec used for function `ffs-echo-progress-format'.
105 
106 %c Number of current slide.
107 %t Total number of slides."
108   :type 'string
109   :local t
110   :package-version '(ffs . "0.2.0"))
111 
112 (defcustom ffs-default-face-height nil
113   "Value of `height' property of `default' face during presentations.
114 If a natural number (non-negative integer), it will be used as the
115 `height' of the `default' face during presentations, useful for having
116 a larger font size when presenting.
117 
118 If nil, don't change the `default' face's `height' in presentations."
119   :type '(choice (const nil)
120                  (natnum :value 250))
121   :package-version '(ffs . "0.2.0"))
122 
123 (defcustom ffs-hide-cursor nil
124   "When non-nil hide the cursor.
125 This is only relevant when `ffs-present-mode' is enabled."
126   :type 'boolean
127   :local t
128   :package-version '(ffs . "0.2.0"))
129 
130 (defcustom ffs-hide-mode-line nil
131   "When non-nil hide the mode line.
132 This is only relevant when `ffs-present-mode' is enabled."
133   :type 'boolean
134   :local t
135   :package-version '(ffs . "0.2.0"))
136 
137 (defcustom ffs-hide-header-line nil
138   "When non-nil hide the header line.
139 This is only relevant when `ffs-present-mode' is enabled."
140   :type 'boolean
141   :local t
142   :package-version '(ffs . "0.2.0"))
143 
144 (defcustom ffs-edit-display-buffer-alist
145   '(display-buffer-same-window
146     (inhibit-same-window . nil))
147   "Window configuration for the `ffs-edit' buffer.
148 By default, it will display the `ffs-edit' buffer in the same window."
149   :type display-buffer--action-custom-type
150   :package-version '(ffs . "0.2.0"))
151 
152 (defcustom ffs-edit-done-hook nil
153   "Hook run after editing a slide (at the end of `ffs-edit-done')."
154   :type 'hook)
155 
156 (defvar ffs-edit-buffer-name "*ffs-edit*"
157   "The name of the `ffs-edit' buffer used when editing a slide.")
158 
159 (defvar ffs-find-speaker-notes-function #'find-file-other-frame
160   "The function to use when finding a speaker's note file.")
161 
162 ;;;;; Internal variables
163 
164 (defvar-local ffs--edit-source-buffer nil
165   "The ffs presentation buffer of the slide being edited.")
166 
167 (defvar-local ffs--new-location nil
168   "The location where the new slide should be inserted.
169 See the docstring for `ffs-edit' for more details.")
170 
171 (defvar-local ffs--slides-buffer nil
172   "The main ffs presentation slides buffer.
173 When the user enables ffs in a buffer using `\\[ffs]', we store a
174 reference to that buffer in this variable.
175 
176 As a special case, in a speaker notes buffer selected by the user
177 using `\\[ffs-find-speaker-notes-file]' from the main ffs slides
178 buffer, this variable will point to the main ffs slides buffer
179 rather than the speaker notes buffer.")
180 
181 (defvar-local ffs--notes-buffer nil
182   "The ffs speaker notes buffer (only if selected).
183 When the user chooses (and opens) a speaker notes file using
184 `\\[ffs-find-speaker-notes-file]', a reference to the file's
185 corresponding buffer is stored in this variable, local to the
186 main ffs presentation slides buffer (`ffs--slides-buffer').")
187 
188 (defvar-local ffs--default-face-height-cookie nil
189   "Cookie returned from `face-remap-add-relative', for later removal.")
190 
191 (defvar ffs--pkg-dir
192   (and-let* ((file (or (and load-in-progress load-file-name)
193                        (eval-when-compile (macroexp-file-name))
194                        (locate-library "ffs")))
195              (dir (file-name-directory file)))
196     dir)
197   "The directory where `ffs' is located.")
198 
199 ␌
200 ;;;; Slide count / presentation progress
201 
202 (declare-function page--what-page "page")
203 (defun ffs-current-slide-number ()
204   "Return the number of current slide."
205   (interactive)
206   (car (page--what-page)))
207 
208 (defun ffs-total-slide-count ()
209   "Return the total number of slides."
210   (interactive)
211   (save-restriction
212     (save-excursion
213       (widen)
214       (goto-char (point-max))
215       (ffs-current-slide-number))))
216 
217 (defun ffs-echo-progress-format ()
218   "Return progress through slides per variable `ffs-echo-progress-format'."
219   (format-spec
220    ffs-echo-progress-format
221    `((?c . ,(ffs-current-slide-number))
222      (?t . ,(ffs-total-slide-count)))))
223 
224 ␌
225 ;;;; Slide motions
226 
227 (defun ffs--goto-previous (buffer)
228   "Go to the previous slide in the given BUFFER."
229   (interactive)
230   (with-current-buffer buffer
231     (let ((n (buffer-narrowed-p)))
232       (when n
233         (goto-char (point-min))
234         (widen)
235         (backward-page))
236       (backward-page)
237       (when n (narrow-to-page)))))
238 
239 (defun ffs--goto-next (buffer)
240   "Go to the next slide in the given BUFFER."
241   (interactive)
242   (with-current-buffer buffer
243     (let ((n (buffer-narrowed-p))
244           (e (= (- (point-max) (point-min)) 0)))
245       (when n
246         (goto-char (point-min))
247         (widen))
248       (unless e (forward-page))
249       (when n (narrow-to-page)))))
250 
251 (defun ffs--goto-first (buffer)
252   "Go to the first slide in the given BUFFER."
253   (interactive)
254   (with-current-buffer buffer
255     (let ((n (buffer-narrowed-p)))
256       (when n (widen))
257       (goto-char (point-min))
258       (when n (narrow-to-page)))))
259 
260 (defun ffs--goto-last (buffer)
261   "Go to the last slide in the given BUFFER."
262   (interactive)
263   (with-current-buffer buffer
264     (let ((n (buffer-narrowed-p)))
265       (when n (widen))
266       (goto-char (point-max))
267       (when n (narrow-to-page)))))
268 
269 (defvar ffs-present-mode)
270 
271 (defmacro ffs--define-goto-slide (name)
272   "Define a function for going to a slide.
273 Symbol NAME is the name describing the movement."
274   (declare (indent 1))
275   (let* ((sn (symbol-name name))
276          (fname (intern (format "ffs-goto-%s" (downcase sn))))
277          (hname (intern (format "ffs--goto-%s" (downcase sn))))
278          (doc (format
279                "Go to %s slide in ffs presentation and speaker notes buffer."
280                sn)))
281     `(defun ,fname ()
282        ,doc
283        (interactive)
284        (,hname ffs--slides-buffer)
285        (when ffs--notes-buffer
286          (,hname ffs--notes-buffer)
287          ;; FIXME: Why is this needed?
288          (redraw-display))
289        (when (and ffs-present-mode ffs-echo-progress)
290          (message (ffs-echo-progress-format))))))
291 
292 (ffs--define-goto-slide previous)
293 (ffs--define-goto-slide next)
294 (ffs--define-goto-slide first)
295 (ffs--define-goto-slide last)
296 
297 ␌
298 ;;;; Slide insertion and editing
299 
300 (defun ffs-edit (&optional add-above-or-below)
301   "Pop to a new buffer to edit a slide.
302 If ADD-ABOVE-OR-BELOW is nil or not given, we are editing an
303 existing slide.  Otherwise, if it is `add-above' then the new
304 slide will be added above/before the current slide, and if it is
305 `add-below' then the new slide will be added below/after the
306 current slide.  The logic is implemented in `ffs-edit-done'."
307   (interactive)
308   (let* ((b (current-buffer))
309          (nb (generate-new-buffer ffs-edit-buffer-name))
310          (fc fill-column)
311          (m major-mode)
312          (n (buffer-narrowed-p))
313          (s (if add-above-or-below      ; if we are adding a new slide
314                 "\n"                    ; start with just a newline
315               (unless n (narrow-to-page))
316               (prog1 (buffer-string)
317                 (unless n (widen))))))
318     (with-current-buffer nb
319       (erase-buffer)
320       (insert s)
321       (goto-char (point-min))
322       (set-buffer-modified-p nil)
323       (setq-local
324        ffs--edit-source-buffer b
325        ffs--new-location add-above-or-below
326        fill-column fc
327        header-line-format
328        (substitute-command-keys "Edit, then use `\\[ffs-edit-done]' \
329 to apply your changes or `\\[ffs-edit-discard]' to discard them."))
330       (funcall m)
331       (ffs-edit-mode 1))
332     (let ((window (display-buffer nb ffs-edit-display-buffer-alist)))
333       (when window
334         (select-window window)))))
335 
336 (defun ffs-new-above ()
337   "Add a new slide above/before the current slide."
338   (interactive)
339   (ffs-edit 'add-above))
340 
341 (defun ffs-new-below ()
342   "Add a new slide below/after the current slide."
343   (interactive)
344   (ffs-edit 'add-below))
345 
346 (defun ffs-edit-discard ()
347   "Discard current `ffs-edit' buffer and return to the presentation."
348   (interactive)
349   (let ((b (current-buffer)))
350     (quit-windows-on b)
351     (kill-buffer b)))
352 
353 (defun ffs-edit-done ()
354   "Apply the `ffs-edit' changes and return to the presentation."
355   (interactive)
356   (let* ((f nil)
357          (str (buffer-string))
358          (s (if (string-suffix-p "\n" str)
359                 str
360               (concat str "\n")))
361          (sn (format "\n%s%s" s ffs-page-delimiter))
362          (l ffs--new-location))
363     (ffs-edit-mode -1)
364     (with-current-buffer ffs--edit-source-buffer
365       (let ((inhibit-read-only t))
366         (save-excursion
367           (cond
368            ((eq l 'add-above)
369             (backward-page)
370             (insert sn)
371             (setq f #'ffs-goto-previous))
372            ((eq l 'add-below)
373             (forward-page)
374             (insert sn)
375             (setq f #'ffs-goto-next))
376            ((null l)
377             (narrow-to-page)
378             (delete-region (point-min) (point-max))
379             (insert s)
380             (widen))))))
381     (ffs-edit-discard)
382     (when (functionp f)
383       (funcall f)))
384   (run-hooks 'ffs-edit-done-hook))
385 
386 (defvar ffs-edit-mode-map
387   (let ((map (make-sparse-keymap)))
388     (define-key map (kbd "C-c C-k") #'ffs-edit-discard)
389     (define-key map (kbd "C-c C-c") #'ffs-edit-done)
390     map)
391   "Keymap for `ffs-edit-mode'.")
392 
393 (define-minor-mode ffs-edit-mode
394   "Minor mode for editing a single ffs slide.
395 When done editing the slide, run \\[ffs-edit-done] to apply your
396 changes, or \\[ffs-edit-discard] to discard them."
397   :lighter " ffs-edit")
398 
399 ␌
400 ;;;; Focus toggles
401 
402 ;; XXX user option for more sophisticated behaviour?
403 ;; set-face-attribute  for specific frames
404 ;; face-list  reset to defaults
405 (defun ffs-toggle-dark-mode ()
406   "Swap the frame background and foreground colours."
407   (interactive)
408   (let ((bg (frame-parameter nil 'background-color))
409         (fg (frame-parameter nil 'foreground-color)))
410     (set-background-color fg)
411     (set-foreground-color bg)))
412 
413 ;; I learned about the method of using `ffs-set-buffer-local-value'
414 ;; from Protesilaos <https://protesilaos.com> and his Logos package,
415 ;; who in turn learned about it from Daniel Mendler.  Protesilaos's
416 ;; version simply uses `push', but I need to retrieve specific values
417 ;; later, so I use a plist and `plist-put' instead.
418 (defvar-local ffs--restore nil)
419 
420 (defun ffs-set-buffer-local-value (var val)
421   "Set VAR to buffer-local VAL."
422   (let ((old (and (boundp var) (symbol-value var))))
423     (unless (equal old val)
424       (set var val)
425       (if (local-variable-p var)
426           (setq-local
427            ffs--restore
428            (plist-put ffs--restore var (lambda () (set var old))))
429         (make-local-variable var)
430         (setq-local
431          ffs--restore
432          (plist-put
433           ffs--restore var (lambda () (kill-local-variable var))))))))
434 
435 (defun ffs-hide-cursor ()
436   "Hide cursor if variable `ffs-hide-cursor' is non-nil.
437 If we already hid the cursor, restore it.  Otherwise, when variable
438 `ffs-hide-cursor' is non-nil, set `cursor-type' to nil."
439   (interactive)
440   (if-let* ((f (plist-get ffs--restore 'cursor-type)))
441       (progn
442         (funcall f)
443         (setq-local
444          ffs--restore (map-delete ffs--restore 'cursor-type)))
445     (when ffs-hide-cursor
446       (ffs-set-buffer-local-value 'cursor-type nil))))
447 
448 (defun ffs-hide-mode-line ()
449   "Hide mode line if variable `ffs-hide-mode-line' is non-nil.
450 If we already hid the mode line, restore it.  Otherwise, when variable
451 `ffs-hide-mode-line' is non-nil, set `mode-line-format' to nil."
452   (interactive)
453   (if-let* ((f (plist-get ffs--restore 'mode-line-format)))
454       (progn
455         (funcall f)
456         (setq-local
457          ffs--restore (map-delete ffs--restore 'mode-line-format)))
458     (when ffs-hide-mode-line
459       (ffs-set-buffer-local-value 'mode-line-format nil)))
460   (redraw-display))
461 
462 (defun ffs-hide-header-line ()
463   "Hide header line if variable `ffs-hide-header-line' is non-nil.
464 If we already hid the header line, restore it.  Otherwise, when variable
465 `ffs-hide-header-line' is non-nil, set `header-line-format' to nil."
466   (interactive)
467   (if-let* ((f (plist-get ffs--restore 'header-line-format)))
468       (progn
469         (funcall f)
470         (setq-local
471          ffs--restore (map-delete ffs--restore 'header-line-format)))
472     (when ffs-hide-header-line
473       (ffs-set-buffer-local-value 'header-line-format nil))))
474 
475 (defun ffs-toggle-echo-progress ()
476   "Toggle variable `ffs-echo-progress'."
477   (interactive)
478   (setq-local ffs-echo-progress (not ffs-echo-progress))
479   (message
480    "%s is now locally set to %s"
481    'ffs-echo-progress ffs-echo-progress))
482 
483 (defun ffs-toggle-hide-cursor ()
484   "Toggle variable `ffs-hide-cursor'."
485   (interactive)
486   (setq-local ffs-hide-cursor (not ffs-hide-cursor))
487   (message
488    "%s is now locally set to %s"
489    'ffs-hide-cursor ffs-hide-cursor)
490   (when ffs-present-mode
491     (ffs-hide-cursor)))
492 
493 (defun ffs-toggle-hide-mode-line ()
494   "Toggle variable `ffs-hide-mode-line'."
495   (interactive)
496   (setq-local ffs-hide-mode-line (not ffs-hide-mode-line))
497   (message
498    "%s is now locally set to %s"
499    'ffs-hide-mode-line ffs-hide-mode-line)
500   (when ffs-present-mode
501     (ffs-hide-mode-line)))
502 
503 (defun ffs-toggle-hide-header-line ()
504   "Toggle variable `ffs-hide-header-line'."
505   (interactive)
506   (setq-local ffs-hide-header-line (not ffs-hide-header-line))
507   (message
508    "%s is now locally set to %s"
509    'ffs-hide-header-line ffs-hide-header-line)
510   (when ffs-present-mode
511     (ffs-hide-header-line)))
512 
513 (defvar ffs-toggle-prefix-map
514   (let ((map (make-sparse-keymap)))
515     (define-key map (kbd "e") #'ffs-toggle-echo-progress)
516     (define-key map (kbd "c") #'ffs-toggle-hide-cursor)
517     (define-key map (kbd "m") #'ffs-toggle-hide-mode-line)
518     (define-key map (kbd "h") #'ffs-toggle-hide-header-line)
519     (define-key map (kbd "d") #'ffs-toggle-dark-mode)
520     map)
521   "Keymap for ffs toggle commands.")
522 
523 ␌
524 ;;;; Miscellaneous
525 
526 (defvar ffs-mode)
527 
528 (defun ffs-start ()
529   "Start presenting."
530   (interactive)
531   (unless ffs-mode
532     (ffs-mode 1))
533   (unless ffs-present-mode
534     (ffs-present-mode 1)))
535 
536 (defun ffs-stop-or-quit ()
537   "Stop presenting.  If not currently presenting, disable `ffs-mode'."
538   (interactive)
539   (when ffs-mode
540     (if ffs-present-mode
541         (ffs-present-mode -1)
542       (ffs-mode -1))))
543 
544 (defun ffs-undo (&optional arg)
545   "Like `undo', but it works even when the buffer is read-only.
546 Repeat this command to undo more changes.
547 A numeric ARG serves as a repeat count."
548   (interactive "P")
549   (let ((inhibit-read-only t))
550     (undo arg)))
551 
552 (defun ffs-find-speaker-notes-file (file)
553   "Prompt user for a speaker notes FILE, open it in a new frame."
554   (interactive "Fspeaker's notes buffer: ")
555   (let ((b (current-buffer)))
556     (save-excursion
557       (funcall ffs-find-speaker-notes-function file)
558       (ffs-mode 1)
559       (setq-local
560        ffs--slides-buffer b
561        ffs--notes-buffer (current-buffer)))
562     (setq-local ffs--notes-buffer (get-file-buffer file))))
563 
564 ;; XXX write all slides to one file?
565 (defun ffs-export-slides-to-pdf ()
566   "Export slides to PDF (needs Emacs built with Cairo)."
567   (interactive)
568   (with-current-buffer ffs--slides-buffer
569     (ffs-goto-first)
570     (let ((c 1)
571           (fringe fringe-mode))
572       (fringe-mode 0)
573       (while (not (eobp))
574         (let ((fn (format "%s-%03d.pdf"
575                           (file-name-sans-extension (buffer-name))
576                           c))
577               (data (x-export-frames nil 'pdf)))
578           (with-temp-file fn
579             (insert data)))
580         (setq c (+ c 1))
581         (ffs-goto-next))
582       (fringe-mode fringe))))
583 
584 (defun ffs-news ()
585   "Show ffs news in a manner similar to `view-emacs-news'."
586   (interactive)
587   (if ffs--pkg-dir
588       (progn
589         (find-file (expand-file-name "NEWS" ffs--pkg-dir))
590         (when (fboundp 'emacs-news-view-mode)
591           (emacs-news-view-mode))
592         (goto-address-mode 1))
593     (message "Could not find ffs NEWS file")))
594 
595 ␌
596 ;;;; Main minor modes
597 
598 (defvar ffs-mode-map
599   (let ((map (make-sparse-keymap)))
600     (define-key map (kbd "p") #'ffs-goto-previous)
601     (define-key map (kbd "n") #'ffs-goto-next)
602     (define-key map (kbd "DEL") #'ffs-goto-previous)
603     (define-key map (kbd "SPC") #'ffs-goto-next)
604     (define-key map (kbd "[") #'ffs-goto-previous)
605     (define-key map (kbd "]") #'ffs-goto-next)
606     (define-key map (kbd "<") #'ffs-goto-first)
607     (define-key map (kbd ">") #'ffs-goto-last)
608     (define-key map (kbd "s") #'ffs-start)
609     (define-key map (kbd "q") #'ffs-stop-or-quit)
610     (define-key map (kbd "e") #'ffs-edit)
611     (define-key map (kbd "C-c '") #'ffs-edit)
612     (define-key map (kbd "O") #'ffs-new-above)
613     (define-key map (kbd "o") #'ffs-new-below)
614     (define-key map (kbd "S") #'ffs-find-speaker-notes-file)
615     (define-key map (kbd "N") #'narrow-to-page)
616     (define-key map (kbd "W") #'widen)
617     (define-key map [remap undo] #'ffs-undo) ; `C-_', `C-/', `C-x u'
618     (define-key map (kbd "t") ffs-toggle-prefix-map)
619     (define-key map (kbd "?") #'describe-mode)
620     map)
621   "Keymap for `ffs-mode'.")
622 
623 ;;;###autoload
624 (define-minor-mode ffs-mode
625   "Minor mode for form feed-separated plain text presentations."
626   :lighter " ffs"
627   (setq-local
628    buffer-read-only ffs-mode
629    ffs--slides-buffer (current-buffer)))
630 
631 ;;;###autoload
632 (defalias 'ffs #'ffs-mode)
633 
634 (defvar ffs-present-mode-map
635   (let ((map (make-sparse-keymap)))
636     (set-keymap-parent map ffs-mode-map)
637     (define-key map (kbd "s") #'ffs-stop-or-quit)
638     map)
639   "Keymap for `ffs-present-mode'.")
640 
641 (declare-function face-remap-add-relative "face-remap" (face &rest specs))
642 (declare-function face-remap-remove-relative "face-remap" (cookie))
643 (define-minor-mode ffs-present-mode
644   "Minor mode for active ffs presentations."
645   :lighter nil
646   (map-do (lambda (_var fun) (funcall fun)) ffs--restore)
647   (setq-local ffs--restore nil)
648   (if ffs-present-mode
649       (progn
650         (ffs-hide-cursor)
651         (ffs-hide-mode-line)
652         (ffs-hide-header-line)
653         (when (natnump ffs-default-face-height)
654           (setq-local
655            ffs--default-face-height-cookie
656            (face-remap-add-relative
657             'default :height ffs-default-face-height)))
658         (unless (buffer-narrowed-p)
659           (narrow-to-page))
660         (when ffs-echo-progress
661           (message (ffs-echo-progress-format))))
662     (when ffs--default-face-height-cookie
663       (face-remap-remove-relative ffs--default-face-height-cookie))
664     (when (buffer-narrowed-p)
665       (goto-char (point-min))
666       (widen))))
667 
668 (provide 'ffs)
669 ;;; ffs.el ends here