Add reading-mode
This commit is contained in:
parent
a4b634cf9c
commit
84fe18046d
23
init.el
23
init.el
|
@ -63,6 +63,12 @@
|
|||
(append +pulse-location-commands) 'lui-track-jump-to-indicator)
|
||||
(+pulse-location-mode +1))
|
||||
|
||||
(setup (:require reading))
|
||||
|
||||
(setup Info
|
||||
(:hook 'variable-pitch-mode
|
||||
'reading-mode))
|
||||
|
||||
(setup abbrev
|
||||
(:option abbrev-file-name (sync/ "abbrev.el")
|
||||
save-abbrevs 'silent)
|
||||
|
@ -228,6 +234,9 @@
|
|||
(:when-loaded
|
||||
(setenv "PAGER" "cat")))
|
||||
|
||||
(setup eww
|
||||
(:hook 'reading-mode))
|
||||
|
||||
(setup magit
|
||||
;; This setup is weird because of dependency issues
|
||||
(:straight (transient :host github :repo "magit/transient" :branch "master")
|
||||
|
@ -517,7 +526,8 @@ See also `crux-reopen-as-root-mode'."
|
|||
(autoload 'dictionary-tooltip-mode "dictionary"
|
||||
"Display tooltips for the current word" t)
|
||||
(autoload 'global-dictionary-tooltip-mode "dictionary"
|
||||
"Enable/disable dictionary-tooltip-mode for all buffers" t))
|
||||
"Enable/disable dictionary-tooltip-mode for all buffers" t)
|
||||
(:hook 'reading-mode))
|
||||
|
||||
(setup (:straight (discord
|
||||
:host github
|
||||
|
@ -535,7 +545,8 @@ See also `crux-reopen-as-root-mode'."
|
|||
elfeed-db-directory (sync/ "elfeed/db/" t))
|
||||
(:with-mode elfeed-show-mode
|
||||
(:bind "SPC" '+elfeed-scroll-up-command
|
||||
"S-SPC" '+elfeed-scroll-down-command)))
|
||||
"S-SPC" '+elfeed-scroll-down-command)
|
||||
(:hook 'reading-mode)))
|
||||
|
||||
(setup (:straight elfeed-org)
|
||||
(:option rmh-elfeed-org-files (list (sync/ "elfeed/elfeed.org" t)))
|
||||
|
@ -789,6 +800,7 @@ See also `crux-reopen-as-root-mode'."
|
|||
(eq system-type 'gnu/linux))
|
||||
(pdf-tools-install))
|
||||
|
||||
|
||||
(setup (:straight (shell-command+
|
||||
:host nil
|
||||
:repo "https://git.sr.ht/~pkal/shell-command-plus"))
|
||||
|
@ -803,6 +815,7 @@ See also `crux-reopen-as-root-mode'."
|
|||
(:option simple-modeline-segments '((;; left
|
||||
+modeline-ace-window-display
|
||||
+modeline-modified
|
||||
+modeline-reading-mode
|
||||
+modeline-narrowed
|
||||
+modeline-buffer-name
|
||||
+modeline-position
|
||||
|
@ -894,11 +907,11 @@ See also `crux-reopen-as-root-mode'."
|
|||
(add-hook 'rfn-eshadow-update-overlay-hook 'vertico-directory-tidy))
|
||||
|
||||
(setup (:straight visual-fill-column)
|
||||
(:option visual-fill-column-center-text t)
|
||||
(:option visual-fill-column-center-text t
|
||||
(append reading-modes) '(visual-fill-column-mode . +1))
|
||||
(:hook 'visual-line-mode)
|
||||
(:hook-into org-mode)
|
||||
(with-eval-after-load 'visual-fill-column
|
||||
(advice-add 'text-scale-adjust :after 'visual-fill-column-adjust)))
|
||||
(advice-add 'text-scale-adjust :after 'visual-fill-column-adjust))
|
||||
|
||||
(setup (:straight vlf)
|
||||
(:require vlf-setup))
|
||||
|
|
|
@ -111,6 +111,26 @@ The order of elements matters: whichever one matches first is applied."
|
|||
'face 'font-lock-doc-face
|
||||
'mouse-face 'mode-line-highlight))))
|
||||
|
||||
(defun +modeline-reading-mode ()
|
||||
"Display an indication that the buffer is in `reading-mode'."
|
||||
(when reading-mode
|
||||
(concat " "
|
||||
(propertize "R"
|
||||
'help-echo (format "%s\n%s"
|
||||
"Buffer is in reading-mode."
|
||||
"mouse-2: disable reading-mode.")
|
||||
'local-map (purecopy
|
||||
(simple-modeline-make-mouse-map
|
||||
'mouse-2 (lambda (ev)
|
||||
(interactive "e")
|
||||
(with-selected-window
|
||||
(posn-window
|
||||
(event-start ev))
|
||||
(reading-mode -1)
|
||||
(force-mode-line-update)))))
|
||||
'face 'font-lock-doc-face
|
||||
'mouse-face 'mode-line-highlight))))
|
||||
|
||||
(define-minor-mode file-percentage-mode
|
||||
"Toggle the percentage display in the mode line (File Percentage Mode)."
|
||||
:init-value t :global t :group 'mode-line)
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
;;; reading.el --- minor mode for reading -*- lexical-binding: t; -*-
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defgroup reading nil
|
||||
"Group for Reading mode customizations."
|
||||
:prefix "reading-"
|
||||
:group 'convenience)
|
||||
|
||||
(defcustom reading-vars '((indicate-empty-lines . nil)
|
||||
(indicate-buffer-boundaries . nil))
|
||||
"Alist of variables to set in function `reading-mode'.
|
||||
The car of each cell is the variable name, and the cdr is the
|
||||
value to set it to."
|
||||
:type '(alist :key-type variable
|
||||
:value-type sexp))
|
||||
|
||||
(defcustom reading-modes '((display-fill-column-indicator-mode . -1)
|
||||
(blink-cursor-mode . -1))
|
||||
"Alist of modes to set in function `reading-mode'.
|
||||
The car of each cell is the function name, and the cdr is the
|
||||
value to call it with."
|
||||
:type '(alist :key-type function
|
||||
:value-type sexp))
|
||||
|
||||
;;; Internal
|
||||
|
||||
(defvar reading--remembered-template "reading--remembered-%s-value"
|
||||
"The template passed to `format' for remembered modes and variables.")
|
||||
|
||||
(defun reading--remember (things func)
|
||||
"Apply FUNC to THINGS, remembering their previous value for later."
|
||||
(declare (indent 1))
|
||||
(unless (listp things)
|
||||
(setq things (list things)))
|
||||
(dolist (thing things)
|
||||
(set (make-local-variable
|
||||
(intern (format reading--remembered-template thing)))
|
||||
(and (boundp thing)
|
||||
(symbol-value thing)))
|
||||
(funcall func thing)))
|
||||
|
||||
(defun reading--recall (things func)
|
||||
"Recall previously remembered THINGS by applying FUNC to them.
|
||||
FUNC should be a function with the signature (THING REMEMBERED-SETTING)."
|
||||
(declare (indent 1))
|
||||
(unless (listp things)
|
||||
(setq things (list things)))
|
||||
(dolist (thing things)
|
||||
(with-demoted-errors "reading--recall: %S"
|
||||
(let ((value (symbol-value
|
||||
(intern
|
||||
(format reading--remembered-template thing)))))
|
||||
(funcall func thing value)))))
|
||||
|
||||
;;; Mode
|
||||
|
||||
;;;###autoload
|
||||
(define-minor-mode reading-mode
|
||||
"A mode for reading."
|
||||
:init-value nil
|
||||
:lighter " Read"
|
||||
:keymap (make-sparse-keymap)
|
||||
(if reading-mode
|
||||
;; turn on
|
||||
(progn
|
||||
(reading--remember (mapcar #'car reading-vars)
|
||||
(lambda (var)
|
||||
(set (make-local-variable var)
|
||||
(cdr (assoc var reading-vars)))))
|
||||
(reading--remember (mapcar #'car reading-modes)
|
||||
(lambda (mode)
|
||||
(funcall mode (cdr (assoc mode reading-modes))))))
|
||||
;; turn off
|
||||
(reading--recall (mapcar #'car reading-vars)
|
||||
(lambda (var orig-val)
|
||||
(set (make-local-variable var) orig-val)))
|
||||
(reading--recall (mapcar #'car reading-modes)
|
||||
(lambda (mode orig-setting)
|
||||
(funcall mode (if orig-setting +1 -1))))))
|
||||
|
||||
(provide 'reading)
|
||||
;;; reading.el ends here
|
Loading…
Reference in New Issue