unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#52743: 29.0.50; Ispell completion-at-point function
@ 2021-12-22 23:24 Eric Abrahamsen
       [not found] ` <handler.52743.B.164021551331652.ack@debbugs.gnu.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Abrahamsen @ 2021-12-22 23:24 UTC (permalink / raw)
  To: 52743


Ispell doesn't currently come with a function suitable for use in
`completion-at-point-functions' -- there's a FIXME comment to that
effect on `ispell-complete-word'.

I really don't think that `flyspell-mode' should be clobbering C-M-i by
default, and replacing it with `flyspell-auto-correct-word': this
essentially bypasses the entire capf machinery, and means you can't
combine dictionary-based completion with any other completion.

I've taken a stab at writing an `ispell-completion-at-point' function,
to be added to `completion-at-point-functions'. Perhaps
`flyspell-use-meta-tab' could be extended to accept the symbol 'capf, in
which case `ispell-completion-at-point' would be added to
`c-a-p-functions', and M-TAB/C-M-i would be left alone.

The function currently doesn't work very well. I don't know what the
`ispell-filter' is, or why it raises an error with "Ispell and its
process have different character maps", but I'm sure I can figure that
out. I wanted to raise this here first, to get some feedback.

I know capf prefers its functions to simply return a table, but that
seems unwieldy when we're talking about a completion dictionary with
potentially hundreds of thousands of entries. The function below tries
two things:

- ispell-lookup-words, which uses the ispell process against
  `ispell-complete-word-dict' and `ispell-alternate-dictionary' to find
  completions.
- ispell--run-on-word, which does a full spell-check on the word, and
  returns a list of potential corrections. This function and its return
  value are more complicated than I fully understand now, but I can
  spend some time figuring them out.

So both options involve invoking the ispell process, and the function
does the filtering itself. I know this isn't optimal, and I could also
do a version that reads ispell-complete-word-dict or
ispell-alternate-dictionary and returns the whole contents, with
caching.

(defun ispell-completion-at-point ()
  (condition-case nil
      (progn
	(ispell-set-spellchecker-params)
	(ispell-accept-buffer-local-defs)
	(pcase-let* ((`(,word ,start ,end) (ispell-get-word nil))
		     (table
		      (or (ignore-errors (ispell-lookup-words word))
			  (let ((run-return (ispell--run-on-word word)))
			    (when (and (listp run-return)
				       (> (length run-return) 0))
			      run-return)))))
	  (list start end table)))
    ;; `user-error' is signaled when ispell fails to find a word to
    ;; work on, in which case we want to silently return nil.
    (user-error nil)))


Anyway, please comment!

Eric





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#52743: Acknowledgement (29.0.50; Ispell completion-at-point function)
       [not found] ` <handler.52743.B.164021551331652.ack@debbugs.gnu.org>
@ 2021-12-24  1:51   ` Eric Abrahamsen
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Abrahamsen @ 2021-12-24  1:51 UTC (permalink / raw)
  To: 52743; +Cc: monnier

Politely cc'ing Stefan, who is probably the only person who cares about this...





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-24  1:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-22 23:24 bug#52743: 29.0.50; Ispell completion-at-point function Eric Abrahamsen
     [not found] ` <handler.52743.B.164021551331652.ack@debbugs.gnu.org>
2021-12-24  1:51   ` bug#52743: Acknowledgement (29.0.50; Ispell completion-at-point function) Eric Abrahamsen

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).