all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Agustin Martin <agustin.martin@hispalinux.es>
To: emacs-devel@gnu.org
Subject: Re: Adding ispell-multi.el and friends to Emacs
Date: Tue, 19 Jun 2007 17:13:34 +0200	[thread overview]
Message-ID: <20070619151333.GA3891@agmartin.aq.upm.es> (raw)
In-Reply-To: <46767C80.4010505@gmx.at>

[-- Attachment #1: Type: text/plain, Size: 2551 bytes --]

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

[-- Attachment #2: flyspell.el_session_localwords.diff --]
[-- Type: text/x-diff, Size: 1024 bytes --]

--- 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

[-- Attachment #3: ispell.el_session_localwords.diff --]
[-- Type: text/x-diff, Size: 3609 bytes --]

--- 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)

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

  reply	other threads:[~2007-06-19 15:13 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-14 12:58 Adding ispell-multi.el and friends to Emacs Peter Heslin
2007-06-15  8:48 ` Richard Stallman
2007-06-15 23:00   ` Peter Heslin
2007-06-16 18:50     ` Richard Stallman
2007-06-16 19:46       ` Frank Schmitt
2007-06-17 21:05         ` Agustin Martin
2007-06-17 21:31           ` Juri Linkov
2007-06-17 23:11             ` Peter Heslin
2007-06-18  9:55               ` Agustin Martin
2007-06-18 12:35                 ` martin rudalics
2007-06-19 13:14                   ` Agustin Martin
2007-06-20 12:46                     ` martin rudalics
2007-06-20 23:09                       ` Agustin Martin
2007-06-21 18:44                 ` Davis Herring
2007-06-18 21:31               ` Richard Stallman
2007-06-15  9:21 ` martin rudalics
2007-06-15 22:53   ` Peter Heslin
2007-06-16 10:03     ` martin rudalics
2007-06-16 10:55     ` Eli Zaretskii
2007-06-16 12:24       ` martin rudalics
2007-06-18 10:02     ` Agustin Martin
2007-06-18 12:37       ` martin rudalics
2007-06-19 15:13         ` Agustin Martin [this message]
2007-06-20 12:47           ` martin rudalics
2007-06-20 23:33             ` Agustin Martin
2007-06-21 17:32               ` Richard Stallman
2007-06-21 17:59                 ` David Kastrup
2007-06-21 21:39                 ` Peter Heslin
2007-06-22 16:24                   ` Richard Stallman
2007-06-22 21:22                     ` Peter Heslin
2007-06-23 18:26                       ` Richard Stallman
2008-01-13 17:19                         ` Dan Nicolaescu
2007-06-21 21:25               ` Peter Heslin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070619151333.GA3891@agmartin.aq.upm.es \
    --to=agustin.martin@hispalinux.es \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.