diff options
| author | Simeon Simeonov | 2016-12-14 14:28:58 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2016-12-14 14:28:58 +0100 |
| commit | 30436a90f50cc2dea0dc0dfcd4df46b8003d1c0a (patch) | |
| tree | 6be2e65392fb35e7d3b84104c1643ffb9ef914be /.emacs.d/lisp/yasnippet.el | |
| parent | 27eb5412df5b4971fa9facb5241db6be52bf37c1 (diff) | |
Update php-mode and yasnippet
Diffstat (limited to '.emacs.d/lisp/yasnippet.el')
| -rw-r--r-- | .emacs.d/lisp/yasnippet.el | 262 |
1 files changed, 160 insertions, 102 deletions
diff --git a/.emacs.d/lisp/yasnippet.el b/.emacs.d/lisp/yasnippet.el index c308c9b..e0333bb 100644 --- a/.emacs.d/lisp/yasnippet.el +++ b/.emacs.d/lisp/yasnippet.el | |||
| @@ -2842,7 +2842,7 @@ Otherwise throw exception." | |||
| 2842 | "Get the string for field with NUMBER. | 2842 | "Get the string for field with NUMBER. |
| 2843 | 2843 | ||
| 2844 | Use this in primary and mirror transformations to tget." | 2844 | Use this in primary and mirror transformations to tget." |
| 2845 | (let* ((snippet (car (yas--snippets-at-point))) | 2845 | (let* ((snippet (car (yas-active-snippets))) |
| 2846 | (field (and snippet | 2846 | (field (and snippet |
| 2847 | (yas--snippet-find-field snippet number)))) | 2847 | (yas--snippet-find-field snippet number)))) |
| 2848 | (when field | 2848 | (when field |
| @@ -2902,10 +2902,11 @@ Use this in primary and mirror transformations to tget." | |||
| 2902 | (put 'yas--active-field-overlay 'permanent-local t) | 2902 | (put 'yas--active-field-overlay 'permanent-local t) |
| 2903 | (put 'yas--field-protection-overlays 'permanent-local t) | 2903 | (put 'yas--field-protection-overlays 'permanent-local t) |
| 2904 | 2904 | ||
| 2905 | (cl-defstruct (yas--snippet (:constructor yas--make-snippet ())) | 2905 | (cl-defstruct (yas--snippet (:constructor yas--make-snippet (expand-env))) |
| 2906 | "A snippet. | 2906 | "A snippet. |
| 2907 | 2907 | ||
| 2908 | ..." | 2908 | ..." |
| 2909 | expand-env | ||
| 2909 | (fields '()) | 2910 | (fields '()) |
| 2910 | (exit nil) | 2911 | (exit nil) |
| 2911 | (id (yas--snippet-next-id) :read-only t) | 2912 | (id (yas--snippet-next-id) :read-only t) |
| @@ -2954,6 +2955,12 @@ DEPTH is a count of how many nested mirrors can affect this mirror" | |||
| 2954 | marker | 2955 | marker |
| 2955 | next) | 2956 | next) |
| 2956 | 2957 | ||
| 2958 | (defmacro yas--letenv (env &rest body) | ||
| 2959 | "Evaluate BODY with bindings from ENV. | ||
| 2960 | ENV is a list of elements with the form (VAR FORM)." | ||
| 2961 | (declare (debug (form body)) (indent 1)) | ||
| 2962 | `(eval (cl-list* 'let* ,env ',body))) | ||
| 2963 | |||
| 2957 | (defun yas--apply-transform (field-or-mirror field &optional empty-on-nil-p) | 2964 | (defun yas--apply-transform (field-or-mirror field &optional empty-on-nil-p) |
| 2958 | "Calculate transformed string for FIELD-OR-MIRROR from FIELD. | 2965 | "Calculate transformed string for FIELD-OR-MIRROR from FIELD. |
| 2959 | 2966 | ||
| @@ -3039,18 +3046,30 @@ through the field's start point" | |||
| 3039 | (not (and (yas--field-number field) | 3046 | (not (and (yas--field-number field) |
| 3040 | (zerop (yas--field-number field)))))) | 3047 | (zerop (yas--field-number field)))))) |
| 3041 | 3048 | ||
| 3042 | (defun yas--snippets-at-point (&optional all-snippets) | 3049 | (defun yas-active-snippets (&optional beg end) |
| 3043 | "Return a sorted list of snippets at point. | 3050 | "Return a sorted list of active snippets. |
| 3051 | The most recently-inserted snippets are returned first. | ||
| 3044 | 3052 | ||
| 3045 | The most recently-inserted snippets are returned first." | 3053 | Only snippets overlapping the region BEG ... END are returned. |
| 3046 | (sort | 3054 | Overlapping has the same meaning as described in `overlays-in'. |
| 3047 | (delq nil (delete-dups | 3055 | If END is omitted, it defaults to (1+ BEG). If BEG is omitted, |
| 3048 | (mapcar (lambda (ov) (overlay-get ov 'yas--snippet)) | 3056 | it defaults to point. A non-nil, non-buffer position BEG is |
| 3049 | (if all-snippets (overlays-in (point-min) (point-max)) | 3057 | equivalent to a range covering the whole buffer." |
| 3050 | (nconc (overlays-at (point)) | 3058 | (unless beg |
| 3051 | (overlays-at (1- (point)))))))) | 3059 | (setq beg (point))) |
| 3052 | #'(lambda (s1 s2) | 3060 | (cond ((not (or (integerp beg) (markerp beg))) |
| 3053 | (<= (yas--snippet-id s2) (yas--snippet-id s1))))) | 3061 | (setq beg (point-min) end (point-max))) |
| 3062 | ((not end) | ||
| 3063 | (setq end (1+ beg)))) | ||
| 3064 | (cl-sort | ||
| 3065 | (delete-dups ;; Snippets have multiple overlays. | ||
| 3066 | (delq nil | ||
| 3067 | (mapcar (lambda (ov) (overlay-get ov 'yas--snippet)) | ||
| 3068 | (overlays-in beg end)))) | ||
| 3069 | #'>= :key #'yas--snippet-id)) | ||
| 3070 | |||
| 3071 | (define-obsolete-function-alias 'yas--snippets-at-point | ||
| 3072 | 'yas-active-snippets "0.12") | ||
| 3054 | 3073 | ||
| 3055 | (defun yas-next-field-or-maybe-expand () | 3074 | (defun yas-next-field-or-maybe-expand () |
| 3056 | "Try to expand a snippet at a key before point. | 3075 | "Try to expand a snippet at a key before point. |
| @@ -3067,7 +3086,7 @@ Otherwise delegate to `yas-next-field'." | |||
| 3067 | 3086 | ||
| 3068 | (defun yas-next-field-will-exit-p (&optional arg) | 3087 | (defun yas-next-field-will-exit-p (&optional arg) |
| 3069 | "Return non-nil if (yas-next-field ARG) would exit the current snippet." | 3088 | "Return non-nil if (yas-next-field ARG) would exit the current snippet." |
| 3070 | (let ((snippet (car (yas--snippets-at-point))) | 3089 | (let ((snippet (car (yas-active-snippets))) |
| 3071 | (active (overlay-get yas--active-field-overlay 'yas--field))) | 3090 | (active (overlay-get yas--active-field-overlay 'yas--field))) |
| 3072 | (when snippet | 3091 | (when snippet |
| 3073 | (not (yas--find-next-field arg snippet active))))) | 3092 | (not (yas--find-next-field arg snippet active))))) |
| @@ -3087,18 +3106,19 @@ Otherwise delegate to `yas-next-field'." | |||
| 3087 | If there's none, exit the snippet." | 3106 | If there's none, exit the snippet." |
| 3088 | (interactive) | 3107 | (interactive) |
| 3089 | (unless arg (setq arg 1)) | 3108 | (unless arg (setq arg 1)) |
| 3090 | (let* ((snippet (car (yas--snippets-at-point))) | 3109 | (let* ((snippet (car (yas-active-snippets))) |
| 3091 | (active-field (overlay-get yas--active-field-overlay 'yas--field)) | 3110 | (active-field (overlay-get yas--active-field-overlay 'yas--field)) |
| 3092 | (target-field (yas--find-next-field arg snippet active-field))) | 3111 | (target-field (yas--find-next-field arg snippet active-field))) |
| 3093 | ;; Apply transform to active field. | 3112 | (yas--letenv (yas--snippet-expand-env snippet) |
| 3094 | (when active-field | 3113 | ;; Apply transform to active field. |
| 3095 | (let ((yas-moving-away-p t)) | 3114 | (when active-field |
| 3096 | (when (yas--field-update-display active-field) | 3115 | (let ((yas-moving-away-p t)) |
| 3097 | (yas--update-mirrors snippet)))) | 3116 | (when (yas--field-update-display active-field) |
| 3098 | ;; Now actually move... | 3117 | (yas--update-mirrors snippet)))) |
| 3099 | (if target-field | 3118 | ;; Now actually move... |
| 3100 | (yas--move-to-field snippet target-field) | 3119 | (if target-field |
| 3101 | (yas-exit-snippet snippet)))) | 3120 | (yas--move-to-field snippet target-field) |
| 3121 | (yas-exit-snippet snippet))))) | ||
| 3102 | 3122 | ||
| 3103 | (defun yas--place-overlays (snippet field) | 3123 | (defun yas--place-overlays (snippet field) |
| 3104 | "Correctly place overlays for SNIPPET's FIELD." | 3124 | "Correctly place overlays for SNIPPET's FIELD." |
| @@ -3136,13 +3156,13 @@ Also create some protection overlays" | |||
| 3136 | (defun yas-abort-snippet (&optional snippet) | 3156 | (defun yas-abort-snippet (&optional snippet) |
| 3137 | (interactive) | 3157 | (interactive) |
| 3138 | (let ((snippet (or snippet | 3158 | (let ((snippet (or snippet |
| 3139 | (car (yas--snippets-at-point))))) | 3159 | (car (yas-active-snippets))))) |
| 3140 | (when snippet | 3160 | (when snippet |
| 3141 | (setf (yas--snippet-force-exit snippet) t)))) | 3161 | (setf (yas--snippet-force-exit snippet) t)))) |
| 3142 | 3162 | ||
| 3143 | (defun yas-exit-snippet (snippet) | 3163 | (defun yas-exit-snippet (snippet) |
| 3144 | "Goto exit-marker of SNIPPET." | 3164 | "Goto exit-marker of SNIPPET." |
| 3145 | (interactive (list (cl-first (yas--snippets-at-point)))) | 3165 | (interactive (list (cl-first (yas-active-snippets)))) |
| 3146 | (when snippet | 3166 | (when snippet |
| 3147 | (setf (yas--snippet-force-exit snippet) t) | 3167 | (setf (yas--snippet-force-exit snippet) t) |
| 3148 | (goto-char (if (yas--snippet-exit snippet) | 3168 | (goto-char (if (yas--snippet-exit snippet) |
| @@ -3155,7 +3175,7 @@ Also create some protection overlays" | |||
| 3155 | (mapc #'(lambda (snippet) | 3175 | (mapc #'(lambda (snippet) |
| 3156 | (yas-exit-snippet snippet) | 3176 | (yas-exit-snippet snippet) |
| 3157 | (yas--check-commit-snippet)) | 3177 | (yas--check-commit-snippet)) |
| 3158 | (yas--snippets-at-point 'all-snippets))) | 3178 | (yas-active-snippets 'all))) |
| 3159 | 3179 | ||
| 3160 | 3180 | ||
| 3161 | ;;; Some low level snippet-routines: | 3181 | ;;; Some low level snippet-routines: |
| @@ -3222,30 +3242,31 @@ This renders the snippet as ordinary text." | |||
| 3222 | "Check if point exited the currently active field of the snippet. | 3242 | "Check if point exited the currently active field of the snippet. |
| 3223 | 3243 | ||
| 3224 | If so cleans up the whole snippet up." | 3244 | If so cleans up the whole snippet up." |
| 3225 | (let* ((snippets (yas--snippets-at-point 'all-snippets)) | 3245 | (let* ((snippets (yas-active-snippets 'all)) |
| 3226 | (snippets-left snippets) | 3246 | (snippets-left snippets) |
| 3227 | (snippet-exit-transform)) | 3247 | (snippet-exit-transform)) |
| 3228 | (dolist (snippet snippets) | 3248 | (dolist (snippet snippets) |
| 3229 | (let ((active-field (yas--snippet-active-field snippet))) | 3249 | (let ((active-field (yas--snippet-active-field snippet))) |
| 3230 | (setq snippet-exit-transform (yas--snippet-force-exit snippet)) | 3250 | (yas--letenv (yas--snippet-expand-env snippet) |
| 3231 | (cond ((or snippet-exit-transform | 3251 | (setq snippet-exit-transform (yas--snippet-force-exit snippet)) |
| 3232 | (not (and active-field (yas--field-contains-point-p active-field)))) | 3252 | (cond ((or snippet-exit-transform |
| 3233 | (setq snippets-left (delete snippet snippets-left)) | 3253 | (not (and active-field (yas--field-contains-point-p active-field)))) |
| 3234 | (setf (yas--snippet-force-exit snippet) nil) | 3254 | (setq snippets-left (delete snippet snippets-left)) |
| 3235 | (yas--commit-snippet snippet)) | 3255 | (setf (yas--snippet-force-exit snippet) nil) |
| 3236 | ((and active-field | 3256 | (yas--commit-snippet snippet)) |
| 3237 | (or (not yas--active-field-overlay) | 3257 | ((and active-field |
| 3238 | (not (overlay-buffer yas--active-field-overlay)))) | 3258 | (or (not yas--active-field-overlay) |
| 3239 | ;; | 3259 | (not (overlay-buffer yas--active-field-overlay)))) |
| 3240 | ;; stacked expansion: this case is mainly for recent | 3260 | ;; |
| 3241 | ;; snippet exits that place us back int the field of | 3261 | ;; stacked expansion: this case is mainly for recent |
| 3242 | ;; another snippet | 3262 | ;; snippet exits that place us back int the field of |
| 3243 | ;; | 3263 | ;; another snippet |
| 3244 | (save-excursion | 3264 | ;; |
| 3245 | (yas--move-to-field snippet active-field) | 3265 | (save-excursion |
| 3246 | (yas--update-mirrors snippet))) | 3266 | (yas--move-to-field snippet active-field) |
| 3247 | (t | 3267 | (yas--update-mirrors snippet))) |
| 3248 | nil)))) | 3268 | (t |
| 3269 | nil))))) | ||
| 3249 | (unless (or (null snippets) snippets-left) | 3270 | (unless (or (null snippets) snippets-left) |
| 3250 | (if snippet-exit-transform | 3271 | (if snippet-exit-transform |
| 3251 | (yas--eval-lisp-no-saves snippet-exit-transform)) | 3272 | (yas--eval-lisp-no-saves snippet-exit-transform)) |
| @@ -3416,14 +3437,15 @@ field start. This hook does nothing if an undo is in progress." | |||
| 3416 | (field (overlay-get overlay 'yas--field)) | 3437 | (field (overlay-get overlay 'yas--field)) |
| 3417 | (snippet (overlay-get yas--active-field-overlay 'yas--snippet))) | 3438 | (snippet (overlay-get yas--active-field-overlay 'yas--snippet))) |
| 3418 | (save-match-data | 3439 | (save-match-data |
| 3419 | (when (yas--skip-and-clear-field-p field beg end length) | 3440 | (yas--letenv (yas--snippet-expand-env snippet) |
| 3420 | ;; We delete text starting from the END of insertion. | 3441 | (when (yas--skip-and-clear-field-p field beg end length) |
| 3421 | (yas--skip-and-clear field end)) | 3442 | ;; We delete text starting from the END of insertion. |
| 3422 | (setf (yas--field-modified-p field) t) | 3443 | (yas--skip-and-clear field end)) |
| 3423 | (yas--advance-end-maybe field (overlay-end overlay)) | 3444 | (setf (yas--field-modified-p field) t) |
| 3424 | (save-excursion | 3445 | (yas--advance-end-maybe field (overlay-end overlay)) |
| 3425 | (yas--field-update-display field)) | 3446 | (save-excursion |
| 3426 | (yas--update-mirrors snippet))))) | 3447 | (yas--field-update-display field)) |
| 3448 | (yas--update-mirrors snippet)))))) | ||
| 3427 | 3449 | ||
| 3428 | ;;; Apropos protection overlays: | 3450 | ;;; Apropos protection overlays: |
| 3429 | ;; | 3451 | ;; |
| @@ -3474,7 +3496,7 @@ Move the overlays, or create them if they do not exit." | |||
| 3474 | (not after?) | 3496 | (not after?) |
| 3475 | (= length (- end beg)) ; deletion or insertion | 3497 | (= length (- end beg)) ; deletion or insertion |
| 3476 | (yas--undo-in-progress)) | 3498 | (yas--undo-in-progress)) |
| 3477 | (let ((snippets (yas--snippets-at-point))) | 3499 | (let ((snippets (yas-active-snippets))) |
| 3478 | (yas--message 2 "Committing snippets. Action would destroy a protection overlay.") | 3500 | (yas--message 2 "Committing snippets. Action would destroy a protection overlay.") |
| 3479 | (cl-loop for snippet in snippets | 3501 | (cl-loop for snippet in snippets |
| 3480 | do (yas--commit-snippet snippet))))) | 3502 | do (yas--commit-snippet snippet))))) |
| @@ -3570,13 +3592,9 @@ considered when expanding the snippet." | |||
| 3570 | ;; insert things that are not valid in the | 3592 | ;; insert things that are not valid in the |
| 3571 | ;; major-mode language syntax anyway. | 3593 | ;; major-mode language syntax anyway. |
| 3572 | (syntax-propertize-function nil)) | 3594 | (syntax-propertize-function nil)) |
| 3595 | (insert content) | ||
| 3573 | (setq snippet | 3596 | (setq snippet |
| 3574 | (if expand-env | 3597 | (yas--snippet-create expand-env start (point)))) |
| 3575 | (eval `(let* ,expand-env | ||
| 3576 | (insert content) | ||
| 3577 | (yas--snippet-create start (point)))) | ||
| 3578 | (insert content) | ||
| 3579 | (yas--snippet-create start (point))))) | ||
| 3580 | ;; Invalidate any syntax-propertizing done while `syntax-propertize-function' was nil | 3598 | ;; Invalidate any syntax-propertizing done while `syntax-propertize-function' was nil |
| 3581 | (syntax-ppss-flush-cache start)) | 3599 | (syntax-ppss-flush-cache start)) |
| 3582 | 3600 | ||
| @@ -3656,27 +3674,28 @@ After revival, push the `yas--take-care-of-redo' in the | |||
| 3656 | (push `(apply yas--take-care-of-redo ,beg ,end ,snippet) | 3674 | (push `(apply yas--take-care-of-redo ,beg ,end ,snippet) |
| 3657 | buffer-undo-list)))) | 3675 | buffer-undo-list)))) |
| 3658 | 3676 | ||
| 3659 | (defun yas--snippet-create (begin end) | 3677 | (defun yas--snippet-create (expand-env begin end) |
| 3660 | "Create a snippet from a template inserted at BEGIN to END. | 3678 | "Create a snippet from a template inserted at BEGIN to END. |
| 3661 | 3679 | ||
| 3662 | Returns the newly created snippet." | 3680 | Returns the newly created snippet." |
| 3663 | (save-restriction | 3681 | (save-restriction |
| 3664 | (narrow-to-region begin end) | 3682 | (narrow-to-region begin end) |
| 3665 | (let ((snippet (yas--make-snippet))) | 3683 | (let ((snippet (yas--make-snippet expand-env))) |
| 3666 | (goto-char begin) | 3684 | (yas--letenv expand-env |
| 3667 | (yas--snippet-parse-create snippet) | 3685 | (goto-char begin) |
| 3686 | (yas--snippet-parse-create snippet) | ||
| 3668 | 3687 | ||
| 3669 | ;; Sort and link each field | 3688 | ;; Sort and link each field |
| 3670 | (yas--snippet-sort-fields snippet) | 3689 | (yas--snippet-sort-fields snippet) |
| 3671 | 3690 | ||
| 3672 | ;; Create keymap overlay for snippet | 3691 | ;; Create keymap overlay for snippet |
| 3673 | (setf (yas--snippet-control-overlay snippet) | 3692 | (setf (yas--snippet-control-overlay snippet) |
| 3674 | (yas--make-control-overlay snippet (point-min) (point-max))) | 3693 | (yas--make-control-overlay snippet (point-min) (point-max))) |
| 3675 | 3694 | ||
| 3676 | ;; Move to end | 3695 | ;; Move to end |
| 3677 | (goto-char (point-max)) | 3696 | (goto-char (point-max)) |
| 3678 | 3697 | ||
| 3679 | snippet))) | 3698 | snippet)))) |
| 3680 | 3699 | ||
| 3681 | 3700 | ||
| 3682 | ;;; Apropos adjacencies and "fom's": | 3701 | ;;; Apropos adjacencies and "fom's": |
| @@ -3898,40 +3917,78 @@ Meant to be called in a narrowed buffer, does various passes" | |||
| 3898 | (goto-char parse-start) | 3917 | (goto-char parse-start) |
| 3899 | (yas--indent snippet))) | 3918 | (yas--indent snippet))) |
| 3900 | 3919 | ||
| 3920 | ;; HACK: Some implementations of `indent-line-function' (called via | ||
| 3921 | ;; `indent-according-to-mode') delete text before they insert (like | ||
| 3922 | ;; cc-mode), some make complicated regexp replacements (looking at | ||
| 3923 | ;; you, org-mode). To find place where the marker "should" go after | ||
| 3924 | ;; indentation, we create a regexp based on what the line looks like | ||
| 3925 | ;; before, putting a capture group where the marker is. The regexp | ||
| 3926 | ;; matches any whitespace with [[:space:]]* to allow for the | ||
| 3927 | ;; indentation changing whitespace. Additionally, we try to preserve | ||
| 3928 | ;; the amount of whitespace *following* the marker, because | ||
| 3929 | ;; indentation generally affects whitespace at the beginning, not the | ||
| 3930 | ;; end. | ||
| 3931 | ;; | ||
| 3932 | ;; This is all best-effort heuristic stuff, but it should cover 99% of | ||
| 3933 | ;; use-cases. | ||
| 3934 | |||
| 3935 | (defun yas--snapshot-marker-location (marker) | ||
| 3936 | "Returns info for restoring MARKER's location after indent. | ||
| 3937 | The returned value is a list of the form (REGEXP MARKER WS-COUNT)." | ||
| 3938 | (when (and (<= (line-beginning-position) marker) | ||
| 3939 | (<= marker (line-end-position))) | ||
| 3940 | (let ((before | ||
| 3941 | (split-string (buffer-substring-no-properties | ||
| 3942 | (line-beginning-position) marker) "[[:space:]]+" t)) | ||
| 3943 | (after | ||
| 3944 | (split-string (buffer-substring-no-properties | ||
| 3945 | marker (line-end-position)) "[[:space:]]+" t))) | ||
| 3946 | (list (concat "[[:space:]]*" | ||
| 3947 | (mapconcat (lambda (s) | ||
| 3948 | (if (eq s marker) "\\(\\)" | ||
| 3949 | (regexp-quote s))) | ||
| 3950 | (nconc before (list marker) after) | ||
| 3951 | "[[:space:]]*")) | ||
| 3952 | marker | ||
| 3953 | (progn (goto-char marker) | ||
| 3954 | (skip-syntax-forward " " (line-end-position)) | ||
| 3955 | (- (point) marker)))))) | ||
| 3956 | |||
| 3957 | (defun yas--restore-marker-location (re-marker) | ||
| 3958 | "Restores marker based on info from `yas--snapshot-marker-location'." | ||
| 3959 | (let ((regexp (nth 0 re-marker)) | ||
| 3960 | (marker (nth 1 re-marker)) | ||
| 3961 | (ws-count (nth 2 re-marker))) | ||
| 3962 | (beginning-of-line) | ||
| 3963 | (save-restriction | ||
| 3964 | ;; Narrowing is the only way to limit `looking-at'. | ||
| 3965 | (narrow-to-region (point) (line-end-position)) | ||
| 3966 | (if (not (looking-at regexp)) | ||
| 3967 | (lwarn '(yasnippet re-marker) :warning | ||
| 3968 | "Couldn't find: %S" regexp) | ||
| 3969 | (goto-char (match-beginning 1)) | ||
| 3970 | (skip-syntax-forward " ") | ||
| 3971 | (skip-syntax-backward " " (- (point) ws-count)) | ||
| 3972 | (set-marker marker (point)))))) | ||
| 3973 | |||
| 3901 | (defun yas--indent-region (from to snippet) | 3974 | (defun yas--indent-region (from to snippet) |
| 3902 | "Indent the lines between FROM and TO with `indent-according-to-mode'. | 3975 | "Indent the lines between FROM and TO with `indent-according-to-mode'. |
| 3903 | The SNIPPET's markers are preserved." | 3976 | The SNIPPET's markers are preserved." |
| 3904 | ;;; Apropos indenting problems.... | ||
| 3905 | ;; | ||
| 3906 | ;; `indent-according-to-mode' uses whatever `indent-line-function' | ||
| 3907 | ;; is available. Some implementations of these functions delete text | ||
| 3908 | ;; before they insert. If there happens to be a marker just after | ||
| 3909 | ;; the text being deleted, the insertion actually happens after the | ||
| 3910 | ;; marker, which misplaces it. | ||
| 3911 | ;; | ||
| 3912 | ;; This would also happen if we had used overlays with the | ||
| 3913 | ;; `front-advance' property set to nil. | ||
| 3914 | ;; | ||
| 3915 | ;; This is why I have these `trouble-markers', they are the ones at | ||
| 3916 | ;; the first non-whitespace char at the line. After indentation | ||
| 3917 | ;; takes place we should be at the correct to restore them. All | ||
| 3918 | ;; other non-trouble-markers should have been *pushed* and don't | ||
| 3919 | ;; need special attention. | ||
| 3920 | (let* ((snippet-markers (yas--collect-snippet-markers snippet)) | 3977 | (let* ((snippet-markers (yas--collect-snippet-markers snippet)) |
| 3921 | (to (set-marker (make-marker) to))) | 3978 | (to (set-marker (make-marker) to))) |
| 3922 | (save-excursion | 3979 | (save-excursion |
| 3923 | (goto-char from) | 3980 | (goto-char from) |
| 3924 | (save-restriction | 3981 | (save-restriction |
| 3925 | (widen) | 3982 | (widen) |
| 3926 | ;; Indent each non-empty line. | ||
| 3927 | (cl-loop if (/= (line-beginning-position) (line-end-position)) do | 3983 | (cl-loop if (/= (line-beginning-position) (line-end-position)) do |
| 3928 | (back-to-indentation) | 3984 | ;; Indent each non-empty line. |
| 3929 | (let ((trouble-markers ; The markers at (point). | 3985 | (let ((remarkers |
| 3930 | (cl-remove (point) snippet-markers :test #'/=))) | 3986 | (delq nil (mapcar #'yas--snapshot-marker-location |
| 3987 | snippet-markers)))) | ||
| 3931 | (unwind-protect | 3988 | (unwind-protect |
| 3932 | (indent-according-to-mode) | 3989 | (progn (back-to-indentation) |
| 3933 | (dolist (marker trouble-markers) | 3990 | (indent-according-to-mode)) |
| 3934 | (set-marker marker (point))))) | 3991 | (mapc #'yas--restore-marker-location remarkers))) |
| 3935 | while (and (zerop (forward-line 1)) | 3992 | while (and (zerop (forward-line 1)) |
| 3936 | (< (point) to))))))) | 3993 | (< (point) to))))))) |
| 3937 | 3994 | ||
| @@ -4291,10 +4348,11 @@ When multiple expressions are found, only the last one counts." | |||
| 4291 | (yas--advance-start-maybe (yas--mirror-next mirror) (point)) | 4348 | (yas--advance-start-maybe (yas--mirror-next mirror) (point)) |
| 4292 | ;; super-special advance | 4349 | ;; super-special advance |
| 4293 | (yas--advance-end-of-parents-maybe mirror-parent-field (point))) | 4350 | (yas--advance-end-of-parents-maybe mirror-parent-field (point))) |
| 4294 | (let ((yas--inhibit-overlay-hooks t)) | 4351 | (when (eq yas-indent-line 'auto) |
| 4295 | (yas--indent-region (yas--mirror-start mirror) | 4352 | (let ((yas--inhibit-overlay-hooks t)) |
| 4296 | (yas--mirror-end mirror) | 4353 | (yas--indent-region (yas--mirror-start mirror) |
| 4297 | snippet))))) | 4354 | (yas--mirror-end mirror) |
| 4355 | snippet)))))) | ||
| 4298 | 4356 | ||
| 4299 | (defun yas--field-update-display (field) | 4357 | (defun yas--field-update-display (field) |
| 4300 | "Much like `yas--mirror-update-display', but for fields." | 4358 | "Much like `yas--mirror-update-display', but for fields." |
| @@ -4324,7 +4382,7 @@ When multiple expressions are found, only the last one counts." | |||
| 4324 | ;; After undo revival the correct field is sometimes not | 4382 | ;; After undo revival the correct field is sometimes not |
| 4325 | ;; restored correctly, this condition handles that | 4383 | ;; restored correctly, this condition handles that |
| 4326 | ;; | 4384 | ;; |
| 4327 | (let* ((snippet (car (yas--snippets-at-point))) | 4385 | (let* ((snippet (car (yas-active-snippets))) |
| 4328 | (target-field | 4386 | (target-field |
| 4329 | (and snippet | 4387 | (and snippet |
| 4330 | (cl-find-if-not | 4388 | (cl-find-if-not |
