X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/bdfab67eacd874ba927ab75ffad5285ac9933cdf..e9406f51266f9b9179f475886fa4ec78f1ccba44:/yasnippet.el diff --git a/yasnippet.el b/yasnippet.el index 5aa53c611..4f8bc7630 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -3826,6 +3826,9 @@ cons cells to this var.") backquoted Lisp expressions should be inserted at the end of expansion.") +(defvar yas--indent-markers nil + "List of markers for manual indentation.") + (defun yas--snippet-parse-create (snippet) "Parse a recently inserted snippet template, creating all necessary fields, mirrors and exit points. @@ -3845,6 +3848,9 @@ Meant to be called in a narrowed buffer, does various passes" ;; protect escaped characters ;; (yas--protect-escapes) + ;; Parse indent markers: `$>'. + (goto-char parse-start) + (yas--indent-parse-create snippet) ;; parse fields with {} ;; (goto-char parse-start) @@ -3918,7 +3924,8 @@ The SNIPPET's markers are preserved." (goto-char from) (save-restriction (widen) - (cl-loop do + ;; Indent each non-empty line. + (cl-loop if (/= (line-beginning-position) (line-end-position)) do (back-to-indentation) (let ((trouble-markers ; The markers at (point). (cl-remove (point) snippet-markers :test #'/=))) @@ -3931,14 +3938,17 @@ The SNIPPET's markers are preserved." (defvar yas--indent-original-column nil) (defun yas--indent (snippet) - ;; Look for those `$>'. + ;; Indent lines that had indent markers (`$>') on them. (save-excursion - (while (re-search-forward "$>" nil t) - (delete-region (match-beginning 0) (match-end 0)) + (dolist (marker yas--indent-markers) (unless (eq yas-indent-line 'auto) + (goto-char marker) (yas--indent-region (line-beginning-position) (line-end-position) - snippet)))) + snippet)) + ;; Finished with this marker. + (set-marker marker nil)) + (setq yas--indent-markers nil)) ;; Now do stuff for `fixed' and `auto'. (save-excursion (cond ((eq yas-indent-line 'fixed) @@ -4044,6 +4054,16 @@ with their evaluated value into `yas--backquote-markers-and-strings'." (set-marker-insertion-type marker nil) marker)) +(defun yas--indent-parse-create (snippet) + "Parse the \"$>\" indentation markers in SNIPPET." + (setq yas--indent-markers ()) + (while (search-forward "$>" nil t) + (delete-region (match-beginning 0) (match-end 0)) + ;; Mark the beginning of the line. + (push (yas--make-marker (line-beginning-position)) + yas--indent-markers)) + (setq yas--indent-markers (nreverse yas--indent-markers))) + (defun yas--field-parse-create (snippet &optional parent-field) "Parse most field expressions in SNIPPET, except for the simple one \"$n\".