From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#50959: [PATCH] Re: bug#50959: 28.0.50; Shorthand symbols are unknown to Emacs Date: Wed, 06 Oct 2021 11:45:11 +0100 Message-ID: <874k9uwhxk.fsf_-_@gmail.com> References: <16338bdc2497fc51c6fb6d54ab370bfb@webmail.orcon.net.nz> <83y27gijmz.fsf@gnu.org> <8335pmgnjy.fsf@gnu.org> <604da2cb10ac61f2b8b89a02c89056be@webmail.orcon.net.nz> <83a6jtff87.fsf@gnu.org> <5ac7a31cf2959c31c262a3377c736a5a@webmail.orcon.net.nz> <83ilygew7p.fsf@gnu.org> <83fstjdiwl.fsf@gnu.org> <837devdcz0.fsf@gnu.org> <93767e0236e7e85d27186293e38d3d25@webmail.orcon.net.nz> <8335pjd974.fsf@gnu.org> <87v92f3d15.fsf@gmail.com> <83y27bbs4d.fsf@gnu.org> <87mtnr3chk.fsf@gmail.com> <8735pj3amy.fsf@gmail.com> <83r1d3boeh.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32348"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.60 (gnu/linux) Cc: Phil Sainty , 50959@debbugs.gnu.org, Stefan Monnier , rms@gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 06 12:46:16 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 1mY4RD-0008AZ-IY for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 06 Oct 2021 12:46:15 +0200 Original-Received: from localhost ([::1]:58602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mY4RB-0002y0-FB for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 06 Oct 2021 06:46:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mY4R0-0002xb-QR for bug-gnu-emacs@gnu.org; Wed, 06 Oct 2021 06:46:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59363) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mY4R0-0003O2-48 for bug-gnu-emacs@gnu.org; Wed, 06 Oct 2021 06:46:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mY4Qz-0005TI-V9 for bug-gnu-emacs@gnu.org; Wed, 06 Oct 2021 06:46:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 06 Oct 2021 10:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50959 X-GNU-PR-Package: emacs Original-Received: via spool by 50959-submit@debbugs.gnu.org id=B50959.163351712020975 (code B ref 50959); Wed, 06 Oct 2021 10:46:01 +0000 Original-Received: (at 50959) by debbugs.gnu.org; 6 Oct 2021 10:45:20 +0000 Original-Received: from localhost ([127.0.0.1]:42676 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mY4QK-0005SE-51 for submit@debbugs.gnu.org; Wed, 06 Oct 2021 06:45:20 -0400 Original-Received: from mail-wr1-f43.google.com ([209.85.221.43]:37554) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mY4QG-0005S0-Kg for 50959@debbugs.gnu.org; Wed, 06 Oct 2021 06:45:19 -0400 Original-Received: by mail-wr1-f43.google.com with SMTP id e12so7461544wra.4 for <50959@debbugs.gnu.org>; Wed, 06 Oct 2021 03:45:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=jE1nWPv8g4H/ESI8yerT8NvmR5+taiLq26MMft3EL5s=; b=adLe6IVokIbJorNTeGJtB5sM3Z6mfGsfoA40GJDVbPt6xOR8KpU+2hq6XGrBJwba0/ GbQaxg6qRxBJz1PX1qKEJDKDHyI43pJUR4OtqgXswvbifMyaeAmzqdEWgYnYdhVwZiR3 g7xaGH446j0vDJyYF8RUb0XT3PXUt+k6PC4CIj3Lit4tT7KT61XseyMjYgItV1Gn5J14 PB32N8ggTDgLlBKV0J4I2mEWet3XCw6inzQPo/TCyXcuQ75vn+G3GA8nTjufcyTBiQRD 2Jpd0mxGICfvEqkhLg/qYntrvkW8xwQH6ukuO6odH1B85sPCoN4lMrhGsu5r6vWxL8DA HC+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=jE1nWPv8g4H/ESI8yerT8NvmR5+taiLq26MMft3EL5s=; b=7aIUhxkZgWlfY5d4BgzHZ/cGZuodmiqFJMkRGXWyo9MhEdO6FFJ/R0H8AOF6dMxtEJ 28XtR2e5d6naI1P2Gt1tHIGZYQH/9lfs8XanOscJ+w3LiuhPgM3UPp/v7/ptj2KDhZvK 0TTdZrgb8plbifpKS8qB7ShwYzbxHwfy6H2yeLL41V+5rEE3MP3MWKA2EWh2Fr9khlbn gF5VVEgjYAzSznBKn2wBtO7lAt/mhl2F9nluJPk4g6IsTQFQU0FsXIoc2QzRrLof7aqI 4MYmtcskIHn+m+epkxfaPogNl0s8ejXmD6uDr81V4XOJZQ2KuciMiP5xbCA0IZsmiABk wbEw== X-Gm-Message-State: AOAM531YHpLhQ3FKxs2dsm/b3NWRLzwcDB/OXXuHGElJ/ipaDpUapREn 3oI9PYYX3LCR5SFsmt47rz4KE3Gqg2E= X-Google-Smtp-Source: ABdhPJy/ZAXJYC+1mBAJ94IHuChSreOtXTMJ6ArQGu35qBDTh5RxfnDcZ4ydz9UghRmxjlq7dDwkmg== X-Received: by 2002:adf:a3c9:: with SMTP id m9mr25047712wrb.237.1633517110468; Wed, 06 Oct 2021 03:45:10 -0700 (PDT) Original-Received: from krug ([87.196.156.235]) by smtp.gmail.com with ESMTPSA id o12sm1239738wrw.73.2021.10.06.03.45.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 03:45:09 -0700 (PDT) In-Reply-To: ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Sat, 2 Oct 2021 15:02:41 +0100") 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:216539 Archived-At: Jo=C3=A3o T=C3=A1vora writes: > On Sat, Oct 2, 2021 at 1:30 PM Eli Zaretskii wrote: >> > 0. no integration >> > >> > 1. This is the current integration. I.e. when C-h o is pressed on the >> > symbol the global name is discovered and used as the default. This >> > is how SLIME work with CL's namespacing system. SLIME is a very we= ll >> > tested and widely appreciated Common Lisp IDE for Emcas. >> > >> > 2. The shorthands from the buffer where the minibuffer was entered are >> > _not_ in the completions list, but typing one of them interns the >> > symbol with those shorthands present, so you get the desired result. >> > This would fix Phil's visually-copy-and-type scenario. >> > >> > 3. The completion list would be augmented with the shorthands from >> > the buffer where the minibuffer was entered from. Hello Eli, I've implemented a variation on 2 based on the later suggestion you gave in emacs-devel: > That is, the user types "C-h o s-foo " and that > replaces s-foo with the expansion, the "real" symbol. Is that > feasible? Yes, it is. is, of course, TAB. Here is a patch for people to try out which I will push in a few days time if there are no objections. Cc-ing completion-style specialist Stefan. Patch just below, Jo=C3=A3o commit f9f64c4b3287d7276c8edeacdecfa9c78194447b Author: Jo=C3=A3o T=C3=A1vora Date: Wed Oct 6 11:30:29 2021 +0100 Complete shorthands to longhands for symbol-completing tables =20=20=20=20 Shorthands aren't symbols, they're text forms that 'read' into symbols. As such, shorthands aren't candidates in these tables of symbols. But in some situations, if no other candidates match the pattern, we can e.g. complete "x-foo" to "xavier-foo" if the shorthand =20=20=20=20 (("x-" . "xavier-")) =20=20=20=20 is set up in the buffer of origin. =20=20=20=20 bug#50959 =20=20=20=20 * lisp/help-fns.el (help--symbol-completion-table): Report `symbol-help' category. =20=20=20=20 * lisp/minibuffer.el (completion-styles-alist): New 'shorthand' style. (completion-category-defaults): Link 'symbol-help' category with 'shorthand' style. (minibuffer--original-buffer): New variable. (completing-read-default): Setup minibuffer--original-buffer. (completion-shorthand-try-completion) (completion-shorthand-all-completions): New helpers. diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 6be5cd4a50..03bbc979a9 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -176,8 +176,11 @@ help--symbol-completion-table-affixation completions)) =20 (defun help--symbol-completion-table (string pred action) - (if (and completions-detailed (eq action 'metadata)) - '(metadata (affixation-function . help--symbol-completion-table-affi= xation)) + (if (eq action 'metadata) + `(metadata + ,@(when completions-detailed + '((affixation-function . help--symbol-completion-table-affixat= ion))) + (category . symbol-help)) (when help-enable-completion-autoload (let ((prefixes (radix-tree-prefixes (help-definition-prefixes) stri= ng))) (help--load-prefixes prefixes))) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 1e1a6f852e..48859585bc 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -943,7 +943,12 @@ completion-styles-alist completion-initials-try-completion completion-initials-all-completions "Completion of acronyms and initialisms. E.g. can complete M-x lch to list-command-history -and C-x C-f ~/sew to ~/src/emacs/work.")) +and C-x C-f ~/sew to ~/src/emacs/work.") + (shorthand + completion-shorthand-try-completion completion-shorthand-all-completi= ons + "Completion of symbol shorthands setup in `read-symbol-shorthands'. +E.g. can complete \"x-foo\" to \"xavier-foo\" if the shorthand +((\"x-\" . \"xavier-\")) is set up in the buffer of origin.")) "List of available completion styles. Each element has the form (NAME TRY-COMPLETION ALL-COMPLETIONS DOC): where NAME is the name that should be used in `completion-styles', @@ -990,7 +995,8 @@ completion-category-defaults ;; e.g. one that does not anchor to bos. (project-file (styles . (substring))) (xref-location (styles . (substring))) - (info-menu (styles . (basic substring)))) + (info-menu (styles . (basic substring))) + (symbol-help (styles . (basic shorthand substring)))) "Default settings for specific completion categories. Each entry has the shape (CATEGORY . ALIST) where ALIST is an association list that can specify properties such as: @@ -1618,6 +1624,9 @@ minibuffer-confirm-exit-commands (defvar minibuffer--require-match nil "Value of REQUIRE-MATCH passed to `completing-read'.") =20 +(defvar minibuffer--original-buffer nil + "Buffer that was current when `completing-read' was called.") + (defun minibuffer-complete-and-exit () "Exit if the minibuffer contains a valid completion. Otherwise, try to complete the minibuffer contents. If @@ -4080,6 +4089,40 @@ completion-initials-try-completion (let ((newstr (completion-initials-expand string table pred))) (when newstr (completion-pcm-try-completion newstr table pred (length newstr))))) + +;; Shorthand completion +;; +;; Iff there is a (("x-" . "string-library-")) shorthand setup and +;; string-library-foo is in candidates, complete x-foo to it. + +(defun completion-shorthand-try-completion (string table pred point) + "Try completion with `read-symbol-shorthands' of original buffer." + (cl-loop with expanded + for (short . long) in + (with-current-buffer minibuffer--original-buffer + read-symbol-shorthands) + for probe =3D + (and (> point (length short)) + (string-prefix-p short string) + (try-completion (setq expanded + (concat long + (substring + string + (length short)))) + table pred)) + when probe + do (message "Shorthand expansion") + and return (cons expanded (max (length long) + (+ (- point (length short)) + (length long)))))) + +(defun completion-shorthand-all-completions (string table pred _point) + ;; no-op: For now, we don't want shorthands to list all the possible + ;; locally active longhands. For the completion categories where + ;; this style is active, it could hide other more interesting + ;; matches from subsequent styles. + nil) + (defvar completing-read-function #'completing-read-default "The function called by `completing-read' to do its work. @@ -4111,6 +4154,7 @@ completing-read-default ;; in minibuffer-local-filename-completion-map can ;; override bindings in base-keymap. base-keymap))) + (buffer (current-buffer)) (result (minibuffer-with-setup-hook (lambda () @@ -4119,7 +4163,8 @@ completing-read-default ;; FIXME: Remove/rename this var, see the next one. (setq-local minibuffer-completion-confirm (unless (eq require-match t) require-match)) - (setq-local minibuffer--require-match require-match)) + (setq-local minibuffer--require-match require-match) + (setq-local minibuffer--original-buffer buffer)) (read-from-minibuffer prompt initial-input keymap nil hist def inherit-input-method)))) (when (and (equal result "") def)