Function: compat--set-transient-map

compat--set-transient-map is a byte-compiled function defined in compat-29.el.

Signature

(compat--set-transient-map MAP &optional KEEP-PRED ON-EXIT MESSAGE TIMEOUT)

Documentation

[Compatibility function for set-transient-map, defined in Emacs 29.1. See
(compat) Emacs 29.1' for more details.]

Handle the optional arguments MESSAGE and TIMEOUT.

Source Code

;; Defined in ~/.emacs.d/elpa/compat-30.1.0.1/compat-29.el
(compat-defun set-transient-map (map &optional keep-pred on-exit message timeout) ;; <compat-tests:set-transient-map>
  "Handle the optional arguments MESSAGE and TIMEOUT."
  :extended t
  (unless (fboundp 'format-spec)
    (require 'format-spec))
  (let* ((timeout (or set-transient-map-timeout timeout))
         (message
          (when message
            (let (keys)
              (map-keymap (lambda (key cmd) (and cmd (push key keys))) map)
              (format-spec (if (stringp message) message "Repeat with %k")
                           `((?k . ,(mapconcat
                                     (lambda (key)
                                       (substitute-command-keys
                                        (format "\\`%s'"
                                                (key-description (vector key)))))
                                     keys ", ")))))))
         (clearfun (make-symbol "clear-transient-map"))
         (exitfun
          (lambda ()
            (internal-pop-keymap map 'overriding-terminal-local-map)
            (remove-hook 'pre-command-hook clearfun)
            (when message (message ""))
            (when set-transient-map-timer (cancel-timer set-transient-map-timer))
            (when on-exit (funcall on-exit)))))
    (fset clearfun
          (lambda ()
            (with-demoted-errors "set-transient-map PCH: %S"
              (if (cond
                       ((null keep-pred) nil)
                       ((and (not (eq map (cadr overriding-terminal-local-map)))
                             (memq map (cddr overriding-terminal-local-map)))
                        t)
                       ((eq t keep-pred)
                        (let ((mc (lookup-key map (this-command-keys-vector))))
                          (when (and mc (symbolp mc))
                            (setq mc (or (command-remapping mc) mc)))
                          (and mc (eq this-command mc))))
                       (t (funcall keep-pred)))
                  (when message (message "%s" message))
                (funcall exitfun)))))
    (add-hook 'pre-command-hook clearfun)
    (internal-push-keymap map 'overriding-terminal-local-map)
    (when timeout
      (when set-transient-map-timer (cancel-timer set-transient-map-timer))
      (setq set-transient-map-timer (run-with-idle-timer timeout nil exitfun)))
    (when message (message "%s" message))
    exitfun))