From 633aa066a900607361b85b110db9ac387b5f258b Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Mon, 24 Apr 2017 12:23:56 +0200 Subject: php-mode yasnippet upgrade --- .emacs.d/lisp/yasnippet.el | 84 +++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 27 deletions(-) (limited to '.emacs.d/lisp/yasnippet.el') 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 @@ :prefix "yas-" :group 'editing) +(defconst yas--loaddir + (file-name-directory (or load-file-name buffer-file-name)) + "Directory that yasnippet was loaded from.") + (defvar yas-installed-snippets-dir nil) (setq yas-installed-snippets-dir - (when load-file-name - (expand-file-name "snippets" (file-name-directory load-file-name)))) + (expand-file-name "snippets" yas--loaddir)) (defconst yas--default-user-snippets-dir (expand-file-name "snippets" user-emacs-directory)) @@ -577,7 +580,9 @@ conditions. "Holds the YASnippet menu.") (defun yas--maybe-expand-key-filter (cmd) - (if (yas--templates-for-key-at-point) cmd)) + (when (let ((yas--condition-cache-timestamp (current-time))) + (yas--templates-for-key-at-point)) + cmd)) (defconst yas-maybe-expand '(menu-item "" yas-expand :filter yas--maybe-expand-key-filter) @@ -1977,9 +1982,24 @@ This works by stubbing a few functions, then calling (defun yas-about () (interactive) - (message (concat "yasnippet (version " - yas--version - ") -- pluskid/joaotavora/npostavs"))) + (message "yasnippet (version %s) -- pluskid/joaotavora/npostavs" + (or (ignore-errors (car (let ((default-directory yas--loaddir)) + (process-lines "git" "describe" + "--tags" "--dirty")))) + (when (and (featurep 'package) + (fboundp 'package-desc-version) + (fboundp 'package-version-join)) + (defvar package-alist) + (ignore-errors + (let* ((yas-pkg (cdr (assq 'yasnippet package-alist))) + (version (package-version-join + (package-desc-version (car yas-pkg))))) + ;; Special case for MELPA's bogus version numbers. + (if (string-match "\\`20..[01][0-9][0-3][0-9][.][0-9]\\{3,4\\}\\'" + version) + (concat yas--version "-snapshot" version) + version)))) + yas--version))) ;;; Apropos snippet menu: @@ -2212,7 +2232,8 @@ object satisfying `yas--field-p' to restrict the expansion to." (yas--fallback)))) (defun yas--maybe-expand-from-keymap-filter (cmd) - (let* ((vec (cl-subseq (this-command-keys-vector) + (let* ((yas--condition-cache-timestamp (current-time)) + (vec (cl-subseq (this-command-keys-vector) (if current-prefix-arg (length (this-command-keys)) 0))) @@ -3272,7 +3293,8 @@ This renders the snippet as ordinary text." (overlay-buffer control-overlay)) (setq yas-snippet-beg (overlay-start control-overlay)) (setq yas-snippet-end (overlay-end control-overlay)) - (delete-overlay control-overlay)) + (delete-overlay control-overlay) + (setf (yas--snippet-control-overlay snippet) nil)) (let ((yas--inhibit-overlay-hooks t)) (when yas--active-field-overlay @@ -3427,8 +3449,9 @@ If so cleans up the whole snippet up." ;; ;; This was found useful for performance reasons, so that an excessive ;; number of live markers aren't kept around in the -;; `buffer-undo-list'. We reuse the original marker object, although -;; that's probably not necessary. +;; `buffer-undo-list'. We don't reuse the original marker object +;; because that leaves an unreadable object in the history list and +;; undo-tree persistence has trouble with that. ;; ;; This shouldn't bring horrible problems with undo/redo, but you ;; never know. @@ -3436,16 +3459,13 @@ If so cleans up the whole snippet up." (defun yas--markers-to-points (snippet) "Save all markers of SNIPPET as positions." (yas--snippet-map-markers (lambda (m) - (prog1 (cons (marker-position m) m) + (prog1 (marker-position m) (set-marker m nil))) snippet)) (defun yas--points-to-markers (snippet) "Restore SNIPPET's marker positions, saved by `yas--markers-to-points'." - (yas--snippet-map-markers (lambda (p-m) - (set-marker (cdr p-m) (car p-m)) - (cdr p-m)) - snippet)) + (yas--snippet-map-markers #'copy-marker snippet)) (defun yas--maybe-move-to-active-field (snippet) "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." (reoverlays nil)) (dolist (snippet snippets) (dolist (m (yas--collect-snippet-markers snippet)) - (push (yas--snapshot-marker-location m beg end) remarkers)) + (when (and (<= beg m) (<= m end)) + (push (yas--snapshot-marker-location m beg end) remarkers))) (push (yas--snapshot-overlay-location (yas--snippet-control-overlay snippet) beg end) reoverlays)) @@ -3790,6 +3811,7 @@ considered when expanding the snippet." (yas--letenv (yas--snippet-expand-env snippet) (yas--move-to-field snippet first-field)))) (yas--message 4 "snippet expanded.") + (setq deactivate-mark nil) t)))) (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)." (nconc before (list marker) after) "[[:space:]\n]*")) (progn (goto-char marker) - (skip-syntax-forward " " end) + (skip-chars-forward "[:space:]\n" end) (- (point) marker))))) (defun yas--snapshot-overlay-location (overlay beg end) "Like `yas--snapshot-marker-location' for overlays. -The returned format is (OVERLAY (RE WS) (RE WS))." - (list overlay - (cdr (yas--snapshot-marker-location (overlay-start overlay) beg end)) - (cdr (yas--snapshot-marker-location (overlay-end overlay) beg end)))) +The returned format is (OVERLAY (RE WS) (RE WS)). Either of +the (RE WS) lists may be nil if the start or end, respectively, +of the overlay is outside the range BEG .. END." + (let ((obeg (overlay-start overlay)) + (oend (overlay-end overlay))) + (list overlay + (when (and (<= beg obeg) (< obeg end)) + (cdr (yas--snapshot-marker-location obeg beg end))) + (when (and (<= beg oend) (< oend end)) + (cdr (yas--snapshot-marker-location oend beg end)))))) (defun yas--snapshot-overlay-line-location (overlay) "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." (lwarn '(yasnippet re-marker) :warning "Couldn't find: %S" regexp) (goto-char (match-beginning 1)) - (skip-syntax-forward " ") - (skip-syntax-backward " " (- (point) ws-count)))) + (skip-chars-forward "[:space:]\n") + (skip-chars-backward "[:space:]\n" (- (point) ws-count)))) (defun yas--restore-marker-location (re-marker) "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." Buffer must be narrowed to BEG..END used to create the snapshot info." (cl-destructuring-bind (overlay loc-beg loc-end) ov-locations (move-overlay overlay - (progn (apply #'yas--goto-saved-location loc-beg) - (point)) - (progn (apply #'yas--goto-saved-location loc-end) - (point))))) + (if (not loc-beg) (overlay-start overlay) + (apply #'yas--goto-saved-location loc-beg) + (point)) + (if (not loc-end) (overlay-end overlay) + (apply #'yas--goto-saved-location loc-end) + (point))))) (defun yas--restore-overlay-line-location (ov-locations) -- cgit v1.3