mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
overlay created.
This commit is contained in:
parent
1438d90813
commit
dc60b10e57
42
yasnippet.el
42
yasnippet.el
@ -185,23 +185,27 @@ have, compare through the start point of the overlay."
|
|||||||
start
|
start
|
||||||
end))))
|
end))))
|
||||||
|
|
||||||
(defun yas/create-snippet (template
|
(defun yas/expand-snippet (start end template)
|
||||||
indent? column tabify? tab-width)
|
"Expand snippet at current point. Text between START and END
|
||||||
"Create a snippet according to TEMPLATE. Each line is indented to
|
will be deleted before inserting template."
|
||||||
current column if `yas/indent-line' is non-`nil'."
|
(goto-char start)
|
||||||
(with-temp-buffer
|
|
||||||
(insert template)
|
|
||||||
|
|
||||||
|
(let ((length (- end start))
|
||||||
|
(column (current-column)))
|
||||||
|
(save-restriction
|
||||||
|
(narrow-to-region start start)
|
||||||
|
|
||||||
|
(insert template)
|
||||||
;; Step 1: do necessary indent
|
;; Step 1: do necessary indent
|
||||||
(when indent?
|
(when yas/indent-line
|
||||||
(let* ((indent (if tabify?
|
(let* ((indent (if indent-tabs-mode
|
||||||
(concat (make-string (/ column tab-width) ?\t)
|
(concat (make-string (/ column tab-width) ?\t)
|
||||||
(make-string (% column tab-width) ?\ ))
|
(make-string (% column tab-width) ?\ ))
|
||||||
(make-string column ?\ ))))
|
(make-string column ?\ ))))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(while (zerop (forward-line))
|
(while (and (zerop (forward-line))
|
||||||
(insert indent)
|
(= (current-column) 0))
|
||||||
(end-of-line))))
|
(insert indent))))
|
||||||
|
|
||||||
;; Step 2: protect backslash and backquote
|
;; Step 2: protect backslash and backquote
|
||||||
(yas/replace-all "\\\\" yas/escape-backslash)
|
(yas/replace-all "\\\\" yas/escape-backslash)
|
||||||
@ -266,19 +270,11 @@ current column if `yas/indent-line' is non-`nil'."
|
|||||||
(yas/replace-all yas/escape-backquote "`")
|
(yas/replace-all yas/escape-backquote "`")
|
||||||
(yas/replace-all yas/escape-backslash "\\")
|
(yas/replace-all yas/escape-backslash "\\")
|
||||||
|
|
||||||
(buffer-string)))
|
(goto-char (point-max)))
|
||||||
|
|
||||||
|
(delete-char length)))
|
||||||
|
|
||||||
|
|
||||||
(defun yas/expand-snippet (start end template)
|
|
||||||
"Expand snippet at current point. Text between START and END
|
|
||||||
will be deleted before inserting template."
|
|
||||||
(goto-char start)
|
|
||||||
(insert (yas/create-snippet template
|
|
||||||
yas/indent-line ; indent?
|
|
||||||
(current-column) ; column
|
|
||||||
indent-tabs-mode ; tabify?
|
|
||||||
tab-width ; tab-width
|
|
||||||
))
|
|
||||||
(delete-char (- end start)))
|
|
||||||
|
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user