summary refs log tree commit diff stats
path: root/lisp/reading.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/reading.el')
-rw-r--r--lisp/reading.el83
1 files changed, 83 insertions, 0 deletions
diff --git a/lisp/reading.el b/lisp/reading.el new file mode 100644 index 0000000..d00172b --- /dev/null +++ b/lisp/reading.el
@@ -0,0 +1,83 @@
1;;; reading.el --- minor mode for reading -*- lexical-binding: t; -*-
2
3;;; Code:
4
5(defgroup reading nil
6 "Group for Reading mode customizations."
7 :prefix "reading-"
8 :group 'convenience)
9
10(defcustom reading-vars '((indicate-empty-lines . nil)
11 (indicate-buffer-boundaries . nil))
12 "Alist of variables to set in function `reading-mode'.
13The car of each cell is the variable name, and the cdr is the
14value to set it to."
15 :type '(alist :key-type variable
16 :value-type sexp))
17
18(defcustom reading-modes '((display-fill-column-indicator-mode . -1)
19 (blink-cursor-mode . -1))
20 "Alist of modes to set in function `reading-mode'.
21The car of each cell is the function name, and the cdr is the
22value to call it with."
23 :type '(alist :key-type function
24 :value-type sexp))
25
26;;; Internal
27
28(defvar reading--remembered-template "reading--remembered-%s-value"
29 "The template passed to `format' for remembered modes and variables.")
30
31(defun reading--remember (things func)
32 "Apply FUNC to THINGS, remembering their previous value for later."
33 (declare (indent 1))
34 (unless (listp things)
35 (setq things (list things)))
36 (dolist (thing things)
37 (set (make-local-variable
38 (intern (format reading--remembered-template thing)))
39 (and (boundp thing)
40 (symbol-value thing)))
41 (funcall func thing)))
42
43(defun reading--recall (things func)
44 "Recall previously remembered THINGS by applying FUNC to them.
45FUNC should be a function with the signature (THING REMEMBERED-SETTING)."
46 (declare (indent 1))
47 (unless (listp things)
48 (setq things (list things)))
49 (dolist (thing things)
50 (with-demoted-errors "reading--recall: %S"
51 (let ((value (symbol-value
52 (intern
53 (format reading--remembered-template thing)))))
54 (funcall func thing value)))))
55
56;;; Mode
57
58;;;###autoload
59(define-minor-mode reading-mode
60 "A mode for reading."
61 :init-value nil
62 :lighter " Read"
63 :keymap (make-sparse-keymap)
64 (if reading-mode
65 ;; turn on
66 (progn
67 (reading--remember (mapcar #'car reading-vars)
68 (lambda (var)
69 (set (make-local-variable var)
70 (cdr (assoc var reading-vars)))))
71 (reading--remember (mapcar #'car reading-modes)
72 (lambda (mode)
73 (funcall mode (cdr (assoc mode reading-modes))))))
74 ;; turn off
75 (reading--recall (mapcar #'car reading-vars)
76 (lambda (var orig-val)
77 (set (make-local-variable var) orig-val)))
78 (reading--recall (mapcar #'car reading-modes)
79 (lambda (mode orig-setting)
80 (funcall mode (if orig-setting +1 -1))))))
81
82(provide 'reading)
83;;; reading.el ends here