Refactor feature/file-templates

This removes its dependency on the feature/snippets.
This commit is contained in:
Henrik Lissner 2018-06-03 23:43:27 +02:00
parent cd0e9826ac
commit 818cb27724
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 22 additions and 13 deletions

View file

@ -73,6 +73,17 @@ evil is loaded and enabled)."
(file-relative-name path doom-emacs-dir)) (file-relative-name path doom-emacs-dir))
((abbreviate-file-name path))))) ((abbreviate-file-name path)))))
;;;###autoload
(defun +file-template-p (rule)
"Return t if RULE applies to the current buffer."
(let ((pred (car rule))
(plist (cdr rule)))
(and (cond ((and (stringp pred) buffer-file-name) (string-match-p pred buffer-file-name))
((symbolp pred) (eq major-mode pred)))
(or (not (plist-member plist :when))
(funcall (plist-get plist :when) buffer-file-name))
rule)))
;; ;;
;; Commands ;; Commands

View file

@ -1,7 +1,5 @@
;;; feature/file-templates/config.el -*- lexical-binding: t; -*- ;;; feature/file-templates/config.el -*- lexical-binding: t; -*-
(require! :feature snippets)
(defvar +file-templates-dir (defvar +file-templates-dir
(expand-file-name "templates/" (file-name-directory load-file-name)) (expand-file-name "templates/" (file-name-directory load-file-name))
"The path to a directory of yasnippet folders to use for file templates.") "The path to a directory of yasnippet folders to use for file templates.")
@ -103,16 +101,6 @@ more information.")
;; Library ;; Library
;; ;;
(defun +file-template-p (rule)
"Return t if RULE applies to the current buffer."
(let ((pred (car rule))
(plist (cdr rule)))
(and (cond ((and (stringp pred) buffer-file-name) (string-match-p pred buffer-file-name))
((symbolp pred) (eq major-mode pred)))
(or (not (plist-member plist :when))
(funcall (plist-get plist :when) buffer-file-name))
rule)))
(defun +file-templates-in-emacs-dirs-p (file) (defun +file-templates-in-emacs-dirs-p (file)
"Returns t if FILE is in Doom or your private directory." "Returns t if FILE is in Doom or your private directory."
(or (file-in-directory-p file doom-private-dir) (or (file-in-directory-p file doom-private-dir)
@ -133,6 +121,16 @@ must be non-read-only, empty, and there must be a rule in
;; Bootstrap ;; Bootstrap
;; ;;
(def-package! yasnippet
:unless (featurep! :feature snippets)
:config
(setq yas-verbosity (if doom-debug-mode 3 0)
yas-prompt-functions (delq #'yas-dropdown-prompt yas-prompt-functions)
yas-snippet-dirs nil)
;; Exit snippets on ESC from normal mode
(add-hook 'doom-escape-hook #'yas-abort-snippet))
(defun +file-templates|init () (defun +file-templates|init ()
(after! yasnippet (after! yasnippet
(add-to-list 'yas-snippet-dirs '+file-templates-dir 'append #'eq)) (add-to-list 'yas-snippet-dirs '+file-templates-dir 'append #'eq))

View file

@ -1,5 +1,5 @@
;; -*- no-byte-compile: t; -*- ;; -*- no-byte-compile: t; -*-
;;; feature/file-templates/packages.el ;;; feature/file-templates/packages.el
(depends-on! :feature snippets) (package! yasnippet)