]> git.eshelyaron.com Git - emacs.git/commitdiff
ispell.el,flyspell.el: Preserve session localwords when switching back buffers.
authorAgustín Martín <agustin.martin@hispalinux.es>
Mon, 23 Apr 2012 10:33:25 +0000 (12:33 +0200)
committerAgustín Martín <agustin.martin@hispalinux.es>
Mon, 23 Apr 2012 10:33:25 +0000 (12:33 +0200)
Once a word is declared valid for a session and a buffer it should
stay valid for that buffer regardless buffer switches unless ispell
process is explicitly killed or dictionary changed for that buffer.

However, it is currently lost when we switch to a different buffer
that triggers a new ispell process and then switch back to the
original buffer (triggering a  new ispell restart).

These changes try to keep buffer session localwords accepted in above
case.

lisp/ChangeLog
lisp/textmodes/flyspell.el
lisp/textmodes/ispell.el

index 5afe17b6f74e5d82a6637f57497294dbd1da9c63..5ead85734af146cf0f031a8ec4db73080a2a4796 100644 (file)
@@ -1,3 +1,19 @@
+2012-04-23  Agustín Martín Domingo  <agustin.martin@hispalinux.es>
+
+       Preserve ispell session localwords when switching back to
+       original buffer.
+
+       * ispell.el (ispell-buffer-session-localwords): New buffer-local
+       variable to hold buffer session localwords.
+       (ispell-kill-ispell): add option 'clear to delete session
+       localwords.
+       (ispell-command-loop, ispell-change-dictionary)
+       (ispell-buffer-local-words): Preserve session localwords when
+       needed.
+
+       * flyspell.el (flyspell-process-localwords, flyspell-do-correct):
+       Preserve session localwords when needed.
+
 2012-04-23  Agustín Martín Domingo  <agustin.martin@hispalinux.es>
 
        * ispell.el (ispell-insert-word) Remove unneeded function using
index 72a3eb474f8cc360e11e3529ebf07f702a94fe50..33fa551c8a4da74887b43f3c594fde90a9e97ae4 100644 (file)
@@ -1479,7 +1479,8 @@ The buffer to mark them in is `flyspell-large-region-buffer'."
 ;;*    declared correct.                                                */
 ;;*---------------------------------------------------------------------*/
 (defun flyspell-process-localwords (misspellings-buffer)
-  (let (localwords case-fold-search
+  (let ((localwords ispell-buffer-session-localwords)
+       case-fold-search
        (ispell-casechars (ispell-get-casechars)))
     ;; Get localwords from the original buffer
     (save-excursion
@@ -2147,6 +2148,9 @@ If OPOINT is non-nil, restore point there after adjusting it for replacement."
         (setq ispell-pdict-modified-p '(t)))
        ((or (eq replace 'buffer) (eq replace 'session))
         (ispell-send-string (concat "@" word "\n"))
+        (add-to-list 'ispell-buffer-session-localwords word)
+        (or ispell-buffer-local-name ; session localwords might conflict
+            (setq ispell-buffer-local-name (buffer-name)))
         (flyspell-unhighlight-at cursor-location)
         (if (null ispell-pdict-modified-p)
             (setq ispell-pdict-modified-p
index ba333117e08173c9e08d733fd16580168bc83a7a..db058d05f35cb5e100e12bd865882adc914c02ed 100644 (file)
@@ -1184,7 +1184,8 @@ The variable `ispell-library-directory' defines their location."
        `(menu-item ,(purecopy "Change Dictionary...") ispell-change-dictionary
                    :help ,(purecopy "Supply explicit dictionary file name")))
       (define-key ispell-menu-map [ispell-kill-ispell]
-       `(menu-item ,(purecopy "Kill Process") ispell-kill-ispell
+       `(menu-item ,(purecopy "Kill Process")
+                   (lambda () (interactive) (ispell-kill-ispell nil 'clear))
                    :enable (and (boundp 'ispell-process) ispell-process
                                 (eq (ispell-process-status) 'run))
                    :help ,(purecopy "Terminate Ispell subprocess")))
@@ -1268,7 +1269,7 @@ The variable `ispell-library-directory' defines their location."
             ["Continue Check"  ispell-continue                 t]
             ["Complete Word Frag"ispell-complete-word-interior-frag t]
             ["Complete Word"   ispell-complete-word            t]
-            ["Kill Process"    ispell-kill-ispell              t]
+            ["Kill Process"    (ispell-kill-ispell nil 'clear) t]
             ["Customize..."    (customize-group 'ispell)       t]
             ;; flyspell-mode may not be bound...
             ;;["flyspell"      flyspell-mode
@@ -1537,6 +1538,11 @@ local variable syntax.")
   "Contains the buffer name if local word definitions were used.
 Ispell is then restarted because the local words could conflict.")
 
+(defvar ispell-buffer-session-localwords nil
+  "List of words accepted for session in this buffer.")
+
+(make-variable-buffer-local 'ispell-buffer-session-localwords)
+
 (defvar ispell-parser 'use-mode-name
   "Indicates whether ispell should parse the current buffer as TeX Code.
 Special value `use-mode-name' tries to guess using the name of `major-mode'.
@@ -2025,6 +2031,9 @@ Global `ispell-quit' set to start location to continue spell session."
                    nil)
                   ((or (= char ?a) (= char ?A)) ; accept word without insert
                    (ispell-send-string (concat "@" word "\n"))
+                   (add-to-list 'ispell-buffer-session-localwords word)
+                   (or ispell-buffer-local-name ; session localwords might conflict
+                       (setq ispell-buffer-local-name (buffer-name)))
                    (if (null ispell-pdict-modified-p)
                        (setq ispell-pdict-modified-p
                              (list ispell-pdict-modified-p)))
@@ -2770,13 +2779,16 @@ Keeps argument list for future ispell invocations for no async support."
              (process-kill-without-query ispell-process)))))))
 
 ;;;###autoload
-(defun ispell-kill-ispell (&optional no-error)
+(defun ispell-kill-ispell (&optional no-error clear)
   "Kill current Ispell process (so that you may start a fresh one).
-With NO-ERROR, just return non-nil if there was no Ispell running."
+With NO-ERROR, just return non-nil if there was no Ispell running.
+With CLEAR, buffer session localwords are cleaned."
   (interactive)
   ;; This hook is typically used by flyspell to flush some variables used
   ;; to optimize the common cases.
   (run-hooks 'ispell-kill-ispell-hook)
+  (if (or clear (interactive-p))
+      (setq ispell-buffer-session-localwords nil))
   (if (not (and ispell-process
                (eq (ispell-process-status) 'run)))
       (or no-error
@@ -2837,6 +2849,7 @@ By just answering RET you can find out what the current dictionary is."
               (setq ispell-local-dictionary-overridden t))
           (error "Undefined dictionary: %s" dict))
         (ispell-internal-change-dictionary)
+        (setq ispell-buffer-session-localwords nil)
         (message "%s Ispell dictionary set to %s"
                  (if arg "Global" "Local")
                  dict))))
@@ -3906,6 +3919,11 @@ Both should not be used to define a buffer-local dictionary."
   ;; Actually start a new ispell process, because we need
   ;; to send commands now to specify the local words to it.
   (ispell-init-process)
+  (dolist (session-localword ispell-buffer-session-localwords)
+    (ispell-send-string (concat "@" session-localword "\n")))
+  (or ispell-buffer-local-name
+      (if ispell-buffer-session-localwords
+         (setq ispell-buffer-local-name (buffer-name))))
   (save-excursion
     (goto-char (point-min))
     (while (search-forward ispell-words-keyword nil t)