+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
;;* 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
(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
`(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")))
["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
"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'.
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)))
(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
(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))))
;; 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)