I use company for completion and I have company-indent-or-complete-common
bound to tab for certain modes. In org mode, tab is bound to org-cycle
, which either cycles visibility or calls the global binding for tab depending on context. I would like to have org-cycle
call company-indent-or-complete-common
instead of the global binding for tab, but I don't know how to do this. Is there a simple way to trick org-cycle
into having this behavior?
Edit: I managed to find a solution on my own (for some reason @tjg's answer doesn't work for me). At first I was using
(defun org-cycle-advice (old-fn &rest r)
(let ((old-tab (global-key-binding (kbd "TAB"))))
(global-set-key (kbd "TAB") 'company-indent-or-complete-common)
(apply old-fn r)
(global-set-key (kbd "TAB") old-tab)))
(advice-add 'org-cycle :around 'org-cycle-advice)
but that didn't generalize to outshine-cycle
well, so now I am using
(defun company-outline-cycle-indent-or-complete-common ()
(interactive)
(if (not (outline-on-heading-p))
(if (string= major-mode "org-mode")
(org-cycle)
(if (bound-and-true-p outshine-mode)
(outshine-cycle)))))