Skip to content

Commit 91fc795

Browse files
committed
🐛 Allow aborting gitmojis select.
1. Use `condition-case` to check quit signal, if quit, retrun nil. 2. Only eval `gitmoji-insert--action` if X not nil. issue: #1
1 parent d6e2870 commit 91fc795

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

gitmoji.el

+29-17
Original file line numberDiff line numberDiff line change
@@ -153,35 +153,48 @@ These can have one of the following values
153153
gitmojis-list))
154154

155155
(defun gitmoji-insert--action (x)
156-
(let ((utf8 (cadddr x))
157-
(shortcode (caddr x)))
158-
(if gitmoji--insert-utf8-emoji
159-
(insert-char utf8)
160-
(insert shortcode)))
161-
(insert " "))
156+
"Insert either Gitmoji's symbol or shortcode.
157+
Based on the value of gitmoji--insert-utf8-emoji global variable,
158+
followed by a space character.
159+
It takes a single argument X, which is a list of selected Gitmoji's information."
160+
(if x
161+
(progn
162+
(let ((utf8 (cadddr x))
163+
(shortcode (caddr x)))
164+
(if gitmoji--insert-utf8-emoji
165+
(insert-char utf8)
166+
(insert shortcode)))
167+
(insert " "))))
162168

163169
(defun gitmoji-insert-ivy ()
164170
"Choose a gitmoji with ivy and insert it in the current buffer."
165171
(interactive)
166172
(let ((candidates (gitmoji-insert--candidates)))
167-
(ivy-read
168-
"Choose a gitmoji: "
169-
candidates
170-
:action #'gitmoji-insert--action
171-
)))
173+
(condition-case nil
174+
(ivy-read
175+
"Choose a gitmoji: "
176+
candidates
177+
:action #'gitmoji-insert--action)
178+
(quit nil))))
172179

173180
(defun gitmoji-insert-helm ()
174181
"Choose a gitmoji with helm and insert it in the current buffer."
175182
(interactive)
176-
(helm :sources `((name . "Choose a gitmoji:")
177-
(candidates . ,(gitmoji-insert--candidates))
178-
(action . (lambda (candidate) (gitmoji-insert--action (append '(" ") candidate)))))))
183+
(condition-case nil
184+
(helm :sources `((name . "Choose a gitmoji:")
185+
(candidates . ,(gitmoji-insert--candidates))
186+
(action . (lambda (candidate) (gitmoji-insert--action (append '(" ") candidate))))))
187+
(helm-quit nil)))
179188

180189
(defun gitmoji-insert-consult ()
181190
"Choose a gitmoji with consult and insert it in the current buffer."
182191
(interactive)
183192
(let* ((candidates (gitmoji-insert--candidates))
184-
(candidate (assoc (completing-read "Choose a gitmoji: " candidates) candidates)))
193+
(candidate (assoc
194+
(condition-case nil
195+
(completing-read "Choose a gitmoji: " candidates)
196+
(quit nil))
197+
candidates)))
185198
(gitmoji-insert--action candidate)))
186199

187200
(defun gitmoji-insert ()
@@ -191,8 +204,7 @@ These can have one of the following values
191204
((and (memql 'ivy gitmoji-selection-backend) (featurep 'ivy)) (gitmoji-insert-ivy))
192205
((and (memql 'helm gitmoji-selection-backend) (featurep 'helm)) (gitmoji-insert-helm))
193206
((and (memql 'consult gitmoji-selection-backend) (featurep 'consult)) (gitmoji-insert-consult))
194-
(t (warn "No valid backend selected for Gitmoji."))
195-
))
207+
(t (warn "No valid backend selected for Gitmoji."))))
196208

197209
;;;###autoload
198210
(define-minor-mode gitmoji-commit-mode

0 commit comments

Comments
 (0)