lisp/so-long.el: Improve support for major mode hooks
* lisp/so-long.el (so-long-remember-all, so-long-disable-minor-modes) (so-long-override-variables): Store and use the `so-long-minor-modes' and `so-long-variable-overrides' values seen by the original major mode, so that buffer-local changes made in the major mode hook will be respected. Add documentation of this and other major mode hook usage.
This commit is contained in:
parent
8576297b2a
commit
fa20e443c8
1 changed files with 46 additions and 3 deletions
|
@ -282,6 +282,43 @@
|
||||||
;; '((show-trailing-whitespace . nil)
|
;; '((show-trailing-whitespace . nil)
|
||||||
;; (truncate-lines . nil))))
|
;; (truncate-lines . nil))))
|
||||||
|
|
||||||
|
;; * Mode-specific configuration
|
||||||
|
;; -----------------------------
|
||||||
|
;; The `so-long-predicate' function is called in the context of the buffer's
|
||||||
|
;; original major mode, and therefore major mode hooks can be used to control
|
||||||
|
;; the criteria for calling `so-long' in any given mode (plus its derivatives)
|
||||||
|
;; by setting buffer-local values for the variables in question. This includes
|
||||||
|
;; `so-long-predicate' itself, as well as any variables used by the predicate
|
||||||
|
;; when determining the result. By default this means `so-long-max-lines',
|
||||||
|
;; `so-long-skip-leading-comments', and `so-long-threshold'. E.g.:
|
||||||
|
;;
|
||||||
|
;; (add-hook 'js-mode-hook 'my-js-mode-hook)
|
||||||
|
;;
|
||||||
|
;; (defun my-js-mode-hook ()
|
||||||
|
;; "Custom `js-mode' behaviours."
|
||||||
|
;; (setq-local so-long-max-lines 100)
|
||||||
|
;; (setq-local so-long-threshold 1000))
|
||||||
|
;;
|
||||||
|
;; `so-long-variable-overrides' and `so-long-minor-modes' may also be given
|
||||||
|
;; buffer-local values in order to apply different settings to different types
|
||||||
|
;; of file. For example, the Bidirectional Parentheses Algorithm does not apply
|
||||||
|
;; to `<' and `>' characters by default, and therefore one might prefer to not
|
||||||
|
;; set `bidi-inhibit-bpa' in XML files, on the basis that XML files with long
|
||||||
|
;; lines are less likely to trigger BPA-related performance problems:
|
||||||
|
;;
|
||||||
|
;; (add-hook 'nxml-mode-hook 'my-nxml-mode-hook)
|
||||||
|
;;
|
||||||
|
;; (defun my-nxml-mode-hook ()
|
||||||
|
;; "Custom `nxml-mode' behaviours."
|
||||||
|
;; (require 'so-long)
|
||||||
|
;; (setq-local so-long-variable-overrides
|
||||||
|
;; (remove '(bidi-inhibit-bpa . t) so-long-variable-overrides)))
|
||||||
|
;;
|
||||||
|
;; Finally, note that setting `so-long-target-modes' to nil buffer-locally in
|
||||||
|
;; a major mode hook would prevent that mode from ever being targeted. With
|
||||||
|
;; `prog-mode' being targeted by default, specific derivatives of `prog-mode'
|
||||||
|
;; could therefore be un-targeted if desired.
|
||||||
|
|
||||||
;; * Other ways of using so-long
|
;; * Other ways of using so-long
|
||||||
;; -----------------------------
|
;; -----------------------------
|
||||||
;; It may prove useful to automatically invoke major mode `so-long-mode' for
|
;; It may prove useful to automatically invoke major mode `so-long-mode' for
|
||||||
|
@ -886,9 +923,15 @@ buffer-local."
|
||||||
Stores the existing value for each entry in `so-long-variable-overrides'.
|
Stores the existing value for each entry in `so-long-variable-overrides'.
|
||||||
Stores the name of each enabled mode from the list `so-long-minor-modes'.
|
Stores the name of each enabled mode from the list `so-long-minor-modes'.
|
||||||
|
|
||||||
|
The lists themselves are also remembered, so that major mode hooks can
|
||||||
|
provide buffer-local modifications which are still accessible after changing
|
||||||
|
to `so-long-mode'.
|
||||||
|
|
||||||
If RESET is non-nil, remove any existing values before storing the new ones."
|
If RESET is non-nil, remove any existing values before storing the new ones."
|
||||||
(when reset
|
(when reset
|
||||||
(setq so-long-original-values nil))
|
(setq so-long-original-values nil))
|
||||||
|
(so-long-remember 'so-long-variable-overrides)
|
||||||
|
(so-long-remember 'so-long-minor-modes)
|
||||||
(dolist (ovar so-long-variable-overrides)
|
(dolist (ovar so-long-variable-overrides)
|
||||||
(so-long-remember (car ovar)))
|
(so-long-remember (car ovar)))
|
||||||
(dolist (mode so-long-minor-modes)
|
(dolist (mode so-long-minor-modes)
|
||||||
|
@ -1286,7 +1329,7 @@ Calls `so-long-disable-minor-modes' and `so-long-override-variables'."
|
||||||
|
|
||||||
(defun so-long-disable-minor-modes ()
|
(defun so-long-disable-minor-modes ()
|
||||||
"Disable any active minor modes listed in `so-long-minor-modes'."
|
"Disable any active minor modes listed in `so-long-minor-modes'."
|
||||||
(dolist (mode so-long-minor-modes)
|
(dolist (mode (so-long-original 'so-long-minor-modes))
|
||||||
(when (and (boundp mode) mode)
|
(when (and (boundp mode) mode)
|
||||||
(funcall mode 0))))
|
(funcall mode 0))))
|
||||||
|
|
||||||
|
@ -1302,7 +1345,7 @@ The modes are enabled in accordance with what was remembered in `so-long'."
|
||||||
|
|
||||||
(defun so-long-override-variables ()
|
(defun so-long-override-variables ()
|
||||||
"Set the buffer-local values defined by `so-long-variable-overrides'."
|
"Set the buffer-local values defined by `so-long-variable-overrides'."
|
||||||
(dolist (ovar so-long-variable-overrides)
|
(dolist (ovar (so-long-original 'so-long-variable-overrides))
|
||||||
(set (make-local-variable (car ovar)) (cdr ovar))))
|
(set (make-local-variable (car ovar)) (cdr ovar))))
|
||||||
|
|
||||||
(defun so-long-restore-variables ()
|
(defun so-long-restore-variables ()
|
||||||
|
@ -1877,7 +1920,7 @@ If it appears in `%s', you should remove it."
|
||||||
; LocalWords: defadvice nadvice whitespace ie bos eos eobp origmode un Un setq
|
; LocalWords: defadvice nadvice whitespace ie bos eos eobp origmode un Un setq
|
||||||
; LocalWords: docstring auf Wiedersehen longlines alist autoload Refactored Inc
|
; LocalWords: docstring auf Wiedersehen longlines alist autoload Refactored Inc
|
||||||
; LocalWords: MERCHANTABILITY RET REGEXP VAR ELPA WS mitigations EmacsWiki eval
|
; LocalWords: MERCHANTABILITY RET REGEXP VAR ELPA WS mitigations EmacsWiki eval
|
||||||
; LocalWords: rx filename filenames bidi bpa
|
; LocalWords: rx filename filenames js defun bidi bpa prog
|
||||||
|
|
||||||
;; So long, farewell, auf Wiedersehen, goodbye
|
;; So long, farewell, auf Wiedersehen, goodbye
|
||||||
;; You have to go, this code is minified
|
;; You have to go, this code is minified
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue