1

I am creating a new, special kind of buffer that I am using to display messages. I want to disable all keymaps within this new buffer.

This special buffer could be created at any time, and therefore, I don't know which keymaps may or may not currently active at the time of this buffer's creation.

Is there any way to disable each and every active keymap for a given buffer?

Thanks in advance.

HippoMan
  • 582
  • 2
  • 11
  • Do you mean "frame" or "window"? In general, a frame can display multiple buffers -- and a frame can have multiple windows. If you have a buffer in frame A with keymap Z, that keymap will not disappear if you view the same buffer in frame B. Keymaps are not frame-local. You can have buffer-local keymaps. For a better understanding of how this might work, see "**How to display a help buffer/window full frame size (not full screen)**": http://emacs.stackexchange.com/a/24037/2287 That answer contains buffer-local keymap – lawlist Dec 07 '16 at 23:54
  • I know the difference between buffers, windows, and frames, but I didn't ask my question clearly. I want to create a new, unique buffer and open it within a unique frame in one, single window. I already know how to do all that. And I know about buffer-local keymaps, and that's what I plan to create. However, what I want to figure out is this: I want to also disable all _other_ keymaps that might be active at the time I create this new buffer. – HippoMan Dec 08 '16 at 01:58
  • There are too many possibilities, in my opinion, to answer the question: new buffer has a major-mode v. new buffer is in fundamental mode; new buffer is a cloned/indirect buffer; how many minor-modes with keymaps are active in the new buffer; are there local keymaps in the buffer; are there mouse-over keymaps and mode-line keymaps in the new buffer; etc. If you already know how to handle everything about creating a new frame and buffer-local keymaps, then consider removing all of that from the question so the readers do not spend time thinking about that aspect. – lawlist Dec 08 '16 at 02:23
  • See also the section of the manual regarding **Active Keymaps**: https://www.gnu.org/software/emacs/manual/html_node/elisp/Active-Keymaps.html E.g., the function `current-active-maps` – lawlist Dec 08 '16 at 02:42
  • I have now rewritten my question. – HippoMan Dec 08 '16 at 02:42
  • Could you describe why you want to do this? You could define a minor-mode which captures all keypresses except property keymaps. – clemera Dec 08 '16 at 09:39
  • In such a minor mode, I would have to write code to capture all 256 possible key presses. It seems to me that disabling the existing active keymaps would require less code. But perhaps I'm wrong. – HippoMan Dec 08 '16 at 12:33

2 Answers2

4

You can use a minor-mode and use a default mapping. Have a look at the define-key documentation for details about default definitions in keymaps.

(define-minor-mode disable-keys-mode
  "Disables all keys."
  :lighter " dk"
  :keymap (let ((map (make-sparse-keymap)))
            (define-key map (kbd "C-g") (lambda ()
                                          (interactive)
                                          (disable-keys-mode -1)))
            (define-key map [t] 'ignore)
            map))
clemera
  • 3,401
  • 13
  • 40
  • 1
    Ah ... I didn't know about `[t]`. That saves a lot of code. Thank you. I take this as the best answer. – HippoMan Dec 08 '16 at 14:44
0

Thanks to the pointer from lawlist, I now know how to do this. This over-simplified code gives a general overview of the procedure ...

(let ((cam (current-active-maps t))
      (lm))
  (while cam
    (setq lm (copy-keymap (car cam)))
    (setq cam (cdr cam))
    (suppress-keymap lm)
    (use-local-map lm)))
HippoMan
  • 582
  • 2
  • 11