diff options
Diffstat (limited to '.emacs.d/lisp/yasnippet.el')
| -rw-r--r-- | .emacs.d/lisp/yasnippet.el | 107 |
1 files changed, 65 insertions, 42 deletions
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index d130cb9..fa36be7 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el | |||
| @@ -824,6 +824,10 @@ which decides on the snippet to expand.") | |||
| 824 | ;; Prevent sharing the tail. | 824 | ;; Prevent sharing the tail. |
| 825 | (append lists '(()) ))))))) | 825 | (append lists '(()) ))))))) |
| 826 | 826 | ||
| 827 | (defun yas--flush-all-parents (mode) | ||
| 828 | (if (get mode 'yas--all-parents) | ||
| 829 | (put mode 'yas--all-parents nil))) | ||
| 830 | |||
| 827 | (defun yas--all-parents (mode) | 831 | (defun yas--all-parents (mode) |
| 828 | "Like `derived-mode-all-parents' but obeying `yas--parents'." | 832 | "Like `derived-mode-all-parents' but obeying `yas--parents'." |
| 829 | (or (get mode 'yas--all-parents) ;; FIXME: Use `with-memoization'? | 833 | (or (get mode 'yas--all-parents) ;; FIXME: Use `with-memoization'? |
| @@ -854,6 +858,7 @@ which decides on the snippet to expand.") | |||
| 854 | 'fundamental-mode) | 858 | 'fundamental-mode) |
| 855 | ,(let ((alias (symbol-function mode))) | 859 | ,(let ((alias (symbol-function mode))) |
| 856 | (when (symbolp alias) alias)) | 860 | (when (symbolp alias) alias)) |
| 861 | ,@(get mode 'derived-mode-extra-parents) | ||
| 857 | ,@(gethash mode yas--parents))))))))) | 862 | ,@(gethash mode yas--parents))))))))) |
| 858 | (dolist (parent all-parents) | 863 | (dolist (parent all-parents) |
| 859 | (cl-pushnew mode (get parent 'yas--cached-children))) | 864 | (cl-pushnew mode (get parent 'yas--cached-children))) |
| @@ -1833,10 +1838,17 @@ the current buffers contents." | |||
| 1833 | (insert "\n\n")) | 1838 | (insert "\n\n")) |
| 1834 | ;; Normal case. | 1839 | ;; Normal case. |
| 1835 | (let ((snippet-table (yas--table-get-create mode)) | 1840 | (let ((snippet-table (yas--table-get-create mode)) |
| 1841 | (uuids nil) | ||
| 1836 | (template nil)) | 1842 | (template nil)) |
| 1837 | (dolist (snippet snippets) | 1843 | (dolist (snippet snippets) |
| 1838 | (setq template (yas--define-snippets-1 snippet | 1844 | (setq template (yas--define-snippets-1 snippet |
| 1839 | snippet-table))) | 1845 | snippet-table)) |
| 1846 | (let ((uuid (yas--template-uuid template))) | ||
| 1847 | (if (member uuid uuids) | ||
| 1848 | ;; It's normal for a snippet to override another one | ||
| 1849 | ;; in `snippet-table`, but not one in `snippets`. | ||
| 1850 | (message "Multiple snippets with same identity: %S" uuid) | ||
| 1851 | (push uuid uuids)))) | ||
| 1840 | template))) | 1852 | template))) |
| 1841 | 1853 | ||
| 1842 | 1854 | ||
| @@ -2002,6 +2014,9 @@ prefix argument." | |||
| 2002 | (with-current-buffer buffer | 2014 | (with-current-buffer buffer |
| 2003 | yas--editing-template)) | 2015 | yas--editing-template)) |
| 2004 | (buffer-list)))) | 2016 | (buffer-list)))) |
| 2017 | |||
| 2018 | (mapatoms #'yas--flush-all-parents) | ||
| 2019 | |||
| 2005 | ;; Warn if there are buffers visiting snippets, since reloading will break | 2020 | ;; Warn if there are buffers visiting snippets, since reloading will break |
| 2006 | ;; any on-line editing of those buffers. | 2021 | ;; any on-line editing of those buffers. |
| 2007 | ;; | 2022 | ;; |
| @@ -3994,7 +4009,7 @@ SNIPPET may be a snippet structure (e.g., as returned by | |||
| 3994 | `yas-lookup-snippet'), or just a snippet body (which is a string | 4009 | `yas-lookup-snippet'), or just a snippet body (which is a string |
| 3995 | for normal snippets, and a list for command snippets)." | 4010 | for normal snippets, and a list for command snippets)." |
| 3996 | (cl-assert (and yas-minor-mode | 4011 | (cl-assert (and yas-minor-mode |
| 3997 | (memq 'yas--post-command-handler post-command-hook)) | 4012 | (memq #'yas--post-command-handler post-command-hook)) |
| 3998 | nil | 4013 | nil |
| 3999 | "[yas] `yas-expand-snippet' needs properly setup `yas-minor-mode'") | 4014 | "[yas] `yas-expand-snippet' needs properly setup `yas-minor-mode'") |
| 4000 | (run-hooks 'yas-before-expand-snippet-hook) | 4015 | (run-hooks 'yas-before-expand-snippet-hook) |
| @@ -4715,20 +4730,22 @@ When multiple expressions are found, only the last one counts." | |||
| 4715 | (point))) | 4730 | (point))) |
| 4716 | (number (and (match-string-no-properties 1) | 4731 | (number (and (match-string-no-properties 1) |
| 4717 | (string-to-number (match-string-no-properties 1)))) | 4732 | (string-to-number (match-string-no-properties 1)))) |
| 4718 | (brand-new-field (and real-match-end-0 | 4733 | (field2 (match-string-no-properties 2)) |
| 4719 | ;; break if on "$(" immediately | 4734 | (simple-fom (string-match-p "\\`[0-9]+\\'" field2)) |
| 4720 | ;; after the ":", this will be | 4735 | (brand-new-field |
| 4721 | ;; caught as a mirror with | 4736 | (and ;; break if on "$(" immediately after the ":", this |
| 4722 | ;; transform later. | 4737 | ;; will be caught as a mirror with transform later. |
| 4723 | (not (string-match-p "\\`\\$[ \t\n]*(" | 4738 | (not (string-match-p "\\`\\$[ \t\n]*(" field2)) |
| 4724 | (match-string-no-properties 2))) | 4739 | ;; allow ${0: some exit text} |
| 4725 | ;; allow ${0: some exit text} | 4740 | ;; (not (and number (zerop number))) |
| 4726 | ;; (not (and number (zerop number))) | 4741 | (yas--make-field number |
| 4727 | (yas--make-field number | 4742 | (yas--make-marker (match-beginning 2)) |
| 4728 | (yas--make-marker (match-beginning 2)) | 4743 | (yas--make-marker (1- real-match-end-0)) |
| 4729 | (yas--make-marker (1- real-match-end-0)) | 4744 | parent-field)))) |
| 4730 | parent-field)))) | 4745 | (cond |
| 4731 | (when brand-new-field | 4746 | ((and (not number) simple-fom) |
| 4747 | (yas--one-simple-fom snippet field2)) | ||
| 4748 | (brand-new-field | ||
| 4732 | (goto-char real-match-end-0) | 4749 | (goto-char real-match-end-0) |
| 4733 | (push (cons (1- real-match-end-0) real-match-end-0) | 4750 | (push (cons (1- real-match-end-0) real-match-end-0) |
| 4734 | yas--dollar-regions) | 4751 | yas--dollar-regions) |
| @@ -4737,9 +4754,11 @@ When multiple expressions are found, only the last one counts." | |||
| 4737 | (push brand-new-field (yas--snippet-fields snippet)) | 4754 | (push brand-new-field (yas--snippet-fields snippet)) |
| 4738 | (save-excursion | 4755 | (save-excursion |
| 4739 | (save-restriction | 4756 | (save-restriction |
| 4740 | (narrow-to-region (yas--field-start brand-new-field) (yas--field-end brand-new-field)) | 4757 | (narrow-to-region (yas--field-start brand-new-field) |
| 4758 | (yas--field-end brand-new-field)) | ||
| 4741 | (goto-char (point-min)) | 4759 | (goto-char (point-min)) |
| 4742 | (yas--field-parse-create snippet brand-new-field))))))) | 4760 | (yas--field-parse-create snippet brand-new-field)))))))) |
| 4761 | |||
| 4743 | ;; if we entered from a parent field, now search for the | 4762 | ;; if we entered from a parent field, now search for the |
| 4744 | ;; `yas--multi-dollar-lisp-expression-regexp'. This is used for | 4763 | ;; `yas--multi-dollar-lisp-expression-regexp'. This is used for |
| 4745 | ;; primary field transformations | 4764 | ;; primary field transformations |
| @@ -4796,31 +4815,35 @@ When multiple expressions are found, only the last one counts." | |||
| 4796 | (defun yas--simple-fom-create (snippet) | 4815 | (defun yas--simple-fom-create (snippet) |
| 4797 | "Parse the simple \"$n\" fields/mirrors/exitmarkers in SNIPPET." | 4816 | "Parse the simple \"$n\" fields/mirrors/exitmarkers in SNIPPET." |
| 4798 | (while (re-search-forward yas--simple-mirror-regexp nil t) | 4817 | (while (re-search-forward yas--simple-mirror-regexp nil t) |
| 4799 | (let ((number (string-to-number (match-string-no-properties 1)))) | 4818 | (yas--one-simple-fom snippet (match-string-no-properties 1)))) |
| 4800 | (cond ((zerop number) | 4819 | |
| 4801 | (setf (yas--snippet-exit snippet) | 4820 | (defun yas--one-simple-fom (snippet numstring) |
| 4802 | (yas--make-exit (yas--make-marker (match-end 0)))) | 4821 | (let ((number (string-to-number numstring))) |
| 4803 | (push (cons (match-beginning 0) (yas--exit-marker (yas--snippet-exit snippet))) | 4822 | (cond ((zerop number) |
| 4804 | yas--dollar-regions)) | 4823 | (setf (yas--snippet-exit snippet) |
| 4805 | (t | 4824 | (yas--make-exit (yas--make-marker (match-end 0)))) |
| 4806 | (let ((field (yas--snippet-find-field snippet number)) | 4825 | (push (cons (match-beginning 0) |
| 4807 | (fom)) | 4826 | (yas--exit-marker (yas--snippet-exit snippet))) |
| 4808 | (if field | 4827 | yas--dollar-regions)) |
| 4809 | (push | 4828 | (t |
| 4810 | (setq fom (yas--make-mirror | 4829 | (let ((field (yas--snippet-find-field snippet number)) |
| 4811 | (yas--make-marker (match-beginning 0)) | 4830 | (fom)) |
| 4812 | (yas--make-marker (match-beginning 0)) | 4831 | (if field |
| 4813 | nil)) | ||
| 4814 | (yas--field-mirrors field)) | ||
| 4815 | (push | 4832 | (push |
| 4816 | (setq fom (yas--make-field number | 4833 | (setq fom (yas--make-mirror |
| 4817 | (yas--make-marker (match-beginning 0)) | 4834 | (yas--make-marker (match-beginning 0)) |
| 4818 | (yas--make-marker (match-beginning 0)) | 4835 | (yas--make-marker (match-beginning 0)) |
| 4819 | nil)) | 4836 | nil)) |
| 4820 | (yas--snippet-fields snippet))) | 4837 | (yas--field-mirrors field)) |
| 4821 | (yas--calculate-simple-fom-parentage snippet fom)) | 4838 | (push |
| 4822 | (push (cons (match-beginning 0) (match-end 0)) | 4839 | (setq fom (yas--make-field number |
| 4823 | yas--dollar-regions)))))) | 4840 | (yas--make-marker (match-beginning 0)) |
| 4841 | (yas--make-marker (match-beginning 0)) | ||
| 4842 | nil)) | ||
| 4843 | (yas--snippet-fields snippet))) | ||
| 4844 | (yas--calculate-simple-fom-parentage snippet fom)) | ||
| 4845 | (push (cons (match-beginning 0) (match-end 0)) | ||
| 4846 | yas--dollar-regions))))) | ||
| 4824 | 4847 | ||
| 4825 | (defun yas--delete-regions (regions) | 4848 | (defun yas--delete-regions (regions) |
| 4826 | "Sort disjuct REGIONS by start point, then delete from the back." | 4849 | "Sort disjuct REGIONS by start point, then delete from the back." |
