this post was submitted on 18 Sep 2023
6 points (100.0% liked)

Emacs

2201 readers
2 users here now

Our infinitely powerful editor.

founded 4 years ago
MODERATORS
 

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)
you are viewing a single comment's thread
view the rest of the comments
[โ€“] bahmanm@lemmy.ml 1 points 1 year 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)