I'd like to set some things (e.g., cursor shape) when in read-only-mode. That part is easy enough with

  (add-hook 'read-only-mode-hook 
             (lambda() (setq-local cursor-type 'box)))

Then I'd like to switch it back when exiting read-only-mode. Something like

  (add-hook 'read-write-mode-hook 
             (lambda() (setq-local cursor-type 'bar)))

except that there is no such thing as read-write-mode.

1 Answer 1


Like all minor mode hooks, read-only-mode-hook runs when entering or leaving read-only mode. So you only need to make the setting of the cursor a bit smarter, probably by checking the value of buffer-read-only and acting appropriately.

  • 1
    Ah, I have achieved enlightenment, and all it cost me was the embarrassment of asking a stupid question in the internet.
    – Ista
    Commented May 5, 2017 at 18:44
  • @Stefan. Interesting. I understand this is because of the "toggle" nature of minor modes but I can't find any explicit mention of it in the documentation. Did I miss it?
    – JeanPierre
    Commented May 5, 2017 at 20:01
  • 1
    The doc for read-only-mode-hook explicitly mentions "entering or leaving". Not sure about a more general statement, although the define-minor-mode doc in the Elisp manual say that it runs MODE-hook, but you still have to make the connection that it runs it whenever it is called (i.e. both entering and leaving) which I had not made before @Stefan pointed it out.
    – NickD
    Commented May 5, 2017 at 20:37
  • 2
    At present you could still use MODE-on-hook and MODE-off-hook for minor modes, but the code indicates that these are only there for backwards-compatibility, so they might be removed at some point in the future. The intention is certainly that you use MODE-hook and test the value of the MODE variable.
    – phils
    Commented May 5, 2017 at 23:43
  • @ista: thanks for your "stupid question" - I think it enlightened quite a few of us!
    – NickD
    Commented May 7, 2017 at 12:18

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.