summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
authorCase Duckworth2021-09-30 23:23:57 -0500
committerCase Duckworth2021-09-30 23:23:57 -0500
commitce522ca1a7b5919d5444ef47561c12f89cac6b0c (patch)
tree708c24c21e5d8d10b62e83544be45c649c6c8473 /lisp
parentAdd circe-command-SLAP (diff)
parentRe-write acdw-reading.el (diff)
downloademacs-ce522ca1a7b5919d5444ef47561c12f89cac6b0c.tar.gz
emacs-ce522ca1a7b5919d5444ef47561c12f89cac6b0c.zip
Merge branch 'main' of https://tildegit.org/acdw/emacs
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw-reading.el103
1 files changed, 69 insertions, 34 deletions
diff --git a/lisp/acdw-reading.el b/lisp/acdw-reading.el index 5d43dac..ff4f0c2 100644 --- a/lisp/acdw-reading.el +++ b/lisp/acdw-reading.el
@@ -17,8 +17,60 @@
17 17
18;;; Code: 18;;; Code:
19 19
20(defvar-local //indicate-empty-lines nil) 20;;; Customizations
21(defvar-local //indicate-buffer-boundaries nil) 21
22(defgroup reading nil
23 "Group for Reading mode customizations."
24 :prefix "reading-"
25 :group 'convenience) ; i need to figure this out
26
27(defcustom reading-vars '((indicate-empty-lines . nil)
28 (indicate-buffer-boundaries . nil))
29 "Alist of variables to set in function `reading-mode'.
30The car of each cell is the variable name, and the cdr is the
31value to set it to."
32 :type '(alist :key-type variable
33 :value-type sexp))
34
35(defcustom reading-modes '((display-fill-column-indicator-mode . -1)
36 (blink-cursor-mode . -1))
37 "Alist of modes to set in function `reading-mode'.
38The car of each cell is the function name, and the cdr is the
39value to call it with."
40 :type '(alist :key-type function
41 :value-type sexp))
42
43;;; Internal
44
45(defvar reading--remembered-template "reading--remembered-%s-value"
46 "The template passed to `format' for remembered modes and variables.")
47
48(defun reading--remember (things func)
49 "Apply FUNC to THINGS, remembering their previous value for later."
50 (declare (indent 1))
51 (unless (listp things)
52 (setq things (list things)))
53 (dolist (thing things)
54 (set (make-local-variable
55 (intern (format reading--remembered-template thing)))
56 (and (boundp thing)
57 (symbol-value thing)))
58 (funcall func thing)))
59
60(defun reading--recall (things func)
61 "Recall previously remembered THINGS by applying FUNC to them.
62FUNC should be a function with the signature (THING REMEMBERED-SETTING)."
63 (declare (indent 1))
64 (unless (listp things)
65 (setq things (list things)))
66 (dolist (thing things)
67 (with-demoted-errors "reading--recall: %S"
68 (let ((value (symbol-value
69 (intern
70 (format reading--remembered-template thing)))))
71 (funcall func thing value)))))
72
73;;; Mode
22 74
23;;;###autoload 75;;;###autoload
24(define-minor-mode reading-mode 76(define-minor-mode reading-mode
@@ -27,39 +79,22 @@
27 :lighter " Read" 79 :lighter " Read"
28 :keymap (make-sparse-keymap) 80 :keymap (make-sparse-keymap)
29 (if reading-mode 81 (if reading-mode
30 (progn ;; turn on 82 ;; turn on
31 ;; settings 83 (progn
32 (setq-local //indicate-empty-lines indicate-empty-lines 84 (reading--remember (mapcar #'car reading-vars)
33 indicate-empty-lines nil 85 (lambda (var)
34 //indicate-buffer-boundaries indicate-buffer-boundaries 86 (set (make-local-variable var)
35 indicate-buffer-boundaries nil) 87 (cdr (assoc var reading-vars)))))
36 ;; disable modes 88 (reading--remember (mapcar #'car reading-modes)
37 (dolist (mode '(display-fill-column-indicator-mode 89 (lambda (mode)
38 blink-cursor-mode)) 90 (funcall mode (cdr (assoc mode reading-modes))))))
39 (when (fboundp mode)
40 (set (make-local-variable
41 (intern (format "//%s" mode)))
42 (symbol-value mode))
43 (funcall mode -1)))
44 ;; enable modes
45 (dolist (mode '(olivetti-mode))
46 (when (fboundp mode)
47 (set (make-local-variable
48 (intern (format "//%s" mode)))
49 (symbol-value mode))
50 (funcall mode +1))))
51 ;; turn off 91 ;; turn off
52 ;; restore settings 92 (reading--recall (mapcar #'car reading-vars)
53 (setq-local indicate-empty-lines //indicate-empty-lines 93 (lambda (var orig-val)
54 indicate-buffer-boundaries //indicate-buffer-boundaries) 94 (set (make-local-variable var) orig-val)))
55 ;; restore modes 95 (reading--recall (mapcar #'car reading-modes)
56 (dolist (mode '(display-fill-column-indicator-mode 96 (lambda (mode orig-setting)
57 olivetti-mode 97 (funcall mode (if orig-setting +1 -1))))))
58 blink-cursor-mode))
59 (when (fboundp mode)
60 (funcall mode (if (symbol-value (intern (format "//%s" mode)))
61 +1
62 -1))))))
63 98
64(provide 'acdw-reading) 99(provide 'acdw-reading)
65;;; acdw-reading.el ends here 100;;; acdw-reading.el ends here