diff options
| author | John Wiegley | 2004-05-08 12:48:49 +0000 |
|---|---|---|
| committer | John Wiegley | 2004-05-08 12:48:49 +0000 |
| commit | 4c685fb8211cb405d7febe40c68207a2185bfcc9 (patch) | |
| tree | cb6b6732546b0093320e2d56875f8b79710764a9 | |
| parent | 811a8484c03099f8b55ea9d14442ad53a2732148 (diff) | |
| download | emacs-4c685fb8211cb405d7febe40c68207a2185bfcc9.tar.gz emacs-4c685fb8211cb405d7febe40c68207a2185bfcc9.zip | |
2004-05-08 John Wiegley <johnw@newartisans.com>
* textmodes/flyspell.el (flyspell-highlight-incorrect-region):
Ignore the read-only property when flyspell highlighting is on.
Not ignoring it leads to a series of confusing errors.
(flyspell-highlight-duplicate-region): Ignore read-only, as above,
but also make sure to call flyspell-incorrect-hook.
(flyspell-maybe-correct-transposition): Perform transposition test
by bit twiddling a string, rather than using a temp buffer.
(flyspell-maybe-correct-doubling): Use a string rather than a temp
buffer. This is also the original version of the code, which
could not be checked in before due to a previous lack of
assignment papers. This version has seen heavy usage on my system
for several years now.
| -rw-r--r-- | lisp/textmodes/flyspell.el | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index 3d41042e8d7..5d21fda6a9a 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el | |||
| @@ -1516,46 +1516,51 @@ for the overlay." | |||
| 1516 | ;*---------------------------------------------------------------------*/ | 1516 | ;*---------------------------------------------------------------------*/ |
| 1517 | (defun flyspell-highlight-incorrect-region (beg end poss) | 1517 | (defun flyspell-highlight-incorrect-region (beg end poss) |
| 1518 | "Set up an overlay on a misspelled word, in the buffer from BEG to END." | 1518 | "Set up an overlay on a misspelled word, in the buffer from BEG to END." |
| 1519 | (unless (run-hook-with-args-until-success | 1519 | (let ((inhibit-read-only t)) |
| 1520 | 'flyspell-incorrect-hook beg end poss) | 1520 | (unless (run-hook-with-args-until-success |
| 1521 | (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg))) | 1521 | 'flyspell-incorrect-hook beg end poss) |
| 1522 | (progn | 1522 | (if (or flyspell-highlight-properties |
| 1523 | ;; we cleanup current overlay at the same position | 1523 | (not (flyspell-properties-at-p beg))) |
| 1524 | (if (and (not flyspell-persistent-highlight) | 1524 | (progn |
| 1525 | (overlayp flyspell-overlay)) | 1525 | ;; we cleanup current overlay at the same position |
| 1526 | (delete-overlay flyspell-overlay) | 1526 | (if (and (not flyspell-persistent-highlight) |
| 1527 | (let ((overlays (overlays-at beg))) | 1527 | (overlayp flyspell-overlay)) |
| 1528 | (while (consp overlays) | 1528 | (delete-overlay flyspell-overlay) |
| 1529 | (if (flyspell-overlay-p (car overlays)) | 1529 | (let ((overlays (overlays-at beg))) |
| 1530 | (delete-overlay (car overlays))) | 1530 | (while (consp overlays) |
| 1531 | (setq overlays (cdr overlays))))) | 1531 | (if (flyspell-overlay-p (car overlays)) |
| 1532 | ;; now we can use a new overlay | 1532 | (delete-overlay (car overlays))) |
| 1533 | (setq flyspell-overlay | 1533 | (setq overlays (cdr overlays))))) |
| 1534 | (make-flyspell-overlay beg end | 1534 | ;; now we can use a new overlay |
| 1535 | 'flyspell-incorrect-face | 1535 | (setq flyspell-overlay |
| 1536 | 'highlight)))))) | 1536 | (make-flyspell-overlay |
| 1537 | beg end 'flyspell-incorrect-face 'highlight))))))) | ||
| 1537 | 1538 | ||
| 1538 | ;*---------------------------------------------------------------------*/ | 1539 | ;*---------------------------------------------------------------------*/ |
| 1539 | ;* flyspell-highlight-duplicate-region ... */ | 1540 | ;* flyspell-highlight-duplicate-region ... */ |
| 1540 | ;*---------------------------------------------------------------------*/ | 1541 | ;*---------------------------------------------------------------------*/ |
| 1541 | (defun flyspell-highlight-duplicate-region (beg end) | 1542 | (defun flyspell-highlight-duplicate-region (beg end) |
| 1542 | "Set up an overlay on a duplicated word, in the buffer from BEG to END." | 1543 | "Set up an overlay on a duplicated word, in the buffer from BEG to END." |
| 1543 | (if (or flyspell-highlight-properties (not (flyspell-properties-at-p beg))) | 1544 | (let ((inhibit-read-only t)) |
| 1544 | (progn | 1545 | (unless (run-hook-with-args-until-success |
| 1545 | ;; we cleanup current overlay at the same position | 1546 | 'flyspell-incorrect-hook beg end poss) |
| 1546 | (if (and (not flyspell-persistent-highlight) | 1547 | (if (or flyspell-highlight-properties |
| 1547 | (overlayp flyspell-overlay)) | 1548 | (not (flyspell-properties-at-p beg))) |
| 1548 | (delete-overlay flyspell-overlay) | 1549 | (progn |
| 1549 | (let ((overlays (overlays-at beg))) | 1550 | ;; we cleanup current overlay at the same position |
| 1550 | (while (consp overlays) | 1551 | (if (and (not flyspell-persistent-highlight) |
| 1551 | (if (flyspell-overlay-p (car overlays)) | 1552 | (overlayp flyspell-overlay)) |
| 1552 | (delete-overlay (car overlays))) | 1553 | (delete-overlay flyspell-overlay) |
| 1553 | (setq overlays (cdr overlays))))) | 1554 | (let ((overlays (overlays-at beg))) |
| 1554 | ;; now we can use a new overlay | 1555 | (while (consp overlays) |
| 1555 | (setq flyspell-overlay | 1556 | (if (flyspell-overlay-p (car overlays)) |
| 1556 | (make-flyspell-overlay beg end | 1557 | (delete-overlay (car overlays))) |
| 1557 | 'flyspell-duplicate-face | 1558 | (setq overlays (cdr overlays))))) |
| 1558 | 'highlight))))) | 1559 | ;; now we can use a new overlay |
| 1560 | (setq flyspell-overlay | ||
| 1561 | (make-flyspell-overlay beg end | ||
| 1562 | 'flyspell-duplicate-face | ||
| 1563 | 'highlight))))))) | ||
| 1559 | 1564 | ||
| 1560 | ;*---------------------------------------------------------------------*/ | 1565 | ;*---------------------------------------------------------------------*/ |
| 1561 | ;* flyspell-auto-correct-cache ... */ | 1566 | ;* flyspell-auto-correct-cache ... */ |
| @@ -2061,23 +2066,23 @@ possible corrections as returned by 'ispell-parse-output'. | |||
| 2061 | 2066 | ||
| 2062 | This function is meant to be added to 'flyspell-incorrect-hook'." | 2067 | This function is meant to be added to 'flyspell-incorrect-hook'." |
| 2063 | (when (consp poss) | 2068 | (when (consp poss) |
| 2064 | (let ((temp-buffer (get-buffer-create " *flyspell-temp*")) | 2069 | (catch 'done |
| 2065 | found) | 2070 | (let ((str (buffer-substring beg end)) |
| 2066 | (save-excursion | 2071 | (i 0) (len (- end beg)) tmp) |
| 2067 | (copy-to-buffer temp-buffer beg end) | 2072 | (while (< (1+ i) len) |
| 2068 | (set-buffer temp-buffer) | 2073 | (setq tmp (aref str i)) |
| 2069 | (goto-char (1+ (point-min))) | 2074 | (aset str i (aref str (1+ i))) |
| 2070 | (while (and (not (eobp)) (not found)) | 2075 | (aset str (1+ i) tmp) |
| 2071 | (transpose-chars 1) | 2076 | (when (member str (nth 2 poss)) |
| 2072 | (if (member (buffer-string) (nth 2 poss)) | 2077 | (save-excursion |
| 2073 | (setq found (point)) | 2078 | (goto-char (+ beg i 1)) |
| 2074 | (transpose-chars -1) | 2079 | (transpose-chars 1)) |
| 2075 | (forward-char)))) | 2080 | (throw 'done t)) |
| 2076 | (when found | 2081 | (setq tmp (aref str i)) |
| 2077 | (save-excursion | 2082 | (aset str i (aref str (1+ i))) |
| 2078 | (goto-char (+ beg found -1)) | 2083 | (aset str (1+ i) tmp) |
| 2079 | (transpose-chars -1) | 2084 | (setq i (1+ i)))) |
| 2080 | t))))) | 2085 | nil))) |
| 2081 | 2086 | ||
| 2082 | (defun flyspell-maybe-correct-doubling (beg end poss) | 2087 | (defun flyspell-maybe-correct-doubling (beg end poss) |
| 2083 | "Check replacements for doubled characters. | 2088 | "Check replacements for doubled characters. |
| @@ -2091,24 +2096,19 @@ possible corrections as returned by 'ispell-parse-output'. | |||
| 2091 | 2096 | ||
| 2092 | This function is meant to be added to 'flyspell-incorrect-hook'." | 2097 | This function is meant to be added to 'flyspell-incorrect-hook'." |
| 2093 | (when (consp poss) | 2098 | (when (consp poss) |
| 2094 | (let ((temp-buffer (get-buffer-create " *flyspell-temp*")) | 2099 | (catch 'done |
| 2095 | found) | 2100 | (let ((str (buffer-substring beg end)) |
| 2096 | (save-excursion | 2101 | (i 0) (len (- end beg))) |
| 2097 | (copy-to-buffer temp-buffer beg end) | 2102 | (while (< (1+ i) len) |
| 2098 | (set-buffer temp-buffer) | 2103 | (when (and (= (aref str i) (aref str (1+ i))) |
| 2099 | (goto-char (1+ (point-min))) | 2104 | (member (concat (substring str 0 (1+ i)) |
| 2100 | (while (and (not (eobp)) (not found)) | 2105 | (substring str (+ i 2))) |
| 2101 | (when (char-equal (char-after) (char-before)) | 2106 | (nth 2 poss))) |
| 2102 | (delete-char 1) | 2107 | (goto-char (+ beg i)) |
| 2103 | (if (member (buffer-string) (nth 2 poss)) | 2108 | (delete-char 1) |
| 2104 | (setq found (point)) | 2109 | (throw 'done t)) |
| 2105 | (insert-char (char-before) 1))) | 2110 | (setq i (1+ i)))) |
| 2106 | (forward-char))) | 2111 | nil))) |
| 2107 | (when found | ||
| 2108 | (save-excursion | ||
| 2109 | (goto-char (+ beg found -1)) | ||
| 2110 | (delete-char 1) | ||
| 2111 | t))))) | ||
| 2112 | 2112 | ||
| 2113 | ;*---------------------------------------------------------------------*/ | 2113 | ;*---------------------------------------------------------------------*/ |
| 2114 | ;* flyspell-already-abbrevp ... */ | 2114 | ;* flyspell-already-abbrevp ... */ |