rje
rje

Reputation: 6438

showing message to user in mode hook

I'm writing a hook to add some custom key bindings to org mode, it looks like this:

(defun course-export-org-mode-hook ()
    (define-key org-mode-map (kbd "C-x .") 'my-custom-func)
    (message "Remember that we can use 'C-x .' to run my custom func."))

I'd like to show the message in the last line to the user as a tip, to remember that the keybinding is active.

What happens now is that the message is shown very briefly during the running of the mode hook, but before the contents of the file is actually shown. By the time the buffer is visible, the message has already disappeared.

How can I show the message once the file contents are shown, and perhaps have it stay on the screen for a while so the user has time to read it?

Upvotes: 0

Views: 29

Answers (1)

phils
phils

Reputation: 73324

Your code works fine for me, so I presume something else in your config is clobbering that message. You could try using a timer to set the message after any synchronous activities have finished:

(defun course-export-org-mode-hook ()
  (run-with-timer 0 nil (lambda () (message "Remember that we can \
use 'C-x .' to run my custom func."))))

Upvotes: 1

Related Questions