diff options
Diffstat (limited to 'lisp/textmodes/flyspell.el')
| -rw-r--r-- | lisp/textmodes/flyspell.el | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index 54b67a258a6..23f4756f4a7 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el | |||
| @@ -271,21 +271,23 @@ If `flyspell-large-region' is nil, all regions are treated as small." | |||
| 271 | ;;* using flyspell with mail-mode add the following expression */ | 271 | ;;* using flyspell with mail-mode add the following expression */ |
| 272 | ;;* in your .emacs file: */ | 272 | ;;* in your .emacs file: */ |
| 273 | ;;* (add-hook 'mail-mode */ | 273 | ;;* (add-hook 'mail-mode */ |
| 274 | ;;* '(lambda () (setq flyspell-generic-check-word-p */ | 274 | ;;* '(lambda () (setq flyspell-generic-check-word-predicate */ |
| 275 | ;;* 'mail-mode-flyspell-verify))) */ | 275 | ;;* 'mail-mode-flyspell-verify))) */ |
| 276 | ;;*---------------------------------------------------------------------*/ | 276 | ;;*---------------------------------------------------------------------*/ |
| 277 | (defvar flyspell-generic-check-word-p nil | 277 | (defvar flyspell-generic-check-word-predicate nil |
| 278 | "Function providing per-mode customization over which words are flyspelled. | 278 | "Function providing per-mode customization over which words are flyspelled. |
| 279 | Returns t to continue checking, nil otherwise. | 279 | Returns t to continue checking, nil otherwise. |
| 280 | Flyspell mode sets this variable to whatever is the `flyspell-mode-predicate' | 280 | Flyspell mode sets this variable to whatever is the `flyspell-mode-predicate' |
| 281 | property of the major mode name.") | 281 | property of the major mode name.") |
| 282 | (make-variable-buffer-local 'flyspell-generic-check-word-p) | 282 | (make-variable-buffer-local 'flyspell-generic-check-word-predicate) |
| 283 | (defvaralias 'flyspell-generic-check-word-p | ||
| 284 | 'flyspell-generic-check-word-predicate) | ||
| 283 | 285 | ||
| 284 | ;;*--- mail mode -------------------------------------------------------*/ | 286 | ;;*--- mail mode -------------------------------------------------------*/ |
| 285 | (put 'mail-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) | 287 | (put 'mail-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) |
| 286 | (put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) | 288 | (put 'message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify) |
| 287 | (defun mail-mode-flyspell-verify () | 289 | (defun mail-mode-flyspell-verify () |
| 288 | "This function is used for `flyspell-generic-check-word-p' in Mail mode." | 290 | "Function used for `flyspell-generic-check-word-predicate' in Mail mode." |
| 289 | (let ((header-end (save-excursion | 291 | (let ((header-end (save-excursion |
| 290 | (goto-char (point-min)) | 292 | (goto-char (point-min)) |
| 291 | (re-search-forward | 293 | (re-search-forward |
| @@ -313,7 +315,7 @@ property of the major mode name.") | |||
| 313 | ;;*--- texinfo mode ----------------------------------------------------*/ | 315 | ;;*--- texinfo mode ----------------------------------------------------*/ |
| 314 | (put 'texinfo-mode 'flyspell-mode-predicate 'texinfo-mode-flyspell-verify) | 316 | (put 'texinfo-mode 'flyspell-mode-predicate 'texinfo-mode-flyspell-verify) |
| 315 | (defun texinfo-mode-flyspell-verify () | 317 | (defun texinfo-mode-flyspell-verify () |
| 316 | "This function is used for `flyspell-generic-check-word-p' in Texinfo mode." | 318 | "Function used for `flyspell-generic-check-word-predicate' in Texinfo mode." |
| 317 | (save-excursion | 319 | (save-excursion |
| 318 | (forward-word -1) | 320 | (forward-word -1) |
| 319 | (not (looking-at "@")))) | 321 | (not (looking-at "@")))) |
| @@ -321,7 +323,7 @@ property of the major mode name.") | |||
| 321 | ;;*--- tex mode --------------------------------------------------------*/ | 323 | ;;*--- tex mode --------------------------------------------------------*/ |
| 322 | (put 'tex-mode 'flyspell-mode-predicate 'tex-mode-flyspell-verify) | 324 | (put 'tex-mode 'flyspell-mode-predicate 'tex-mode-flyspell-verify) |
| 323 | (defun tex-mode-flyspell-verify () | 325 | (defun tex-mode-flyspell-verify () |
| 324 | "This function is used for `flyspell-generic-check-word-p' in LaTeX mode." | 326 | "Function used for `flyspell-generic-check-word-predicate' in LaTeX mode." |
| 325 | (and | 327 | (and |
| 326 | (not (save-excursion | 328 | (not (save-excursion |
| 327 | (re-search-backward "^[ \t]*%%%[ \t]+Local" nil t))) | 329 | (re-search-backward "^[ \t]*%%%[ \t]+Local" nil t))) |
| @@ -338,7 +340,7 @@ property of the major mode name.") | |||
| 338 | (put 'html-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify) | 340 | (put 'html-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify) |
| 339 | 341 | ||
| 340 | (defun sgml-mode-flyspell-verify () | 342 | (defun sgml-mode-flyspell-verify () |
| 341 | "This function is used for `flyspell-generic-check-word-p' in SGML mode." | 343 | "Function used for `flyspell-generic-check-word-predicate' in SGML mode." |
| 342 | (not (save-excursion | 344 | (not (save-excursion |
| 343 | (let ((this (point-marker)) | 345 | (let ((this (point-marker)) |
| 344 | (s (progn (beginning-of-line) (point-marker))) | 346 | (s (progn (beginning-of-line) (point-marker))) |
| @@ -368,7 +370,7 @@ property of the major mode name.") | |||
| 368 | "Faces corresponding to text in programming-mode buffers.") | 370 | "Faces corresponding to text in programming-mode buffers.") |
| 369 | 371 | ||
| 370 | (defun flyspell-generic-progmode-verify () | 372 | (defun flyspell-generic-progmode-verify () |
| 371 | "Used for `flyspell-generic-check-word-p' in programming modes." | 373 | "Used for `flyspell-generic-check-word-predicate' in programming modes." |
| 372 | (let ((f (get-text-property (point) 'face))) | 374 | (let ((f (get-text-property (point) 'face))) |
| 373 | (memq f flyspell-prog-text-faces))) | 375 | (memq f flyspell-prog-text-faces))) |
| 374 | 376 | ||
| @@ -376,7 +378,8 @@ property of the major mode name.") | |||
| 376 | (defun flyspell-prog-mode () | 378 | (defun flyspell-prog-mode () |
| 377 | "Turn on `flyspell-mode' for comments and strings." | 379 | "Turn on `flyspell-mode' for comments and strings." |
| 378 | (interactive) | 380 | (interactive) |
| 379 | (setq flyspell-generic-check-word-p 'flyspell-generic-progmode-verify) | 381 | (setq flyspell-generic-check-word-predicate |
| 382 | 'flyspell-generic-progmode-verify) | ||
| 380 | (flyspell-mode 1) | 383 | (flyspell-mode 1) |
| 381 | (run-hooks 'flyspell-prog-mode-hook)) | 384 | (run-hooks 'flyspell-prog-mode-hook)) |
| 382 | 385 | ||
| @@ -483,6 +486,18 @@ in your .emacs file. | |||
| 483 | (flyspell-mode-on) | 486 | (flyspell-mode-on) |
| 484 | (flyspell-mode-off))) | 487 | (flyspell-mode-off))) |
| 485 | 488 | ||
| 489 | ;;;###autoload | ||
| 490 | (defun turn-on-flyspell () | ||
| 491 | "Unconditionally turn on Flyspell mode." | ||
| 492 | (flyspell-mode 1)) | ||
| 493 | |||
| 494 | ;;;###autoload | ||
| 495 | (defun turn-off-flyspell () | ||
| 496 | "Unconditionally turn off Flyspell mode." | ||
| 497 | (flyspell-mode -1)) | ||
| 498 | |||
| 499 | (custom-add-option 'text-mode-hook 'turn-on-flyspell) | ||
| 500 | |||
| 486 | ;;*---------------------------------------------------------------------*/ | 501 | ;;*---------------------------------------------------------------------*/ |
| 487 | ;;* flyspell-buffers ... */ | 502 | ;;* flyspell-buffers ... */ |
| 488 | ;;* ------------------------------------------------------------- */ | 503 | ;;* ------------------------------------------------------------- */ |
| @@ -563,10 +578,10 @@ in your .emacs file. | |||
| 563 | (add-hook 'pre-command-hook (function flyspell-pre-command-hook) t t) | 578 | (add-hook 'pre-command-hook (function flyspell-pre-command-hook) t t) |
| 564 | ;; we bound flyspell action to after-change hook | 579 | ;; we bound flyspell action to after-change hook |
| 565 | (add-hook 'after-change-functions 'flyspell-after-change-function nil t) | 580 | (add-hook 'after-change-functions 'flyspell-after-change-function nil t) |
| 566 | ;; set flyspell-generic-check-word-p based on the major mode | 581 | ;; set flyspell-generic-check-word-predicate based on the major mode |
| 567 | (let ((mode-predicate (get major-mode 'flyspell-mode-predicate))) | 582 | (let ((mode-predicate (get major-mode 'flyspell-mode-predicate))) |
| 568 | (if mode-predicate | 583 | (if mode-predicate |
| 569 | (setq flyspell-generic-check-word-p mode-predicate))) | 584 | (setq flyspell-generic-check-word-predicate mode-predicate))) |
| 570 | ;; the welcome message | 585 | ;; the welcome message |
| 571 | (if (and flyspell-issue-message-flag | 586 | (if (and flyspell-issue-message-flag |
| 572 | flyspell-issue-welcome-flag | 587 | flyspell-issue-welcome-flag |
| @@ -979,8 +994,8 @@ Mostly we check word delimiters." | |||
| 979 | (flyspell-word (flyspell-get-word following)) | 994 | (flyspell-word (flyspell-get-word following)) |
| 980 | start end poss word) | 995 | start end poss word) |
| 981 | (if (or (eq flyspell-word nil) | 996 | (if (or (eq flyspell-word nil) |
| 982 | (and (fboundp flyspell-generic-check-word-p) | 997 | (and (fboundp flyspell-generic-check-word-predicate) |
| 983 | (not (funcall flyspell-generic-check-word-p)))) | 998 | (not (funcall flyspell-generic-check-word-predicate)))) |
| 984 | t | 999 | t |
| 985 | (progn | 1000 | (progn |
| 986 | ;; destructure return flyspell-word info list. | 1001 | ;; destructure return flyspell-word info list. |