aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/help.el
diff options
context:
space:
mode:
authorElías Gabriel Pérez2025-10-30 13:04:46 -0600
committerJuri Linkov2025-11-05 09:17:51 +0200
commite7505ca213d77ea2f34caeb01d185e340641b5f4 (patch)
tree487b160eff0bcc80ca92a1f1cc29688fba22e6ac /lisp/help.el
parent2f6e5d2eda006cfa65a6f4e2aa0d63e20a47c0ec (diff)
downloademacs-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.
Diffstat (limited to 'lisp/help.el')
-rw-r--r--lisp/help.el120
1 files changed, 94 insertions, 26 deletions
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.
525If non-nil, the lossage buffer will be refreshed automatically for each
526new 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.
536If MOST-RECENT is non-nil, only return the most recent key and its
537command."
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.
697For convenience this uses the same format as 758For convenience this uses the same format as
698`edit-last-kbd-macro'. 759`edit-last-kbd-macro'.
699See `lossage-size' to update the number of recorded keystrokes. 760See `lossage-size' to update the number of recorded keystrokes.
700 761
762With argument, auto-refresh the lossage buffer for each new input
763keystroke, see also `view-lossage-auto-refresh'.
764
701To record all your input, use `open-dribble-file'." 765To 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