diff options
Diffstat (limited to 'lisp/so-long.el')
| -rw-r--r-- | lisp/so-long.el | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/lisp/so-long.el b/lisp/so-long.el index f2c078ba841..f8a5cc920d9 100644 --- a/lisp/so-long.el +++ b/lisp/so-long.el | |||
| @@ -255,8 +255,7 @@ | |||
| 255 | ;; `so-long-mode', completely bypassing the automated decision process. | 255 | ;; `so-long-mode', completely bypassing the automated decision process. |
| 256 | ;; Refer to M-: (info "(emacs) Specifying File Variables") RET | 256 | ;; Refer to M-: (info "(emacs) Specifying File Variables") RET |
| 257 | ;; | 257 | ;; |
| 258 | ;; If so-long itself is causing problems, it can be inhibited by setting the | 258 | ;; If so-long itself causes problems, disable the automated behaviour with |
| 259 | ;; `so-long-enabled' variable to nil, or by disabling the global mode with | ||
| 260 | ;; M-- M-x global-so-long-mode, or M-: (global-so-long-mode 0) | 259 | ;; M-- M-x global-so-long-mode, or M-: (global-so-long-mode 0) |
| 261 | 260 | ||
| 262 | ;; * Example configuration | 261 | ;; * Example configuration |
| @@ -282,6 +281,43 @@ | |||
| 282 | ;; '((show-trailing-whitespace . nil) | 281 | ;; '((show-trailing-whitespace . nil) |
| 283 | ;; (truncate-lines . nil)))) | 282 | ;; (truncate-lines . nil)))) |
| 284 | 283 | ||
| 284 | ;; * Mode-specific configuration | ||
| 285 | ;; ----------------------------- | ||
| 286 | ;; The `so-long-predicate' function is called in the context of the buffer's | ||
| 287 | ;; original major mode, and therefore major mode hooks can be used to control | ||
| 288 | ;; the criteria for calling `so-long' in any given mode (plus its derivatives) | ||
| 289 | ;; by setting buffer-local values for the variables in question. This includes | ||
| 290 | ;; `so-long-predicate' itself, as well as any variables used by the predicate | ||
| 291 | ;; when determining the result. By default this means `so-long-max-lines', | ||
| 292 | ;; `so-long-skip-leading-comments', and `so-long-threshold'. E.g.: | ||
| 293 | ;; | ||
| 294 | ;; (add-hook 'js-mode-hook 'my-js-mode-hook) | ||
| 295 | ;; | ||
| 296 | ;; (defun my-js-mode-hook () | ||
| 297 | ;; "Custom `js-mode' behaviours." | ||
| 298 | ;; (setq-local so-long-max-lines 100) | ||
| 299 | ;; (setq-local so-long-threshold 1000)) | ||
| 300 | ;; | ||
| 301 | ;; `so-long-variable-overrides' and `so-long-minor-modes' may also be given | ||
| 302 | ;; buffer-local values in order to apply different settings to different types | ||
| 303 | ;; of file. For example, the Bidirectional Parentheses Algorithm does not apply | ||
| 304 | ;; to `<' and `>' characters by default, and therefore one might prefer to not | ||
| 305 | ;; set `bidi-inhibit-bpa' in XML files, on the basis that XML files with long | ||
| 306 | ;; lines are less likely to trigger BPA-related performance problems: | ||
| 307 | ;; | ||
| 308 | ;; (add-hook 'nxml-mode-hook 'my-nxml-mode-hook) | ||
| 309 | ;; | ||
| 310 | ;; (defun my-nxml-mode-hook () | ||
| 311 | ;; "Custom `nxml-mode' behaviours." | ||
| 312 | ;; (require 'so-long) | ||
| 313 | ;; (setq-local so-long-variable-overrides | ||
| 314 | ;; (remove '(bidi-inhibit-bpa . t) so-long-variable-overrides))) | ||
| 315 | ;; | ||
| 316 | ;; Finally, note that setting `so-long-target-modes' to nil buffer-locally in | ||
| 317 | ;; a major mode hook would prevent that mode from ever being targeted. With | ||
| 318 | ;; `prog-mode' being targeted by default, specific derivatives of `prog-mode' | ||
| 319 | ;; could therefore be un-targeted if desired. | ||
| 320 | |||
| 285 | ;; * Other ways of using so-long | 321 | ;; * Other ways of using so-long |
| 286 | ;; ----------------------------- | 322 | ;; ----------------------------- |
| 287 | ;; It may prove useful to automatically invoke major mode `so-long-mode' for | 323 | ;; It may prove useful to automatically invoke major mode `so-long-mode' for |
| @@ -376,7 +412,6 @@ | |||
| 376 | ;; - Added mode-line indicator, user option `so-long-mode-line-label', | 412 | ;; - Added mode-line indicator, user option `so-long-mode-line-label', |
| 377 | ;; and faces `so-long-mode-line-active', `so-long-mode-line-inactive'. | 413 | ;; and faces `so-long-mode-line-active', `so-long-mode-line-inactive'. |
| 378 | ;; - New help commands `so-long-commentary' and `so-long-customize'. | 414 | ;; - New help commands `so-long-commentary' and `so-long-customize'. |
| 379 | ;; - Renamed `so-long-mode-enabled' to `so-long-enabled'. | ||
| 380 | ;; - Refactored the default hook values using variable overrides | 415 | ;; - Refactored the default hook values using variable overrides |
| 381 | ;; (and returning all the hooks to nil default values). | 416 | ;; (and returning all the hooks to nil default values). |
| 382 | ;; - Performance improvements for `so-long-detected-long-line-p'. | 417 | ;; - Performance improvements for `so-long-detected-long-line-p'. |
| @@ -416,9 +451,14 @@ | |||
| 416 | (declare-function longlines-mode "longlines") | 451 | (declare-function longlines-mode "longlines") |
| 417 | (defvar longlines-mode) | 452 | (defvar longlines-mode) |
| 418 | (defvar so-long-enabled nil | 453 | (defvar so-long-enabled nil |
| 419 | "Set to nil to prevent `so-long' from being triggered automatically. | 454 | ;; This was initially a renaming of the old `so-long-mode-enabled' and |
| 420 | 455 | ;; documented as "Set to nil to prevent `so-long' from being triggered | |
| 421 | Has no effect if `global-so-long-mode' is not enabled.") | 456 | ;; automatically."; however `so-long--ensure-enabled' may forcibly re-enable |
| 457 | ;; it contrary to the user's expectations, so for the present this should be | ||
| 458 | ;; considered internal-use only (with `global-so-long-mode' the interface | ||
| 459 | ;; for enabling or disabling the automated behaviour). FIXME: Establish a | ||
| 460 | ;; way to support the original use-case, or rename to `so-long--enabled'. | ||
| 461 | "Internal use. Non-nil when any so-long functionality has been used.") | ||
| 422 | 462 | ||
| 423 | (defvar-local so-long--active nil ; internal use | 463 | (defvar-local so-long--active nil ; internal use |
| 424 | "Non-nil when `so-long' mitigations are in effect.") | 464 | "Non-nil when `so-long' mitigations are in effect.") |
| @@ -886,9 +926,15 @@ buffer-local." | |||
| 886 | Stores the existing value for each entry in `so-long-variable-overrides'. | 926 | Stores the existing value for each entry in `so-long-variable-overrides'. |
| 887 | Stores the name of each enabled mode from the list `so-long-minor-modes'. | 927 | Stores the name of each enabled mode from the list `so-long-minor-modes'. |
| 888 | 928 | ||
| 929 | The lists themselves are also remembered, so that major mode hooks can | ||
| 930 | provide buffer-local modifications which are still accessible after changing | ||
| 931 | to `so-long-mode'. | ||
| 932 | |||
| 889 | If RESET is non-nil, remove any existing values before storing the new ones." | 933 | If RESET is non-nil, remove any existing values before storing the new ones." |
| 890 | (when reset | 934 | (when reset |
| 891 | (setq so-long-original-values nil)) | 935 | (setq so-long-original-values nil)) |
| 936 | (so-long-remember 'so-long-variable-overrides) | ||
| 937 | (so-long-remember 'so-long-minor-modes) | ||
| 892 | (dolist (ovar so-long-variable-overrides) | 938 | (dolist (ovar so-long-variable-overrides) |
| 893 | (so-long-remember (car ovar))) | 939 | (so-long-remember (car ovar))) |
| 894 | (dolist (mode so-long-minor-modes) | 940 | (dolist (mode so-long-minor-modes) |
| @@ -1288,7 +1334,7 @@ Calls `so-long-disable-minor-modes' and `so-long-override-variables'." | |||
| 1288 | 1334 | ||
| 1289 | (defun so-long-disable-minor-modes () | 1335 | (defun so-long-disable-minor-modes () |
| 1290 | "Disable any active minor modes listed in `so-long-minor-modes'." | 1336 | "Disable any active minor modes listed in `so-long-minor-modes'." |
| 1291 | (dolist (mode so-long-minor-modes) | 1337 | (dolist (mode (so-long-original 'so-long-minor-modes)) |
| 1292 | (when (and (boundp mode) mode) | 1338 | (when (and (boundp mode) mode) |
| 1293 | (funcall mode 0)))) | 1339 | (funcall mode 0)))) |
| 1294 | 1340 | ||
| @@ -1304,7 +1350,7 @@ The modes are enabled in accordance with what was remembered in `so-long'." | |||
| 1304 | 1350 | ||
| 1305 | (defun so-long-override-variables () | 1351 | (defun so-long-override-variables () |
| 1306 | "Set the buffer-local values defined by `so-long-variable-overrides'." | 1352 | "Set the buffer-local values defined by `so-long-variable-overrides'." |
| 1307 | (dolist (ovar so-long-variable-overrides) | 1353 | (dolist (ovar (so-long-original 'so-long-variable-overrides)) |
| 1308 | (set (make-local-variable (car ovar)) (cdr ovar)))) | 1354 | (set (make-local-variable (car ovar)) (cdr ovar)))) |
| 1309 | 1355 | ||
| 1310 | (defun so-long-restore-variables () | 1356 | (defun so-long-restore-variables () |
| @@ -1879,7 +1925,7 @@ If it appears in `%s', you should remove it." | |||
| 1879 | ; LocalWords: defadvice nadvice whitespace ie bos eos eobp origmode un Un setq | 1925 | ; LocalWords: defadvice nadvice whitespace ie bos eos eobp origmode un Un setq |
| 1880 | ; LocalWords: docstring auf Wiedersehen longlines alist autoload Refactored Inc | 1926 | ; LocalWords: docstring auf Wiedersehen longlines alist autoload Refactored Inc |
| 1881 | ; LocalWords: MERCHANTABILITY RET REGEXP VAR ELPA WS mitigations EmacsWiki eval | 1927 | ; LocalWords: MERCHANTABILITY RET REGEXP VAR ELPA WS mitigations EmacsWiki eval |
| 1882 | ; LocalWords: rx filename filenames bidi bpa | 1928 | ; LocalWords: rx filename filenames js defun bidi bpa prog FIXME |
| 1883 | 1929 | ||
| 1884 | ;; So long, farewell, auf Wiedersehen, goodbye | 1930 | ;; So long, farewell, auf Wiedersehen, goodbye |
| 1885 | ;; You have to go, this code is minified | 1931 | ;; You have to go, this code is minified |