See my reply below (https://lemmy.ml/comment/3972018) for a working solution.
I've got quite a few useful minor modes enabled globally, namely puni-mode
and display-line-numbers-mode
.
However, I'd like to be able to disable (one or more of) them for certain major modes. For example, I don't want puni or display-line-number to be activated when using vterm
.
I've been trying to make the following snippet do the job for me to no avail. What am I missing?
I'd appreciate any hints/help ๐
(defvar bahman/display-line-numbers-mode.disabled-modes
'(vterm-mode erlang-shell-mode)
"Disable `display-line-numbers' for the specified modes.")
(defvar bahman/puni-mode.disabled-modes
'(vterm-mode)
"Disable `puni-mode' for the specificied modes.")
(defun bahman/after-change-major-mode-hook.disable-minor-modes ()
"Disable certain minor modes for certain major modes ๐คท.
See
`bahman/display-line-numbers-mode.disabled-modes'
`bahman/puni-mode.disabled-modes'"
(with-current-buffer (current-buffer)
(when (seq-contains-p bahman/display-line-numbers-mode.disabled-modes
major-mode
#'eq)
(display-line-numbers-mode -1))
(when (seq-contains-p bahman/puni-mode.disabled-modes
major-mode
#'eq)
(puni-mode -1))))
(add-hook 'after-change-major-mode-hook
#'bahman/after-change-major-mode-hook.disable-minor-modes)
I cross-posted the same questions on Matrix and got the answer there.
The hook I'm using is invoked before the minor modes are setup - that's why it's being overridden. The suggestion was to have a hook function for each minor mode that I want to control. It's not clean but gets the job done.
Here's the working snippet: