My Technical Notes

Wednesday, 16 March 2016

Elisp: Binding a key to an Anonymous Function

Example of Keybinding to an Anonymous Function

The following binds `C-a` (control a) to an anonymous function which calls `mark-whole-buffer`. Note that the `interactive` statement is compulsory when binding keys.


(global-set-key (kbd "C-a") (lambda ()
         (interactive)
         (mark-whole-buffer)))

In reality, if we call only a single function, that is also interactive, we would do the simpler:


(global-set-key (kbd "C-a") 'mark-whole-buffer)

References

No comments: