From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Simon Katz Newsgroups: gmane.emacs.bugs Subject: bug#50042: acknowledged by developer (control message for bug #50042) Date: Wed, 18 Aug 2021 16:33:03 +0100 Message-ID: References: <878s13os3a.fsf@gnus.org> Reply-To: sk@nomistech.com 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="36635"; mail-complaints-to="usenet@ciao.gmane.io" To: 50042@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 18 17:34:21 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 1mGNa7-0009EM-Je for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 18 Aug 2021 17:34:19 +0200 Original-Received: from localhost ([::1]:46342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mGNa5-00038p-HU for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 18 Aug 2021 11:34:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGNZq-00037s-Pe for bug-gnu-emacs@gnu.org; Wed, 18 Aug 2021 11:34:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mGNZq-0004YD-JJ for bug-gnu-emacs@gnu.org; Wed, 18 Aug 2021 11:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mGNZq-0000Bg-Gx for bug-gnu-emacs@gnu.org; Wed, 18 Aug 2021 11:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Simon Katz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 18 Aug 2021 15:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50042 X-GNU-PR-Package: emacs Original-Received: via spool by 50042-submit@debbugs.gnu.org id=B50042.1629300819662 (code B ref 50042); Wed, 18 Aug 2021 15:34:02 +0000 Original-Received: (at 50042) by debbugs.gnu.org; 18 Aug 2021 15:33:39 +0000 Original-Received: from localhost ([127.0.0.1]:57319 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mGNZF-0000AD-Cx for submit@debbugs.gnu.org; Wed, 18 Aug 2021 11:33:38 -0400 Original-Received: from s30.dg.net.uk ([91.224.108.30]:37316) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mGNZA-00009q-89 for 50042@debbugs.gnu.org; Wed, 18 Aug 2021 11:33:24 -0400 Original-Received: from mail-wr1-f54.google.com ([209.85.221.54]:42624) by s30.dg.net.uk with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1mGNZ4-0002Jk-OY for 50042@debbugs.gnu.org; Wed, 18 Aug 2021 16:33:14 +0100 Original-Received: by mail-wr1-f54.google.com with SMTP id q11so4158666wrr.9 for <50042@debbugs.gnu.org>; Wed, 18 Aug 2021 08:33:14 -0700 (PDT) X-Gm-Message-State: AOAM530bc0dv0eXnbFfhsdtJGwA2kHJBxo4jE4x3nXURKO2tKAH2F4e+ jK/YSALBBJjQmLpLyXTU+VmGxsTAb3TqWrlsurQ= X-Google-Smtp-Source: ABdhPJyrw0p2VUejtkWh82G0C9quznIUozUgyS+XeOeTNJKk+XJKUGckNZA+0rhBOGL5QowpRTqoHu5lbLQlY9OYU6o= X-Received: by 2002:adf:e845:: with SMTP id d5mr11725194wrn.228.1629300794279; Wed, 18 Aug 2021 08:33:14 -0700 (PDT) In-Reply-To: X-Gmail-Original-Message-ID: X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - s30.dg.net.uk X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nomistech.com X-Get-Message-Sender-Via: s30.dg.net.uk: authenticated_id: non-junk@nomistech.com X-Authenticated-Sender: s30.dg.net.uk: non-junk@nomistech.com 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:212154 Archived-At: Oh, I'm really sorry=E2=80=A6 I was playing around and I accidentally left in the `(setq suggest-key-bindings nil)` form. Please remove that in order to reproduce the problem! On Wed, 18 Aug 2021 at 16:27, Simon Katz wrote: > > Hi Lars, > > Thanks for fixing the bug I reported. > > You mentioned that there might be some peculiarities in this > area, and indeed that seems to be the case. > > I still have a problem. If you are interested in what I am trying > to fix, see https://github.com/emacs-lsp/lsp-ui/issues/647 > > Note that everything is fine if I set `suggest-key-bindings` to > `nil`. > > The problems seem to be with commands that both (a) write > messages to the echo area, and (b) have key bindings. > > The code below reproduces the problem. See the comments at the > beginning for instructions. > > > -------------------------------------------------------------------------= ------- > > ;;; demo-post-command-hook-slow-with-m-x-commands-v2.el --- Demo that > post-command hooks are slow with M-x commands -*- > lexical-binding: t; -*- > > ;; This demonstrates an issue with: > ;; `(add-hook 'post-command-hook ...)`. > ;; It's a follow-up to an already-reported and partially-fixed problem --= see > ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D50042 > > ;; To reproduce the problem: > ;; > ;; - Run `emacs -q -l ` > ;; > ;; - Enter `M-x **-msg-cmd-without-key-binding`. > ;; - Observe that it takes many seconds (~15 for me) to produce output to= the > ;; "my-output" buffer, and that the "*Messages*" buffer has the message= : > ;; You can run the command =E2=80=98**-msg-cmd-without-key-binding=E2= =80=99 with > M-x -witho RET > ;; > ;; - Enter `M-x **-msg-cmd-without-key-binding` again. > ;; - Observe that both the "*Messages*" buffer and the "my-output" buffer= update > ;; immediately. > ;; - Repeatedly enter `M-x **-msg-cmd-without-key-binding` and observe th= e same > ;; - result. > ;; > ;; - Enter `M-x **-msg-cmd-with-key-binding`. > ;; - Observe that it takes 2 seconds for output to appear in the "my-outp= ut" > ;; buffer. > ;; - Observe that the behaviour is the same if the command is repeated. > ;; > ;; - Use the `C-c C-c` key binding, to invoke `**-msg-cmd-with-key-bindin= g`. > ;; - Observe that there are no delays. > > > ;; Emacs displays the "*GNU Emacs*" buffer after loading this file, so us= e > ;; `run-at-time` to delay setting up which buffers are displayed. > (run-at-time 1 > nil > (lambda () > (switch-to-buffer "*Messages*" nil t) > (display-buffer (generate-new-buffer "my-output")) > ;; Arrange things so that we see the output as it appears: > (select-window (get-buffer-window "my-output")))) > > (defun date-time () > (format-time-string "%Y-%m-%d %H:%M:%S")) > > (defun post-command-message () > (when (member this-command > '(**-msg-cmd-with-key-binding > **-msg-cmd-without-key-binding)) > (with-current-buffer "my-output" > (goto-char (point-max)) > (insert (date-time) > " The command `" > (format "%s" this-command) > "` was executed\n") > (goto-char (point-max))))) > > (add-hook 'post-command-hook 'post-command-message) > > (defun **-msg-cmd-without-key-binding () > (interactive) > (message "%s Hello from `**-msg-cmd-without-key-binding`" > (date-time))) > > (defun **-msg-cmd-with-key-binding () > (interactive) > (message "%s Hello from `**-msg-cmd-with-key-binding`" > (date-time))) > > (define-key global-map (kbd "C-c C-c") '**-msg-cmd-with-key-binding) > > (setq suggest-key-bindings nil) > > (when t ; Whether to load the changes in Emacs commit 42a98feb5b > > (defvar execute-extended-command--binding-timer nil) > > (defun execute-extended-command (prefixarg &optional command-name typed= ) > ;; Based on Fexecute_extended_command in keyboard.c of Emacs. > ;; Aaron S. Hawley 2009-08-24 > "Read a command name, then read the arguments and call the command. > To pass a prefix argument to the command you are > invoking, give a prefix argument to `execute-extended-command'." > (declare (interactive-only command-execute)) > ;; FIXME: Remember the actual text typed by the user before completio= n, > ;; so that we don't later on suggest the same shortening. > (interactive > (let ((execute-extended-command--last-typed nil)) > (list current-prefix-arg > (read-extended-command) > execute-extended-command--last-typed))) > ;; Emacs<24 calling-convention was with a single `prefixarg' argument= . > (unless command-name > (let ((current-prefix-arg prefixarg) ; for prompt > (execute-extended-command--last-typed nil)) > (setq command-name (read-extended-command)) > (setq typed execute-extended-command--last-typed))) > (let* ((function (and (stringp command-name) (intern-soft command-nam= e))) > (binding (and suggest-key-bindings > (not executing-kbd-macro) > (where-is-internal function overriding-local-map= t)))) > (unless (commandp function) > (error "`%s' is not a valid command name" command-name)) > ;; Some features, such as novice.el, rely on this-command-keys > ;; including M-x COMMAND-NAME RET. > (set--this-command-keys (concat "\M-x" (symbol-name function) "\r")= ) > (setq this-command function) > ;; Normally `real-this-command' should never be changed, but > here we really > ;; want to pretend that M-x RET is nothing more than a "key > ;; binding" for , so the command the user really wanted to run= is > ;; `function' and not `execute-extended-command'. The difference i= s > ;; visible in cases such as M-x RET and then C-x z (bug#11506= ). > (setq real-this-command function) > (let ((prefix-arg prefixarg)) > (command-execute function 'record)) > ;; If enabled, show which key runs this command. > ;; But first wait, and skip the message if there is input. > (let* ((waited > ;; If this command displayed something in the echo area; > ;; wait a few seconds, then display our suggestion message. > ;; FIXME: Wait *after* running post-command-hook! > ;; FIXME: If execute-extended-command--shorter were > ;; faster, we could compute the result here first too. > (when (and suggest-key-bindings > (or binding > (and extended-command-suggest-shorter typed)= )) > (sit-for (cond > ((zerop (length (current-message))) 0) > ((numberp suggest-key-bindings) suggest-key-bin= dings) > (t 2)))))) > (when (and waited (not (consp unread-command-events))) > (unless (or (not extended-command-suggest-shorter) > binding executing-kbd-macro (not (symbolp function)= ) > (<=3D (length (symbol-name function)) 2)) > ;; There's no binding for CMD. Let's try and find the shorte= st > ;; string to use in M-x. > ;; FIXME: Can be slow. Cache it maybe? > (while-no-input > (setq binding (execute-extended-command--shorter > (symbol-name function) typed)))) > (when binding > ;; This is normally not necessary -- the timer should run > ;; immediately, but be defensive and ensure that we never > ;; have two of these timers in flight. > (when execute-extended-command--binding-timer > (cancel-timer execute-extended-command--binding-timer)) > (setq execute-extended-command--binding-timer > (run-at-time > 0 nil > (lambda () > (with-temp-message > (format-message "You can run the command `%s' wi= th %s" > function > (if (stringp binding) > (concat "M-x " binding " RET= ") > (key-description binding))) > (sit-for (if (numberp suggest-key-bindings) > suggest-key-bindings > 2)))))))))))) > > (provide 'demo-post-command-hook-slow-with-m-x-commands-v2) > ;;; demo-post-command-hook-slow-with-m-x-commands-v2.el ends here > > -------------------------------------------------------------------------= -------