How to add item to toolbar in Emacs - emacs

I want to add item to toolbar in Emacs. I heard Emacs can add even menu item to toolbar.
Thanks.

Hi i found a simple solution to add a toolbar button
"spell" is the image in /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")

Here's an example from LaTeX mode:
;;; 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)))
Found using M-x apropos <RET> toolbar <RET> and clicking through to the source EL file…
The documentation for toolbarx-install-toolbar is pretty lengthy:
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.

Related

What is includeInputInList property is used for in Autocomplete from Material-ui?

Have a study of Material-UI's Autocomplete with the playground on https://material-ui.com/components/autocomplete/, I really cannot see any difference with/without includeInputInList property? The document says 'If true, the highlight can move to the input.' I tried it, highlight never move to the input field.
The includeInputInList has 2 associated unit tests.
The description of the tests says:
it considers the textbox the predessor of the first option when pressing Up
it considers the textbox the successor of the last option when pressing Down
This means that with includeInputInList, when you have the focus on the component and you press key up, if it's the first item, the focus will go to the textbox (the input element), before continuing on the items. And if you press down and it's the last item, the focus will also go to the textbox.
Without that option the focus stays on the displayed items and never goes to the textbox, it jumps from the first to the last item (key up), and from the last to the first (key down) while you have the focus on them and just press key up or key down.
You can try on the example provided on the Material UI docs: press tab until you are on the MUI component, and then play with key up or down, with and without the includeInputInList prop on the Autocomplete component.

in org-mode how to auto create new numbering?

I write this in org-mode
SomeTopic
Anything I can click here to automatically create the below 1.
Anything I can click here to automatically create the below 1. automatically indented below?
1.
For example, I have this line (non header, text):
1. some item
I want to click something so it will open 2. so after I click that something I will have:
1. some item
2.
Try M-RET which is bound to org-meta-return which in list context calls
org-insert-item. E.g.
* foo
Let's have a list:
1. itemX
where X marks the position of the cursor.
Now press M-RET:
* foo
Let's have a list:
1. item
2.
The Plain lists section of the manual explains this and many other things that you can do with lists.

What's this box around my function input?

Whenever I write an auto-completed function call and start typing something, a black rectangle is drawn around the input, like below:
Why does eclipse do this and how can I turn it off? I've looked the different editor settings but I haven't found anything that describes this behavior.
This is called place holder. Keep caret anywhere in between the class methods and inside the class body and type public and press Ctrl + Space and select public_method option. Then you will get a template looks like this:
Here return_type is covered with rectangle and highlighted this means you can type the return type as void, int etc and this will appear in this rectangle box.
Use TAB key to traverse next place holders i.e name is also covered with rectangle box. After typing the return type when you press TAB key you will jump to next place holder(i.e name).
You can go back to the previous place holder by pressing Shift + TAB key. Green color caret represent the end of place holders.
While you are in any place holder if you press Enter key you will be directly taken to the end of the place holder(i.e green caret).
Check the template grammar for public_method template here Windows > Preferences > Java > Editors > Templates
It looks as
public ${return_type} ${name}(${}) {
${cursor}
}
You can edit this. If you remove ${cursor} then green colour caret will not appear and so on.
You can turn if off by
Deleting template(Not recommended)
Editing template grammer
Or just by pressing Enter key(Recommended)
Also check the grammar of static_final template. Here you will get the drop down menu along with rectangular box.

what is the usage of :type in defcustom?

I am not sure I understand the property type in defcustom. I can perfectly define the following variables without conforming to the type. what is the purpose of type in this context?
(defcustom foo 1 "foo" :type 'string)
(defcustom spam "a" "foo" :type 'integer)
First of all, the type for integer is integer, not int, so your specific example will not work with Customize.
The :type determines the edit control used, and provides completion and type checking when saving customization:
Edit control
M-x customize-variable picks an edit control which is best suited to enter a value for the expected type. For instance, a boolean type becomes a toggle button, simple types as integer or string get a line edit, choice becomes a value menu, set a list of checkboxes, etc.
Completion
Within certain edit controls, Customize provides completion. For instance, when you press M-Tab in a line edit for a function type (as used for hook variables), Customize automatically completes function names. If there is more than one matching name, you'll see a pop up buffer with all completion candidates. Likewise, a color widget provides you with completion for all known color names.
Type checking
For all edit controls, Customize checks the type of the current value before saving, and refuses to apply any customization with a non-matching type.
For instance, if you enter a non-numeric into an integer widget, and try to apply or save the customization, Customize will refuse to do so and signal a “This field should contain an integer” error.
As the Elisp manual (node Variable Definitions) says: It specifies which values are legitimate, and how to display the value."
This affects "appropriate edit control for the user to customize with", as #amalloy says. It affects also whether Customize shows the current value as valid for the :type or is a type mismatch.
In sum, it provides type-checking and editing assistance for users, and it determines how Customize displays the value (as a Lisp value, Boolean, etc.).
Setting a :type causes customize-variable to present an appropriate edit control for the user to customize with.

Deselect text programmatically

I am using a Text widget.
I have over-ridden the right click to display a popup menu in my Perl/Tk GUI. But whenever I right click at any position, the text from the earlier cursor location till the location where I have right clicked gets highlighted.
I don't know what is causing this, so I simply want to programmatically deselect this highlighted text.
How do I go about doing this?
Thanks!
EDIT:
I have made a bind for right-click and this is the subroutine that is called:
sub rightClickMenu {
my ($self, $x, $y) = #_;
$txt->tagRemove('sel', '1.0', 'end');
$rightMenu -> post($x, $y);
$txt->tagRemove('sel', '1.0', 'end');
}
I have removed the sel tag twice (just to be sure). $rightMenu is the menu that is popped up. It shows perfectly fine when right-clicked.
The selection in the text widget is handled by setting the tag sel for the selected range of characters. This tag can be removed like this:
.t tag remove sel 1.0 end
assuming the pathname of your text widget is .t. This specifies that for all characters from the first (1.0) to the character position after the last character (end) the tag sel is to be removed.
Note: normally when removing a tag one has to deal with the possibility that it has been assigned to multiple ranges in the text. The tag removal invocation above clears the tag from the whole text, and that's fine for the selection tag since you're (usually) only supposed to have one selected range anyway. If there are multiple ranges that have the tag foo and you want to clear just one of them, you first need to find the starting and ending indices of that range and clear (by calling tag remove) the tag only between those.
Note 2: All this is assuming that the visible effect is actually caused by the sel tag getting set. In Tk, it's not a standard binding for button 2 to set this tag: it could be that some non-standard binding in Perl-Tk sets some other tag that is displayed visually in the same way as the sel tag is. For further investigation, this command may be useful:
.t tag names $placeWhereIRightClicked
(again assuming the pathname of your text widget is .t, and that placeWhereIRightClicked holds the index of the place where the right clicking occurred) will tell you all tags that are active at that index.
(The command
.t tag names
will list tags for the whole text.)
TkDocs has an article about the text widget where the tag remove command is mentioned, but how to do it in Perl-Tk isn't showed.
The CPAN documentation for the text widget says that the syntax for the command is
$text->tagRemove(tagName, index1, ?index2, index1, index2, ...?)
so I suppose
$text->tagRemove('sel', '1.0', 'end')
or something like that is the way to do it (no Perl, can't test).
(Note: the 'Hoodiecrow' mentioned in the comments is me, I used that nick earlier.)