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

Kei*_*awa 6 emacs menu add toolbar

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

在此处输入图片说明

谢谢。

use*_*990 6

您好,我找到了一个简单的解决方案来添加工具栏按钮“拼写”是 /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")
Run Code Online (Sandbox Code Playgroud)


BRP*_*ock 3

这是 LaTeX 模式的示例:

\n\n
;;; Installation of the tool bar\n;;;###autoload\n(defun LaTeX-install-toolbar ()\n  "Install toolbar buttons for LaTeX mode."\n  (interactive)\n  (require \'toolbar-x)\n  (add-to-list \'toolbarx-image-path\n           (expand-file-name "images" TeX-data-directory))\n  (add-hook \'TeX-PDF-mode-hook \'toolbarx-refresh nil t)\n  (toolbarx-install-toolbar TeX-bar-LaTeX-buttons\n                (let ((append-list))\n                  (dolist (elt TeX-bar-LaTeX-all-button-alists)\n                (setq append-list (append append-list\n                              (eval elt))))\n                  append-list)))\n
Run Code Online (Sandbox Code Playgroud)\n\n

使用发现M-x apropos <RET> toolbar <RET>并点击进入源EL文件\xe2\x80\xa6

\n\n

其文档toolbarx-install-toolbar相当冗长:

\n\n
Install toolbar buttons given in BUTTONS.\nButton properties are optionally given in MEANING-ALIST.  If\nGLOBAL-FLAG is non-nil, toolbar is installed globally (on every\nbuffer that does not have a toolbar set locally).  BUTTONS is a\nlist of format\n  (ELEM ... ELEM . PROPS),\nwhere each ELEM is either\n\n - a list in the same format od BUTTONS, which is going to be\n   refered as a *group*; groups are used to distribute properties\n   recursively to its elements; there are groups with special\n   format for special purpose: *dropdown groups* and also *eval\n   groups*.\n\n - a symbol, which could be associated in MEANING-ALIST with a\n   list of button properties (symbol + properties = a *button*)\n   or associated to a special kind of group (an *alias group*).\n\n - a vector, which elements are on the previous formats (but not\n   another vector); this is useful to specify different\n   ingredients to the toolbar depending if editor is Emacs or\n   XEmacs; the first element will be used in Emacs; the second\n   element is going to be used in XEmacs.\n\nMeaning alist\n=============\n\nMEANING-ALIST is a list where each element is in one of the\nformats (SYMB . BUTTON-PROPS-LIST) or (SYMB .  ALIAS-GROUP).\nBUTTON-PROPS-LIST is a list in one of the formats\n  (IMAGE COMMAND PROP VAL PROP VAL ... PROP VAL)  or\n  (PROP VAL PROP VAL ... PROP VAL).\nThe IMAGE is going to be used as the `:image\' property of the\nbutton (see button properties bellow), and COMMAND shall be used\nas the `:command\' property of the button.  Each PROP is one of\nthe button properties, and VAL is its respective value.\nALIAS-GROUP is a list which first element is the symbol `:alias\'\nand the cdr shall be processed as a group.\n\nHowever, a symbol is not required to have an association in\nMEANING-ALIST, which is only a way to specify properties to a\nbutton.  One can use groups to specify properties.  Nil is a good\nMEANING-ALIST.\n\nButtons\n=======\n\nA toolbar button in `toolbarx\' is the set with a symbol and\nproperties used to display the button, like a image and a command\nto call when the button is pressed (which are the minimal\nelements that a button should have.)  The supported properties\nfor buttons and their `basic types\' (see note on how values of\nproperties are obtained!) are:\n\n :image -- in Emacs, either a string or image descriptor (see\n   info for a definition), or a variable bound to a image\n   descriptor (like those defined with `defimage\') or a list of 4\n   strings or image descriptors; in XEmacs, either a string or a\n   glyph, or a symbol bount to a glyph, or a list of at least 1\n   and at most 6 strings or glyphs or nil (not the first element\n   though); defines the image file displayed by the button.  If\n   it is a string, the image file found with that name (always\n   using the function `toolbarx-find-image\' to make the\n   \\`internal\\\' image descriptor) is used as button image.  For\n   the other formats, the button image is handled in the same way\n   as it is treated by the editors; see info nodes bellow for a\n   description of the capabilities of each editor\n      Emacs: info file \\"elisp\\", node \\"Tool Bar\\" (see `:image\'\n             property);\n             PS: a *vector* of four strings is used in the Emacs\n             Lisp documentation as the `more ellaborated\' image\n             property format, but here we reserve vectors to\n             provide editor-dependent values; this motivates our\n             choice for a list instead of vector (however,\n             internally the list becomes a vector when displaying\n             the button).\n     XEmacs: info file \\"lispref\\", node \\"Toolbar Descriptor\n             Format\\" (see GLYPH-LIST) or the documentation of\n             the variable `default-toolbar\'; check the inheritage\n             in case of a ommited glyph or nil instead of glyph.\n\n :command -- a form; if the form happens to be a command, it will\n   be called with `call-interactively\'.\n\n :append-command -- a form added to the end of the value of\n   `:command\'.\n\n :prepend-command -- a form added at the beginning of the value\n   of `:command\'.\n\n :help -- either a string or nil; defined the help string of the\n   button;\n\n :enable -- a form, evaluated constantly by both editors to\n   determine if a button is active (enabled) or not.\n\n :visible -- in Emacs, a form that is evaluated constantly to\n   determine if a button is visible; in XEmacs, this property is\n   ignored.\n\n :button -- in Emacs, a cons cell (TYPE .  SELECTED) where the\n   TYPE should be `:toggle\' or `:radio\' and the cdr should be a\n   form.  SELECTED is evaluated to determine when the button is\n   selected.  This property is ignored in XEmacs.\n\n :insert -- a form that is evaluated every time that the toolbar\n   is refresh (a call of `toolbarx-refresh\') to determine if the\n   button is inserted or just ignored (until next refresh).\n\n :toolbar -- in XEmacs, either one of the symbols `default\',\n   `top\', `bottom\', `left\', `right\', or a cons cell\n   (POS . POS-AVOID-DEFAULT) where POS and POS-AVOID-DEFAULT\n   should be one of the symbols `top\', `bottom\', `left\', `right\';\n   if a symbol, the button will be inserted in one of these\n   toolbars; if a cons cell, button will be inserted in toolbar\n   POS unless the position of the default toolbar is POS (then,\n   the default toolbar would override the position-specific\n   toolbar), and in this case, button will be inserted in toolbar\n   POS-AVOID-DEFAULT; in Emacs, this property is meaningless, and\n   therefore ignored.  Hint of use of this property: in a\n   program, use or everything with `default\' and the cons format\n   to avoid the default toolbar, or use only the position\n   specific buttons (symbols that are not `default\'), because of\n   the `overriding\' system in XEmacs, when a position-specific\n   toolbar overrides the default toolbar; for instance, if you\n   put a button in the default toolbar and another in the top\n   toolbar (and the default toolbar is in the top), then *only*\n   the ones in the top toolbar will be visible!\n\nHow to specify a button\n=======================\n\nOne can specify a button by its symbol or by a group to specify\nproperties.  For example,\n  BUTTON =\n    ( foo\n      (bar :image [\\"bar-Emacs\\" \\"bar-XEmacs\\"]\n           :command bar-function :help \\"Bar help string\\")\n      :insert foo-bar )\n  MEANING-ALIST = ( (foo :image \\"foo\\" :command foo-function) )\nspecifiy two buttons `foo\' and `bar\', each one with its necessary\n:image and :command properties, and both use the :insert property\nspecified ate the end of BUTTONS (because groups distribute\nproperties to all its elements).  `foo\' and `bar\' will be\ninserted only if `foo-bar\' evaluation yields non-nil.  `bar\' used\na different :image property depending if editor is Emacs or\nXEmacs.\n\nNote on how values of properties are obtained\n=============================================\n\nFor each property PROP, its value should be either:\n   i) a vector of 2 elements; then each element should be of the\n      basic type of PROP.\n  ii) an element on the basic type of PROP.\n iii) a function (that does not need arguments); it is evaluated\n      and the return should be ot type i) or ii) above\n  iv) a symbol bound to a element of type i) or ii).\n\nThe type is cheched in the order i), ii) iii) and iv).  This\nevaluations are done every time that the oolbar is refresh.\n\nPs.: in order to specify a vector as value of a property (like\nthe :image in Emacs), it is necessary to provide the vector as\nelement of another vector.\n\nSpecial groups\n==============\n\nEval groups\n-----------\n\nIf the first element of a group is the symbol `:eval-group\', each\nelement is evaluated (with `eval\'), put inside a list and\nprocessed like a group.  Eval groups are useful to store\ndefinition of buttons in a variable.\n\nDropdown groups\n---------------\n\nThe idea is to specify a set of buttons that appear when a\ndetermined menu item of a dropdown menu is active.  The dropdown\nmenu appears when a button (by default with a triangle pointing\ndown) is clicked.  This button is called `dropdown button\'.  The\ndropdown button appears on the left of the currently visible\nbuttons of the dropdown group.\n\nA dropdown group is a list which first element is the symbol\n`:dropdown-group\' and in one of the following formats\n  (:dropdown-group SYMBOL-1 ... SYMBOL-n  PROP-1 VAL-1 ... PROP-k VAL-k)\nor\n  (:dropdown-group\n     STRING-1 ITEM-11 ... ITEM-1n\n     STRING-2 ITEM-21 ... ITEM-2m\n       . . .\n     STRING-n ITEM-n1 ... ITEM-np\n       PROP-1 VAL-1 ... PROP-j VAL-j)\nwhere\n SYMBOL-* is a symbol that defines a button in MEANING-ALIST;\n STRING-* is a string that will appear in the dropdown menu;\n ITEM-* is any format that define buttons or groups.\n\n\\(a dropdown group of first format is internally converted to the\nsecond by making strings from the symbols and each symbol is the\nitem)\n\nThe same rules for obtaining property values, described above,\napply here.  Properties are also distributed by groups.  The\nsupported properties and their basic type are:\n\n :type -- one of the symbols `radio\' (default) or `toggle\'; if\n   type is radio, only one of the itens may be active, and if\n   type is toggle, any item number of itens can be active.\n\n :variable -- a symbol; it is the variable that govern the\n   dropdown button; every time the value should be an integer\n   starting from 1 (if type is radio) or a list of integers (if\n   type is toggle).  The Nth set of buttons is :insert\'ed.\n\n :default -- determines the default value when the menu is\n   installed; it is ignored if a value was saved with custom; it\n   defaults to 1 if type is radio or nil if type is toggle.  If\n   value is a integer and type is `toggle\', value used is a list\n   with that integer.\n\n :save -- one of the symbols nil (default), `offer\' or\n   `always\'; determined if it is possible for the user to save\n   the which menu itens are active, for a next session.  If value\n   is `offer\', a item (offering to save) is added to the\n   popup menu.  If the value is `always\', every time that a item\n   is selected, the variable is saved.  If value is nil, variable\n   shall not be saved.  If value is non-nil then `:variable\' is\n   mandatory.\n\n :title -- a string or nil; if a string, the popup menu will show\n   is as menu title; if nil, no title is shown.\n\n :dropdown-help -- a string or nil; the help string of the\n   dropdown button.\n\n :dropdown-image -- in Emacs, either a string or a vector of 4\n   strings; in XEmacs, either a string or a glyph or a list of at\n   least 1 and at most 6 strings or glyphs; defines the image\n   file displayed by the dropdown button; by default, it is the\n   string \\"dropdown\\".\n\n :dropdown-append-command,\n :dropdownprepend-command -- a form; append or prepend forms to\n   the command that shows the dropdown menu, allowing extra code\n   to run before or after the menu appears (remember that every\n   menu item clicked refresh the toolbar.)\n\n :dropdown-enable -- a form; evaluated constantly by both editors\n   to determine if the dropdown button is active (enabled) or\n   not.\n\n :dropdown-visible -- a form; in Emacs, it is evaluated\n   constantly to determine if the dropdown button is visible; in\n   XEmacs, this property is ignored.\n\n :dropdown-toolbar -- in XEmacs, one of the symbols `default\',\n   `opposite\', `top\', `bottom\', `left\' or `right\'; ignored in\n   Emacs; in XEmacs, the toolbar where the dropdown button will\n   appear.\n\nAlso, if the symbol `dropdown\' is associted in MEANING-ALIST\nwith some properties, these properties override (or add) with\nhigher precedence.\n\nSpecial buttons\n===============\n\nIf the symbol of a button is `:new-line\', it is inserted\na (faked) return, and the next button will be displayed a next\nline of buttons.  The only property supported for this button is\n`:insert\'.  This feature is available only in Emacs.  In XEmacs,\nthis button is ignored.\n
Run Code Online (Sandbox Code Playgroud)\n