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:27:21 +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="5752"; 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:28:10 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 1mGNU9-0001FX-GO for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 18 Aug 2021 17:28:09 +0200 Original-Received: from localhost ([::1]:39158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mGNU8-0006TI-Aj for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 18 Aug 2021 11:28:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGNU2-0006Sv-8S for bug-gnu-emacs@gnu.org; Wed, 18 Aug 2021 11:28:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mGNU2-0001hI-1s for bug-gnu-emacs@gnu.org; Wed, 18 Aug 2021 11:28:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mGNU1-0008PV-Uw for bug-gnu-emacs@gnu.org; Wed, 18 Aug 2021 11:28:01 -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:28:01 +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.162930046732309 (code B ref 50042); Wed, 18 Aug 2021 15:28:01 +0000 Original-Received: (at 50042) by debbugs.gnu.org; 18 Aug 2021 15:27:47 +0000 Original-Received: from localhost ([127.0.0.1]:57302 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mGNTm-0008P3-Up for submit@debbugs.gnu.org; Wed, 18 Aug 2021 11:27:47 -0400 Original-Received: from s30.dg.net.uk ([91.224.108.30]:36956) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mGNTh-0008Oh-CN for 50042@debbugs.gnu.org; Wed, 18 Aug 2021 11:27:45 -0400 Original-Received: from mail-wm1-f54.google.com ([209.85.128.54]:55913) by s30.dg.net.uk with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1mGNTZ-0001s8-A1 for 50042@debbugs.gnu.org; Wed, 18 Aug 2021 16:27:33 +0100 Original-Received: by mail-wm1-f54.google.com with SMTP id w24so1871903wmi.5 for <50042@debbugs.gnu.org>; Wed, 18 Aug 2021 08:27:32 -0700 (PDT) X-Gm-Message-State: AOAM533mSY/8P8h3mXqB3HJD1+Qm0OOx3g5EFocHjAnE5HbdwbcorjxL UbCpiLsmKcVa89BJauUr4wQhbVnWBxyCL1HOK0U= X-Google-Smtp-Source: ABdhPJxWvXJqLjxJ0JLuBaPdvW5/7i6zllVOgLBwyf8+AneIj3X+x0XTWzuFm+G4pe7B+GFbNWmpInOqXgcxz2tY/uM= X-Received: by 2002:a1c:2283:: with SMTP id i125mr9018074wmi.41.1629300452711; Wed, 18 Aug 2021 08:27:32 -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:212153 Archived-At: 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 -- s= ee ;; 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 t= he ;; "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 u= pdate ;; immediately. ;; - Repeatedly enter `M-x **-msg-cmd-without-key-binding` and observe the = same ;; - result. ;; ;; - Enter `M-x **-msg-cmd-with-key-binding`. ;; - Observe that it takes 2 seconds for output to appear in the "my-output= " ;; 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-binding`= . ;; - Observe that there are no delays. ;; Emacs displays the "*GNU Emacs*" buffer after loading this file, so use ;; `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 completion, ;; 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-name)= )) (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 i= s ;; `function' and not `execute-extended-command'. The difference is ;; 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-bindi= ngs) (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 shortest ;; 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' with= %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 ---------------------------------------------------------------------------= -----