fd-trigger do nothing if the buffer is read-only

This commit is contained in:
syl20bnr 2014-10-03 22:42:29 -04:00
parent 286af87c7c
commit 5144fd6021

View file

@ -153,23 +153,24 @@ which require an initialization must be listed explicitly in the list.")
(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.1)))
(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))))))))
(unless buffer-read-only
(let ((modified (buffer-modified-p)))
(insert "f")
(let ((evt (read-event
(format "Insert %c to exit insert state" ?d)
nil 0.1)))
(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)))))))))
;; load evil-leader
(use-package evil-leader
:init