mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
Added $> support, fixed issue 16
This commit is contained in:
parent
cca2df173d
commit
535a1ef314
@ -748,3 +748,29 @@ is not. Here's an snippet for rst title:
|
|||||||
.. [1] With some minor change, mainly for fixing some trivial bugs.
|
.. [1] With some minor change, mainly for fixing some trivial bugs.
|
||||||
.. [2] This is done when you call ``yas/initialize``.
|
.. [2] This is done when you call ``yas/initialize``.
|
||||||
.. [3] Of course, this can be customized.
|
.. [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$>
|
||||||
|
}$>
|
||||||
|
|
||||||
|
@ -797,7 +797,14 @@ will be deleted before inserting template."
|
|||||||
(yas/group-primary-field
|
(yas/group-primary-field
|
||||||
(car groups)))))
|
(car groups)))))
|
||||||
;; no need to call exit-snippet, since no overlay created.
|
;; 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)
|
(defun yas/current-snippet-overlay (&optional point)
|
||||||
"Get the most proper overlay which is belongs to a snippet."
|
"Get the most proper overlay which is belongs to a snippet."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user