diff options
| author | Elías Gabriel Pérez | 2025-10-30 13:04:46 -0600 |
|---|---|---|
| committer | Juri Linkov | 2025-11-05 09:17:51 +0200 |
| commit | e7505ca213d77ea2f34caeb01d185e340641b5f4 (patch) | |
| tree | 487b160eff0bcc80ca92a1f1cc29688fba22e6ac | |
| parent | 2f6e5d2eda006cfa65a6f4e2aa0d63e20a47c0ec (diff) | |
| download | emacs-e7505ca213d77ea2f34caeb01d185e340641b5f4.tar.gz emacs-e7505ca213d77ea2f34caeb01d185e340641b5f4.zip | |
Add option to auto-refresh the lossage buffer. (Bug#79732)
* lisp/help.el (view-lossage-auto-refresh): New user option.
(help--lossage-update): New variable.
(help--lossage-make-recent-keys, help--refresh-lossage-buffer):
New functions.
(view-lossage): Rework.
* doc/emacs/help.texi (Misc Help):
* etc/NEWS: Document change.
| -rw-r--r-- | doc/emacs/help.texi | 10 | ||||
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/help.el | 120 |
3 files changed, 108 insertions, 28 deletions
diff --git a/doc/emacs/help.texi b/doc/emacs/help.texi index 6ea7b5783c2..879967ddfb2 100644 --- a/doc/emacs/help.texi +++ b/doc/emacs/help.texi | |||
| @@ -716,8 +716,14 @@ use @kbd{C-h l} (@code{view-lossage}). @kbd{C-h l} displays your last | |||
| 716 | input keystrokes and the commands they invoked. By default, Emacs | 716 | input keystrokes and the commands they invoked. By default, Emacs |
| 717 | stores the last 300 keystrokes; if you wish, you can change this number with | 717 | stores the last 300 keystrokes; if you wish, you can change this number with |
| 718 | the command @code{lossage-size}. | 718 | the command @code{lossage-size}. |
| 719 | If you see commands that you are not familiar with, you can use @kbd{C-h k} or | 719 | If you see commands that you are not familiar with, use |
| 720 | @kbd{C-h f} to find out what they do. | 720 | @kbd{C-h k}, or press @kbd{RET} or click on them to find out what they do. |
| 721 | |||
| 722 | @vindex view-lossage-auto-refresh | ||
| 723 | By default, after the lossage buffer is displayed it will not show the | ||
| 724 | most recent keystroke and command that you are currently typing, to | ||
| 725 | change this set the variable @code{view-lossage-auto-refresh} to | ||
| 726 | @code{t}. | ||
| 721 | 727 | ||
| 722 | @kindex C-h e | 728 | @kindex C-h e |
| 723 | @findex view-echo-area-messages | 729 | @findex view-echo-area-messages |
| @@ -690,6 +690,12 @@ or strings. If set to 'on-mismatch', mismatched parens inside comments | |||
| 690 | and strings will not be highlighted. If set to nil (the default), | 690 | and strings will not be highlighted. If set to nil (the default), |
| 691 | highlight the parens wherever they are. | 691 | highlight the parens wherever they are. |
| 692 | 692 | ||
| 693 | +++ | ||
| 694 | ** New user option 'view-lossage-auto-refresh'. | ||
| 695 | If this option is non-nil, the lossage buffer in 'view-lossage' will be | ||
| 696 | refreshed automatically for each new input keystroke and command | ||
| 697 | performed. | ||
| 698 | |||
| 693 | ** Change in SVG foreground color handling. | 699 | ** Change in SVG foreground color handling. |
| 694 | SVG images no longer have the 'fill' attribute set to the value of | 700 | SVG images no longer have the 'fill' attribute set to the value of |
| 695 | ':foreground' or the current text foreground color. The 'currentcolor' | 701 | ':foreground' or the current text foreground color. The 'currentcolor' |
diff --git a/lisp/help.el b/lisp/help.el index 4ba99868c4a..8cf91faf174 100644 --- a/lisp/help.el +++ b/lisp/help.el | |||
| @@ -518,6 +518,67 @@ If that doesn't give a function, return nil." | |||
| 518 | (and (fboundp sym) sym)))))))) | 518 | (and (fboundp sym) sym)))))))) |
| 519 | 519 | ||
| 520 | 520 | ||
| 521 | ;;; Lossage | ||
| 522 | |||
| 523 | (defcustom view-lossage-auto-refresh nil | ||
| 524 | "Whether to auto-refresh the lossage buffer. | ||
| 525 | If non-nil, the lossage buffer will be refreshed automatically for each | ||
| 526 | new input keystroke and command performed." | ||
| 527 | :type 'boolean | ||
| 528 | :group 'help | ||
| 529 | :version "31.1") | ||
| 530 | |||
| 531 | (defvar-local help--lossage-update nil | ||
| 532 | "Variable used to determine if lossage buffer should be refreshed.") | ||
| 533 | |||
| 534 | (defun help--lossage-make-recent-keys (&optional most-recent) | ||
| 535 | "Return a string containing all the recent keys and its commands. | ||
| 536 | If MOST-RECENT is non-nil, only return the most recent key and its | ||
| 537 | command." | ||
| 538 | (let ((keys | ||
| 539 | (if most-recent | ||
| 540 | `[,@(this-single-command-raw-keys) (nil . ,this-command)] | ||
| 541 | (recent-keys 'include-cmds)))) | ||
| 542 | (mapconcat | ||
| 543 | (lambda (key) | ||
| 544 | (cond | ||
| 545 | ((and (consp key) (null (car key))) | ||
| 546 | (concat | ||
| 547 | ";; " | ||
| 548 | (if (symbolp (cdr key)) | ||
| 549 | (buttonize | ||
| 550 | (symbol-name (cdr key)) | ||
| 551 | (lambda (&rest _) | ||
| 552 | (interactive) | ||
| 553 | (describe-function (cdr key))) | ||
| 554 | "mouse-1: go to the documentation for this command.") | ||
| 555 | (propertize "anonymous-command" 'face 'shadow)) | ||
| 556 | "\n")) | ||
| 557 | ((or (integerp key) (symbolp key) (listp key)) | ||
| 558 | (propertize (single-key-description key) | ||
| 559 | 'face 'help-key-binding | ||
| 560 | 'rear-nonsticky t)) | ||
| 561 | (t | ||
| 562 | (propertize (prin1-to-string key nil) | ||
| 563 | 'face 'help-key-binding | ||
| 564 | 'rear-nonsticky t)))) | ||
| 565 | keys | ||
| 566 | " "))) | ||
| 567 | |||
| 568 | (defun help--refresh-lossage-buffer () | ||
| 569 | (if-let* ((buf (get-buffer "*Help*")) | ||
| 570 | (_ (buffer-local-value 'help--lossage-update buf))) | ||
| 571 | (with-current-buffer buf | ||
| 572 | (let ((inhibit-read-only t)) | ||
| 573 | (save-excursion | ||
| 574 | (goto-char (point-max)) | ||
| 575 | (insert-before-markers | ||
| 576 | (concat " " (help--lossage-make-recent-keys :most-recent))) | ||
| 577 | (forward-line -1) | ||
| 578 | (comment-indent)))) | ||
| 579 | (remove-hook 'post-command-hook #'help--refresh-lossage-buffer))) | ||
| 580 | |||
| 581 | |||
| 521 | ;;; `User' help functions | 582 | ;;; `User' help functions |
| 522 | 583 | ||
| 523 | (defun view-help-file (file &optional dir) | 584 | (defun view-help-file (file &optional dir) |
| @@ -692,43 +753,50 @@ the variable `message-log-max'." | |||
| 692 | (interactive) | 753 | (interactive) |
| 693 | (info "(efaq)Packages that do not come with Emacs")) | 754 | (info "(efaq)Packages that do not come with Emacs")) |
| 694 | 755 | ||
| 695 | (defun view-lossage () | 756 | (defun view-lossage (&optional auto-refresh) |
| 696 | "Display last few input keystrokes and the commands run. | 757 | "Display last few input keystrokes and the commands run. |
| 697 | For convenience this uses the same format as | 758 | For convenience this uses the same format as |
| 698 | `edit-last-kbd-macro'. | 759 | `edit-last-kbd-macro'. |
| 699 | See `lossage-size' to update the number of recorded keystrokes. | 760 | See `lossage-size' to update the number of recorded keystrokes. |
| 700 | 761 | ||
| 762 | With argument, auto-refresh the lossage buffer for each new input | ||
| 763 | keystroke, see also `view-lossage-auto-refresh'. | ||
| 764 | |||
| 701 | To record all your input, use `open-dribble-file'." | 765 | To record all your input, use `open-dribble-file'." |
| 702 | (interactive) | 766 | (interactive "P") |
| 703 | (let ((help-buffer-under-preparation t)) | 767 | (let ((help-buffer-under-preparation t) |
| 704 | (help-setup-xref (list #'view-lossage) | 768 | (view-lossage-auto-refresh |
| 705 | (called-interactively-p 'interactive)) | 769 | (if auto-refresh t view-lossage-auto-refresh))) |
| 770 | (unless view-lossage-auto-refresh | ||
| 771 | ;; `view-lossage-auto-refresh' conflicts with xref buttons, add | ||
| 772 | ;; them if `view-lossage-auto-refresh' is nil. | ||
| 773 | (help-setup-xref (list #'view-lossage) | ||
| 774 | (called-interactively-p 'interactive))) | ||
| 706 | (with-help-window (help-buffer) | 775 | (with-help-window (help-buffer) |
| 707 | (princ " ") | 776 | (princ " ") |
| 708 | (princ (mapconcat (lambda (key) | 777 | (insert (help--lossage-make-recent-keys)) |
| 709 | (cond | ||
| 710 | ((and (consp key) (null (car key))) | ||
| 711 | (format ";; %s\n" (if (symbolp (cdr key)) (cdr key) | ||
| 712 | "anonymous-command"))) | ||
| 713 | ((or (integerp key) (symbolp key) (listp key)) | ||
| 714 | (single-key-description key)) | ||
| 715 | (t | ||
| 716 | (prin1-to-string key nil)))) | ||
| 717 | (recent-keys 'include-cmds) | ||
| 718 | " ")) | ||
| 719 | (with-current-buffer standard-output | 778 | (with-current-buffer standard-output |
| 720 | (goto-char (point-min)) | 779 | (goto-char (point-min)) |
| 721 | (let ((comment-start ";; ") | 780 | (setq-local comment-start ";; " |
| 722 | ;; Prevent 'comment-indent' from handling a single | 781 | ;; Prevent 'comment-indent' from handling a single |
| 723 | ;; semicolon as the beginning of a comment. | 782 | ;; semicolon as the beginning of a comment. |
| 724 | (comment-start-skip ";; ") | 783 | comment-start-skip ";; " |
| 725 | (comment-use-syntax nil) | 784 | comment-use-syntax nil |
| 726 | (comment-column 24)) | 785 | comment-column 24) |
| 727 | (while (not (eobp)) | 786 | (while (not (eobp)) |
| 728 | (comment-indent) | 787 | (comment-indent) |
| 729 | (forward-line 1))) | 788 | (forward-line 1)) |
| 730 | ;; Show point near the end of "lossage", as we did in Emacs 24. | 789 | ;; Show point near the end of "lossage", as we did in Emacs 24. |
| 731 | (set-marker help-window-point-marker (point)))))) | 790 | (set-marker help-window-point-marker (point)) |
| 791 | |||
| 792 | (when view-lossage-auto-refresh | ||
| 793 | (setq-local help--lossage-update t) | ||
| 794 | (add-hook 'post-command-hook #'help--refresh-lossage-buffer)))) | ||
| 795 | |||
| 796 | ;; `help-make-xrefs' adds a newline at the end of the buffer, which | ||
| 797 | ;; makes impossible to reposition point in `with-help-window'. | ||
| 798 | (when view-lossage-auto-refresh | ||
| 799 | (set-window-point (get-buffer-window (help-buffer)) (point-max))))) | ||
| 732 | 800 | ||
| 733 | 801 | ||
| 734 | ;; Key bindings | 802 | ;; Key bindings |