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)
  • bahmanm@lemmy.mlOP
    link
    fedilink
    English
    arrow-up
    1
    ·
    10 months ago

    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:

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    (defun bahman/helm-major-mode.hook ()
     (display-line-numbers-mode -1)
     (puni-mode -1))
    
    (add-hook 'helm-major-mode-hook
             #'bahman/helm-major-mode.hook)
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    (defvar bahman/display-line-numbers-mode.disabled-modes
     '(vterm-mode erlang-shell-mode)
     "Disable `display-line-numbers' for the specified modes.")
    
    (defun bahman/display-line-numbers-mode.hook ()
     (when (seq-contains-p bahman/display-line-numbers-mode.disabled-modes
                           major-mode)
         (display-line-numbers-mode -1)))
    
    (add-hook 'display-line-numbers-mode-hook
             #'bahman/display-line-numbers-mode.hook)
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    (defvar bahman/puni-mode.disabled-modes
     '(vterm-mode)
     "Disable `puni-mode' for the specificied modes.")
    
    (defun bahman/puni-mode.hook ()
     (when (seq-contains-p bahman/puni-mode.disabled-modes
                           major-mode)
       (puni-mode -1)))
    
    (add-hook 'puni-mode-hook
             #'bahman/puni-mode.hook)