about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--init.el23
-rw-r--r--lisp/+modeline.el20
-rw-r--r--lisp/reading.el83
3 files changed, 121 insertions, 5 deletions
diff --git a/init.el b/init.el index 835af08..5e06539 100644 --- a/init.el +++ b/init.el
@@ -63,6 +63,12 @@
63 (append +pulse-location-commands) 'lui-track-jump-to-indicator) 63 (append +pulse-location-commands) 'lui-track-jump-to-indicator)
64 (+pulse-location-mode +1)) 64 (+pulse-location-mode +1))
65 65
66(setup (:require reading))
67
68(setup Info
69 (:hook 'variable-pitch-mode
70 'reading-mode))
71
66(setup abbrev 72(setup abbrev
67 (:option abbrev-file-name (sync/ "abbrev.el") 73 (:option abbrev-file-name (sync/ "abbrev.el")
68 save-abbrevs 'silent) 74 save-abbrevs 'silent)
@@ -228,6 +234,9 @@
228 (:when-loaded 234 (:when-loaded
229 (setenv "PAGER" "cat"))) 235 (setenv "PAGER" "cat")))
230 236
237(setup eww
238 (:hook 'reading-mode))
239
231(setup magit 240(setup magit
232 ;; This setup is weird because of dependency issues 241 ;; This setup is weird because of dependency issues
233 (:straight (transient :host github :repo "magit/transient" :branch "master") 242 (:straight (transient :host github :repo "magit/transient" :branch "master")
@@ -517,7 +526,8 @@ See also `crux-reopen-as-root-mode'."
517 (autoload 'dictionary-tooltip-mode "dictionary" 526 (autoload 'dictionary-tooltip-mode "dictionary"
518 "Display tooltips for the current word" t) 527 "Display tooltips for the current word" t)
519 (autoload 'global-dictionary-tooltip-mode "dictionary" 528 (autoload 'global-dictionary-tooltip-mode "dictionary"
520 "Enable/disable dictionary-tooltip-mode for all buffers" t)) 529 "Enable/disable dictionary-tooltip-mode for all buffers" t)
530 (:hook 'reading-mode))
521 531
522(setup (:straight (discord 532(setup (:straight (discord
523 :host github 533 :host github
@@ -535,7 +545,8 @@ See also `crux-reopen-as-root-mode'."
535 elfeed-db-directory (sync/ "elfeed/db/" t)) 545 elfeed-db-directory (sync/ "elfeed/db/" t))
536 (:with-mode elfeed-show-mode 546 (:with-mode elfeed-show-mode
537 (:bind "SPC" '+elfeed-scroll-up-command 547 (:bind "SPC" '+elfeed-scroll-up-command
538 "S-SPC" '+elfeed-scroll-down-command))) 548 "S-SPC" '+elfeed-scroll-down-command)
549 (:hook 'reading-mode)))
539 550
540(setup (:straight elfeed-org) 551(setup (:straight elfeed-org)
541 (:option rmh-elfeed-org-files (list (sync/ "elfeed/elfeed.org" t))) 552 (:option rmh-elfeed-org-files (list (sync/ "elfeed/elfeed.org" t)))
@@ -789,6 +800,7 @@ See also `crux-reopen-as-root-mode'."
789 (eq system-type 'gnu/linux)) 800 (eq system-type 'gnu/linux))
790 (pdf-tools-install)) 801 (pdf-tools-install))
791 802
803
792(setup (:straight (shell-command+ 804(setup (:straight (shell-command+
793 :host nil 805 :host nil
794 :repo "https://git.sr.ht/~pkal/shell-command-plus")) 806 :repo "https://git.sr.ht/~pkal/shell-command-plus"))
@@ -803,6 +815,7 @@ See also `crux-reopen-as-root-mode'."
803 (:option simple-modeline-segments '((;; left 815 (:option simple-modeline-segments '((;; left
804 +modeline-ace-window-display 816 +modeline-ace-window-display
805 +modeline-modified 817 +modeline-modified
818 +modeline-reading-mode
806 +modeline-narrowed 819 +modeline-narrowed
807 +modeline-buffer-name 820 +modeline-buffer-name
808 +modeline-position 821 +modeline-position
@@ -894,11 +907,11 @@ See also `crux-reopen-as-root-mode'."
894 (add-hook 'rfn-eshadow-update-overlay-hook 'vertico-directory-tidy)) 907 (add-hook 'rfn-eshadow-update-overlay-hook 'vertico-directory-tidy))
895 908
896(setup (:straight visual-fill-column) 909(setup (:straight visual-fill-column)
897 (:option visual-fill-column-center-text t) 910 (:option visual-fill-column-center-text t
911 (append reading-modes) '(visual-fill-column-mode . +1))
898 (:hook 'visual-line-mode) 912 (:hook 'visual-line-mode)
899 (:hook-into org-mode) 913 (:hook-into org-mode)
900 (with-eval-after-load 'visual-fill-column 914 (advice-add 'text-scale-adjust :after 'visual-fill-column-adjust))
901 (advice-add 'text-scale-adjust :after 'visual-fill-column-adjust)))
902 915
903(setup (:straight vlf) 916(setup (:straight vlf)
904 (:require vlf-setup)) 917 (:require vlf-setup))
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