[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master e9406f5 26/36: Document $> and fix escaping
From: |
Noam Postavsky |
Subject: |
[elpa] master e9406f5 26/36: Document $> and fix escaping |
Date: |
Sat, 11 Jun 2016 19:21:11 +0000 (UTC) |
branch: master
commit e9406f51266f9b9179f475886fa4ec78f1ccba44
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
Document $> and fix escaping
* doc/snippet-development.org: New "Indentation markers" section.
* yasnippet-tests.el (indentation-markers): New test.
* yasnippet.el (yas--indent-markers): New variable.
(yas--indent): Use it instead of searching for $> directly.
(yas--indent-parse-create): New function, records occurences of $> into
`yas--indent-markers'.
(yas--snippet-parse-create): Call it.
---
doc/snippet-development.org | 6 ++++++
yasnippet-tests.el | 13 +++++++++++++
yasnippet.el | 27 +++++++++++++++++++++++----
3 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/doc/snippet-development.org b/doc/snippet-development.org
index 768684c..c792483 100644
--- a/doc/snippet-development.org
+++ b/doc/snippet-development.org
@@ -422,3 +422,9 @@ the exit marker.
By the way, =C-d= will only clear the field if you cursor is at the
beginning of the field /and/ it hasn't been changed yet. Otherwise, it
performs the normal Emacs =delete-char= command.
+
+** Indentation markers
+
+If [[sym:yas-indent-line][=yas-indent-line=]] is *not* set to '=auto=, it's
still possible to
+indent specific lines by adding an indentation marker, =$>=, somewhere
+on the line.
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 8ba4632..9d2074a 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -215,6 +215,19 @@ end" (buffer-string)))
end" (buffer-string)))
(should (= 4 (current-column)))))
+(ert-deftest indentation-markers ()
+ "Test a snippet with indentation markers (`$<')."
+ (with-temp-buffer
+ (ruby-mode)
+ (yas-minor-mode 1)
+ (set (make-local-variable 'yas-indent-line) nil)
+ (yas-expand-snippet "def ${1:method}${2:(${3:args})}\n$>Indent\nNo
indent\\$>\nend")
+ (should (string= "def method(args)
+ Indent
+No indent$>
+end" (buffer-string)))))
+
+
(ert-deftest navigate-a-snippet-with-multiline-mirrors-issue-665 ()
"In issue 665, a multi-line mirror is attempted.
diff --git a/yasnippet.el b/yasnippet.el
index 2da3062..4f8bc76 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)
@@ -3932,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)
@@ -4045,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\".
- [elpa] master 14f830a 13/36: Test expansion in an empty buffer, (continued)
- [elpa] master 14f830a 13/36: Test expansion in an empty buffer, Noam Postavsky, 2016/06/11
- [elpa] master a87ec54 12/36: yasnippet.el (yas-next-field-will-exit-p): New function., Noam Postavsky, 2016/06/11
- [elpa] master 7799aa9 09/36: Document .yas-setup.el, Noam Postavsky, 2016/06/11
- [elpa] master 4f2aa15 05/36: Only kill snippets for text length change, Noam Postavsky, 2016/06/11
- [elpa] master 8771082 03/36: Don't add useless kill ring entries, Noam Postavsky, 2016/06/11
- [elpa] master cc14db3 11/36: Refactor yas-next-field a bit, Noam Postavsky, 2016/06/11
- [elpa] master db4cd31 20/36: Delete active region for trigger key expansion, Noam Postavsky, 2016/06/11
- [elpa] master e37ce9e 18/36: Disable region wrapping for trigger key expansion, Noam Postavsky, 2016/06/11
- [elpa] master 6180cc4 28/36: Fix field transform application in yas-next-field, Noam Postavsky, 2016/06/11
- [elpa] master 146b161 25/36: Don't indent empty lines in snippet expansion, Noam Postavsky, 2016/06/11
- [elpa] master e9406f5 26/36: Document $> and fix escaping,
Noam Postavsky <=
- [elpa] master 6f97316 27/36: Fix outdated and misformatted docs, Noam Postavsky, 2016/06/11
- [elpa] master bd30a30 04/36: yas-dont-activate is a hook, Noam Postavsky, 2016/06/11
- [elpa] master c1b2cb7 17/36: Improve documentation for new register option, Noam Postavsky, 2016/06/11
- [elpa] master 4c6064c 01/36: Avoid potential problems with user's hooks, Noam Postavsky, 2016/06/11
- [elpa] master 5d44a9f 19/36: Revert "Disable region wrapping for trigger key expansion", Noam Postavsky, 2016/06/11
- [elpa] master beb2ba4 21/36: Fix fields following $0 + region insertion, Noam Postavsky, 2016/06/11
- [elpa] master eeb4b62 14/36: Add new tests for multi-line mirror indentation, Noam Postavsky, 2016/06/11
- [elpa] master 78fe979 22/36: Support htmlize.el in Rakefile doc target, Noam Postavsky, 2016/06/11
- [elpa] master 7f03a23 07/36: Change Emacs installation method for Travis CI, Noam Postavsky, 2016/06/11
- [elpa] master 0d79e69 30/36: Extra measures to prevent premature yas-minor-mode, Noam Postavsky, 2016/06/11