mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-14 05:23:04 +00:00
* Support exits in the form of ${0:ephemeral text}
* Clean up whitespace * Minor bug fixes
This commit is contained in:
parent
83a81b2a9c
commit
4a8651f34f
75
yasnippet.el
75
yasnippet.el
@ -1066,7 +1066,8 @@ This function implements the rules described in
|
|||||||
(if (eq requirement 'always)
|
(if (eq requirement 'always)
|
||||||
templates
|
templates
|
||||||
(remove-if-not #'(lambda (pair)
|
(remove-if-not #'(lambda (pair)
|
||||||
(yas/template-can-expand-p (yas/template-condition (cdr pair)) requirement))
|
(yas/template-can-expand-p
|
||||||
|
(yas/template-condition (cdr pair)) requirement))
|
||||||
templates))))
|
templates))))
|
||||||
|
|
||||||
(defun yas/require-template-specific-condition-p ()
|
(defun yas/require-template-specific-condition-p ()
|
||||||
@ -1527,9 +1528,12 @@ TEMPLATES is a list of `yas/template'."
|
|||||||
(unless (file-exists-p (concat directory "/" ".yas-skip"))
|
(unless (file-exists-p (concat directory "/" ".yas-skip"))
|
||||||
(let* ((major-mode-and-parents (if mode-sym
|
(let* ((major-mode-and-parents (if mode-sym
|
||||||
(cons mode-sym parents)
|
(cons mode-sym parents)
|
||||||
(yas/compute-major-mode-and-parents (concat directory "/dummy"))))
|
(yas/compute-major-mode-and-parents (concat directory
|
||||||
(yas/ignore-filenames-as-triggers (or yas/ignore-filenames-as-triggers
|
"/dummy"))))
|
||||||
(file-exists-p (concat directory "/" ".yas-ignore-filenames-as-triggers"))))
|
(yas/ignore-filenames-as-triggers
|
||||||
|
(or yas/ignore-filenames-as-triggers
|
||||||
|
(file-exists-p (concat directory "/"
|
||||||
|
".yas-ignore-filenames-as-triggers"))))
|
||||||
(snippet-defs nil))
|
(snippet-defs nil))
|
||||||
;; load the snippet files
|
;; load the snippet files
|
||||||
;;
|
;;
|
||||||
@ -1664,7 +1668,8 @@ Here's the default value for all the parameters:
|
|||||||
(require 'yasnippet-bundle)`\"
|
(require 'yasnippet-bundle)`\"
|
||||||
\"dropdown-list.el\")
|
\"dropdown-list.el\")
|
||||||
"
|
"
|
||||||
(interactive "ffind the yasnippet.el file: \nFTarget bundle file: \nDSnippet directory to bundle: \nMExtra code? \nfdropdown-library: ")
|
(interactive (concat "ffind the yasnippet.el file: \nFTarget bundle file: "
|
||||||
|
"\nDSnippet directory to bundle: \nMExtra code? \nfdropdown-library: "))
|
||||||
|
|
||||||
(let* ((yasnippet (or yasnippet
|
(let* ((yasnippet (or yasnippet
|
||||||
"yasnippet.el"))
|
"yasnippet.el"))
|
||||||
@ -2059,7 +2064,8 @@ object satisfying `yas/field-p' to restrict the expansion to."
|
|||||||
(setq yas/condition-cache-timestamp (current-time))
|
(setq yas/condition-cache-timestamp (current-time))
|
||||||
(multiple-value-bind (templates start end) (if field
|
(multiple-value-bind (templates start end) (if field
|
||||||
(save-restriction
|
(save-restriction
|
||||||
(narrow-to-region (yas/field-start field) (yas/field-end field))
|
(narrow-to-region (yas/field-start field)
|
||||||
|
(yas/field-end field))
|
||||||
(yas/current-key))
|
(yas/current-key))
|
||||||
(yas/current-key))
|
(yas/current-key))
|
||||||
(if templates
|
(if templates
|
||||||
@ -2300,6 +2306,7 @@ lurking."
|
|||||||
(if guessed-directories
|
(if guessed-directories
|
||||||
(yas/table-name (car (first guessed-directories)))
|
(yas/table-name (car (first guessed-directories)))
|
||||||
"unknown mode")))
|
"unknown mode")))
|
||||||
|
(erase-buffer)
|
||||||
(snippet-mode)
|
(snippet-mode)
|
||||||
(setq yas/guessed-directories guessed-directories)
|
(setq yas/guessed-directories guessed-directories)
|
||||||
(unless (and choose-instead-of-guess
|
(unless (and choose-instead-of-guess
|
||||||
@ -2527,11 +2534,13 @@ With optional prefix argument KILL quit the window and buffer."
|
|||||||
(test-mode (or (and (car major-mode-and-parent)
|
(test-mode (or (and (car major-mode-and-parent)
|
||||||
(fboundp (car major-mode-and-parent))
|
(fboundp (car major-mode-and-parent))
|
||||||
(car major-mode-and-parent))
|
(car major-mode-and-parent))
|
||||||
|
(and yas/guessed-directories
|
||||||
|
(intern (yas/table-name (car (first yas/guessed-directories)))))
|
||||||
(intern (read-from-minibuffer "[yas] please input a mode: "))))
|
(intern (read-from-minibuffer "[yas] please input a mode: "))))
|
||||||
(template (and parsed
|
(template (and parsed
|
||||||
(fboundp test-mode)
|
(fboundp test-mode)
|
||||||
(yas/populate-template (yas/make-blank-template)
|
(yas/populate-template (yas/make-blank-template)
|
||||||
:table nil ;; an ephemeral snippet has no table...
|
:table nil ;; no tables for ephemeral snippets
|
||||||
:key (first parsed)
|
:key (first parsed)
|
||||||
:content (second parsed)
|
:content (second parsed)
|
||||||
:name (third parsed)
|
:name (third parsed)
|
||||||
@ -2541,7 +2550,7 @@ With optional prefix argument KILL quit the window and buffer."
|
|||||||
(set-buffer (switch-to-buffer buffer-name))
|
(set-buffer (switch-to-buffer buffer-name))
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(setq buffer-undo-list nil)
|
(setq buffer-undo-list nil)
|
||||||
(funcall test-mode)
|
(condition-case nil (funcall test-mode) (error nil))
|
||||||
(yas/expand-snippet (yas/template-content template)
|
(yas/expand-snippet (yas/template-content template)
|
||||||
(point-min)
|
(point-min)
|
||||||
(point-max)
|
(point-max)
|
||||||
@ -2684,7 +2693,7 @@ Otherwise throw exception."
|
|||||||
(yas/throw (format "[yas] field only allows %s" possibilities))))
|
(yas/throw (format "[yas] field only allows %s" possibilities))))
|
||||||
|
|
||||||
(defun yas/ephemeral-field (number)
|
(defun yas/ephemeral-field (number)
|
||||||
"Automatically exit snippet when something is type in field NUMBER.
|
"Automatically exit snippet when something is typed in field NUMBER.
|
||||||
|
|
||||||
To be used as a primary field transformation."
|
To be used as a primary field transformation."
|
||||||
(when yas/modified-p (yas/exit-snippet (first (yas/snippets-at-point))) (yas/field-value number)))
|
(when yas/modified-p (yas/exit-snippet (first (yas/snippets-at-point))) (yas/field-value number)))
|
||||||
@ -2808,8 +2817,7 @@ With optional string TEXT do it in that string."
|
|||||||
"Sort the fields of SNIPPET in navigation order."
|
"Sort the fields of SNIPPET in navigation order."
|
||||||
(setf (yas/snippet-fields snippet)
|
(setf (yas/snippet-fields snippet)
|
||||||
(sort (yas/snippet-fields snippet)
|
(sort (yas/snippet-fields snippet)
|
||||||
'(lambda (field1 field2)
|
#'yas/snippet-field-compare)))
|
||||||
(yas/snippet-field-compare field1 field2)))))
|
|
||||||
|
|
||||||
(defun yas/snippet-field-compare (field1 field2)
|
(defun yas/snippet-field-compare (field1 field2)
|
||||||
"Compare two fields. The field with a number is sorted first.
|
"Compare two fields. The field with a number is sorted first.
|
||||||
@ -2819,10 +2827,11 @@ have, compare through the field's start point"
|
|||||||
(n2 (yas/field-number field2)))
|
(n2 (yas/field-number field2)))
|
||||||
(if n1
|
(if n1
|
||||||
(if n2
|
(if n2
|
||||||
(< n1 n2)
|
(or (zerop n2) (and (not (zerop n1))
|
||||||
t)
|
(< n1 n2)))
|
||||||
|
(not (zerop n1)))
|
||||||
(if n2
|
(if n2
|
||||||
nil
|
(zerop n2)
|
||||||
(< (yas/field-start field1)
|
(< (yas/field-start field1)
|
||||||
(yas/field-start field2))))))
|
(yas/field-start field2))))))
|
||||||
|
|
||||||
@ -3176,13 +3185,19 @@ Only clears the field if it hasn't been modified and it point it
|
|||||||
at field start. This hook doesn't do anything if an undo is in
|
at field start. This hook doesn't do anything if an undo is in
|
||||||
progress."
|
progress."
|
||||||
(unless (yas/undo-in-progress)
|
(unless (yas/undo-in-progress)
|
||||||
(let ((field (overlay-get yas/active-field-overlay 'yas/field)))
|
(let* ((field (overlay-get yas/active-field-overlay 'yas/field))
|
||||||
|
(number (and field (yas/field-number field)))
|
||||||
|
(snippet (overlay-get yas/active-field-overlay 'yas/snippet)))
|
||||||
(cond (after?
|
(cond (after?
|
||||||
(yas/advance-end-maybe field (overlay-end overlay))
|
(yas/advance-end-maybe field (overlay-end overlay))
|
||||||
;;; primary field transform: normal calls to expression
|
;; primary field transform: normal calls to expression or
|
||||||
|
;; force an exit on next `post-command-hook' if the
|
||||||
|
;; number is 0
|
||||||
|
(if (and number (zerop number))
|
||||||
|
(setf (yas/snippet-force-exit snippet) t)
|
||||||
(let ((saved-point (point)))
|
(let ((saved-point (point)))
|
||||||
(yas/field-update-display field (car (yas/snippets-at-point)))
|
(yas/field-update-display field (car (yas/snippets-at-point)))
|
||||||
(goto-char saved-point))
|
(goto-char saved-point)))
|
||||||
(yas/update-mirrors (car (yas/snippets-at-point))))
|
(yas/update-mirrors (car (yas/snippets-at-point))))
|
||||||
(field
|
(field
|
||||||
(when (and (not after?)
|
(when (and (not after?)
|
||||||
@ -3651,18 +3666,16 @@ Meant to be called in a narrowed buffer, does various passes"
|
|||||||
(defun yas/indent-according-to-mode (snippet-markers)
|
(defun yas/indent-according-to-mode (snippet-markers)
|
||||||
"Indent current line according to mode, preserving
|
"Indent current line according to mode, preserving
|
||||||
SNIPPET-MARKERS."
|
SNIPPET-MARKERS."
|
||||||
;; XXX: Here seems to be the indent problem:
|
;;; Apropos indenting problems....
|
||||||
;;
|
;;
|
||||||
;; `indent-according-to-mode' uses whatever
|
;; `indent-according-to-mode' uses whatever `indent-line-function'
|
||||||
;; `indent-line-function' is available. Some
|
;; is available. Some implementations of these functions delete text
|
||||||
;; implementations of these functions delete text
|
;; before they insert. If there happens to be a marker just after
|
||||||
;; before they insert. If there happens to be a marker
|
;; the text being deleted, the insertion actually happens after the
|
||||||
;; just after the text being deleted, the insertion
|
;; marker, which misplaces it.
|
||||||
;; actually happens after the marker, which misplaces
|
|
||||||
;; it.
|
|
||||||
;;
|
;;
|
||||||
;; This would also happen if we had used overlays with
|
;; This would also happen if we had used overlays with the
|
||||||
;; the `front-advance' property set to nil.
|
;; `front-advance' property set to nil.
|
||||||
;;
|
;;
|
||||||
;; This is why I have these `trouble-markers', they are the ones at
|
;; This is why I have these `trouble-markers', they are the ones at
|
||||||
;; they are the ones at the first non-whitespace char at the line
|
;; they are the ones at the first non-whitespace char at the line
|
||||||
@ -3817,7 +3830,8 @@ When multiple expressions are found, only the last one counts."
|
|||||||
(not (save-match-data
|
(not (save-match-data
|
||||||
(eq (string-match "$[ \t\n]*("
|
(eq (string-match "$[ \t\n]*("
|
||||||
(match-string-no-properties 2)) 0)))
|
(match-string-no-properties 2)) 0)))
|
||||||
(not (and number (zerop number)))
|
;; allow ${0: some exit text}
|
||||||
|
;; (not (and number (zerop number)))
|
||||||
(yas/make-field number
|
(yas/make-field number
|
||||||
(yas/make-marker (match-beginning 2))
|
(yas/make-marker (match-beginning 2))
|
||||||
(yas/make-marker (1- real-match-end-0))
|
(yas/make-marker (1- real-match-end-0))
|
||||||
@ -3888,7 +3902,7 @@ When multiple expressions are found, only the last one counts."
|
|||||||
(push (cons (match-beginning 0) real-match-end-0) yas/dollar-regions)))))
|
(push (cons (match-beginning 0) real-match-end-0) yas/dollar-regions)))))
|
||||||
|
|
||||||
(defun yas/simple-mirror-parse-create (snippet)
|
(defun yas/simple-mirror-parse-create (snippet)
|
||||||
"Parse the simple \"$n\" mirrors and the exit-marker."
|
"Parse the simple \"$n\" fields/mirrors/exitmarkers."
|
||||||
(while (re-search-forward yas/simple-mirror-regexp nil t)
|
(while (re-search-forward yas/simple-mirror-regexp nil t)
|
||||||
(let ((number (string-to-number (match-string-no-properties 1))))
|
(let ((number (string-to-number (match-string-no-properties 1))))
|
||||||
(cond ((zerop number)
|
(cond ((zerop number)
|
||||||
@ -4053,7 +4067,8 @@ that the rest of `yas/post-command-handler' runs.")
|
|||||||
(put 'yas/expand 'function-documentation '(yas/expand-from-trigger-key-doc))
|
(put 'yas/expand 'function-documentation '(yas/expand-from-trigger-key-doc))
|
||||||
(defun yas/expand-from-trigger-key-doc ()
|
(defun yas/expand-from-trigger-key-doc ()
|
||||||
"A doc synthethizer for `yas/expand-from-trigger-key-doc'."
|
"A doc synthethizer for `yas/expand-from-trigger-key-doc'."
|
||||||
(let ((fallback-description (cond ((eq yas/fallback-behavior 'call-other-command)
|
(let ((fallback-description
|
||||||
|
(cond ((eq yas/fallback-behavior 'call-other-command)
|
||||||
(let* ((yas/minor-mode nil)
|
(let* ((yas/minor-mode nil)
|
||||||
(fallback (key-binding (read-kbd-macro yas/trigger-key))))
|
(fallback (key-binding (read-kbd-macro yas/trigger-key))))
|
||||||
(or (and fallback
|
(or (and fallback
|
||||||
|
Loading…
x
Reference in New Issue
Block a user