6

I've been using emacs for a while, but am being quite dismayed by some quite hectic pinky-pain, so have just started using Chris Done's god-mode, which is great, I like it so far.

The problem is that with a few buffers open it's hard to easy know if I'm in god-mode in the given buffer.

I'm not accustomed to this "vim" way of doing things and am being confused by which buffer is currently in "god-mode".

So the question is generally:

How do I make a buffer (either in the mode-line or in some other place) more distinctive in some way when I'm in a particular minor-mode, in my case in god-mode, so I don't have to move my eyes to the mode-line or test by pressing something.

3
  • 1
    How about changing the mode-line :lighter from _God to _GOD!? github.com/chrisdone/god-mode/blob/master/god-mode.el#L98 Do you want this to be a different color? What do you want the entire mode-line background to change colors? Do you want ...? Here is an example for Magnar's mutliple-cursor library for a :lighter that changes depending upon the number of cursors: github.com/magnars/multiple-cursors.el/blob/master/…
    – lawlist
    Commented Jun 20, 2017 at 21:55
  • 3
    Here is a link to another idea to change the buffer default face (e.g., foreground and/or background) using the face-remapping-alist with the function face-remap-add-relative: stackoverflow.com/a/28008006/2112489 Create a simple function to turn it on and attach that function to the god-mode-enabled-hook and turn it off with a similar function attached to the god-mode-disabled-hook. It could be a subtle color change, or an eye-popping change, whatever suits your personal taste.
    – lawlist
    Commented Jun 20, 2017 at 23:56
  • 2
    When I used to use evil I had the same problem (a problem I believe UI/UX people call "modal confusion"). After trying a few options I settled on changing the color of the mode-line's background.
    – Omar
    Commented Jun 21, 2017 at 2:23

5 Answers 5

5

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 can hook it to more functions as you wish.

  (defun hook-update-cursor ()
    (cond ((or (bound-and-true-p god-mode)
               (bound-and-true-p god-global-mode))
           (set-cursor-color "lime green"))
          (t (set-cursor-color "dark orange"))))

  (add-hook 'buffer-list-update-hook 'hook-update-cursor)
1
  • 2
    Cursor color affects the whole frame, not just the buffer that has god-mode enabled. This is a built-in limitation with Emacs components written in C. The cursor color could be different for each buffer (or even each window) if someone cared enough to implement that in C, but it doesn't yet exist.
    – lawlist
    Commented Jul 14, 2017 at 14:24
5

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-foreground 'mode-line "gray")
           (set-face-background 'mode-line-inactive "gray30")
           (set-face-foreground 'mode-line-inactive "red")))
        (t
         (progn
           (set-face-background 'mode-line-inactive "gray30")
           (set-face-foreground 'mode-line-inactive "gray80")
           (set-face-background 'mode-line "gray75")
           (set-face-foreground 'mode-line "black")))))

(add-hook 'god-mode-enabled-hook #'me//god-mode-indicator)
(add-hook 'god-mode-disabled-hook #'me//god-mode-indicator))
1
  • This works sort of okay, but it would be great if the modeline change would somehow be restricted to the current buffer/frame. Is there anyway to achieve that yet? Maybe you could redefine mode-line-format to reflect wether you are in god mode or not?)
    – rien333
    Commented Jun 26, 2020 at 16:24
2

Just following up I ended up going with a simplified version of the example code (https://github.com/emacsorphanage/god-mode#change-modeline-color) and adding cursor change:

;; Update cursor
(defun my-god-mode-update-cursor ()
    (setq cursor-type (if (or god-local-mode buffer-read-only)
                        'box
                        'bar)))
(add-hook 'god-mode-enabled-hook #'my-god-mode-update-cursor)
(add-hook 'god-mode-disabled-hook #'my-god-mode-update-cursor)


;; Update mode-line
(defun my-god-mode-enabled-modeline () 
    (set-face-background 'mode-line "#fff3e1")
)
(defun my-god-mode-disabled-modeline () 
    (set-face-background 'mode-line "#0a2832")
)
(add-hook 'god-mode-enabled-hook #'my-god-mode-enabled-modeline)
(add-hook 'god-mode-disabled-hook #'my-god-mode-disabled-modeline)

This only effects the current buffer. This also changes the cursor.

This version is extensible, and seems to work well in practice. It seems easy to add more bells and whistles, but actually just don't need to, this is good enough for me. Simple and good.

1

If you are ready for a more radical change in your default modeline setting, doom-modeline has a nice indicator to show whether you are in god mode or not.

0

I personally use the following code snippet:

(defvar god-modeline-active-face
  (list :background "firebrick" :box nil)
  "Face for modeline of active buffer while in god-mode.")
(defvar god-modeline-inactive-face
  (list :background "darkred" :box nil)
  "Face for modeline of inactive buffer while in god-mode.")

(defun god-modeline-enable ()
  (message "GOD mode on!")
  (face-remap-add-relative
   (quote mode-line)
   god-modeline-active-face)
  (face-remap-add-relative
   (quote mode-line-inactive)
   god-modeline-inactive-face))
(defun god-modeline-disable ()
  (message "GOD mode off!")
  (face-remap-remove-relative
   (cons
    (quote mode-line)
    god-modeline-active-face))
  (face-remap-remove-relative
   (cons
    (quote mode-line-inactive)
    god-modeline-inactive-face)))

(add-hook god-mode-enabled-hook god-modeline-enable)
(add-hook god-mode-disabled-hook god-modeline-disable)

The benefits of this compared to the other answers are:

  • uses firebrick colour on the mode-line of active buffers with god-mode enabled. This is a quite alarming colour, yet not too harsh, and complements well the modus-vivendi colour scheme, IMHO.
  • uses darkred colour on the mode-line of inactive buffers with god-mode enabled, which is duller/darker than firebrick on the active buffer.
  • only changes the mode-line colour on buffers where god-mode is enabled (e.g. not in buffers which are exempt.
  • reverts the mode-line colour to your chosen theme when god-mode is disabled, instead of overriding it with some custom hard-coded value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.