emacs - Elisp: Conditionally change keybinding -
i'm trying write custom tab completion implementation tries bunch of different completions depending on point is. however, if none of conditions completions met tab ever current mode intended do.
something this:
(defun my-custom-tab-completion () (interactive) (cond (some-condition (do-something)) (some-other-condition (do-something-else)) (t (do-whatever-tab-is-supposed-to-do-in-the-current-mode))) ;; how do this? currently i'm checking specific modes , doing right thing mode, solution right thing without me having explicitly add condition specific mode.
any ideas of how this?
thanks! /erik
you use functions such key-binding (or more specific variants global-key-binding, minor-mode-key-binding , local-key-binding) probe active keymaps bindings.
for example:
(call-interactively (key-binding (kbd "tab"))) ;; in emacs-lisp-mode buffer: ;; --> indent-for-tab-command ;; ;; in c++-mode buffer yas/minor-mode: ;; --> yas/expand one way avoid infinite loops if command bound tab put binding in minor mode, , temporarily disable keymap while looking tab binding:
(define-minor-mode my-complete-mode "smart completion" :keymap (let ((map (make-sparse-keymap))) (define-key map (kbd "tab") 'my-complete) map)) (defun my-complete () (interactive) (message "my-complete") (let ((my-complete-mode nil)) (call-interactively (key-binding (kbd "tab")))))
Comments
Post a Comment