* lisp/textmodes/flyspell.el: Commenting style, plus code simplifications.

(flyspell-default-deplacement-commands): Don't spell check after
repeated window/frame switches (e.g. triggered by mouse-movement).
(flyspell-delay-commands, flyspell-deplacement-commands): Use mapc.
(flyspell-debug-signal-word-checked): Simplify and fit in 80 cols.
(flyspell-casechars-cache, flyspell-ispell-casechars-cache)
(flyspell-not-casechars-cache, flyspell-ispell-not-casechars-cache):
Remove unused vars.
(flyspell-get-casechars, flyspell-get-not-casechars):
Simplify; Don't bother removing a ] just to add it back.
* lisp/textmodes/ispell.el (ispell-program-name): Use executable-find.
This commit is contained in:
Stefan Monnier 2012-05-18 15:04:07 -04:00
parent 2947339364
commit 60c4db3a60
3 changed files with 134 additions and 184 deletions

View file

@ -1,3 +1,17 @@
2012-05-18 Stefan Monnier <monnier@iro.umontreal.ca>
* textmodes/flyspell.el: Commenting style, plus code simplifications.
(flyspell-default-deplacement-commands): Don't spell check after
repeated window/frame switches (e.g. triggered by mouse-movement).
(flyspell-delay-commands, flyspell-deplacement-commands): Use mapc.
(flyspell-debug-signal-word-checked): Simplify and fit in 80 cols.
(flyspell-casechars-cache, flyspell-ispell-casechars-cache)
(flyspell-not-casechars-cache, flyspell-ispell-not-casechars-cache):
Remove unused vars.
(flyspell-get-casechars, flyspell-get-not-casechars):
Simplify; Don't bother removing a ] just to add it back.
* textmodes/ispell.el (ispell-program-name): Use executable-find.
2012-05-18 Rüdiger Sonderfeld <ruediger@c-plusplus.de>
* calc/calc-lang.el (math-C-parse-bess, math-C-parse-fma):

View file

@ -143,10 +143,9 @@ whose length is specified by `flyspell-delay'."
:type '(repeat (symbol)))
(defcustom flyspell-default-deplacement-commands
'(next-line
previous-line
scroll-up
scroll-down)
'(next-line previous-line
handle-switch-frame handle-select-window
scroll-up scroll-down)
"The standard list of deplacement commands for Flyspell.
See `flyspell-deplacement-commands'."
:group 'flyspell
@ -631,7 +630,7 @@ in your .emacs file.
(defun flyspell-delay-commands ()
"Install the standard set of Flyspell delayed commands."
(mapc 'flyspell-delay-command flyspell-default-delayed-commands)
(mapcar 'flyspell-delay-command flyspell-delayed-commands))
(mapc 'flyspell-delay-command flyspell-delayed-commands))
;;*---------------------------------------------------------------------*/
;;* flyspell-delay-command ... */
@ -639,7 +638,7 @@ in your .emacs file.
(defun flyspell-delay-command (command)
"Set COMMAND to be delayed, for Flyspell.
When flyspell `post-command-hook' is invoked because a delayed command
as been used the current word is not immediately checked.
has been used, the current word is not immediately checked.
It will be checked only after `flyspell-delay' seconds."
(interactive "SDelay Flyspell after Command: ")
(put command 'flyspell-delayed t))
@ -650,16 +649,15 @@ It will be checked only after `flyspell-delay' seconds."
(defun flyspell-deplacement-commands ()
"Install the standard set of Flyspell deplacement commands."
(mapc 'flyspell-deplacement-command flyspell-default-deplacement-commands)
(mapcar 'flyspell-deplacement-command flyspell-deplacement-commands))
(mapc 'flyspell-deplacement-command flyspell-deplacement-commands))
;;*---------------------------------------------------------------------*/
;;* flyspell-deplacement-command ... */
;;*---------------------------------------------------------------------*/
(defun flyspell-deplacement-command (command)
"Set COMMAND that implement cursor movements, for Flyspell.
When flyspell `post-command-hook' is invoked because of a deplacement command
as been used the current word is checked only if the previous command was
not the very same deplacement command."
When flyspell `post-command-hook' is invoked because a deplacement command
has been used, the current word is not checked."
(interactive "SDeplacement Flyspell after Command: ")
(put command 'flyspell-deplacement t))
@ -680,12 +678,12 @@ not the very same deplacement command."
;;* post command hook, we will check, if the word at this position */
;;* has to be spell checked. */
;;*---------------------------------------------------------------------*/
(defvar flyspell-pre-buffer nil)
(defvar flyspell-pre-point nil)
(defvar flyspell-pre-column nil)
(defvar flyspell-pre-buffer nil "Buffer current before `this-command'.")
(defvar flyspell-pre-point nil "Point before running `this-command'")
(defvar flyspell-pre-column nil "Column before running `this-command'")
(defvar flyspell-pre-pre-buffer nil)
(defvar flyspell-pre-pre-point nil)
(make-variable-buffer-local 'flyspell-pre-point)
(make-variable-buffer-local 'flyspell-pre-point) ;Why?? --Stef
;;*---------------------------------------------------------------------*/
;;* flyspell-previous-command ... */
@ -709,18 +707,18 @@ not the very same deplacement command."
;;;###autoload
(defun flyspell-mode-off ()
"Turn Flyspell mode off."
;; we remove the hooks
;; We remove the hooks.
(remove-hook 'post-command-hook (function flyspell-post-command-hook) t)
(remove-hook 'pre-command-hook (function flyspell-pre-command-hook) t)
(remove-hook 'after-change-functions 'flyspell-after-change-function t)
(remove-hook 'hack-local-variables-hook
(function flyspell-hack-local-variables-hook) t)
;; we remove all the flyspell highlightings
;; We remove all the flyspell highlightings.
(flyspell-delete-all-overlays)
;; we have to erase pre cache variables
;; We have to erase pre cache variables.
(setq flyspell-pre-buffer nil)
(setq flyspell-pre-point nil)
;; we mark the mode as killed
;; We mark the mode as killed.
(setq flyspell-mode nil))
;;*---------------------------------------------------------------------*/
@ -732,9 +730,8 @@ More precisely, it applies to the word that was before point
before the current command."
(let ((ispell-otherchars (ispell-get-otherchars)))
(cond
((or (not (numberp flyspell-pre-point))
(not (bufferp flyspell-pre-buffer))
(not (buffer-live-p flyspell-pre-buffer)))
((not (and (numberp flyspell-pre-point)
(buffer-live-p flyspell-pre-buffer)))
nil)
((and (eq flyspell-pre-pre-point flyspell-pre-point)
(eq flyspell-pre-pre-buffer flyspell-pre-buffer))
@ -794,21 +791,15 @@ before the current command."
;;* flyspell-check-changed-word-p ... */
;;*---------------------------------------------------------------------*/
(defun flyspell-check-changed-word-p (start stop)
"Return t when the changed word has to be checked.
"Return non-nil when the changed word has to be checked.
The answer depends of several criteria.
Mostly we check word delimiters."
(cond
((and (memq (char-after start) '(?\n ? )) (> stop start))
t)
((not (numberp flyspell-pre-point))
t)
((and (>= flyspell-pre-point start) (<= flyspell-pre-point stop))
nil)
((let ((pos (point)))
(or (>= pos start) (<= pos stop) (= pos (1+ stop))))
nil)
(t
t)))
(not (and (not (and (memq (char-after start) '(?\n ? )) (> stop start)))
(numberp flyspell-pre-point)
(or
(and (>= flyspell-pre-point start) (<= flyspell-pre-point stop))
(let ((pos (point)))
(or (>= pos start) (<= pos stop) (= pos (1+ stop))))))))
;;*---------------------------------------------------------------------*/
;;* flyspell-check-word-p ... */
@ -820,7 +811,7 @@ Mostly we check word delimiters."
(let ((ispell-otherchars (ispell-get-otherchars)))
(cond
((<= (- (point-max) 1) (point-min))
;; the buffer is not filled enough
;; The buffer is not filled enough.
nil)
((and (and (> (current-column) 0)
(not (eq (current-column) flyspell-pre-column)))
@ -831,15 +822,15 @@ Mostly we check word delimiters."
(not (looking-at ispell-otherchars)))
(or flyspell-consider-dash-as-word-delimiter-flag
(not (looking-at "-"))))))
;; yes because we have reached or typed a word delimiter.
;; Yes because we have reached or typed a word delimiter.
t)
((symbolp this-command)
(cond
((get this-command 'flyspell-deplacement)
(not (eq flyspell-previous-command this-command)))
((get this-command 'flyspell-delayed)
;; the current command is not delayed, that
;; is that we must check the word now
;; The current command is not delayed, that
;; is that we must check the word now.
(and (not unread-command-events)
(sit-for flyspell-delay)))
(t t)))
@ -877,53 +868,51 @@ Mostly we check word delimiters."
(oldbuf (current-buffer))
(point (point)))
(with-current-buffer (get-buffer-create "*flyspell-debug*")
(insert "WORD:\n")
(insert (format " this-cmd : %S\n" this-command))
(insert (format " delayed : %S\n" (and (symbolp this-command)
(get this-command 'flyspell-delayed))))
(insert (format " point : %S\n" point))
(insert (format " prev-char : [%c] %S\n"
(with-current-buffer oldbuf
(let ((c (if (> (point) (point-min))
(save-excursion
(backward-char 1)
(char-after (point)))
? )))
c))
(with-current-buffer oldbuf
(let ((c (if (> (point) (point-min))
(save-excursion
(backward-char 1)
(and (and (looking-at (flyspell-get-not-casechars)) 1)
(or (string= "" ispell-otherchars)
(not (looking-at ispell-otherchars)))
(and (or flyspell-consider-dash-as-word-delimiter-flag
(not (looking-at "\\-"))) 2))))))
c))))
(insert (format " because : %S\n"
(cond
((not (and (symbolp this-command)
(get this-command 'flyspell-delayed)))
;; the current command is not delayed, that
;; is that we must check the word now
'not-delayed)
((with-current-buffer oldbuf
(let ((c (if (> (point) (point-min))
(save-excursion
(backward-char 1)
(and (looking-at (flyspell-get-not-casechars))
(or (string= "" ispell-otherchars)
(not (looking-at ispell-otherchars)))
(or flyspell-consider-dash-as-word-delimiter-flag
(not (looking-at "\\-"))))))))
c))
;; yes because we have reached or typed a word delimiter.
'separator)
((not (integerp flyspell-delay))
;; yes because the user had set up a no-delay configuration.
'no-delay)
(t
'sit-for))))
(insert
"WORD:\n"
(format " this-cmd : %S\n" this-command)
(format " delayed : %S\n" (and (symbolp this-command)
(get this-command
'flyspell-delayed)))
(format " point : %S\n" point)
(format " prev-char : [%c] %S\n"
(with-current-buffer oldbuf
(if (bobp) ?\ (char-before)))
(with-current-buffer oldbuf
(if (bobp)
nil
(save-excursion
(backward-char 1)
(and (looking-at (flyspell-get-not-casechars))
(or (string= "" ispell-otherchars)
(not (looking-at ispell-otherchars)))
(or flyspell-consider-dash-as-word-delimiter-flag
(not (looking-at "\\-")))
2)))))
(format " because : %S\n"
(cond
((not (and (symbolp this-command)
(get this-command 'flyspell-delayed)))
;; The current command is not delayed, that
;; is that we must check the word now.
'not-delayed)
((with-current-buffer oldbuf
(if (bobp)
nil
(save-excursion
(backward-char 1)
(and (looking-at (flyspell-get-not-casechars))
(or (string= "" ispell-otherchars)
(not (looking-at ispell-otherchars)))
(or flyspell-consider-dash-as-word-delimiter-flag
(not (looking-at "\\-")))))))
;; Yes because we have reached or typed a word delimiter.
'separator)
((not (integerp flyspell-delay))
;; Yes because the user set up a no-delay configuration.
'no-delay)
(t
'sit-for))))
(goto-char (point-max)))))
;;*---------------------------------------------------------------------*/
@ -946,7 +935,7 @@ Mostly we check word delimiters."
;;* 2- the word that used to be the current word before the */
;;* THIS-COMMAND is checked if: */
;;* a- the previous word is different from the current word */
;;* b- the previous word as not just been checked by the */
;;* b- the previous word has not just been checked by the */
;;* previous FLYSPELL-POST-COMMAND-HOOK */
;;* 3- the words changed by the THIS-COMMAND that are neither the */
;;* previous word nor the current word */
@ -973,7 +962,7 @@ Mostly we check word delimiters."
;; we remember which word we have just checked.
;; this will be used next time we will check a word
;; to compare the next current word with the word
;; that as been registered in the pre-command-hook
;; that has been registered in the pre-command-hook
;; that is these variables are used within the predicate
;; FLYSPELL-CHECK-PRE-WORD-P
(setq flyspell-pre-pre-buffer (current-buffer))
@ -1240,63 +1229,8 @@ misspelling and skips redundant spell-checking step."
(>= (match-end 0) b))))))
(flyspell-math-tex-command-p)))
;;*---------------------------------------------------------------------*/
;;* flyspell-casechars-cache ... */
;;*---------------------------------------------------------------------*/
(defvar flyspell-casechars-cache nil)
(defvar flyspell-ispell-casechars-cache nil)
(make-variable-buffer-local 'flyspell-casechars-cache)
(make-variable-buffer-local 'flyspell-ispell-casechars-cache)
;;*---------------------------------------------------------------------*/
;;* flyspell-get-casechars ... */
;;*---------------------------------------------------------------------*/
(defun flyspell-get-casechars ()
"This function builds a string that is the regexp of word chars.
In order to avoid one useless string construction,
this function changes the last char of the `ispell-casechars' string."
(let ((ispell-casechars (ispell-get-casechars)))
(cond
((eq ispell-parser 'tex)
(setq flyspell-ispell-casechars-cache ispell-casechars)
(setq flyspell-casechars-cache
(concat (substring ispell-casechars
0
(- (length ispell-casechars) 1))
"]"))
flyspell-casechars-cache)
(t
(setq flyspell-ispell-casechars-cache ispell-casechars)
(setq flyspell-casechars-cache ispell-casechars)
flyspell-casechars-cache))))
;;*---------------------------------------------------------------------*/
;;* flyspell-get-not-casechars-cache ... */
;;*---------------------------------------------------------------------*/
(defvar flyspell-not-casechars-cache nil)
(defvar flyspell-ispell-not-casechars-cache nil)
(make-variable-buffer-local 'flyspell-not-casechars-cache)
(make-variable-buffer-local 'flyspell-ispell-not-casechars-cache)
;;*---------------------------------------------------------------------*/
;;* flyspell-get-not-casechars ... */
;;*---------------------------------------------------------------------*/
(defun flyspell-get-not-casechars ()
"This function builds a string that is the regexp of non-word chars."
(let ((ispell-not-casechars (ispell-get-not-casechars)))
(cond
((eq ispell-parser 'tex)
(setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
(setq flyspell-not-casechars-cache
(concat (substring ispell-not-casechars
0
(- (length ispell-not-casechars) 1))
"]"))
flyspell-not-casechars-cache)
(t
(setq flyspell-ispell-not-casechars-cache ispell-not-casechars)
(setq flyspell-not-casechars-cache ispell-not-casechars)
flyspell-not-casechars-cache))))
(defalias 'flyspell-get-casechars 'ispell-get-casechars)
(defalias 'flyspell-get-not-casechars 'ispell-get-not-casechars)
;;*---------------------------------------------------------------------*/
;;* flyspell-get-word ... */
@ -1433,7 +1367,7 @@ The buffer to mark them in is `flyspell-large-region-buffer'."
(goto-char buffer-scan-pos)
(let ((keep t))
;; Iterate on string search until string is found as word,
;; not as substring
;; not as substring.
(while keep
(if (search-forward word
flyspell-large-region-end t)
@ -1449,13 +1383,14 @@ The buffer to mark them in is `flyspell-large-region-buffer'."
(when (or
;; Size matches, we really found it.
(= found-length misspell-length)
;; Matches as part of a boundary-char separated word
;; Matches as part of a boundary-char separated
;; word.
(member word
(split-string found ispell-otherchars))
;; Misspelling has higher length than
;; what flyspell considers the
;; word. Caused by boundary-chars
;; mismatch. Validating seems safe.
;; what flyspell considers the word.
;; Caused by boundary-chars mismatch.
;; Validating seems safe.
(< found-length misspell-length)
;; ispell treats beginning of some TeX
;; commands as nroff control sequences
@ -1920,11 +1855,11 @@ This command proposes various successive corrections for the current word."
(interactive)
(let ((pos (point))
(old-max (point-max)))
;; use the correct dictionary
;; Use the correct dictionary.
(flyspell-accept-buffer-local-defs)
(if (and (eq flyspell-auto-correct-pos pos)
(consp flyspell-auto-correct-region))
;; we have already been using the function at the same location
;; We have already been using the function at the same location.
(let* ((start (car flyspell-auto-correct-region))
(len (cdr flyspell-auto-correct-region)))
(flyspell-unhighlight-at start)
@ -1946,7 +1881,7 @@ This command proposes various successive corrections for the current word."
(flyspell-display-next-corrections flyspell-auto-correct-ring))
(flyspell-ajust-cursor-point pos (point) old-max)
(setq flyspell-auto-correct-pos (point)))
;; fetch the word to be checked
;; Fetch the word to be checked.
(let ((word (flyspell-get-word)))
(if (consp word)
(let ((start (car (cdr word)))
@ -1954,30 +1889,30 @@ This command proposes various successive corrections for the current word."
(word (car word))
poss ispell-filter)
(setq flyspell-auto-correct-word word)
;; now check spelling of word.
(ispell-send-string "%\n") ;put in verbose mode
;; Now check spelling of word..
(ispell-send-string "%\n") ;Put in verbose mode.
(ispell-send-string (concat "^" word "\n"))
;; wait until ispell has processed word.
;; Wait until ispell has processed word.
(while (progn
(accept-process-output ispell-process)
(not (string= "" (car ispell-filter)))))
;; Remove leading empty element
;; Remove leading empty element.
(setq ispell-filter (cdr ispell-filter))
;; ispell process should return something after word is sent.
;; Tag word as valid (i.e., skip) otherwise
;; Ispell process should return something after word is sent.
;; Tag word as valid (i.e., skip) otherwise.
(or ispell-filter
(setq ispell-filter '(*)))
(if (consp ispell-filter)
(setq poss (ispell-parse-output (car ispell-filter))))
(cond
((or (eq poss t) (stringp poss))
;; don't correct word
;; Don't correct word.
t)
((null poss)
;; ispell error
;; Ispell error.
(error "Ispell: error in Ispell process"))
(t
;; the word is incorrect, we have to propose a replacement
;; The word is incorrect, we have to propose a replacement.
(let ((replacements (if flyspell-sort-corrections
(sort (car (cdr (cdr poss))) 'string<)
(car (cdr (cdr poss))))))

View file

@ -349,9 +349,9 @@ Must be greater than 1."
:group 'ispell)
(defcustom ispell-program-name
(or (locate-file "aspell" exec-path exec-suffixes 'file-executable-p)
(locate-file "ispell" exec-path exec-suffixes 'file-executable-p)
(locate-file "hunspell" exec-path exec-suffixes 'file-executable-p)
(or (executable-find "aspell")
(executable-find "ispell")
(executable-find "hunspell")
"ispell")
"Program invoked by \\[ispell-word] and \\[ispell-region] commands."
:type 'string
@ -909,7 +909,7 @@ Otherwise returns the library directory name, if that is defined."
;;;###autoload
(defvar ispell-menu-map nil "Key map for ispell menu.")
;;; redo menu when loading ispell to get dictionary modifications
;; Redo menu when loading ispell to get dictionary modifications
(setq ispell-menu-map nil)
;;;###autoload
@ -1175,7 +1175,7 @@ The variable `ispell-library-directory' defines their location."
(push name dict-list)))
dict-list))
;;; define commands in menu in opposite order you want them to appear.
;; Define commands in menu in opposite order you want them to appear.
;;;###autoload
(if ispell-menu-map-needed
(progn
@ -1372,9 +1372,9 @@ Protects against bogus binding of `enable-multibyte-characters' in XEmacs."
(defvar ispell-pdict-modified-p nil
"Non-nil means personal dictionary has modifications to be saved.")
;;; If you want to save the dictionary when quitting, must do so explicitly.
;;; When non-nil, the spell session is terminated.
;;; When numeric, contains cursor location in buffer, and cursor remains there.
;; If you want to save the dictionary when quitting, must do so explicitly.
;; When non-nil, the spell session is terminated.
;; When numeric, contains cursor location in buffer, and cursor remains there.
(defvar ispell-quit nil)
(defvar ispell-process-directory nil
@ -1874,10 +1874,10 @@ which is in `ispell-local-dictionary-alist' or `ispell-dictionary-alist'."
(list word start end))))
;;; Global ispell-pdict-modified-p is set by ispell-command-loop and
;;; tracks changes in the dictionary. The global may either be
;;; a value or a list, whose value is the state of whether the
;;; dictionary needs to be saved.
;; Global ispell-pdict-modified-p is set by ispell-command-loop and
;; tracks changes in the dictionary. The global may either be
;; a value or a list, whose value is the state of whether the
;; dictionary needs to be saved.
;;;###autoload
(defun ispell-pdict-save (&optional no-query force-save)
@ -2416,8 +2416,8 @@ if defined."
(setq start end)))))) ; else move start to next line of input
;;; This function destroys the mark location if it is in the word being
;;; highlighted.
;; This function destroys the mark location if it is in the word being
;; highlighted.
(defun ispell-highlight-spelling-error-generic (start end &optional highlight
refresh)
"Highlight the word from START to END with a kludge using `inverse-video'.
@ -2549,7 +2549,7 @@ scrolling the current window. Leave the new window selected."
(set-window-start (next-window) top))))
;;; Should we add a compound word match return value?
;; Should we add a compound word match return value?
(defun ispell-parse-output (output &optional accept-list shift)
"Parse the OUTPUT string from Ispell process and return:
1: t for an exact match.
@ -2615,8 +2615,8 @@ When asynchronous processes are not supported, `run' is always returned."
(defun ispell-start-process ()
"Start the ispell process, with support for no asynchronous processes.
Keeps argument list for future ispell invocations for no async support."
"Start the Ispell process, with support for no asynchronous processes.
Keeps argument list for future Ispell invocations for no async support."
;; Local dictionary becomes the global dictionary in use.
(setq ispell-current-dictionary
(or ispell-local-dictionary ispell-dictionary))
@ -2792,11 +2792,11 @@ With CLEAR, buffer session localwords are cleaned."
(if (not (and ispell-process
(eq (ispell-process-status) 'run)))
(or no-error
(error "There is no ispell process running!"))
(error "There is no Ispell process running!"))
(if ispell-async-processp
(delete-process ispell-process)
;; synchronous processes
(ispell-send-string "\n") ; make sure side effects occurred.
;; Synchronous processes.
(ispell-send-string "\n") ; Make sure side effects occurred.
(kill-buffer ispell-output-buffer)
(kill-buffer ispell-session-buffer)
(setq ispell-output-buffer nil
@ -2805,8 +2805,8 @@ With CLEAR, buffer session localwords are cleaned."
(message "Ispell process killed")
nil))
;;; ispell-change-dictionary is set in some people's hooks. Maybe this should
;;; call ispell-init-process rather than wait for a spell checking command?
;; ispell-change-dictionary is set in some people's hooks. Maybe this should
;; call ispell-init-process rather than wait for a spell checking command?
;;;###autoload
(defun ispell-change-dictionary (dict &optional arg)
@ -3411,6 +3411,7 @@ If optional INTERIOR-FRAG is non-nil then the word may be a character
sequence inside of a word.
Standard ispell choices are then available."
;; FIXME: completion-at-point-function.
(interactive "P")
(let ((cursor-location (point))
(case-fold-search-val case-fold-search)
@ -3943,7 +3944,7 @@ Both should not be used to define a buffer-local dictionary."
(ispell-send-string (concat "@" string "\n"))))))))
;;; returns optionally adjusted region-end-point.
;; Returns optionally adjusted region-end-point.
;; If comment-padright is defined, newcomment must be loaded.
(declare-function comment-add "newcomment" (arg))