summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/+modeline.el20
-rw-r--r--lisp/reading.el83
2 files changed, 103 insertions, 0 deletions
diff --git a/lisp/+modeline.el b/lisp/+modeline.el index 7615ea7..47299ec 100644 --- a/lisp/+modeline.el +++ b/lisp/+modeline.el
@@ -111,6 +111,26 @@ The order of elements matters: whichever one matches first is applied."
111 'face 'font-lock-doc-face 111 'face 'font-lock-doc-face
112 'mouse-face 'mode-line-highlight)))) 112 'mouse-face 'mode-line-highlight))))
113 113
114(defun +modeline-reading-mode ()
115 "Display an indication that the buffer is in `reading-mode'."
116 (when reading-mode
117 (concat " "
118 (propertize "R"
119 'help-echo (format "%s\n%s"
120 "Buffer is in reading-mode."
121 "mouse-2: disable reading-mode.")
122 'local-map (purecopy
123 (simple-modeline-make-mouse-map
124 'mouse-2 (lambda (ev)
125 (interactive "e")
126 (with-selected-window
127 (posn-window
128 (event-start ev))
129 (reading-mode -1)
130 (force-mode-line-update)))))
131 'face 'font-lock-doc-face
132 'mouse-face 'mode-line-highlight))))
133
114(define-minor-mode file-percentage-mode 134(define-minor-mode file-percentage-mode
115 "Toggle the percentage display in the mode line (File Percentage Mode)." 135 "Toggle the percentage display in the mode line (File Percentage Mode)."
116 :init-value t :global t :group 'mode-line) 136 :init-value t :global t :group 'mode-line)
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