summaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/yasnippet.el
diff options
context:
space:
mode:
authorSimeon Simeonov2015-08-28 11:10:13 +0200
committerSimeon Simeonov2015-08-28 11:10:13 +0200
commit3ec6ac6a8d888043cc12dfe6f77adcd0cfc1b086 (patch)
treec2382110856abc0cae77f8360ea2b0d8962d07f9 /.emacs.d/lisp/yasnippet.el
parenteeeaae3a34ca050c9ea30aa3950dc91db70b9b1a (diff)
Upgrade all, add yaml, few snippet fixes
Diffstat (limited to '.emacs.d/lisp/yasnippet.el')
-rw-r--r--.emacs.d/lisp/yasnippet.el76
1 files changed, 40 insertions, 36 deletions
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el
index 305bb95..1f6c7de 100644
--- a/.emacs.d/lisp/yasnippet.el
+++ b/.emacs.d/lisp/yasnippet.el
@@ -725,7 +725,7 @@ defined direct keybindings to the command
725 yas--direct-keymaps)) 725 yas--direct-keymaps))
726 yas--tables)) 726 yas--tables))
727 727
728(defun yas--modes-to-activate () 728(defun yas--modes-to-activate (&optional mode)
729 "Compute list of mode symbols that are active for `yas-expand' 729 "Compute list of mode symbols that are active for `yas-expand'
730and friends." 730and friends."
731 (let (dfs) 731 (let (dfs)
@@ -740,8 +740,10 @@ and friends."
740 (not (memq neighbour explored)) 740 (not (memq neighbour explored))
741 (symbolp neighbour)) 741 (symbolp neighbour))
742 append (funcall dfs neighbour explored))))) 742 append (funcall dfs neighbour explored)))))
743 (remove-duplicates (append yas--extra-modes 743 (remove-duplicates (if mode
744 (funcall dfs major-mode))))) 744 (funcall dfs mode)
745 (append yas--extra-modes
746 (funcall dfs major-mode))))))
745 747
746(defvar yas-minor-mode-hook nil 748(defvar yas-minor-mode-hook nil
747 "Hook run when `yas-minor-mode' is turned on.") 749 "Hook run when `yas-minor-mode' is turned on.")
@@ -1333,15 +1335,17 @@ return an expression that when evaluated will issue an error."
1333 yas--direct-keymaps)) 1335 yas--direct-keymaps))
1334 table)) 1336 table))
1335 1337
1336(defun yas--get-snippet-tables () 1338(defun yas--get-snippet-tables (&optional mode)
1337 "Get snippet tables for current buffer. 1339 "Get snippet tables for MODE.
1340
1341MODE defaults to the current buffer's `major-mode'.
1338 1342
1339Return a list of `yas--table' objects. The list of modes to 1343Return a list of `yas--table' objects. The list of modes to
1340consider is returned by `yas--modes-to-activate'" 1344consider is returned by `yas--modes-to-activate'"
1341 (remove nil 1345 (remove nil
1342 (mapcar #'(lambda (name) 1346 (mapcar #'(lambda (name)
1343 (gethash name yas--tables)) 1347 (gethash name yas--tables))
1344 (yas--modes-to-activate)))) 1348 (yas--modes-to-activate mode))))
1345 1349
1346(defun yas--menu-keymap-get-create (mode &optional parents) 1350(defun yas--menu-keymap-get-create (mode &optional parents)
1347 "Get or create the menu keymap for MODE and its PARENTS. 1351 "Get or create the menu keymap for MODE and its PARENTS.
@@ -1661,33 +1665,16 @@ file with the same uuid would replace the previous snippet.
1661You can use `yas--parse-template' to return such lists based on 1665You can use `yas--parse-template' to return such lists based on
1662the current buffers contents." 1666the current buffers contents."
1663 (if yas--creating-compiled-snippets 1667 (if yas--creating-compiled-snippets
1664 (progn 1668 (let ((print-length nil))
1665 (insert ";;; Snippet definitions:\n;;;\n") 1669 (insert ";;; Snippet definitions:\n;;;\n")
1666 (let ((literal-snippets (list)) 1670 (dolist (snippet snippets)
1667 (print-length nil)) 1671 ;; We omit file because the snippet will be loaded from
1668 (dolist (snippet snippets) 1672 ;; the compiled file instead, so deleting or changing
1669 (let ((key (nth 0 snippet)) 1673 ;; the original won't have any effect.
1670 (template-content (nth 1 snippet)) 1674 (setcar (nthcdr 6 snippet) nil))
1671 (name (nth 2 snippet)) 1675 (insert (pp-to-string
1672 (condition (nth 3 snippet)) 1676 `(yas-define-snippets ',mode ',snippets)))
1673 (group (nth 4 snippet)) 1677 (insert "\n\n"))
1674 (expand-env (nth 5 snippet))
1675 (file nil) ;; omit on purpose
1676 (binding (nth 7 snippet))
1677 (uuid (nth 8 snippet)))
1678 (push `(,key
1679 ,template-content
1680 ,name
1681 ,condition
1682 ,group
1683 ,expand-env
1684 ,file
1685 ,binding
1686 ,uuid)
1687 literal-snippets)))
1688 (insert (pp-to-string
1689 `(yas-define-snippets ',mode ',literal-snippets)))
1690 (insert "\n\n")))
1691 ;; Normal case. 1678 ;; Normal case.
1692 (let ((snippet-table (yas--table-get-create mode)) 1679 (let ((snippet-table (yas--table-get-create mode))
1693 (template nil)) 1680 (template nil))
@@ -2305,6 +2292,24 @@ Honours `yas-choose-tables-first', `yas-choose-keys-first' and
2305 (remove-duplicates (mapcan #'yas--table-templates tables) 2292 (remove-duplicates (mapcan #'yas--table-templates tables)
2306 :test #'equal)))) 2293 :test #'equal))))
2307 2294
2295(defun yas-lookup-snippet (name &optional mode noerror)
2296 "Get the snippet content for the snippet NAME in MODE's tables.
2297
2298MODE defaults to the current buffer's `major-mode'. If NOERROR
2299is non-nil, then don't signal an error if there isn't any snippet
2300called NAME.
2301
2302Honours `yas-buffer-local-condition'."
2303 (let* ((yas-choose-tables-first nil) ; avoid prompts
2304 (yas-choose-keys-first nil)
2305 (snippet (cl-find name (yas--all-templates
2306 (yas--get-snippet-tables mode))
2307 :key #'yas--template-name :test #'string=)))
2308 (cond
2309 (snippet (yas--template-content snippet))
2310 (noerror nil)
2311 (t (error "No snippet named: %s" name)))))
2312
2308(defun yas-insert-snippet (&optional no-condition) 2313(defun yas-insert-snippet (&optional no-condition)
2309 "Choose a snippet to expand, pop-up a list of choices according 2314 "Choose a snippet to expand, pop-up a list of choices according
2310to `yas-prompt-functions'. 2315to `yas-prompt-functions'.
@@ -2562,10 +2567,9 @@ and `kill-buffer' instead."
2562 ;; 2567 ;;
2563 (not (yas--template-file yas--editing-template)) 2568 (not (yas--template-file yas--editing-template))
2564 (not (file-writable-p (yas--template-file yas--editing-template))) 2569 (not (file-writable-p (yas--template-file yas--editing-template)))
2565 (and (listp yas-snippet-dirs) 2570 (and (cdr-safe yas-snippet-dirs)
2566 (second yas-snippet-dirs) 2571 (not (string-prefix-p (expand-file-name (car yas-snippet-dirs))
2567 (not (string-match (expand-file-name (first yas-snippet-dirs)) 2572 (yas--template-file yas--editing-template)))))
2568 (yas--template-file yas--editing-template)))))
2569 (y-or-n-p (yas--format "Looks like a library or new snippet. Save to new file? "))) 2573 (y-or-n-p (yas--format "Looks like a library or new snippet. Save to new file? ")))
2570 (let* ((option (first (yas--guess-snippet-directories (yas--template-table yas--editing-template)))) 2574 (let* ((option (first (yas--guess-snippet-directories (yas--template-table yas--editing-template))))
2571 (chosen (and option 2575 (chosen (and option