I tried Prelude - WikEmacs,
Every time I open emacs, there is a menu bar at the top:
File Edit Options Buffers Tools Emacs-Lisp Prelude Projectile Help
How can I remove it or prevent it from being shown?
You can disable the menu bar by turning off minor mode menu-bar-mode. C-h f menu-bar-mode tells you this:
menu-bar-mode is an interactive compiled Lisp function in
menu-bar.el.
(menu-bar-mode &optional ARG)
Toggle display of a menu bar on each frame (Menu Bar mode).
With a prefix argument ARG, enable Menu Bar mode if ARG is
positive, and disable it otherwise. If called from Lisp, also
enable Menu Bar mode if ARG is omitted or nil.
This command applies to all frames that exist and frames to be
created in the future.
So to turn it off using Lisp, for example in your init file (~/.emacs), you can do this:
(menu-bar-mode -1)
That description of turning the mode on/off interactively and from Lisp is general for minor modes.
Unfortunately, that doc string does not tell you that menu-bar-mode is a minor mode or that minor modes generally follow the same rules for turning them on/off. But if you click the link in that *Help* output to go to the definition of menu-bar-mode in menu-bar.el then you'll see that it's defined using macro define-minor-mode.
And C-h f define-minor-mode gives you general information about turning on/off a minor mode.
Related
I am unable to show line numbers in Emacs when browsing files using Dired.
Dotspacemacs-line-numbers '(:relative nil
:visual t
:disabled-for-modes ;; dired-mode
doc-view-mode
markdown-mode
;; org-mode
pdf-view-mode
;; text-mode
:size-limit-kb 1000)
but line numbers are not showing.
any idea how to enable line numbers in Dired?
Turn on minor mode display-line-numbers-mode:
M-x display-line-numbers-mode. C-h f tells you:
display-line-numbers-mode is an autoloaded interactive compiled Lisp
function in display-line-numbers.el.
(display-line-numbers-mode &optional ARG)
Toggle display of line numbers in the buffer.
This uses display-line-numbers internally.
This is a minor mode. If called interactively, toggle the
Display-Line-Numbers mode mode. If the prefix argument is positive,
enable the mode, and if it is zero or negative, disable the mode.
If called from Lisp, toggle the mode if ARG is toggle. Enable the
mode if ARG is nil, omitted, or is a positive number. Disable the
mode if ARG is a negative number.
To check whether the minor mode is enabled in the current buffer,
evaluate display-line-numbers-mode.
The mode’s hook is called both when the mode is enabled and when it is
disabled.
To change the type of line numbers displayed by default,
customize display-line-numbers-type. To change the type while
the mode is on, set display-line-numbers directly.
Probably introduced at or before Emacs version 26.1.
I would like to have a shortcut that would toggle the showing of line numbers in Emacs.
This is what I have so far:
(defun my-toggle-display-line-numbers-mode-function ()
"Toggles the line numbers"
(interactive)
(display-line-numbers-mode)
)
(global-set-key [(f7)] 'my-toggle-display-line-numbers-mode-function)
But it will only turn on the line numbers. I can't turn it off, unlike when I use M-x display-line-numbers-mode which will turn on or off without any problem.
Any idea how to improve my script so it works as intended?
describe-function (C-h f) on display-line-numbers-mode gives the following:
Signature:
(display-line-numbers-mode &optional ARG)
Documentation:
[...]
This is a minor mode. If called interactively, toggle the
Display-Line-Numbers mode mode. [...]
If called from Lisp, toggle the mode if ARG is toggle. Enable
the mode if ARG is nil, omitted, or is a positive number.
Disable the mode if ARG is a negative number.
This is the automatic desciption produced by the define-minor-mode macro, and for most minor modes, the previous documentation will be exactly the same.
What we get from this:
When called interactively (i.e. as a command, using for example M-x display-line-numbers-mode) this acts as a toggle.
When called from Elisp source code, you need to specify an argument.
If you want it to act as a toggle, use (display-line-numbers-mode 'toggle) in your code. If you want something slightly more advanced than a simple toggle (for example, checking some extra conditions), use 1 and -1 as arguments to respectively enable and disable the mode (incidentally, and although the documentation is unclear, 0 counts as a negative number here, and so (display-line-numbers-mode 0) disables the mode.
As it is often the case, Emacs built-in documentation shows all there is to know. Try to get familiar with the help system, it's really good compared to a lot of softwares.
In Markdown mode with flyspell enabled, mouse-2 bound to mouse-yank-primary is also bound to flyspell-correct-word, the flyspell function that displays in a menu correction propositions. If the buffer is empty, the menu is displayed, if not, its content is yanked. Grrr.
I spent some time trying to find where to change this second binding but as I'm not an emacs guru, I just got lost. I tried (global-set-key "S-mouse-2" #'flyspell-correct-word) in ~/.emacs.d/init.el but I didn't manage to get anything working properly.
So the question is how and where to bind say S-mouse-2 to that function. A better solution would be to keep both bindings but to prioritize the menu over yanking when the mouse is over a word that needs correction.
On my GNU Emacs 25.2.2 the command (executed from the *scratch* buffer)
(global-set-key "S-mouse-2" #'flyspell-correct-word)
pops up the debugger. However,
(global-set-key [S-mouse-2] #'flyspell-correct-word)
works, as also
(global-set-key [S-mouse-2] 'flyspell-correct-word)
You can check the effect with:
(global-key-binding [S-mouse-2])
I am trying to get emacs to highlight trailing-spaces. I have tried using WhiteSpace, and also tried setting show-trailing-whitespace variable to true, but in each case it changes the representation of newline and space characters to $ and · characters, as shown in this screen capture.
Ideally I would like to just see the trailing whitespace highlighted in red without any such characters.
Disclaimer: I'm new to emacs, so this may well be obvious.
I don't use any library. I just set show-trailing-whitespace to t and any trailing white space is shown in red. The representation of newline and space characters is NOT changed.
Actually, my ".emacs" file contains this simple line:
(setq-default show-trailing-whitespace t)
In case you don't want to edit your ".emacs" file, you may try:
C-h v show-trailing-whitespace RET then click the customize link
(or just M-x customize-variable RET show-trailing-whitespace RET)
Click the toggle button to set it to on (non-nil)
Click the menu button State > Set for Current Session
Click the menu button State > Save for Future Sessions
[EDIT] (thanks to Francesco Frassinelli for his comment)
With setq-default, the value is changed for every mode.
If you want to disable it for some mode (like term-mode for example), you have to:
find the mode name of the current buffer. Usually you can get it from within the buffer with M-x describe-mode RET (shortcut C-h m or <f1> m).
find the entry "hook" for this mode. Usually, it's the mode name with the suffix -hook. You can find it by searching "hook" in the buffer describing the mode. For example, you may read:
Entry to this mode runs the hooks on ‘term-mode-hook’
add the following to your ".emacs" file:
(add-hook 'term-mode-hook (lambda () (setq show-trailing-whitespace nil)))
or you may try:
M-x customize-variable RET term-mode-hook RET
Click the INS button
Paste (lambda () (setq show-trailing-whitespace nil))
Click the menu button State > Set for Current Session
Click the menu button State > Save for Future Sessions
Note that show-trailing-whitespace automatically becomes buffer-local when set with setq.
Change the value of the whitespace-style variable to
(face trailing)
You might need to restart whitespace-mode for the changes to take effect.
To set a variable, use M-xset-variableEnter.
Another answer is to use library highlight-chars.el (description: Highlight library).
Command hc-toggle-highlight-trailing-whitespace does what you request.
You can also turn on such highlighting automatically, either everywhere or in a given buffer or for a given mode.
How to disable auto indent in Emacs globally or only for some modes?
I have a number of packages installed for RubyOnRails (ruby, html, js, css).
Let's say I want to disable autoindent for css-mode.
For me, on emacs 24.x, M-xelectric-indent-mode toggled the behavior that I wanted to disable.
FWIW, the behavior was that RET was bound to the command newline which is defined in simple.el... Among other things, the behavior of that command is altered by electric-indent-mode.
You may want to look for variable names containing the word electric. (This is the common Emacs parlance for actions which occur automatically when particular visible characters are typed.)
In this instance, M-x apropos-variable RET electric RET shows me that there is a css-electric-keys variable containing a list of "Self inserting keys which should trigger re-indentation."
You could use M-x customize-variable RET css-electric-keys RET to set this list to nil, or add (setq css-electric-keys nil) to your init file.
Sometimes a minor mode is used to implement electric behaviours, so that you can switch them on and off more easily. Those would likely be found via M-x apropos-command RET electric RET, and you would probably use a major mode hook to ensure that the electric minor mode was disabled, in a similar fashion to this:
(add-hook 'MAJORMODE-mode-hook 'my-MAJORMODE-mode-hook)
(defun my-MAJORMODE-mode-hook ()
(ELECTRICMODE-mode 0))