Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a key bindings in emacs for easy repeat?

Tags:

emacs

elisp

Let's say I bind the key to a certain function as follows:

(global-set-key (kbd "C-c =") 'function-foo)

Now, I want the key binding to work as:
After I press C-c = for the first time, if I want to repeat the function-foo, I don't need to press C-c again, but simply repeat pressing =. Then, after I call the function-foo for enough times, I can just press keys other than = (or explicitly press C-g) to quit.

How to do this?

like image 365
shelper Avatar asked Jun 19 '13 21:06

shelper


People also ask

How do I set key bindings in Emacs?

First, Emacs checks if there's a minor mode key binding; If there isn't, then Emacs checks if there are any local keys set. Typically this local map is shared by the major mode of the current buffer. So if you want to add a key binding to python-mode , you can use local-set-key to do this.

What are vim bindings?

Probably one of our top feature requests. By Vim, I mean literally Vim, the command-line text editor. And by bindings, I mean keyboard commands that do specific things in the editor.


1 Answers

This may be the thing you are looking for:

(defun function-foo ()
  (interactive)
  (do-your-thing)
  (set-temporary-overlay-map
    (let ((map (make-sparse-keymap)))
      (define-key map (kbd "=") 'function-foo)
      map)))
like image 142
juanleon Avatar answered Sep 17 '22 20:09

juanleon