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))
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))