如何在Emacs中将项目添加到工具栏

如何在Emacs中将项目添加到工具栏,emacs,menu,add,toolbar,Emacs,Menu,Add,Toolbar,我想将项目添加到Emacs中的工具栏。我听说Emacs甚至可以在工具栏上添加菜单项 谢谢。以下是乳胶模式的一个示例: ;;; Installation of the tool bar ;;;###autoload (defun LaTeX-install-toolbar () "Install toolbar buttons for LaTeX mode." (interactive) (require 'toolbar-x) (add-to-list 'toolbarx-im

我想将项目添加到Emacs中的工具栏。我听说Emacs甚至可以在工具栏上添加菜单项


谢谢。

以下是乳胶模式的一个示例:

;;; Installation of the tool bar
;;;###autoload
(defun LaTeX-install-toolbar ()
  "Install toolbar buttons for LaTeX mode."
  (interactive)
  (require 'toolbar-x)
  (add-to-list 'toolbarx-image-path
           (expand-file-name "images" TeX-data-directory))
  (add-hook 'TeX-PDF-mode-hook 'toolbarx-refresh nil t)
  (toolbarx-install-toolbar TeX-bar-LaTeX-buttons
                (let ((append-list))
                  (dolist (elt TeX-bar-LaTeX-all-button-alists)
                (setq append-list (append append-list
                              (eval elt))))
                  append-list)))
使用
M-x apropos工具栏
并点击源EL文件找到

toolbarx安装工具栏的文档相当长:

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*).

 - a vector, which elements are on the previous formats (but not
   another vector); this is useful to specify different
   ingredients to the toolbar depending if editor is Emacs or
   XEmacs; the first element will be used in Emacs; the second
   element is going to be used in XEmacs.

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 -- in Emacs, 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; in XEmacs, either a string or a
   glyph, or a symbol bount to a glyph, or a list of at least 1
   and at most 6 strings or glyphs or nil (not the first element
   though); 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 of each editor
      Emacs: 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).
     XEmacs: info file \"lispref\", node \"Toolbar Descriptor
             Format\" (see GLYPH-LIST) or the documentation of
             the variable `default-toolbar'; check the inheritage
             in case of a ommited glyph or nil instead of glyph.

 :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 -- in Emacs, a form that is evaluated constantly to
   determine if a button is visible; in XEmacs, this property is
   ignored.

 :button -- in Emacs, 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.  This property is ignored in XEmacs.

 :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).

 :toolbar -- in XEmacs, either one of the symbols `default',
   `top', `bottom', `left', `right', or a cons cell
   (POS . POS-AVOID-DEFAULT) where POS and POS-AVOID-DEFAULT
   should be one of the symbols `top', `bottom', `left', `right';
   if a symbol, the button will be inserted in one of these
   toolbars; if a cons cell, button will be inserted in toolbar
   POS unless the position of the default toolbar is POS (then,
   the default toolbar would override the position-specific
   toolbar), and in this case, button will be inserted in toolbar
   POS-AVOID-DEFAULT; in Emacs, this property is meaningless, and
   therefore ignored.  Hint of use of this property: in a
   program, use or everything with `default' and the cons format
   to avoid the default toolbar, or use only the position
   specific buttons (symbols that are not `default'), because of
   the `overriding' system in XEmacs, when a position-specific
   toolbar overrides the default toolbar; for instance, if you
   put a button in the default toolbar and another in the top
   toolbar (and the default toolbar is in the top), then *only*
   the ones in the top toolbar will be visible!

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-Emacs\" \"bar-XEmacs\"]
           :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.  `bar' used
a different :image property depending if editor is Emacs or
XEmacs.

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 -- in Emacs, either a string or a vector of 4
   strings; in XEmacs, either a string or a glyph or a list of at
   least 1 and at most 6 strings or glyphs; 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; in Emacs, it is evaluated
   constantly to determine if the dropdown button is visible; in
   XEmacs, this property is ignored.

 :dropdown-toolbar -- in XEmacs, one of the symbols `default',
   `opposite', `top', `bottom', `left' or `right'; ignored in
   Emacs; in XEmacs, the toolbar where the dropdown button will
   appear.

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'.  This feature is available only in Emacs.  In XEmacs,
this button is ignored.

嗨,我找到了一个简单的解决方案来添加工具栏按钮 “拼写”是/usr/share/emacs/23.4/etc/images中的图像/

(defun omar-hotel ()
 "another nonce menu function"
 (interactive)
 (message "hotel, motel, holiday inn"))

    (tool-bar-add-item "spell" 'omar-hotel
               'omar-hotel
               :help   "Run fonction omar-hotel")

有一节是关于这样做的。根据你的建议,我可以添加项目(使用“工具栏添加项目”)。顺便说一句,我使用16x16xbm文件作为图标。它太小了,画不出图像。我想使用较大尺寸的图标。那么可以使用什么图标大小呢?谢谢。我自己也没试过,所以不能提供任何建议。我在
.emacs
中首先要做的事情之一是关闭工具栏。:)谢谢但我在Emacs环境中找不到“toolbarx安装工具栏”。无论如何,我可以使用“工具栏添加项目”功能将项目添加到工具栏上。(正如努法尔·易卜拉欣对我的问题所作的评论)。非常感谢。这样一个简单的答案,让我们来谈正事吧。