Skip to content

Instantly share code, notes, and snippets.

@syl20bnr
Last active December 10, 2016 03:00
Show Gist options
  • Save syl20bnr/6437663 to your computer and use it in GitHub Desktop.
Save syl20bnr/6437663 to your computer and use it in GitHub Desktop.
This function is for evil-mode Emacs users. It executes the passed callback when 'fd' sequence is quickly pressed.
;; inspired from:
;; https://github.com/roman/emacs.d/blob/master/zoo/zoo-evil.el
(evil-define-command fd-trigger (callback)
"Allows to execute the passed function using 'fd'."
:repeat change
(let ((modified (buffer-modified-p)))
(insert "f")
(let ((evt (read-event
(format "Insert %c to exit insert state" ?d)
nil 0.2)))
(cond
((null evt)
(message ""))
((and (integerp evt)
(char-equal evt ?d))
;; remove the f character
(delete-char -1)
(set-buffer-modified-p modified)
(funcall callback))
(t ; otherwise
(setq unread-command-events (append unread-command-events
(list evt))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment