From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#51173: 28.0.60; gnus-article-describe-key doesn't work Date: Mon, 18 Oct 2021 19:20:00 +0300 Organization: LINKOV.NET Message-ID: <87ilxumi07.fsf@mail.linkov.net> References: <87h7dl6spg.fsf@gnus.org> <87r1cox4th.fsf@mail.linkov.net> <87h7dkx2g5.fsf@mail.linkov.net> <87r1cm3hqb.fsf@mail.linkov.net> <87h7dgg8go.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27325"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: Lars Ingebrigtsen , Katsumi Yamaoka , 51173@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 18 18:36:29 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 1mcVci-0006mU-J3 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Oct 2021 18:36:28 +0200 Original-Received: from localhost ([::1]:56408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcVch-0004hz-Fj for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 18 Oct 2021 12:36:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33190) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mcVOl-0008H7-7c for bug-gnu-emacs@gnu.org; Mon, 18 Oct 2021 12:22:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36815) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mcVOk-0000SH-RM for bug-gnu-emacs@gnu.org; Mon, 18 Oct 2021 12:22:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mcVOk-0001N7-Iz; Mon, 18 Oct 2021 12:22:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bugs@gnus.org Resent-Date: Mon, 18 Oct 2021 16:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51173 X-GNU-PR-Package: emacs,gnus Original-Received: via spool by 51173-submit@debbugs.gnu.org id=B51173.16345741025240 (code B ref 51173); Mon, 18 Oct 2021 16:22:02 +0000 Original-Received: (at 51173) by debbugs.gnu.org; 18 Oct 2021 16:21:42 +0000 Original-Received: from localhost ([127.0.0.1]:48359 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mcVOP-0001MR-PN for submit@debbugs.gnu.org; Mon, 18 Oct 2021 12:21:42 -0400 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:43599) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mcVOK-0001Lq-Cl for 51173@debbugs.gnu.org; Mon, 18 Oct 2021 12:21:37 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id D5F6E40006; Mon, 18 Oct 2021 16:21:27 +0000 (UTC) In-Reply-To: (Stefan Monnier's message of "Sat, 16 Oct 2021 15:53:03 -0400") 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:217498 Archived-At: --=-=-= Content-Type: text/plain >> There is still something missing: `gnus-article-describe-key` >> already selects the required buffer with `with-current-buffer`. >> Then why should it provide the same buffer as an argument >> to `describe-key` to select it again in `describe-key`? > > Because `describe-key` otherwise uses the buffer of the window > associated with the event (this is in done in `help--analyse-key` where > we currently use `mouse-set-point`). So we need to pass an explicit > buffer to tell `describe-key` to ignore the event's window (and we need > to change this part of `describe-key/help--analyse-key` to obey such a > buffer argument). > >> (defn (if (not buffer) >> (save-excursion (mouse-set-point event) (key-binding key t)) >> (key-binding key t))) >> >> IOW, the semantics of `buffer` is not clear here. > > If nil it means "defaults to the (window-buffer (posn-window (event-end event)))" > >>> OTOH we should probably try and change the `key` arg to use the new >>> key-list format expected by `describe-key` (i.e. a list of (SEQ >>> . RAW-SEQ) pairs). >> >> `gnus-article-describe-key` just passes down the value >> that `read-key-sequence` returns. > > I know. This is the old calling convention of `describe-key`; we > should move to the new one. Is seems everything is covered by this patch: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=help--analyze-key.patch diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el index bb466b9400..930c739a73 100644 --- a/lisp/gnus/gnus-art.el +++ b/lisp/gnus/gnus-art.el @@ -6865,7 +6865,9 @@ gnus-article-describe-key unread-command-events)) (let ((cursor-in-echo-area t) gnus-pick-mode) - (describe-key (read-key-sequence nil t)))) + (describe-key (cons (read-key-sequence nil t) + (this-single-command-raw-keys)) + (current-buffer)))) (describe-key key))) (defun gnus-article-describe-key-briefly (key &optional insert) @@ -6888,7 +6890,9 @@ gnus-article-describe-key-briefly unread-command-events)) (let ((cursor-in-echo-area t) gnus-pick-mode) - (describe-key-briefly (read-key-sequence nil t) insert))) + (describe-key-briefly (cons (read-key-sequence nil t) + (this-single-command-raw-keys)) + insert (current-buffer)))) (describe-key-briefly key insert))) ;;`gnus-agent-mode' in gnus-agent.el will define it. diff --git a/lisp/help.el b/lisp/help.el index 9666ef9805..a7084d29ce 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -677,9 +677,11 @@ help-key-description (defun help--binding-undefined-p (defn) (or (null defn) (integerp defn) (equal defn 'undefined))) -(defun help--analyze-key (key untranslated) +(defun help--analyze-key (key untranslated &optional buffer) "Get information about KEY its corresponding UNTRANSLATED events. -Returns a list of the form (BRIEF-DESC DEFN EVENT MOUSE-MSG)." +Returns a list of the form (BRIEF-DESC DEFN EVENT MOUSE-MSG). +When BUFFER is nil, it defaults to the +`(window-buffer (posn-window (event-end event)))'." (if (numberp untranslated) (error "Missing `untranslated'!")) (let* ((event (when (> (length key) 0) @@ -699,9 +701,8 @@ help--analyze-key ;; is selected from the context menu that should describe KEY ;; at the position of mouse click that opened the context menu. ;; When no mouse was involved, don't use `mouse-set-point'. - (defn (if (consp event) - (save-excursion (mouse-set-point event) (key-binding key t)) - (key-binding key t)))) + (defn (if buffer (key-binding key t) + (save-excursion (mouse-set-point event) (key-binding key t))))) ;; Handle the case where we faked an entry in "Select and Paste" menu. (when (and (eq defn nil) (stringp (aref key (1- (length key)))) @@ -731,7 +732,7 @@ help--filter-info-list ;; If nothing left, then keep one (the last one). (last info-list))) -(defun describe-key-briefly (&optional key-list insert untranslated) +(defun describe-key-briefly (&optional key-list insert buffer) "Print the name of the functions KEY-LIST invokes. KEY-LIST is a list of pairs (SEQ . RAW-SEQ) of key sequences, where RAW-SEQ is the untranslated form of the key sequence SEQ. @@ -739,8 +740,10 @@ describe-key-briefly While reading KEY-LIST interactively, this command temporarily enables menu items or tool-bar buttons that are disabled to allow getting help -on them." - (declare (advertised-calling-convention (key-list &optional insert) "27.1")) +on them. + +BUFFER is the buffer in which to lookup those keys; it defaults to the +current buffer." (interactive ;; Ignore mouse movement events because it's too easy to miss the ;; message while moving the mouse. @@ -748,15 +751,13 @@ describe-key-briefly `(,key-list ,current-prefix-arg))) (when (arrayp key-list) ;; Old calling convention, changed - (setq key-list (list (cons key-list - (if (numberp untranslated) - (this-single-command-raw-keys) - untranslated))))) - (let* ((info-list (mapcar (lambda (kr) - (help--analyze-key (car kr) (cdr kr))) - key-list)) - (msg (mapconcat #'car (help--filter-info-list info-list 1) "\n"))) - (if insert (insert msg) (message "%s" msg)))) + (setq key-list (list (cons key-list nil)))) + (with-current-buffer (if (buffer-live-p buffer) buffer (current-buffer)) + (let* ((info-list (mapcar (lambda (kr) + (help--analyze-key (car kr) (cdr kr) buffer)) + key-list)) + (msg (mapconcat #'car (help--filter-info-list info-list 1) "\n"))) + (if insert (insert msg) (message "%s" msg))))) (defun help--key-binding-keymap (key &optional accept-default no-remap position) "Return a keymap holding a binding for KEY within current keymaps. @@ -916,7 +917,7 @@ describe-key (mapcar (lambda (x) (pcase-let* ((`(,seq . ,raw-seq) x) (`(,brief-desc ,defn ,event ,_mouse-msg) - (help--analyze-key seq raw-seq)) + (help--analyze-key seq raw-seq buffer)) (locus (help--binding-locus seq (event-start event)))) --=-=-=--