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)