Re-write acdw-reading.el
This commit is contained in:
parent
8c14455783
commit
2c93878756
|
@ -17,8 +17,60 @@
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(defvar-local //indicate-empty-lines nil)
|
;;; Customizations
|
||||||
(defvar-local //indicate-buffer-boundaries nil)
|
|
||||||
|
(defgroup reading nil
|
||||||
|
"Group for Reading mode customizations."
|
||||||
|
:prefix "reading-"
|
||||||
|
:group 'convenience) ; i need to figure this out
|
||||||
|
|
||||||
|
(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
|
;;;###autoload
|
||||||
(define-minor-mode reading-mode
|
(define-minor-mode reading-mode
|
||||||
|
@ -27,41 +79,22 @@
|
||||||
:lighter " Read"
|
:lighter " Read"
|
||||||
:keymap (make-sparse-keymap)
|
:keymap (make-sparse-keymap)
|
||||||
(if reading-mode
|
(if reading-mode
|
||||||
(progn ;; turn on
|
;; turn on
|
||||||
;; settings
|
(progn
|
||||||
(setq-local //indicate-empty-lines indicate-empty-lines
|
(reading--remember (mapcar #'car reading-vars)
|
||||||
indicate-empty-lines nil
|
(lambda (var)
|
||||||
//indicate-buffer-boundaries indicate-buffer-boundaries
|
(set (make-local-variable var)
|
||||||
indicate-buffer-boundaries nil)
|
(cdr (assoc var reading-vars)))))
|
||||||
;; disable modes
|
(reading--remember (mapcar #'car reading-modes)
|
||||||
(dolist (mode '(display-fill-column-indicator-mode
|
(lambda (mode)
|
||||||
blink-cursor-mode))
|
(funcall mode (cdr (assoc mode reading-modes))))))
|
||||||
(when (fboundp mode)
|
|
||||||
(set (make-local-variable
|
|
||||||
(intern (format "//%s" mode)))
|
|
||||||
(and (boundp mode)
|
|
||||||
(symbol-value mode)))
|
|
||||||
(funcall mode -1)))
|
|
||||||
;; enable modes
|
|
||||||
(dolist (mode '(olivetti-mode))
|
|
||||||
(when (fboundp mode)
|
|
||||||
(set (make-local-variable
|
|
||||||
(intern (format "//%s" mode)))
|
|
||||||
(and (boundp mode)
|
|
||||||
(symbol-value mode)))
|
|
||||||
(funcall mode +1))))
|
|
||||||
;; turn off
|
;; turn off
|
||||||
;; restore settings
|
(reading--recall (mapcar #'car reading-vars)
|
||||||
(setq-local indicate-empty-lines //indicate-empty-lines
|
(lambda (var orig-val)
|
||||||
indicate-buffer-boundaries //indicate-buffer-boundaries)
|
(set (make-local-variable var) orig-val)))
|
||||||
;; restore modes
|
(reading--recall (mapcar #'car reading-modes)
|
||||||
(dolist (mode '(display-fill-column-indicator-mode
|
(lambda (mode orig-setting)
|
||||||
olivetti-mode
|
(funcall mode (if orig-setting +1 -1))))))
|
||||||
blink-cursor-mode))
|
|
||||||
(when (fboundp mode)
|
|
||||||
(funcall mode (if (symbol-value (intern (format "//%s" mode)))
|
|
||||||
+1
|
|
||||||
-1))))))
|
|
||||||
|
|
||||||
(provide 'acdw-reading)
|
(provide 'acdw-reading)
|
||||||
;;; acdw-reading.el ends here
|
;;; acdw-reading.el ends here
|
||||||
|
|
Loading…
Reference in New Issue