emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 9abf842 19/63: Enable snippet-mode automatically


From: Noam Postavsky
Subject: [elpa] master 9abf842 19/63: Enable snippet-mode automatically
Date: Mon, 17 Jul 2017 22:54:13 -0400 (EDT)

branch: master
commit 9abf842e356e7b42fa105fe6284fb5ebe58a7ed1
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Enable snippet-mode automatically
    
    * yasnippet.el (yas-snippet-mode-buffer-p): New function, detects
    buffers visiting files under `yas-snippet-dirs'.  Add it
    `magic-fallback-mode-alist' to enable `snippet-mode' automatically,.
---
 yasnippet.el | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/yasnippet.el b/yasnippet.el
index fa538c1..644aa90 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -915,6 +915,21 @@ Honour `yas-dont-activate-functions', which see."
   (set (make-local-variable 'comment-start-skip) "#+[\t ]*")
   (add-hook 'after-save-hook #'yas-maybe-load-snippet-buffer nil t))
 
+(defun yas-snippet-mode-buffer-p ()
+  "Return non-nil if current buffer should be in `snippet-mode'.
+Meaning it's visiting a file under one of the mode directories in
+`yas-snippet-dirs'."
+  (when buffer-file-name
+    (member
+     (expand-file-name
+      ".."
+      (file-name-directory buffer-file-name))
+     (yas-snippet-dirs))))
+
+;; We're abusing `magic-fallback-mode-alist' here because
+;; `auto-mode-alist' doesn't support function matchers.
+(add-to-list 'magic-fallback-mode-alist
+             `(yas-snippet-mode-buffer-p . snippet-mode))
 
 
 ;;; Internal structs for template management



reply via email to

[Prev in Thread] Current Thread [Next in Thread]