Added $> support, fixed issue 16

This commit is contained in:
Zhang Chiyuan 2008-09-02 13:06:51 +00:00
parent cca2df173d
commit 535a1ef314
2 changed files with 34 additions and 1 deletions

View File

@ -748,3 +748,29 @@ is not. Here's an snippet for rst title:
.. [1] With some minor change, mainly for fixing some trivial bugs.
.. [2] This is done when you call ``yas/initialize``.
.. [3] Of course, this can be customized.
Indenting
---------
Many people miss the indenting feature of smart-snippet: when you
place a ``$>`` in your snippet, an ``(indent-according-to-mode)`` will
be executed there to indent the line. So you'll not need to hard-code
the indenting in the snippet template, and it will be very convenient
when you need to work with several different project where coding
styles are different.
The reason why this feature wasn't added to YASnippet until after
0.5.6 is that it doesn't work well for all modes. In some cases
(e.g. python-mode), calling ``indent-according-to-mode`` will break
the overlays created by YASnippet.
However, since many people asked for this feature, I finally added
this to YASnippet. Here's an example of the usage:
.. sourcecode:: text
for (${int i = 0}; ${i < 10}; ${++i})
{$>
$0$>
}$>

View File

@ -797,7 +797,14 @@ will be deleted before inserting template."
(yas/group-primary-field
(car groups)))))
;; no need to call exit-snippet, since no overlay created.
(yas/exit-snippet snippet)))))))
(yas/exit-snippet snippet)))
;; Step 16: Do necessary indenting
(save-excursion
(goto-char (overlay-start (yas/snippet-overlay snippet)))
(while (re-search-forward "$>" nil t)
(replace-match "")
(indent-according-to-mode)))))))
(defun yas/current-snippet-overlay (&optional point)
"Get the most proper overlay which is belongs to a snippet."