First of all, thank you for the tutorial and the code! Outshine has
become
a major component of my workflow, I use it in all my source
code buffers (sql, R, elisp).
I have one question/proposal regarding key bindings. Outshine binds
TAB
to outshine-cycle-subtree which only does something useful (calls
outshine-cycle)
when the point is on a header line, otherwise it
prints a message. TAB is used
heavily in various source code -related
modes (yasnippets, smart-tab, etc.
behavior which I don't want to lose. There is some support of other TAB behaviors in
outline-cycle but it is not used (and it ignores the user-defined bindings).
A while back I wrote a macro (based on the advice in
bindings when a condition is true and fall
back to previous bindings otherwise:
(defmacro define-key-with-fallback (keymap key def condition &optional mode)
"Define key with fallback. Binds KEY to definition DEF in keymap KEYMAP, the
binding is active when the CONDITION is true. Otherwise turns MODE off and
re-enables previous definition for KEY. If MODE is nil, tries to recover it by
stripping off \"-map\" from KEYMAP name."
`(define-key ,keymap ,key
(lambda () (interactive)
(if ,condition ,def
(let* ((,(if mode mode
(let* ((keymap-str (symbol-name keymap))
(mode-name-end (- (string-width keymap-str) 4)))
(if (string= "-map" (substring keymap-str mode-name-end))
(intern (substring keymap-str 0 mode-name-end))
(error "Could not deduce mode name from keymap name (\"-map\" missing?)"))))
nil)
(original-func (key-binding ,key)))
(call-interactively original-func))))))
So now I can just do
(define-key-with-fallback outline-minor-mode-map (kbd "TAB")
(outline-cycle 1) (outline-on-heading-p))
and have my yasnippets and smart indentation/completion active again. My question is am I reinventing
the wheel? Is there a function/macro in org-mode or elsewhere that would allow me define key bindings
with fallback?
Thanks again,
Alex