1

I have a large number of org files that are created to store some specific information, that wont change. I am trying to create a function to go find that file and insert it into a temporary buffer so that I can view it, but making it dissappear when I hit "q" like a temp buffer. The functionality That I want is special-mode but the problem is that when I enable special-mode I lose the syntax-highlighting of org-mode, and when I enabled org-mode it overwrites the keybindings that I need for special-mode to quit easily. My current solution would be to bind the key for (quit-window) to "q" manually, but I dont know how to do that only for this temporary window, and not for the shared org-mode buffers that I might have open at the same time.

(let ((bufferName "*Temp Buffer*"))
  (get-buffer-create bufferName)
  (switch-to-buffer-other-window bufferName)
  (insert-file-contents "file-that-i-want-to-insert.org")
  (mygroup/minor-special-mode) ;; Originally was (special-mode)
  (org-mode)
  (outline-show-all))

SOLVED

As per the accepted answer below I created a minor mode and that allowed me to override the "q" binding from org-mode.

NOTE I had to restart my emacs for this to work properly, otherwise it was keeping the org-mode binding for q even with the minor mode enabled.

This was the minor mode I created for anyone needing the same solution:

(define-minor-mode mygroup/minor-special-mode
    "Toggle Special minor  mode."
    ;; The initial value.
    :init-value nil
    ;; The indicator for the mode line.
    :lighter " mSpecial"
    ;; The group this mode is in.
    :group 'mygroup
    ;; The minor mode bindings.
    :keymap (let ((map (make-sparse-keymap)))
    (define-key map (kbd "q") 'quit-window)
    map))
2

Special mode is a major mode, and you can only have one major mode active at a time. However, you can have an arbitrary number of minor modes active on top of the major mode, and the keymaps for the minor mode take precedence over the major mode. So I would suggest you put your temporary buffer into org mode, and also create a custom minor mode that has your key bindings set.

  • I tried this and defined a minor mode: (define-minor-mode minor-special-mode :init-value nil :lighter " mSpecial" :keymap '((q . (quit-window))) :group 'mygroup) but when I hit (C-h k q) in my buffer after initializing this mode I see this: q runs the command org-self-insert-command (found in org-mode-map), – HHoverton Jun 14 '18 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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