From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.bugs Subject: bug#52743: 29.0.50; Ispell completion-at-point function Date: Wed, 22 Dec 2021 15:24:55 -0800 Message-ID: <877dbw8bp4.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15724"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) To: 52743@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 23 00:26:11 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n0Azp-0003u2-NR for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 23 Dec 2021 00:26:09 +0100 Original-Received: from localhost ([::1]:59096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n0Azo-0005pY-6A for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Dec 2021 18:26:08 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n0Azi-0005pO-4k for bug-gnu-emacs@gnu.org; Wed, 22 Dec 2021 18:26:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48454) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n0Azh-0002Ip-RS for bug-gnu-emacs@gnu.org; Wed, 22 Dec 2021 18:26:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n0Azh-0008Fe-PL for bug-gnu-emacs@gnu.org; Wed, 22 Dec 2021 18:26:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eric Abrahamsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 Dec 2021 23:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 52743 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.164021551331652 (code B ref -1); Wed, 22 Dec 2021 23:26:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Dec 2021 23:25:13 +0000 Original-Received: from localhost ([127.0.0.1]:60000 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n0Ayv-0008ES-8O for submit@debbugs.gnu.org; Wed, 22 Dec 2021 18:25:13 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:60594) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n0Ays-0008EI-On for submit@debbugs.gnu.org; Wed, 22 Dec 2021 18:25:11 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:43164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n0Ays-0005fO-GH for bug-gnu-emacs@gnu.org; Wed, 22 Dec 2021 18:25:10 -0500 Original-Received: from mail.ericabrahamsen.net ([52.70.2.18]:36400) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n0Aym-00024n-Gr for bug-gnu-emacs@gnu.org; Wed, 22 Dec 2021 18:25:10 -0500 Original-Received: from localhost (c-71-197-232-41.hsd1.wa.comcast.net [71.197.232.41]) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id C7979FA093 for ; Wed, 22 Dec 2021 23:24:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericabrahamsen.net; s=mail; t=1640215497; bh=vMklkQtEsaGV2+SmlMgKdpndfZl3hV2UmQSviVlaDak=; h=From:To:Subject:Date:From; b=UrhB8SUSJP41wIOxMRpZo9PVE2bFDxAkdJHAgyLG9uDvbzw2LZZlbp/daTMCytQZY v0CVI7rXEbI+ewtlT6sw7QAnbEu7WUozY1skcZXPqJsPNiK5G2BQTjqwWP80l037Iy OkNz+uDx2SNhH27xlsHpgsMtFOkcxwUxWBElBzsY= Received-SPF: pass client-ip=52.70.2.18; envelope-from=eric@ericabrahamsen.net; helo=mail.ericabrahamsen.net X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:222964 Archived-At: 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