Subject: bug#15903: 24.3.50; Fix small issue with ispell-hunspell when dictionary is set to default (nil)

From: Vladimir Lomov <[email-masked]>
Date: Mon, 18 Nov 2013 15:33:00 +0900

Hello,
** Agustin Martin [2013-11-16 12:43:02 +0100]:

> 2013/11/15 Vladimir Lomov <[email-masked]>

>> Hello,
>> according to variable 'ispell-dictionary-base-alist' defined in
>> 'ispell.el' if 'ispell-dictionary' is nil then it is considered as
>> default value for dictionary. Unfortunately, when hunspell is used as
>> ispell program function 'ispell-parse-hunspell-affix-file' fails because
>> it doesn't expect nil as argument.

>> I propose small and simple patch. I checked it starting emacs as:
>>   emacs -Q
>> and evaluating in *scratch*:
>>   (setq ispell-program-name "hunspell")
>>   (setq ispell-really-hunspell t)
>> after that I run 'M-$' while point is on first 's' of
>>   (message)

>> In minibuffer I see
>>   MESSAGE is correct

>> Without this patch the same steps lead to message
>>   ispell-phaf: No matching entry for nil.

> Hi,

> Cannot reproduce it here. By the way, once initialized for hunspell
> ispell.el provides a match for default (nil) value, here

> (nil [[:alpha:]] [^[:alpha:]] ['] nil (-B) nil utf-8)

Wouldn't you mind to share how you get this?

I tried hard to prepare minimal example to catch when the problem
appears but I know a very little of Emacs Lisp.

This is my investigation and results.

My system:
OS: Archlinux x86_64,
Emacs: compiled from trunk (rev. 115132), with original ispell.el
env. variables:
  DICTIONARY=russian
  LANG=ru_RU.UTF-8
  LC_CTYPE="ru_RU.UTF-8"
  LC_NUMERIC="ru_RU.UTF-8"
  LC_TIME="ru_RU.UTF-8"
  LC_COLLATE=C
  LC_MONETARY="ru_RU.UTF-8"
  LC_MESSAGES="ru_RU.UTF-8"
  LC_PAPER="ru_RU.UTF-8"
  LC_NAME="ru_RU.UTF-8"
  LC_ADDRESS="ru_RU.UTF-8"
  LC_TELEPHONE="ru_RU.UTF-8"
  LC_MEASUREMENT="ru_RU.UTF-8"
  LC_IDENTIFICATION="ru_RU.UTF-8"
  LC_ALL=
aspell: @(#) International Ispell Version 3.1.20 (but really Aspell 0.60.6.1)
hunspell: @(#) International Ispell Version 3.2.06 (but really Hunspell 1.3.2)

System has both Russian and English dictionaries.

I tested both aspell and hunspell variants. Emacs is started from rxvt
terminal as
  emacs -Q -l min-VARIANT.el
both min-VARIANT.el, VARIANT={a,hun}spell are attached (and also can be
found in repository https://bitbucket.org/vp1981/issues,
https://bitbucket.org/vp1981/issues/src/452f8c393983a875cb46e96d9c9b5d42cb5e1dc7/emacs/ispell/?at=default)

Then I open one of three test files VARIANT-exN.el, (N=,2,3) and
evaluate commands. The only difference between test files is that
- VARIANT-ex.el:  dictionary is not set explicitly,
- VARIANT-ex2.el: dictionary is set to string 'english',
- VARIANT-ex3.el: dictionary is set to nil,

The rest of test files are the same:
1. output values of several variables: ispell-VARIANT-dictionary-alist,
   ispell-dictionary and ispell-{local,current}-dictionary;
2. run 'ispell-word';
3. output values of the same variables;
4. run 'ispell-word' again;
5. output values of the same variables.

Results are shown in table

         \  |      aspell       |     hunspell
Test file \ | 1 | 2 | 3 | 4 | 5 | 1 | 2 | 3 | 4 | 5 |
------------+---+---+---+---+---+---+---+---+---+---+
   ex.el    | n | - | + | - | + | n |e11| + |e12| + |
  ex2.el    | n |+n | + |+n | + | n |e11| + |e2 | + |
  ex3.el    | n | - | + | - | + | n |e11| + |e12| + |

Here:
n:   means 'nil' (return value);
+n:  means successful run and nil is returned;
+:   means successful run;
-:   means 'ispell-word' was run but seems can't find word "message" in
     a dictionary (may be it didn't use any);
e1*: 'ispell-phaf' error (No matching entry for nil);
     difference between e11 and e12 is that first calls 'find-dictionaries'
     while second one calls 'fill-dictionary-entry';
e2:  Lisp error, (No data for dictionary \"english\"...)

Reports (backtrace) from Debugger are attached.

What I expect in all cases:
if either dictionary set to a valid string, to nil or doesn't set at
all, call of 'ispell-word' (or M-$) should give result, may be zero
one but not an error.

These test files show (on my system) some problem with ispell. Of course
I could be wrong and do something unusual but I tried to minimize any
side-effects of my /real/ Emacs configuration.

If I apply patch proposed in first message and run tests again (only
hunspell part) then all three test files would give positive results
(evaluating 'ispell-word' function gives nil, M-$ gives message in
minibuffer "MESSAGE is correct").

P.S. Seems there might be a problem with aspell but here I want to clarify
issue with hunspell.

---
WBR, Vladimir Lomov

-- 
Churchill's Commentary on Man:
	Man will occasionally stumble over the truth,
	but most of the time he will pick himself up and continue on.