Function: window-tool-bar--keymap-entry-to-string
window-tool-bar--keymap-entry-to-string is a byte-compiled function
defined in window-tool-bar.el.gz.
Signature
(window-tool-bar--keymap-entry-to-string MENU-ITEM)
Documentation
Convert MENU-ITEM into a (propertized) string representation.
MENU-ITEM is a menu item to convert. See info node (elisp)Tool Bar.
Source Code
;; Defined in /usr/src/emacs/lisp/window-tool-bar.el.gz
(defun window-tool-bar--keymap-entry-to-string (menu-item)
"Convert MENU-ITEM into a (propertized) string representation.
MENU-ITEM is a menu item to convert. See info node `(elisp)Tool Bar'."
(pcase-exhaustive menu-item
;; Separators
((or `(,_ "--")
`(,_ menu-item ,(and (pred stringp)
(pred (string-prefix-p "--")))))
(if (eq 'text (window-tool-bar--style)) "|"
window-tool-bar--graphical-separator))
;; Menu item, turn into propertized string button
(`(,key menu-item ,name-expr ,binding . ,plist)
(let* ((visible-entry (plist-member plist :visible))
(visible (or (null visible-entry) ;Default is visible
(eval (cadr visible-entry))))
(wrap (plist-get plist :wrap))
(filter (plist-get plist :filter)))
(when filter
(setf binding
;; You would expect this to use `funcall', but existing
;; code in `parse_tool_bar_item' uses `eval'.
(eval `(,filter ',binding))))
(when (and binding
visible
(null wrap))
(let* ((name (eval name-expr))
(str (upcase-initials (or (plist-get plist :label)
(string-trim-right name "\\.+"))))
(len (length str))
(enable-form (plist-get plist :enable))
(enabled (or (not enable-form)
(eval enable-form)))
(button-spec (plist-get plist :button))
(button-selected (eval (cdr-safe button-spec)))
(vert-only (plist-get plist :vert-only))
image-start
image-end)
;; Depending on style, Images can be displayed to the
;; left, to the right, or in place of the text
(pcase-exhaustive (window-tool-bar--style)
('image
(setf image-start 0
image-end len))
('text
;; Images shouldn't be available
)
((or 'both 'both-horiz)
(if vert-only
(setf image-start 0 image-end len)
(setf str (concat " " str)
image-start 0
image-end 1
len (1+ len))))
('text-image-horiz
(if vert-only
(setf image-start 0 image-end len)
(setf str (concat str " ")
image-start len
image-end (1+ len)
len (1+ len)))))
(cond
((and enabled button-selected)
(add-text-properties 0 len
'(mouse-face
window-tool-bar-button-checked-hover
keymap window-tool-bar--button-keymap
face window-tool-bar-button-checked)
str))
(enabled
(add-text-properties 0 len
'(mouse-face window-tool-bar-button-hover
keymap window-tool-bar--button-keymap
face window-tool-bar-button)
str))
(t
(put-text-property 0 len
'face
'window-tool-bar-button-disabled
str)))
(when-let* ((spec (and image-start image-end
(plist-get menu-item :image))))
(put-text-property image-start image-end
'display
(append spec
(if enabled '(:margin 2 :ascent center)
'(:margin 2 :ascent center
:conversion disabled)))
str))
(let ((help-text (or (plist-get plist :help) name))
(keys (where-is-internal binding nil t)))
(put-text-property 0 len
'help-echo
(if keys
(concat help-text
" ("
(key-description keys)
")")
help-text)
str))
(put-text-property 0 len 'tool-bar-key key str)
str))))))