From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Agustin Martin Newsgroups: gmane.emacs.devel Subject: Re: Adding ispell-multi.el and friends to Emacs Date: Tue, 19 Jun 2007 17:13:34 +0200 Message-ID: <20070619151333.GA3891@agmartin.aq.upm.es> References: <87zm32k7zl.fsf@dur.ac.uk> <46725A27.4070406@gmx.at> <87ir9ohlt1.fsf@heslin.eclipse.co.uk> <20070618100200.GB4724@agmartin.aq.upm.es> <46767C80.4010505@gmx.at> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="WIyZ46R2i8wDzkSu" X-Trace: sea.gmane.org 1182266026 6038 80.91.229.12 (19 Jun 2007 15:13:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 19 Jun 2007 15:13:46 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 19 17:13:44 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1I0fOo-00075l-Vf for ged-emacs-devel@m.gmane.org; Tue, 19 Jun 2007 17:13:43 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I0fOo-0002wR-0s for ged-emacs-devel@m.gmane.org; Tue, 19 Jun 2007 11:13:42 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I0fOk-0002wG-SE for emacs-devel@gnu.org; Tue, 19 Jun 2007 11:13:38 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I0fOj-0002uq-9x for emacs-devel@gnu.org; Tue, 19 Jun 2007 11:13:37 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I0fOj-0002uZ-6j for emacs-devel@gnu.org; Tue, 19 Jun 2007 11:13:37 -0400 Original-Received: from edison.ccupm.upm.es ([138.100.4.49]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1I0fOi-0007Zv-Gf for emacs-devel@gnu.org; Tue, 19 Jun 2007 11:13:36 -0400 Original-Received: from mala.aq.upm.es (Agmartin.aq.upm.es [138.100.41.131]) by edison.ccupm.upm.es (8.13.8/8.13.8) with ESMTP id l5JFDY9e030792; Tue, 19 Jun 2007 17:13:34 +0200 Original-Received: by mala.aq.upm.es (Postfix, from userid 1000) id 23CF12F11; Tue, 19 Jun 2007 17:13:34 +0200 (CEST) Mail-Followup-To: emacs-devel@gnu.org Content-Disposition: inline In-Reply-To: <46767C80.4010505@gmx.at> User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: Linux 2.4-2.6 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:73311 Archived-At: --WIyZ46R2i8wDzkSu Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Jun 18, 2007 at 02:37:20PM +0200, martin rudalics wrote: > > Current ispell.el behavior wrt localwords when switching buffers with the > > same language is to restart ispell if localwords are present, to avoid the > > problem of conflicting localwords. > > With the consequence that all "session-local" words are lost. But the underlying problem is the lack of full support for buffer session-local words. I have been playing a bit with ispell.el and flyspell.el to try dealing with this. I am attaching a couple of patches with the current status of my experiments. Note that they are minimally tested, but seem to work reasonably. A new buffer local variable `ispell-buffer-session-localwords' is used that will contain a list of words accepted for session in each buffer. Each time a buffer is parsed for localwords, those sesion localwords are sent to the ispell process as accepted and the buffer marked as having localwords. same when a word is accepted for session by either ispell.el or flyspell.el. A new option CLEAR is added to (ispell-kill-ispell). For a buffer `ispell-buffer-session-localwords' is cleaned when dict is explicitely changed for that buffer with (ispell-change-dictionary) or when ispell process is killed, either interactively or through the pop-up menu (using the 'clear). flyspell.el is modified for the same purpose. I will try to test this more in depth, but I think the ideas behind the changes are reasonable. > > If ispell-multi.el starts a new ispell > > process in this case, keeping two processes for the same language, it > might > > also be made aware that words are accepted for that buffer session. > > ispell-multi.el seems to be able to retain "session-local" words for the > original buffer. If they are present (or introduced) it should probably > start a new process for the second buffer. As long as the ispell process is not killed those words will remain accepted. > A different problem occurs when you check one and the same buffer with > multiple processes: In this case "session-local" words should be shared > by all processes checking this buffer. Otherwise, an abbreviation would > be marked erroneous by the French process and not marked by the Italian > one. As I mentioned earlier, it's much simpler to have Emacs maintain > these words in buffer-local hash-lists and have Emacs override the > results reported by the spell processes. I do not think there is currently support for multi-language buffer accepted localwords, so that seems indeed simpler. -- Agustin --WIyZ46R2i8wDzkSu Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="flyspell.el_session_localwords.diff" --- flyspell.el.orig 2007-06-19 15:04:09.000000000 +0200 +++ flyspell.el 2007-06-19 15:04:21.000000000 +0200 @@ -1445,7 +1445,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 @@ -2085,6 +2086,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 --WIyZ46R2i8wDzkSu Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="ispell.el_session_localwords.diff" --- ispell.el.orig 2007-06-19 15:04:13.000000000 +0200 +++ ispell.el 2007-06-19 15:04:37.000000000 +0200 @@ -1050,7 +1050,8 @@ '(menu-item "Change Dictionary..." ispell-change-dictionary :help "Supply explicit dictionary file name")) (define-key ispell-menu-map [ispell-kill-ispell] - '(menu-item "Kill Process" ispell-kill-ispell + '(menu-item "Kill Process" + (lambda () (interactive) (ispell-kill-ispell nil 'clear)) :enable (and (boundp 'ispell-process) ispell-process (eq (ispell-process-status) 'run)) :help "Terminate Ispell subprocess")) @@ -1132,7 +1133,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 t 'clear] ["Customize..." (customize-group 'ispell) t] ;; flyspell-mode may not be bound... ;;["flyspell" flyspell-mode @@ -1397,6 +1398,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'. @@ -1875,6 +1881,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))) @@ -2554,13 +2563,16 @@ (set-process-query-on-exit-flag ispell-process nil)))) ;;;###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 @@ -2622,6 +2634,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)))) @@ -3708,6 +3721,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) --WIyZ46R2i8wDzkSu Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --WIyZ46R2i8wDzkSu--