emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r108006: ispell.el, flyspell.el: Pres


From: Agustin Martin
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r108006: ispell.el, flyspell.el: Preserve session localwords when switching back buffers.
Date: Mon, 23 Apr 2012 12:33:25 +0200
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 108006
committer: Agustin Martin <address@hidden>
branch nick: trunk
timestamp: Mon 2012-04-23 12:33:25 +0200
message:
  ispell.el,flyspell.el: Preserve session localwords when switching back 
buffers.
  
  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.
modified:
  lisp/ChangeLog
  lisp/textmodes/flyspell.el
  lisp/textmodes/ispell.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-04-23 10:03:33 +0000
+++ b/lisp/ChangeLog    2012-04-23 10:33:25 +0000
@@ -1,5 +1,21 @@
 2012-04-23  Agustín Martín Domingo  <address@hidden>
 
+       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  <address@hidden>
+
        * ispell.el (ispell-insert-word) Remove unneeded function using
        obsolete `translation-table-for-input'.
        (ispell-word, ispell-process-line, ispell-complete-word): Use

=== modified file 'lisp/textmodes/flyspell.el'
--- a/lisp/textmodes/flyspell.el        2012-04-12 14:19:40 +0000
+++ b/lisp/textmodes/flyspell.el        2012-04-23 10:33:25 +0000
@@ -1479,7 +1479,8 @@
 ;;*    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 @@
         (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

=== modified file 'lisp/textmodes/ispell.el'
--- a/lisp/textmodes/ispell.el  2012-04-23 10:03:33 +0000
+++ b/lisp/textmodes/ispell.el  2012-04-23 10:33:25 +0000
@@ -1184,7 +1184,8 @@
        `(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 @@
             ["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 @@
   "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 @@
                    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 @@
              (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 @@
               (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 @@
   ;; 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)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]