19 votes

Get list of active minor modes in buffer

If you're just looking to see what minor modes are being used in a buffer, but don't need to use the list programmatically use: M-x describe-mode This command will open a new buffer that begins with ...
Wilduck's user avatar
  • 303
15 votes
Accepted

Disabling electric-indent-mode for one mode (latex mode) only

The command you need is electric-indent-local-mode. You can use this to turn off electric-indent-mode in any buffer by calling it manually: M-x electric-indent-local-mode. This is a toggle, so calling ...
Tyler's user avatar
  • 22.1k
12 votes
Accepted

Disable Minor Mode in Major Mode

As per comments, this is because you're using a globalized minor mode: https://stackoverflow.com/questions/6837511/automatically-disable-a-global-minor-mode-for-a-specific-major-mode C-hf global-...
phils's user avatar
  • 50.5k
10 votes
Accepted

How to automatically remove a hook provided by a minor mode after disabling that mode?

The minor mode's hook is called both when activating and deactivating the minor mode, so how 'bout (add-hook 'my-minor-mode-name-hook (lambda () (if my-minor-mode-name ...
Stefan's user avatar
  • 26.3k
7 votes
Accepted

How can I 'layer' a keybinding?

There are various ways you could approach this, but one in particular seems more or less designed for the purpose. You define the key using the menu-item syntax, with a :filter function that returns ...
phils's user avatar
  • 50.5k
7 votes
Accepted

How to make a specific read-only buffer writable?

Use (read-only-mode -1), not (read-only-mode nil). See the doc string of macro define-minor-mode (C-h f define-minor-mode) for more info about the argument to a minor-mode function. And see the doc ...
Drew's user avatar
  • 77.1k
6 votes
Accepted

File mode name with -mode suffix or not?

Don't name your file x-mode.el if it does not actually provide a mode of some sort: that seems confusing. If you are providing library x, just call the file x.el. From what I've seen, most modes (...
glucas's user avatar
  • 20.6k
6 votes
Accepted

Proper way to change prefix key for minor-mode map?

It depends on the minor-mode/package. Many make this more configurable, which doesn't seem to be true in this case. I think the simplest thing here would be to just redefine the keymap yourself ...
justbur's user avatar
  • 1,510
5 votes
Accepted

how to disable minor mode (enabled using prog-mode-hook) for a particular major mode

This can be done very easily with hooks for major-modes like so: (add-hook 'python-mode-hook (lambda () (highlight-indent-guides-mode -1))) If for some reason this did ...
Chakravarthy Raghunandan's user avatar
5 votes

How to make electric-pair-mode buffer local?

You can use electric-pair-local-mode instead.
vaer-k's user avatar
  • 231
5 votes

Making it clearer I'm in god-mode

What I did is to add a function that changes the cursor's color if god-mode is enabled in the current buffer. I hook this function so that it is run whenever the buffer list is updated. However, you ...
Trung Ta's user avatar
  • 301
5 votes

Making it clearer I'm in god-mode

I change the mode line color to red when in god mode. (defun me//god-mode-indicator () (cond (god-local-mode (progn (set-face-background 'mode-line "red4") (set-face-...
gongzhitaao's user avatar
5 votes
Accepted

How to suppress a minor mode's key binding in only certain major modes?

I don't think there's an easy way out for this one. You might do something like: (add-hook 'typo-mode-hook (lambda () (when (and typo-mode (derived-mode-p 'markdown-mode)) ...
Stefan's user avatar
  • 26.3k
5 votes
Accepted

How to enable the superword minor mode globally?

I am just wondering how to enable the superword-mode globally? Use (global-superword-mode t).
npostavs's user avatar
  • 9,163
5 votes

How to set minor mode variables in dir-locals?

As @phils suggested you should be able to run M-x add-dir-local-variable. You will be prompted for a mode, and you could type/select lsp-mode (I am guessing that is the mode name). Then, you will be ...
John Kitchin's user avatar
  • 11.8k
5 votes
Accepted

Define new key binding for new minor mode

Your code works perfectly, for me. Did you try it in emacs -Q (no init file)? And if I load library help-fns+.el and then use M-k hello-mode-map it shows me that M-p is bound to an (anonymous) command....
Drew's user avatar
  • 77.1k
5 votes
Accepted

How can I apply diminish to apheleia-mode

Instead of this: (apheleia-global-mode +1) (with-eval-after-load 'apheleia ... ) (diminish 'apheleia-mode) Do this: (diminish 'apheleia-mode) (apheleia-global-mode +1) (with-eval-after-load '...
phils's user avatar
  • 50.5k
5 votes
Accepted

Is it possible to have a minor mode re-evaluate its keymap?

Minor Mode Keymaps The problem with the current code in the question is that it merely updates the variable foo-mode-map but it does not really update the keymap data structure made of cons cells that ...
Susam Pal's user avatar
  • 186
4 votes
Accepted

Is it possible to associate minor modes with windows rather than buffers?

Not as such. Even 'global' minor modes are generally just buffer-local minor modes which are enabled or disabled for multiple buffers en masse. However there's nothing to stop you writing a global ...
phils's user avatar
  • 50.5k
4 votes

Hide list of minor modes in mode-line

It's worth noting that use-package supports diminish and delight. If you use it to manage your packages you can hide the minor modes in the mode line adding the :diminish or :delight keywords. (use-...
Marcos's user avatar
  • 41
4 votes

pop-up a list of enabled minor modes in a readable format?

manage-minor-mode will open a new window which shows two columns of all the active minor modes and inactive minor modes for the current buffer. You can selectively enable/disable minor modes by ...
Chakravarthy Raghunandan's user avatar
4 votes

How to turn on a minor mode in my init file?

It is a minor-mode which can be enabled with: (global-semantic-idle-summary-mode 1) The doc-string states: "Toggle Global Semantic Idle Summary mode. With ARG, turn Global Semantic Idle Summary ...
lawlist's user avatar
  • 19.1k
4 votes

save variable on exit

Emacs provides the Customize system for user-configurable variables. Your definition can include a default value, but Emacs provides an interface for the user to specify their own value. The user-set ...
Tyler's user avatar
  • 22.1k
4 votes
Accepted

Toggle a minor mode with a custom key binding

Add the following to your init file: (global-set-key (kbd "C-c l") 'font-lock-mode) You can follow the same pattern for any minor mode, because all minor modes are commands (meaning they can be ...
phils's user avatar
  • 50.5k
4 votes

Disable minor mode when keys not in it's keymap are pressed

This is exactly the use case for the hydra package, which you can install via package-install from melpa. For example: (defhydra hydra-duplicate-line () "duplicate line" ("d" duplicate-line nil))...
glucas's user avatar
  • 20.6k
4 votes

Are there hooks for leaving modes?

You can use the hook variable change-major-mode-hook for cleaning up major mode settings. It is called right before killing the local variables of the old major mode. Example code: (defun clojure-...
Tobias's user avatar
  • 33.1k
4 votes
Accepted

Enabling a minor mode in all but some buffers

Substitute my-pdf-mode-hook for whichever major-mode that should be excluded. (global-display-line-numbers-mode t) (add-hook 'my-pdf-mode-hook (lambda () (display-line-numbers-mode -1)))
lawlist's user avatar
  • 19.1k
4 votes
Accepted

Swap Shift/non-shift key behavior for particular mode

You can simply map the keys - and _ to do what you want in python mode: (defun insert-underscore () "Guess what!" (interactive) (insert "_")) (defun insert-hyphen () "You know it!" (...
JeanPierre's user avatar
  • 7,423

Only top scored, non community-wiki answers of a minimum length are eligible