summary refs log tree commit diff stats
path: root/lisp/acdw-reading.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/acdw-reading.el')
-rw-r--r--lisp/acdw-reading.el100
1 files changed, 0 insertions, 100 deletions
diff --git a/lisp/acdw-reading.el b/lisp/acdw-reading.el deleted file mode 100644 index ff4f0c2..0000000 --- a/lisp/acdw-reading.el +++ /dev/null
@@ -1,100 +0,0 @@
1;;; acdw-reading.el --- minor mode for reading -*- lexical-binding: t -*-
2
3;; Copyright 2021 Case Duckworth <(rot13-string "npqj@npqj.arg")>
4;; This file is NOT part of GNU Emacs.
5
6;;; License:
7
8;; Everyone is permitted to do whatever with this software, without
9;; limitation. This software comes without any warranty whatsoever,
10;; but with two pieces of advice:
11;; - Don't hurt yourself.
12;; - Make good choices.
13
14;;; Commentary:
15
16;; here is my attempt at a reading mode.
17
18;;; Code:
19
20;;; Customizations
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
74
75;;;###autoload
76(define-minor-mode reading-mode
77 "A mode for reading."
78 :init-value nil
79 :lighter " Read"
80 :keymap (make-sparse-keymap)
81 (if reading-mode
82 ;; turn on
83 (progn
84 (reading--remember (mapcar #'car reading-vars)
85 (lambda (var)
86 (set (make-local-variable var)
87 (cdr (assoc var reading-vars)))))
88 (reading--remember (mapcar #'car reading-modes)
89 (lambda (mode)
90 (funcall mode (cdr (assoc mode reading-modes))))))
91 ;; turn off
92 (reading--recall (mapcar #'car reading-vars)
93 (lambda (var orig-val)
94 (set (make-local-variable var) orig-val)))
95 (reading--recall (mapcar #'car reading-modes)
96 (lambda (mode orig-setting)
97 (funcall mode (if orig-setting +1 -1))))))
98
99(provide 'acdw-reading)
100;;; acdw-reading.el ends here