Function: toolbarx-install-toolbar

toolbarx-install-toolbar is an autoloaded and byte-compiled function defined in toolbar-x.el.

Signature

(toolbarx-install-toolbar BUTTONS &optional MEANING-ALIST GLOBAL-FLAG)

Documentation

Install toolbar buttons given in BUTTONS.

Button properties are optionally given in MEANING-ALIST. If GLOBAL-FLAG is non-nil, toolbar is installed globally (on every buffer that does not have a toolbar set locally). BUTTONS is a list of format
  (ELEM ... ELEM . PROPS),
where each ELEM is either

 - a list in the same format od BUTTONS, which is going to be
   refered as a *group*; groups are used to distribute properties
   recursively to its elements; there are groups with special
   format for special purpose: *dropdown groups* and also *eval
   groups*.

 - a symbol, which could be associated in MEANING-ALIST with a
   list of button properties (symbol + properties = a *button*)
   or associated to a special kind of group (an *alias group*).

Meaning alist
=============

MEANING-ALIST is a list where each element is in one of the formats (SYMB . BUTTON-PROPS-LIST) or (SYMB . ALIAS-GROUP). BUTTON-PROPS-LIST is a list in one of the formats
  (IMAGE COMMAND PROP VAL PROP VAL ... PROP VAL) or
  (PROP VAL PROP VAL ... PROP VAL).
The IMAGE is going to be used as the :image property of the button (see button properties bellow), and COMMAND shall be used as the :command property of the button. Each PROP is one of the button properties, and VAL is its respective value. ALIAS-GROUP is a list which first element is the symbol :alias and the cdr shall be processed as a group.

However, a symbol is not required to have an association in MEANING-ALIST, which is only a way to specify properties to a button. One can use groups to specify properties. Nil is a good MEANING-ALIST.

Buttons
=======

A toolbar button in toolbarx is the set with a symbol and properties used to display the button, like a image and a command to call when the button is pressed (which are the minimal
elements that a button should have.) The supported properties
for buttons and their basic types (see note on how values of properties are obtained!) are:

 :image -- either a string or image descriptor (see
   info for a definition), or a variable bound to a image
   descriptor (like those defined with defimage) or a list of 4
   strings or image descriptors;
   defines the image file displayed by the button. If
   it is a string, the image file found with that name (always
   using the function toolbarx-find-image to make the
   internal image descriptor) is used as button image. For
   the other formats, the button image is handled in the same way
   as it is treated by the editors; see info nodes bellow for a
   description of the capabilities:
             info file "elisp", node "Tool Bar" (see :image property);
             PS: a *vector* of four strings is used in the Emacs
             Lisp documentation as the more ellaborated image
             property format, but here we reserve vectors to
             provide editor-dependent values; this motivates our
             choice for a list instead of vector (however,
             internally the list becomes a vector when displaying
             the button).

 :command -- a form; if the form happens to be a command, it will
   be called with call-interactively.

 :append-command -- a form added to the end of the value of
   :command.

 :prepend-command -- a form added at the beginning of the value
   of :command.

 :help -- either a string or nil; defined the help string of the
   button;

 :enable -- a form, evaluated constantly by both editors to
   determine if a button is active (enabled) or not.

 :visible -- a form that is evaluated constantly to
   determine if a button is visible.

 :button -- a cons cell (TYPE . SELECTED) where the
   TYPE should be :toggle or :radio and the cdr should be a
   form. SELECTED is evaluated to determine when the button is
   selected.

 :insert -- a form that is evaluated every time that the toolbar
   is refresh (a call of toolbarx-refresh) to determine if the
   button is inserted or just ignored (until next refresh).

How to specify a button
=======================

One can specify a button by its symbol or by a group to specify properties. For example,
  BUTTON =
    ( foo
      (bar :image "bar"
           :command bar-function :help "Bar help string")
      :insert foo-bar )
  MEANING-ALIST = ( (foo :image "foo" :command foo-function) )
specifiy two buttons foo and bar, each one with its necessary
:image and :command properties, and both use the :insert property
specified ate the end of BUTTONS (because groups distribute properties to all its elements). foo and bar will be inserted only if foo-bar evaluation yields non-nil.

Note on how values of properties are obtained
=============================================

For each property PROP, its value should be either:
   i) a vector of 2 elements; then each element should be of the
      basic type of PROP.
  ii) an element on the basic type of PROP.
 iii) a function (that does not need arguments); it is evaluated
      and the return should be ot type i) or ii) above
  iv) a symbol bound to a element of type i) or ii).

The type is cheched in the order i), ii) iii) and iv). This evaluations are done every time that the oolbar is refresh.

Ps.: in order to specify a vector as value of a property (like the :image in Emacs), it is necessary to provide the vector as element of another vector.

Special groups
==============

Eval groups
-----------

If the first element of a group is the symbol :eval-group, each element is evaluated (with eval), put inside a list and processed like a group. Eval groups are useful to store definition of buttons in a variable.

Dropdown groups
---------------

The idea is to specify a set of buttons that appear when a determined menu item of a dropdown menu is active. The dropdown menu appears when a button (by default with a triangle pointing down) is clicked. This button is called dropdown button. The dropdown button appears on the left of the currently visible buttons of the dropdown group.

A dropdown group is a list which first element is the symbol
:dropdown-group and in one of the following formats
  (:dropdown-group SYMBOL-1 ... SYMBOL-n PROP-1 VAL-1 ... PROP-k VAL-k)
or
  (:dropdown-group
     STRING-1 ITEM-11 ... ITEM-1n
     STRING-2 ITEM-21 ... ITEM-2m
           . . .
     STRING-n ITEM-n1 ... ITEM-np
       PROP-1 VAL-1 ... PROP-j VAL-j)
where
 SYMBOL-* is a symbol that defines a button in MEANING-ALIST;
 STRING-* is a string that will appear in the dropdown menu;
 ITEM-* is any format that define buttons or groups.

(a dropdown group of first format is internally converted to the
second by making strings from the symbols and each symbol is the item)

The same rules for obtaining property values, described above, apply here. Properties are also distributed by groups. The supported properties and their basic type are:

 :type -- one of the symbols radio (default) or toggle; if
   type is radio, only one of the itens may be active, and if
   type is toggle, any item number of itens can be active.

 :variable -- a symbol; it is the variable that govern the
   dropdown button; every time the value should be an integer
   starting from 1 (if type is radio) or a list of integers (if
   type is toggle). The Nth set of buttons is :insert'ed.

 :default -- determines the default value when the menu is
   installed; it is ignored if a value was saved with custom; it
   defaults to 1 if type is radio or nil if type is toggle. If
   value is a integer and type is toggle, value used is a list
   with that integer.

 :save -- one of the symbols nil (default), offer or
   always; determined if it is possible for the user to save
   the which menu itens are active, for a next session. If value
   is offer, a item (offering to save) is added to the
   popup menu. If the value is always, every time that a item
   is selected, the variable is saved. If value is nil, variable
   shall not be saved. If value is non-nil then :variable is
   mandatory.

 :title -- a string or nil; if a string, the popup menu will show
   is as menu title; if nil, no title is shown.

 :dropdown-help -- a string or nil; the help string of the
   dropdown button.

 :dropdown-image -- either a string or a vector of 4 strings;
   defines the image file displayed by the dropdown button;
   by default, it is the string "dropdown".

 :dropdown-append-command,
 :dropdownprepend-command -- a form; append or prepend forms to
   the command that shows the dropdown menu, allowing extra code
   to run before or after the menu appears (remember that every
   menu item clicked refresh the toolbar.)

 :dropdown-enable -- a form; evaluated constantly by both editors
   to determine if the dropdown button is active (enabled) or
   not.

 :dropdown-visible -- a form; it is evaluated
   constantly to determine if the dropdown button is visible.

Also, if the symbol dropdown is associted in MEANING-ALIST with some properties, these properties override (or add) with higher precedence.

Special buttons
===============

If the symbol of a button is :new-line, it is inserted a (faked) return, and the next button will be displayed a next line of buttons. The only property supported for this button is
:insert.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/toolbar-x.el
;;;###autoload (autoload 'toolbarx-install-toolbar "toolbar-x")

(defun toolbarx-install-toolbar (buttons &optional meaning-alist global-flag)
  "Install toolbar buttons given in BUTTONS.
Button properties are optionally given in MEANING-ALIST.  If
GLOBAL-FLAG is non-nil, toolbar is installed globally (on every
buffer that does not have a toolbar set locally).  BUTTONS is a
list of format
  (ELEM ... ELEM . PROPS),
where each ELEM is either

 - a list in the same format od BUTTONS, which is going to be
   refered as a *group*; groups are used to distribute properties
   recursively to its elements; there are groups with special
   format for special purpose: *dropdown groups* and also *eval
   groups*.

 - a symbol, which could be associated in MEANING-ALIST with a
   list of button properties (symbol + properties = a *button*)
   or associated to a special kind of group (an *alias group*).

Meaning alist
=============

MEANING-ALIST is a list where each element is in one of the
formats (SYMB . BUTTON-PROPS-LIST) or (SYMB .  ALIAS-GROUP).
BUTTON-PROPS-LIST is a list in one of the formats
  (IMAGE COMMAND PROP VAL PROP VAL ... PROP VAL)  or
  (PROP VAL PROP VAL ... PROP VAL).
The IMAGE is going to be used as the `:image' property of the
button (see button properties bellow), and COMMAND shall be used
as the `:command' property of the button.  Each PROP is one of
the button properties, and VAL is its respective value.
ALIAS-GROUP is a list which first element is the symbol `:alias'
and the cdr shall be processed as a group.

However, a symbol is not required to have an association in
MEANING-ALIST, which is only a way to specify properties to a
button.  One can use groups to specify properties.  Nil is a good
MEANING-ALIST.

Buttons
=======

A toolbar button in `toolbarx' is the set with a symbol and
properties used to display the button, like a image and a command
to call when the button is pressed (which are the minimal
elements that a button should have.)  The supported properties
for buttons and their `basic types' (see note on how values of
properties are obtained!) are:

 :image -- either a string or image descriptor (see
   info for a definition), or a variable bound to a image
   descriptor (like those defined with `defimage') or a list of 4
   strings or image descriptors;
   defines the image file displayed by the button.  If
   it is a string, the image file found with that name (always
   using the function `toolbarx-find-image' to make the
   \`internal\' image descriptor) is used as button image.  For
   the other formats, the button image is handled in the same way
   as it is treated by the editors; see info nodes bellow for a
   description of the capabilities:
             info file \"elisp\", node \"Tool Bar\" (see `:image' property);
             PS: a *vector* of four strings is used in the Emacs
             Lisp documentation as the `more ellaborated' image
             property format, but here we reserve vectors to
             provide editor-dependent values; this motivates our
             choice for a list instead of vector (however,
             internally the list becomes a vector when displaying
             the button).

 :command -- a form; if the form happens to be a command, it will
   be called with `call-interactively'.

 :append-command -- a form added to the end of the value of
   `:command'.

 :prepend-command -- a form added at the beginning of the value
   of `:command'.

 :help -- either a string or nil; defined the help string of the
   button;

 :enable -- a form, evaluated constantly by both editors to
   determine if a button is active (enabled) or not.

 :visible -- a form that is evaluated constantly to
   determine if a button is visible.

 :button -- a cons cell (TYPE .  SELECTED) where the
   TYPE should be `:toggle' or `:radio' and the cdr should be a
   form.  SELECTED is evaluated to determine when the button is
   selected.

 :insert -- a form that is evaluated every time that the toolbar
   is refresh (a call of `toolbarx-refresh') to determine if the
   button is inserted or just ignored (until next refresh).

How to specify a button
=======================

One can specify a button by its symbol or by a group to specify
properties.  For example,
  BUTTON =
    ( foo
      (bar :image \"bar\"
           :command bar-function :help \"Bar help string\")
      :insert foo-bar )
  MEANING-ALIST = ( (foo :image \"foo\" :command foo-function) )
specifiy two buttons `foo' and `bar', each one with its necessary
:image and :command properties, and both use the :insert property
specified ate the end of BUTTONS (because groups distribute
properties to all its elements).  `foo' and `bar' will be
inserted only if `foo-bar' evaluation yields non-nil.

Note on how values of properties are obtained
=============================================

For each property PROP, its value should be either:
   i) a vector of 2 elements; then each element should be of the
      basic type of PROP.
  ii) an element on the basic type of PROP.
 iii) a function (that does not need arguments); it is evaluated
      and the return should be ot type i) or ii) above
  iv) a symbol bound to a element of type i) or ii).

The type is cheched in the order i), ii) iii) and iv).  This
evaluations are done every time that the oolbar is refresh.

Ps.: in order to specify a vector as value of a property (like
the :image in Emacs), it is necessary to provide the vector as
element of another vector.

Special groups
==============

Eval groups
-----------

If the first element of a group is the symbol `:eval-group', each
element is evaluated (with `eval'), put inside a list and
processed like a group.  Eval groups are useful to store
definition of buttons in a variable.

Dropdown groups
---------------

The idea is to specify a set of buttons that appear when a
determined menu item of a dropdown menu is active.  The dropdown
menu appears when a button (by default with a triangle pointing
down) is clicked.  This button is called `dropdown button'.  The
dropdown button appears on the left of the currently visible
buttons of the dropdown group.

A dropdown group is a list which first element is the symbol
`:dropdown-group' and in one of the following formats
  (:dropdown-group SYMBOL-1 ... SYMBOL-n  PROP-1 VAL-1 ... PROP-k VAL-k)
or
  (:dropdown-group
     STRING-1 ITEM-11 ... ITEM-1n
     STRING-2 ITEM-21 ... ITEM-2m
           . . .
     STRING-n ITEM-n1 ... ITEM-np
       PROP-1 VAL-1 ... PROP-j VAL-j)
where
 SYMBOL-* is a symbol that defines a button in MEANING-ALIST;
 STRING-* is a string that will appear in the dropdown menu;
 ITEM-* is any format that define buttons or groups.

\(a dropdown group of first format is internally converted to the
second by making strings from the symbols and each symbol is the
item)

The same rules for obtaining property values, described above,
apply here.  Properties are also distributed by groups.  The
supported properties and their basic type are:

 :type -- one of the symbols `radio' (default) or `toggle'; if
   type is radio, only one of the itens may be active, and if
   type is toggle, any item number of itens can be active.

 :variable -- a symbol; it is the variable that govern the
   dropdown button; every time the value should be an integer
   starting from 1 (if type is radio) or a list of integers (if
   type is toggle).  The Nth set of buttons is :insert'ed.

 :default -- determines the default value when the menu is
   installed; it is ignored if a value was saved with custom; it
   defaults to 1 if type is radio or nil if type is toggle.  If
   value is a integer and type is `toggle', value used is a list
   with that integer.

 :save -- one of the symbols nil (default), `offer' or
   `always'; determined if it is possible for the user to save
   the which menu itens are active, for a next session.  If value
   is `offer', a item (offering to save) is added to the
   popup menu.  If the value is `always', every time that a item
   is selected, the variable is saved.  If value is nil, variable
   shall not be saved.  If value is non-nil then `:variable' is
   mandatory.

 :title -- a string or nil; if a string, the popup menu will show
   is as menu title; if nil, no title is shown.

 :dropdown-help -- a string or nil; the help string of the
   dropdown button.

 :dropdown-image -- either a string or a vector of 4 strings;
   defines the image   file displayed by the dropdown button;
   by default, it is the string \"dropdown\".

 :dropdown-append-command,
 :dropdownprepend-command -- a form; append or prepend forms to
   the command that shows the dropdown menu, allowing extra code
   to run before or after the menu appears (remember that every
   menu item clicked refresh the toolbar.)

 :dropdown-enable -- a form; evaluated constantly by both editors
   to determine if the dropdown button is active (enabled) or
   not.

 :dropdown-visible -- a form; it is evaluated
   constantly to determine if the dropdown button is visible.

Also, if the symbol `dropdown' is associted in MEANING-ALIST
with some properties, these properties override (or add) with
higher precedence.

Special buttons
===============

If the symbol of a button is `:new-line', it is inserted
a (faked) return, and the next button will be displayed a next
line of buttons.  The only property supported for this button is
`:insert'."
  (let ((switches (toolbarx-process-group buttons meaning-alist nil nil)))
    (if global-flag
        (setq-default toolbarx-internal-button-switches
                      switches)
      (setq-local toolbarx-internal-button-switches switches)
      (make-local-variable 'tool-bar-map)))
  (toolbarx-refresh global-flag))