emacs: yasnippet: don’t expand on SPC in git-commit-mode
authorAmin Bandali <bandali@gnu.org>
Tue, 27 Aug 2019 05:34:03 +0000 (01:34 -0400)
committerAmin Bandali <bandali@gnu.org>
Tue, 27 Aug 2019 05:38:33 +0000 (01:38 -0400)
guix provides snippets like ‘add’ [0] which would get auto-expanded in
git-commit-mode with SPC, super annoying.

[0]: https://git.savannah.gnu.org/cgit/guix.git/tree/etc/snippets/text-mode/guix-commit-message-add-package

.emacs.d/init.el

index 4002d9a..6210f90 100644 (file)
@@ -1518,7 +1518,16 @@ This function is intended for use with `ivy-ignore-buffers'."
   (add-to-list 'yas-snippet-dirs "~/src/git/guix/etc/snippets" t)
   (yas-reload-all)
   (setq yas-verbosity yas-verbosity-cur)
-  (define-key yas-minor-mode-map (kbd "SPC") yas-maybe-expand)
+
+  (defun b/yas--maybe-expand-key-filter (cmd)
+    (when (and (yas--maybe-expand-key-filter cmd)
+               (not (bound-and-true-p git-commit-mode)))
+      cmd))
+  (defconst b/yas-maybe-expand
+    '(menu-item "" yas-expand :filter b/yas--maybe-expand-key-filter))
+  (define-key yas-minor-mode-map
+    (kbd "SPC") b/yas-maybe-expand)
+
   (yas-global-mode))
 
 (use-package debbugs)