Function: toolbarx-emacs-add-button
toolbarx-emacs-add-button is a byte-compiled function defined in
toolbar-x.el.
Signature
(toolbarx-emacs-add-button BUTTON USED-KEYS KEYMAP)
Documentation
Insert a button where BUTTON is its description.
USED-KEYS should be a list of symbols, where the first element is
:used-symbols. This list should store the symbols of the
buttons already inserted. This list is changed by side effect.
KEYMAP is the keymap where the menu-item corresponding to the
tool-bal button is going to be inserted. Insertion is made in
the end of KEYMAP.
BUTTON should be a list of form (SYMBOL . PROP-LIST). SYMBOL is
a symbol that "names" this button. PROP-LIST is a list in the
format (PROP VAL ... PROP VAL). The supported properties are
:image, :command, :append-command, :prepend-command,
:help, :enable, :visible, :button, and :insert.
For a description of properties, see documentation of
function toolbar-install-toolbar.
Source Code
;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/toolbar-x.el
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Second engine: display parsed buttons in Emacs
(defun toolbarx-emacs-add-button (button used-keys keymap)
"Insert a button where BUTTON is its description.
USED-KEYS should be a list of symbols, where the first element is
`:used-symbols'. This list should store the symbols of the
buttons already inserted. This list is changed by side effect.
KEYMAP is the keymap where the menu-item corresponding to the
tool-bal button is going to be inserted. Insertion is made in
the end of KEYMAP.
BUTTON should be a list of form (SYMBOL . PROP-LIST). SYMBOL is
a symbol that \"names\" this button. PROP-LIST is a list in the
format (PROP VAL ... PROP VAL). The supported properties are
`:image', `:command', `:append-command', `:prepend-command',
`:help', `:enable', `:visible', `:button', and `:insert'.
For a description of properties, see documentation of
function `toolbar-install-toolbar'."
(let* ((symbol (nth 0 button))
(used-keys-list (when used-keys
(cdr used-keys)))
(filtered-props
(let* ((filtered-props-temp)
(prop-good-val)
(prop))
(dolist (p (nth 0 toolbarx-button-props) filtered-props-temp)
;; property -> (car p)
;; test type function -> (cadr p)
;; add-function -> (cddr p)
(setq prop (memq (car p) button))
;; if so, check if value is of correct type
(when prop
;; if property is of add-type, them the value is a list
;; (:add-value-list VAL VAL). Each VAL should be checked.
(if (and (cddr p) (eq :add-value-list (car (cadr prop))))
(let* ((add-list (list (cddr p))))
(dolist (val (cdr (cadr prop)))
(setq prop-good-val (funcall (cadr p) val))
(when (car prop-good-val)
(setq add-list (cons (cdr prop-good-val) add-list))))
(setq add-list (nreverse add-list))
(when (eq 2 (length add-list)) ; just 1 value, no
; add-function
(setq add-list (cadr add-list)))
(setq filtered-props-temp (append
(list (car p) add-list)
filtered-props-temp)))
;; if override-property
(setq prop-good-val (funcall (cadr p) (cadr prop)))
(when (car prop-good-val)
(setq filtered-props-temp (append
(list (car p)
(cdr prop-good-val))
filtered-props-temp))))))))
(insert (or (not (memq :insert filtered-props))
;; (memq :insert filtered-props)
(eval (nth 1 (memq :insert filtered-props)) t))))
(when insert
(cond
(t
;; symbol is not :new-line, therefore a normal button
(let* ((image (cadr (memq :image filtered-props)))
(image-descriptor
(when (memq :image filtered-props)
(cond
((stringp image) ; string
(toolbarx-find-image image))
((and (consp image) ; or image descriptor
(eq (car image) 'image))
image)
((and (symbolp image) ; or a symbol bound to a
(boundp image) ; image descriptor (defined
; with `defimage')g
(consp (symbol-value image))
(eq (car (symbol-value image)) 'image))
(symbol-value image))
(t ; otherwise, must be a list
; with 4 strings or image
; descriptors
(apply #'vector (mapcar (lambda (img)
(if (stringp img)
(toolbarx-find-image img)
img))
image))))))
(command
(let* ((com (nth 1 (memq :command filtered-props)))
(app (nth 1 (memq :append-command filtered-props)))
(prep (nth 1 (memq :prepend-command filtered-props))))
(when (or com app prep)
(toolbarx-make-command com prep app))))
(help (cons (memq :help filtered-props)
(cadr (memq :help filtered-props))))
(enable (cons (memq :enable filtered-props)
(cadr (memq :enable filtered-props))))
(visible (cons (memq :visible filtered-props)
(cadr (memq :visible filtered-props))))
(button (cons (memq :button filtered-props)
(cadr (memq :button filtered-props))))
(menuitem (if (eq symbol 'separator)
'(menu-item "--")
(append
(list 'menu-item
(toolbarx-make-string-from-symbol symbol)
command
:image image-descriptor)
(when (car help)
(list :help (cdr help)))
(when (car enable)
(list :enable (cdr enable)))
(when (car visible)
(list :visible (cdr visible)))
(when (car button)
(list :button (cdr button)))
'(:vert-only t))))
(key-not-used
(let* ((count 0)
(symb symbol))
(while (memq symb used-keys-list)
(setq count (1+ count))
(setq symb (intern (format "%s-%d" symbol count))))
symb)))
(when (and image-descriptor command)
(setq used-keys-list (cons key-not-used used-keys-list))
(define-key-after keymap
(vector key-not-used) menuitem))))))
(when used-keys (setcdr used-keys used-keys-list))))