Subject: Re: bug#6539: ispell-complete-word looks for wrong file (at least on w32)

From: Agustin Martin <[email-masked]>
Date: Mon, 5 Jul 2010 13:52:22 +0200

On Wed, Jun 30, 2010 at 08:35:35PM +0300, Eli Zaretskii wrote:
> > Date: Wed, 30 Jun 2010 14:27:47 +0200
> > From: Agustin Martin <[email-masked]>
> > Cc: 
> > 
> > > > I think that this bug report can be closed or renamed to something like
> > > > 'Improve `ispell-alternate-dictionary' docstring'.
> > > 
> > > I think the default for ispell-alternate-dictionary should be changed on w32.
> > 
> > Or, more globally, find a good and not confusing name for default personal 
> > plain wordlist that can be used in every system, be it w32 or not, so it is 
> > tried first in `ispell-alternate-dictionary', something like
> > 
> > (expand-file-name "~/.personal.words")
> 
> How will that help, exactly?  /usr/dict/words exists on almost every
> Posix system, which is why ispell.el has that as the default.  But
> there's no comparable functionality on Windows, so the only way of
> getting this work on Windows is to find or download such a file from
> somewhere, and manually install it in some arbitrary directory.  How
> is Emacs supposed to know whether such a file exists, and where?

[Really attaching diff]

My initial intention was to provide an out-of-the box default for personal
wordlist, useful for both w32 and *X systems. However, as you point out in
another message, since this is originally an Ispell feature, I think I
should not add an Emacs specific difference. Customizing
`ispell-alternate-dictionary' (or `ispell-complete-word-dict') seems the 
way to go.

However, docstrings and error handling for this complete-word stuff needs 
to be improved, so it provides useful and accurate information. I am 
currently trying something like attached patch where 
`ispell-alternate-dictionary' is set to nil if no default is found and 
checked before use. I find error message too long, but better that before.
As usually, suggestions are welcome.

It also changes `file-exists-p' to `file-readable-p' in
`ispell-alternate-dictionary' definition.

I have also noticed that ispell.el uses `ispell-alternate-dictionary' and
`ispell-complete-word-dict' in a way that seems to be interchangeable, but
confusing. The former was probably used at some time as a real alternate
dictionary for spellchecking, but current use seems to be for completion.
Have to think a bit more about this.

Cheers,

-- 
Agustin
--- ispell.el.orig	2010-07-05 11:31:21.000000000 +0200
+++ ispell.el	2010-07-05 13:25:03.000000000 +0200
@@ -357,21 +357,20 @@
   :group 'ispell)
 
 (defcustom ispell-alternate-dictionary
-  (cond ((file-exists-p "/usr/dict/web2") "/usr/dict/web2")
-	((file-exists-p "/usr/share/dict/web2") "/usr/share/dict/web2")
-	((file-exists-p "/usr/dict/words") "/usr/dict/words")
-	((file-exists-p "/usr/lib/dict/words") "/usr/lib/dict/words")
-	((file-exists-p "/usr/share/dict/words") "/usr/share/dict/words")
-	((file-exists-p "/usr/share/lib/dict/words")
+  (cond ((file-readable-p "/usr/dict/web2") "/usr/dict/web2")
+	((file-readable-p "/usr/share/dict/web2") "/usr/share/dict/web2")
+	((file-readable-p "/usr/dict/words") "/usr/dict/words")
+	((file-readable-p "/usr/lib/dict/words") "/usr/lib/dict/words")
+	((file-readable-p "/usr/share/dict/words") "/usr/share/dict/words")
+	((file-readable-p "/usr/share/lib/dict/words")
 	 "/usr/share/lib/dict/words")
-	((file-exists-p "/sys/dict") "/sys/dict")
-	(t "/usr/dict/words"))
-  "*Alternate dictionary for spelling help."
+	((file-readable-p "/sys/dict") "/sys/dict"))
+  "*Alternate plain word-list dictionary for spelling help."
   :type '(choice file (const :tag "None" nil))
   :group 'ispell)
 
 (defcustom ispell-complete-word-dict ispell-alternate-dictionary
-  "*Dictionary used for word completion."
+  "*Plain word-list dictionary used for word completion."
   :type '(choice file (const :tag "None" nil))
   :group 'ispell)
 
@@ -2273,6 +2272,12 @@
   (if (null lookup-dict)
       (setq lookup-dict ispell-alternate-dictionary))
 
+  (if lookup-dict
+      (unless (file-readable-p lookup-dict)
+	(error "lookup-words error: Unreadable or missing plain word-list %s."
+	       lookup-dict))
+    (error "lookup-words error: No plain word-list found at system default locations. Customize `ispell-alternate-dictionary' to set yours."))
+
   (let* ((process-connection-type ispell-use-ptys-p)
 	 (wild-p (string-match "\\*" word))
 	 (look-p (and ispell-look-p	; Only use look for an exact match.