diff options
| author | Simeon Simeonov | 2017-04-24 12:23:56 +0200 |
|---|---|---|
| committer | Simeon Simeonov | 2017-04-24 12:23:56 +0200 |
| commit | 633aa066a900607361b85b110db9ac387b5f258b (patch) | |
| tree | 2617f1f46d1d19a70eee2731e8970e19e1d107c0 /.emacs.d/lisp/yasnippet.el | |
| parent | 489e9034087868a46dc9a3f6c4298090cb4395ea (diff) | |
php-mode yasnippet upgrade
Diffstat (limited to '.emacs.d/lisp/yasnippet.el')
| -rw-r--r-- | .emacs.d/lisp/yasnippet.el | 84 |
1 files changed, 57 insertions, 27 deletions
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index 47b8ff5..a3a1eaa 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el | |||
| @@ -152,10 +152,13 @@ | |||
| 152 | :prefix "yas-" | 152 | :prefix "yas-" |
| 153 | :group 'editing) | 153 | :group 'editing) |
| 154 | 154 | ||
| 155 | (defconst yas--loaddir | ||
| 156 | (file-name-directory (or load-file-name buffer-file-name)) | ||
| 157 | "Directory that yasnippet was loaded from.") | ||
| 158 | |||
| 155 | (defvar yas-installed-snippets-dir nil) | 159 | (defvar yas-installed-snippets-dir nil) |
| 156 | (setq yas-installed-snippets-dir | 160 | (setq yas-installed-snippets-dir |
| 157 | (when load-file-name | 161 | (expand-file-name "snippets" yas--loaddir)) |
| 158 | (expand-file-name "snippets" (file-name-directory load-file-name)))) | ||
| 159 | 162 | ||
| 160 | (defconst yas--default-user-snippets-dir | 163 | (defconst yas--default-user-snippets-dir |
| 161 | (expand-file-name "snippets" user-emacs-directory)) | 164 | (expand-file-name "snippets" user-emacs-directory)) |
| @@ -577,7 +580,9 @@ conditions. | |||
| 577 | "Holds the YASnippet menu.") | 580 | "Holds the YASnippet menu.") |
| 578 | 581 | ||
| 579 | (defun yas--maybe-expand-key-filter (cmd) | 582 | (defun yas--maybe-expand-key-filter (cmd) |
| 580 | (if (yas--templates-for-key-at-point) cmd)) | 583 | (when (let ((yas--condition-cache-timestamp (current-time))) |
| 584 | (yas--templates-for-key-at-point)) | ||
| 585 | cmd)) | ||
| 581 | 586 | ||
| 582 | (defconst yas-maybe-expand | 587 | (defconst yas-maybe-expand |
| 583 | '(menu-item "" yas-expand :filter yas--maybe-expand-key-filter) | 588 | '(menu-item "" yas-expand :filter yas--maybe-expand-key-filter) |
| @@ -1977,9 +1982,24 @@ This works by stubbing a few functions, then calling | |||
| 1977 | 1982 | ||
| 1978 | (defun yas-about () | 1983 | (defun yas-about () |
| 1979 | (interactive) | 1984 | (interactive) |
| 1980 | (message (concat "yasnippet (version " | 1985 | (message "yasnippet (version %s) -- pluskid/joaotavora/npostavs" |
| 1981 | yas--version | 1986 | (or (ignore-errors (car (let ((default-directory yas--loaddir)) |
| 1982 | ") -- pluskid/joaotavora/npostavs"))) | 1987 | (process-lines "git" "describe" |
| 1988 | "--tags" "--dirty")))) | ||
| 1989 | (when (and (featurep 'package) | ||
| 1990 | (fboundp 'package-desc-version) | ||
| 1991 | (fboundp 'package-version-join)) | ||
| 1992 | (defvar package-alist) | ||
| 1993 | (ignore-errors | ||
| 1994 | (let* ((yas-pkg (cdr (assq 'yasnippet package-alist))) | ||
| 1995 | (version (package-version-join | ||
| 1996 | (package-desc-version (car yas-pkg))))) | ||
| 1997 | ;; Special case for MELPA's bogus version numbers. | ||
| 1998 | (if (string-match "\\`20..[01][0-9][0-3][0-9][.][0-9]\\{3,4\\}\\'" | ||
| 1999 | version) | ||
| 2000 | (concat yas--version "-snapshot" version) | ||
| 2001 | version)))) | ||
| 2002 | yas--version))) | ||
| 1983 | 2003 | ||
| 1984 | 2004 | ||
| 1985 | ;;; Apropos snippet menu: | 2005 | ;;; Apropos snippet menu: |
| @@ -2212,7 +2232,8 @@ object satisfying `yas--field-p' to restrict the expansion to." | |||
| 2212 | (yas--fallback)))) | 2232 | (yas--fallback)))) |
| 2213 | 2233 | ||
| 2214 | (defun yas--maybe-expand-from-keymap-filter (cmd) | 2234 | (defun yas--maybe-expand-from-keymap-filter (cmd) |
| 2215 | (let* ((vec (cl-subseq (this-command-keys-vector) | 2235 | (let* ((yas--condition-cache-timestamp (current-time)) |
| 2236 | (vec (cl-subseq (this-command-keys-vector) | ||
| 2216 | (if current-prefix-arg | 2237 | (if current-prefix-arg |
| 2217 | (length (this-command-keys)) | 2238 | (length (this-command-keys)) |
| 2218 | 0))) | 2239 | 0))) |
| @@ -3272,7 +3293,8 @@ This renders the snippet as ordinary text." | |||
| 3272 | (overlay-buffer control-overlay)) | 3293 | (overlay-buffer control-overlay)) |
| 3273 | (setq yas-snippet-beg (overlay-start control-overlay)) | 3294 | (setq yas-snippet-beg (overlay-start control-overlay)) |
| 3274 | (setq yas-snippet-end (overlay-end control-overlay)) | 3295 | (setq yas-snippet-end (overlay-end control-overlay)) |
| 3275 | (delete-overlay control-overlay)) | 3296 | (delete-overlay control-overlay) |
| 3297 | (setf (yas--snippet-control-overlay snippet) nil)) | ||
| 3276 | 3298 | ||
| 3277 | (let ((yas--inhibit-overlay-hooks t)) | 3299 | (let ((yas--inhibit-overlay-hooks t)) |
| 3278 | (when yas--active-field-overlay | 3300 | (when yas--active-field-overlay |
| @@ -3427,8 +3449,9 @@ If so cleans up the whole snippet up." | |||
| 3427 | ;; | 3449 | ;; |
| 3428 | ;; This was found useful for performance reasons, so that an excessive | 3450 | ;; This was found useful for performance reasons, so that an excessive |
| 3429 | ;; number of live markers aren't kept around in the | 3451 | ;; number of live markers aren't kept around in the |
| 3430 | ;; `buffer-undo-list'. We reuse the original marker object, although | 3452 | ;; `buffer-undo-list'. We don't reuse the original marker object |
| 3431 | ;; that's probably not necessary. | 3453 | ;; because that leaves an unreadable object in the history list and |
| 3454 | ;; undo-tree persistence has trouble with that. | ||
| 3432 | ;; | 3455 | ;; |
| 3433 | ;; This shouldn't bring horrible problems with undo/redo, but you | 3456 | ;; This shouldn't bring horrible problems with undo/redo, but you |
| 3434 | ;; never know. | 3457 | ;; never know. |
| @@ -3436,16 +3459,13 @@ If so cleans up the whole snippet up." | |||
| 3436 | (defun yas--markers-to-points (snippet) | 3459 | (defun yas--markers-to-points (snippet) |
| 3437 | "Save all markers of SNIPPET as positions." | 3460 | "Save all markers of SNIPPET as positions." |
| 3438 | (yas--snippet-map-markers (lambda (m) | 3461 | (yas--snippet-map-markers (lambda (m) |
| 3439 | (prog1 (cons (marker-position m) m) | 3462 | (prog1 (marker-position m) |
| 3440 | (set-marker m nil))) | 3463 | (set-marker m nil))) |
| 3441 | snippet)) | 3464 | snippet)) |
| 3442 | 3465 | ||
| 3443 | (defun yas--points-to-markers (snippet) | 3466 | (defun yas--points-to-markers (snippet) |
| 3444 | "Restore SNIPPET's marker positions, saved by `yas--markers-to-points'." | 3467 | "Restore SNIPPET's marker positions, saved by `yas--markers-to-points'." |
| 3445 | (yas--snippet-map-markers (lambda (p-m) | 3468 | (yas--snippet-map-markers #'copy-marker snippet)) |
| 3446 | (set-marker (cdr p-m) (car p-m)) | ||
| 3447 | (cdr p-m)) | ||
| 3448 | snippet)) | ||
| 3449 | 3469 | ||
| 3450 | (defun yas--maybe-move-to-active-field (snippet) | 3470 | (defun yas--maybe-move-to-active-field (snippet) |
| 3451 | "Try to move to SNIPPET's active (or first) field and return it if found." | 3471 | "Try to move to SNIPPET's active (or first) field and return it if found." |
| @@ -3588,7 +3608,8 @@ field start. This hook does nothing if an undo is in progress." | |||
| 3588 | (reoverlays nil)) | 3608 | (reoverlays nil)) |
| 3589 | (dolist (snippet snippets) | 3609 | (dolist (snippet snippets) |
| 3590 | (dolist (m (yas--collect-snippet-markers snippet)) | 3610 | (dolist (m (yas--collect-snippet-markers snippet)) |
| 3591 | (push (yas--snapshot-marker-location m beg end) remarkers)) | 3611 | (when (and (<= beg m) (<= m end)) |
| 3612 | (push (yas--snapshot-marker-location m beg end) remarkers))) | ||
| 3592 | (push (yas--snapshot-overlay-location | 3613 | (push (yas--snapshot-overlay-location |
| 3593 | (yas--snippet-control-overlay snippet) beg end) | 3614 | (yas--snippet-control-overlay snippet) beg end) |
| 3594 | reoverlays)) | 3615 | reoverlays)) |
| @@ -3790,6 +3811,7 @@ considered when expanding the snippet." | |||
| 3790 | (yas--letenv (yas--snippet-expand-env snippet) | 3811 | (yas--letenv (yas--snippet-expand-env snippet) |
| 3791 | (yas--move-to-field snippet first-field)))) | 3812 | (yas--move-to-field snippet first-field)))) |
| 3792 | (yas--message 4 "snippet expanded.") | 3813 | (yas--message 4 "snippet expanded.") |
| 3814 | (setq deactivate-mark nil) | ||
| 3793 | t)))) | 3815 | t)))) |
| 3794 | 3816 | ||
| 3795 | (defun yas--take-care-of-redo (_beg _end snippet) | 3817 | (defun yas--take-care-of-redo (_beg _end snippet) |
| @@ -4111,15 +4133,21 @@ The returned value is a list of the form (MARKER REGEXP WS-COUNT)." | |||
| 4111 | (nconc before (list marker) after) | 4133 | (nconc before (list marker) after) |
| 4112 | "[[:space:]\n]*")) | 4134 | "[[:space:]\n]*")) |
| 4113 | (progn (goto-char marker) | 4135 | (progn (goto-char marker) |
| 4114 | (skip-syntax-forward " " end) | 4136 | (skip-chars-forward "[:space:]\n" end) |
| 4115 | (- (point) marker))))) | 4137 | (- (point) marker))))) |
| 4116 | 4138 | ||
| 4117 | (defun yas--snapshot-overlay-location (overlay beg end) | 4139 | (defun yas--snapshot-overlay-location (overlay beg end) |
| 4118 | "Like `yas--snapshot-marker-location' for overlays. | 4140 | "Like `yas--snapshot-marker-location' for overlays. |
| 4119 | The returned format is (OVERLAY (RE WS) (RE WS))." | 4141 | The returned format is (OVERLAY (RE WS) (RE WS)). Either of |
| 4120 | (list overlay | 4142 | the (RE WS) lists may be nil if the start or end, respectively, |
| 4121 | (cdr (yas--snapshot-marker-location (overlay-start overlay) beg end)) | 4143 | of the overlay is outside the range BEG .. END." |
| 4122 | (cdr (yas--snapshot-marker-location (overlay-end overlay) beg end)))) | 4144 | (let ((obeg (overlay-start overlay)) |
| 4145 | (oend (overlay-end overlay))) | ||
| 4146 | (list overlay | ||
| 4147 | (when (and (<= beg obeg) (< obeg end)) | ||
| 4148 | (cdr (yas--snapshot-marker-location obeg beg end))) | ||
| 4149 | (when (and (<= beg oend) (< oend end)) | ||
| 4150 | (cdr (yas--snapshot-marker-location oend beg end)))))) | ||
| 4123 | 4151 | ||
| 4124 | (defun yas--snapshot-overlay-line-location (overlay) | 4152 | (defun yas--snapshot-overlay-line-location (overlay) |
| 4125 | "Return info for restoring OVERLAY's line based location. | 4153 | "Return info for restoring OVERLAY's line based location. |
| @@ -4142,8 +4170,8 @@ Buffer must be narrowed to BEG..END used to create the snapshot info." | |||
| 4142 | (lwarn '(yasnippet re-marker) :warning | 4170 | (lwarn '(yasnippet re-marker) :warning |
| 4143 | "Couldn't find: %S" regexp) | 4171 | "Couldn't find: %S" regexp) |
| 4144 | (goto-char (match-beginning 1)) | 4172 | (goto-char (match-beginning 1)) |
| 4145 | (skip-syntax-forward " ") | 4173 | (skip-chars-forward "[:space:]\n") |
| 4146 | (skip-syntax-backward " " (- (point) ws-count)))) | 4174 | (skip-chars-backward "[:space:]\n" (- (point) ws-count)))) |
| 4147 | 4175 | ||
| 4148 | (defun yas--restore-marker-location (re-marker) | 4176 | (defun yas--restore-marker-location (re-marker) |
| 4149 | "Restores marker based on info from `yas--snapshot-marker-location'. | 4177 | "Restores marker based on info from `yas--snapshot-marker-location'. |
| @@ -4156,10 +4184,12 @@ Buffer must be narrowed to BEG..END used to create the snapshot info." | |||
| 4156 | Buffer must be narrowed to BEG..END used to create the snapshot info." | 4184 | Buffer must be narrowed to BEG..END used to create the snapshot info." |
| 4157 | (cl-destructuring-bind (overlay loc-beg loc-end) ov-locations | 4185 | (cl-destructuring-bind (overlay loc-beg loc-end) ov-locations |
| 4158 | (move-overlay overlay | 4186 | (move-overlay overlay |
| 4159 | (progn (apply #'yas--goto-saved-location loc-beg) | 4187 | (if (not loc-beg) (overlay-start overlay) |
| 4160 | (point)) | 4188 | (apply #'yas--goto-saved-location loc-beg) |
| 4161 | (progn (apply #'yas--goto-saved-location loc-end) | 4189 | (point)) |
| 4162 | (point))))) | 4190 | (if (not loc-end) (overlay-end overlay) |
| 4191 | (apply #'yas--goto-saved-location loc-end) | ||
| 4192 | (point))))) | ||
| 4163 | 4193 | ||
| 4164 | 4194 | ||
| 4165 | (defun yas--restore-overlay-line-location (ov-locations) | 4195 | (defun yas--restore-overlay-line-location (ov-locations) |
