diff options
Diffstat (limited to '.emacs.d/lisp/yasnippet.el')
| -rw-r--r-- | .emacs.d/lisp/yasnippet.el | 76 |
1 files changed, 45 insertions, 31 deletions
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index 69f7381..94ccffb 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | ;;; yasnippet.el --- Yet another snippet extension for Emacs. | 1 | ;;; yasnippet.el --- Yet another snippet extension for Emacs. |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2008-2016 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2008-2017 Free Software Foundation, Inc. |
| 4 | ;; Authors: pluskid <pluskid@gmail.com>, | 4 | ;; Authors: pluskid <pluskid@gmail.com>, |
| 5 | ;; João Távora <joaotavora@gmail.com>, | 5 | ;; João Távora <joaotavora@gmail.com>, |
| 6 | ;; Noam Postavsky <npostavs@gmail.com> | 6 | ;; Noam Postavsky <npostavs@gmail.com> |
| 7 | ;; Maintainer: Noam Postavsky <npostavs@gmail.com> | 7 | ;; Maintainer: Noam Postavsky <npostavs@gmail.com> |
| 8 | ;; Version: 0.11.0 | 8 | ;; Version: 0.12.1 |
| 9 | ;; X-URL: http://github.com/joaotavora/yasnippet | 9 | ;; X-URL: http://github.com/joaotavora/yasnippet |
| 10 | ;; Keywords: convenience, emulation | 10 | ;; Keywords: convenience, emulation |
| 11 | ;; URL: http://github.com/joaotavora/yasnippet | 11 | ;; URL: http://github.com/joaotavora/yasnippet |
| @@ -132,6 +132,7 @@ | |||
| 132 | ;;; Code: | 132 | ;;; Code: |
| 133 | 133 | ||
| 134 | (require 'cl-lib) | 134 | (require 'cl-lib) |
| 135 | (declare-function cl-progv-after "cl-extra") ; Needed for 23.4. | ||
| 135 | (require 'easymenu) | 136 | (require 'easymenu) |
| 136 | (require 'help-mode) | 137 | (require 'help-mode) |
| 137 | 138 | ||
| @@ -535,7 +536,7 @@ override bindings from other packages (e.g., `company-mode')." | |||
| 535 | 536 | ||
| 536 | ;;; Internal variables | 537 | ;;; Internal variables |
| 537 | 538 | ||
| 538 | (defconst yas--version "0.11.0") | 539 | (defconst yas--version "0.12.1") |
| 539 | 540 | ||
| 540 | (defvar yas--menu-table (make-hash-table) | 541 | (defvar yas--menu-table (make-hash-table) |
| 541 | "A hash table of MAJOR-MODE symbols to menu keymaps.") | 542 | "A hash table of MAJOR-MODE symbols to menu keymaps.") |
| @@ -585,6 +586,8 @@ override bindings from other packages (e.g., `company-mode')." | |||
| 585 | (defvar yas--minor-mode-menu nil | 586 | (defvar yas--minor-mode-menu nil |
| 586 | "Holds the YASnippet menu.") | 587 | "Holds the YASnippet menu.") |
| 587 | 588 | ||
| 589 | (defvar yas--condition-cache-timestamp nil) | ||
| 590 | |||
| 588 | (defun yas--maybe-expand-key-filter (cmd) | 591 | (defun yas--maybe-expand-key-filter (cmd) |
| 589 | (when (let ((yas--condition-cache-timestamp (current-time))) | 592 | (when (let ((yas--condition-cache-timestamp (current-time))) |
| 590 | (yas--templates-for-key-at-point)) | 593 | (yas--templates-for-key-at-point)) |
| @@ -2183,7 +2186,6 @@ Just put this function in `hippie-expand-try-functions-list'." | |||
| 2183 | ;;; | 2186 | ;;; |
| 2184 | ;;; | 2187 | ;;; |
| 2185 | ;;; | 2188 | ;;; |
| 2186 | (defvar yas--condition-cache-timestamp nil) | ||
| 2187 | (defmacro yas-define-condition-cache (func doc &rest body) | 2189 | (defmacro yas-define-condition-cache (func doc &rest body) |
| 2188 | "Define a function FUNC with doc DOC and body BODY. | 2190 | "Define a function FUNC with doc DOC and body BODY. |
| 2189 | BODY is executed at most once every snippet expansion attempt, to check | 2191 | BODY is executed at most once every snippet expansion attempt, to check |
| @@ -3028,9 +3030,16 @@ DEPTH is a count of how many nested mirrors can affect this mirror" | |||
| 3028 | 3030 | ||
| 3029 | (defmacro yas--letenv (env &rest body) | 3031 | (defmacro yas--letenv (env &rest body) |
| 3030 | "Evaluate BODY with bindings from ENV. | 3032 | "Evaluate BODY with bindings from ENV. |
| 3031 | ENV is a list of elements with the form (VAR FORM)." | 3033 | ENV is a lisp expression that evaluates to list of elements with |
| 3034 | the form (VAR FORM), where VAR is a symbol and FORM is a lisp | ||
| 3035 | expression that evaluates to its value." | ||
| 3032 | (declare (debug (form body)) (indent 1)) | 3036 | (declare (debug (form body)) (indent 1)) |
| 3033 | `(eval (cl-list* 'let* ,env ',body))) | 3037 | (let ((envvar (make-symbol "envvar"))) |
| 3038 | `(let ((,envvar ,env)) | ||
| 3039 | (cl-progv | ||
| 3040 | (mapcar #'car ,envvar) | ||
| 3041 | (mapcar (lambda (v-f) (eval (cadr v-f))) ,envvar) | ||
| 3042 | ,@body)))) | ||
| 3034 | 3043 | ||
| 3035 | (defun yas--snippet-map-markers (fun snippet) | 3044 | (defun yas--snippet-map-markers (fun snippet) |
| 3036 | "Apply FUN to all marker (sub)fields in SNIPPET. | 3045 | "Apply FUN to all marker (sub)fields in SNIPPET. |
| @@ -3635,7 +3644,10 @@ field start. This hook does nothing if an undo is in progress." | |||
| 3635 | (narrow-to-region beg end) | 3644 | (narrow-to-region beg end) |
| 3636 | (mapc #'yas--restore-marker-location remarkers) | 3645 | (mapc #'yas--restore-marker-location remarkers) |
| 3637 | (mapc #'yas--restore-overlay-location reoverlays)) | 3646 | (mapc #'yas--restore-overlay-location reoverlays)) |
| 3638 | (mapc #'yas--update-mirrors snippets)))) | 3647 | (mapc (lambda (snippet) |
| 3648 | (yas--letenv (yas--snippet-expand-env snippet) | ||
| 3649 | (yas--update-mirrors snippet))) | ||
| 3650 | snippets)))) | ||
| 3639 | 3651 | ||
| 3640 | 3652 | ||
| 3641 | ;;; Apropos protection overlays: | 3653 | ;;; Apropos protection overlays: |
| @@ -3828,7 +3840,7 @@ considered when expanding the snippet." | |||
| 3828 | (sit-for 0) ;; fix issue 125 | 3840 | (sit-for 0) ;; fix issue 125 |
| 3829 | (yas--letenv (yas--snippet-expand-env snippet) | 3841 | (yas--letenv (yas--snippet-expand-env snippet) |
| 3830 | (yas--move-to-field snippet first-field)))) | 3842 | (yas--move-to-field snippet first-field)))) |
| 3831 | (yas--message 4 "snippet expanded.") | 3843 | (yas--message 4 "snippet %d expanded." (yas--snippet-id snippet)) |
| 3832 | (setq deactivate-mark nil) | 3844 | (setq deactivate-mark nil) |
| 3833 | t)))) | 3845 | t)))) |
| 3834 | 3846 | ||
| @@ -4540,7 +4552,7 @@ When multiple expressions are found, only the last one counts." | |||
| 4540 | (when parent-field | 4552 | (when parent-field |
| 4541 | (yas--advance-start-maybe mirror (yas--fom-start parent-field)))) | 4553 | (yas--advance-start-maybe mirror (yas--fom-start parent-field)))) |
| 4542 | ;; Update this mirror. | 4554 | ;; Update this mirror. |
| 4543 | do (yas--mirror-update-display mirror field snippet) | 4555 | do (yas--mirror-update-display mirror field) |
| 4544 | ;; Delay indenting until we're done all mirrors. We must do | 4556 | ;; Delay indenting until we're done all mirrors. We must do |
| 4545 | ;; this to avoid losing whitespace between fields that are | 4557 | ;; this to avoid losing whitespace between fields that are |
| 4546 | ;; still empty (i.e., they will be non-empty after updating). | 4558 | ;; still empty (i.e., they will be non-empty after updating). |
| @@ -4557,7 +4569,7 @@ When multiple expressions are found, only the last one counts." | |||
| 4557 | (cl-loop for (beg . end) in (cl-sort indent-regions #'< :key #'car) | 4569 | (cl-loop for (beg . end) in (cl-sort indent-regions #'< :key #'car) |
| 4558 | do (yas--indent-region beg end snippet))))))) | 4570 | do (yas--indent-region beg end snippet))))))) |
| 4559 | 4571 | ||
| 4560 | (defun yas--mirror-update-display (mirror field snippet) | 4572 | (defun yas--mirror-update-display (mirror field) |
| 4561 | "Update MIRROR according to FIELD (and mirror transform)." | 4573 | "Update MIRROR according to FIELD (and mirror transform)." |
| 4562 | 4574 | ||
| 4563 | (let* ((mirror-parent-field (yas--mirror-parent-field mirror)) | 4575 | (let* ((mirror-parent-field (yas--mirror-parent-field mirror)) |
| @@ -4601,27 +4613,29 @@ When multiple expressions are found, only the last one counts." | |||
| 4601 | ;; | 4613 | ;; |
| 4602 | (defun yas--post-command-handler () | 4614 | (defun yas--post-command-handler () |
| 4603 | "Handles various yasnippet conditions after each command." | 4615 | "Handles various yasnippet conditions after each command." |
| 4604 | (yas--finish-moving-snippets) | 4616 | (condition-case err |
| 4605 | (cond ((eq 'undo this-command) | 4617 | (progn (yas--finish-moving-snippets) |
| 4606 | ;; | 4618 | (cond ((eq 'undo this-command) |
| 4607 | ;; After undo revival the correct field is sometimes not | 4619 | ;; |
| 4608 | ;; restored correctly, this condition handles that | 4620 | ;; After undo revival the correct field is sometimes not |
| 4609 | ;; | 4621 | ;; restored correctly, this condition handles that |
| 4610 | (let* ((snippet (car (yas-active-snippets))) | 4622 | ;; |
| 4611 | (target-field | 4623 | (let* ((snippet (car (yas-active-snippets))) |
| 4612 | (and snippet | 4624 | (target-field |
| 4613 | (cl-find-if-not | 4625 | (and snippet |
| 4614 | (lambda (field) | 4626 | (cl-find-if-not |
| 4615 | (yas--field-probably-deleted-p snippet field)) | 4627 | (lambda (field) |
| 4616 | (remq nil | 4628 | (yas--field-probably-deleted-p snippet field)) |
| 4617 | (cons (yas--snippet-active-field snippet) | 4629 | (remq nil |
| 4618 | (yas--snippet-fields snippet))))))) | 4630 | (cons (yas--snippet-active-field snippet) |
| 4619 | (when target-field | 4631 | (yas--snippet-fields snippet))))))) |
| 4620 | (yas--move-to-field snippet target-field)))) | 4632 | (when target-field |
| 4621 | ((not (yas--undo-in-progress)) | 4633 | (yas--move-to-field snippet target-field)))) |
| 4622 | ;; When not in an undo, check if we must commit the snippet | 4634 | ((not (yas--undo-in-progress)) |
| 4623 | ;; (user exited it). | 4635 | ;; When not in an undo, check if we must commit the snippet |
| 4624 | (yas--check-commit-snippet)))) | 4636 | ;; (user exited it). |
| 4637 | (yas--check-commit-snippet)))) | ||
| 4638 | ((debug error) (signal (car err) (cdr err))))) | ||
| 4625 | 4639 | ||
| 4626 | ;;; Fancy docs: | 4640 | ;;; Fancy docs: |
| 4627 | ;; | 4641 | ;; |
