aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJuri Linkov2019-12-22 00:02:10 +0200
committerJuri Linkov2019-12-22 00:02:10 +0200
commit485b423e8f0df2711a850be7f254665f64ab0bdb (patch)
tree02f294b4daa4ec7718769afe8235a7119b52bcb5 /lisp
parent678a71ea2d044f19f75e3f45c930c5e3b707e3dc (diff)
downloademacs-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.el70
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.
751If the value is a number, it should be specified in seconds.
752If the value is not a number, such messages never time out,
753and the text is displayed until the next input event arrives.
754Unlike `minibuffer-message-timeout' used by `minibuffer-message',
755this option affects the pair of functions `set-minibuffer-message'
756and `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.
767The text is displayed for `minibuffer-message-clear-timeout' seconds
768(if the value is a number), or until the next input event arrives,
769whichever comes first.
770Unlike `minibuffer-message', this function is called automatically
771via `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.
808Intended 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.
751In Emacs 22, that was what completion commands operated on. 821In Emacs 22, that was what completion commands operated on.