Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elisp: Conditionally change keybinding

Tags:

emacs

elisp

I'm trying to write a custom tab completion implementation which tries a bunch of different completions depending on where the point is. However, if none of the conditions for completions are met I would like tab to do what ever the current mode originally intended it to do.

Something like 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 I do this?

Currently I'm checking for specific modes and doing the right thing for that mode, but I really would like a solution that just does the right thing without me having to explicitly add a condition for that specific mode.

Any ideas of how to do this?

Thanks! /Erik

like image 514
Erik Öjebo Avatar asked Apr 18 '13 18:04

Erik Öjebo


1 Answers

BTW, here is another solution:

(define-key <map> <key>
  `(menu-item "" <my-cmd> :filter ,(lambda (cmd) (if <my-predicate> cmd))))
like image 98
Stefan Avatar answered Nov 08 '22 04:11

Stefan