diff options
| author | Juri Linkov | 2019-12-22 00:02:10 +0200 |
|---|---|---|
| committer | Juri Linkov | 2019-12-22 00:02:10 +0200 |
| commit | 485b423e8f0df2711a850be7f254665f64ab0bdb (patch) | |
| tree | 02f294b4daa4ec7718769afe8235a7119b52bcb5 /lisp | |
| parent | 678a71ea2d044f19f75e3f45c930c5e3b707e3dc (diff) | |
| download | emacs-485b423e8f0df2711a850be7f254665f64ab0bdb.tar.gz emacs-485b423e8f0df2711a850be7f254665f64ab0bdb.zip | |
New variable set-message-function to show message at the end of the minibuffer
* doc/lispref/display.texi (Displaying Messages): Document
set-message-function and clear-message-function.
* lisp/minibuffer.el (minibuffer-message-clear-timeout): New defcustom.
(minibuffer-message-timer, minibuffer-message-overlay): New variables.
(set-minibuffer-message, clear-minibuffer-message): New functions.
(set-message-function, clear-message-function): Set variables to
set-minibuffer-message and clear-minibuffer-message respectively.
* src/keyboard.c (read_char): Call clear_message when
Vclear_message_function is a function.
* src/xdisp.c (set_message): Call Vset_message_function when it's a function.
(clear_message): Call Vclear_message_function when it's a function.
(syms_of_xdisp): New variables set-message-function and clear-message-function
(bug#38457).
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/minibuffer.el | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 76d8ca44757..5dc753ffd5c 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -746,6 +746,76 @@ If ARGS are provided, then pass MESSAGE through `format-message'." | |||
| 746 | (sit-for (or minibuffer-message-timeout 1000000))) | 746 | (sit-for (or minibuffer-message-timeout 1000000))) |
| 747 | (delete-overlay ol))))) | 747 | (delete-overlay ol))))) |
| 748 | 748 | ||
| 749 | (defcustom minibuffer-message-clear-timeout nil | ||
| 750 | "How long to display an echo-area message when the minibuffer is active. | ||
| 751 | If the value is a number, it should be specified in seconds. | ||
| 752 | If the value is not a number, such messages never time out, | ||
| 753 | and the text is displayed until the next input event arrives. | ||
| 754 | Unlike `minibuffer-message-timeout' used by `minibuffer-message', | ||
| 755 | this option affects the pair of functions `set-minibuffer-message' | ||
| 756 | and `clear-minibuffer-message' called automatically via | ||
| 757 | `set-message-function' and `clear-message-function'." | ||
| 758 | :type '(choice (const :tag "Never time out" nil) | ||
| 759 | (integer :tag "Wait for the number of seconds" 2)) | ||
| 760 | :version "27.1") | ||
| 761 | |||
| 762 | (defvar minibuffer-message-timer nil) | ||
| 763 | (defvar minibuffer-message-overlay nil) | ||
| 764 | |||
| 765 | (defun set-minibuffer-message (message) | ||
| 766 | "Temporarily display MESSAGE at the end of the minibuffer. | ||
| 767 | The text is displayed for `minibuffer-message-clear-timeout' seconds | ||
| 768 | (if the value is a number), or until the next input event arrives, | ||
| 769 | whichever comes first. | ||
| 770 | Unlike `minibuffer-message', this function is called automatically | ||
| 771 | via `set-message-function'." | ||
| 772 | (when (and (not noninteractive) | ||
| 773 | (window-live-p (active-minibuffer-window))) | ||
| 774 | (with-current-buffer (window-buffer (active-minibuffer-window)) | ||
| 775 | (setq message (if (string-match-p "\\` *\\[.+\\]\\'" message) | ||
| 776 | ;; Make sure we can put-text-property. | ||
| 777 | (copy-sequence message) | ||
| 778 | (concat " [" message "]"))) | ||
| 779 | (unless (or (null minibuffer-message-properties) | ||
| 780 | ;; Don't overwrite the face properties the caller has set | ||
| 781 | (text-properties-at 0 message)) | ||
| 782 | (setq message (apply #'propertize message minibuffer-message-properties))) | ||
| 783 | |||
| 784 | (clear-minibuffer-message) | ||
| 785 | |||
| 786 | (setq minibuffer-message-overlay | ||
| 787 | (make-overlay (point-max) (point-max) nil t t)) | ||
| 788 | (unless (zerop (length message)) | ||
| 789 | ;; The current C cursor code doesn't know to use the overlay's | ||
| 790 | ;; marker's stickiness to figure out whether to place the cursor | ||
| 791 | ;; before or after the string, so let's spoon-feed it the pos. | ||
| 792 | (put-text-property 0 1 'cursor t message)) | ||
| 793 | (overlay-put minibuffer-message-overlay 'after-string message) | ||
| 794 | |||
| 795 | (when (numberp minibuffer-message-clear-timeout) | ||
| 796 | (setq minibuffer-message-timer | ||
| 797 | (run-with-timer minibuffer-message-clear-timeout nil | ||
| 798 | #'clear-minibuffer-message))) | ||
| 799 | |||
| 800 | ;; Return `t' telling the caller that the message | ||
| 801 | ;; was handled specially by this function. | ||
| 802 | t))) | ||
| 803 | |||
| 804 | (setq set-message-function 'set-minibuffer-message) | ||
| 805 | |||
| 806 | (defun clear-minibuffer-message () | ||
| 807 | "Clear minibuffer message. | ||
| 808 | Intended to be called via `clear-message-function'." | ||
| 809 | (when (not noninteractive) | ||
| 810 | (when (timerp minibuffer-message-timer) | ||
| 811 | (cancel-timer minibuffer-message-timer) | ||
| 812 | (setq minibuffer-message-timer nil)) | ||
| 813 | (when (overlayp minibuffer-message-overlay) | ||
| 814 | (delete-overlay minibuffer-message-overlay) | ||
| 815 | (setq minibuffer-message-overlay nil)))) | ||
| 816 | |||
| 817 | (setq clear-message-function 'clear-minibuffer-message) | ||
| 818 | |||
| 749 | (defun minibuffer-completion-contents () | 819 | (defun minibuffer-completion-contents () |
| 750 | "Return the user input in a minibuffer before point as a string. | 820 | "Return the user input in a minibuffer before point as a string. |
| 751 | In Emacs 22, that was what completion commands operated on. | 821 | In Emacs 22, that was what completion commands operated on. |