Isaac
Isaac

Reputation: 16392

Keybindings specific to a certain buffer

I use a mode (merlin, but that doesn't matter) which opens a buffer with the name *merlin-type* when displays type information in it. I'd like to be able to type q in that buffer to close it. There's no mode specific to the buffer that I can hook into; what I'd like to do is create a buffer-local keybinding; how do I do this/what else should I be doing?

Upvotes: 1

Views: 71

Answers (1)

Andreas Röhler
Andreas Röhler

Reputation: 4804

There are hooks, which are not mode-specific. For example

(add-hook 'post-self-insert-hook #'DWIM)

or

(add-hook 'post-command-hook #'DWIM)

Then

(defun DWIM ()
  (when (string= MyPrefferedName (buffer-name (get-buffer (current-buffer))))
    DoWhatIWant))

or

(defun DWIM ()
      (when (buffer-live-p MyPrefferedBuffer)
        DoWhatIWant))

Upvotes: 1

Related Questions