* Support exits in the form of ${0:ephemeral text}

* Clean up whitespace
* Minor bug fixes
This commit is contained in:
capitaomorte 2010-03-31 22:54:11 +00:00
parent 83a81b2a9c
commit 4a8651f34f

View File

@ -1066,7 +1066,8 @@ This function implements the rules described in
(if (eq requirement 'always)
templates
(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))))
(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"))
(let* ((major-mode-and-parents (if mode-sym
(cons mode-sym parents)
(yas/compute-major-mode-and-parents (concat directory "/dummy"))))
(yas/ignore-filenames-as-triggers (or yas/ignore-filenames-as-triggers
(file-exists-p (concat directory "/" ".yas-ignore-filenames-as-triggers"))))
(yas/compute-major-mode-and-parents (concat directory
"/dummy"))))
(yas/ignore-filenames-as-triggers
(or yas/ignore-filenames-as-triggers
(file-exists-p (concat directory "/"
".yas-ignore-filenames-as-triggers"))))
(snippet-defs nil))
;; load the snippet files
;;
@ -1664,7 +1668,8 @@ Here's the default value for all the parameters:
(require 'yasnippet-bundle)`\"
\"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
"yasnippet.el"))
@ -2059,7 +2064,8 @@ object satisfying `yas/field-p' to restrict the expansion to."
(setq yas/condition-cache-timestamp (current-time))
(multiple-value-bind (templates start end) (if field
(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))
(if templates
@ -2300,6 +2306,7 @@ lurking."
(if guessed-directories
(yas/table-name (car (first guessed-directories)))
"unknown mode")))
(erase-buffer)
(snippet-mode)
(setq yas/guessed-directories guessed-directories)
(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)
(fboundp (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: "))))
(template (and parsed
(fboundp test-mode)
(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)
:content (second 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))
(erase-buffer)
(setq buffer-undo-list nil)
(funcall test-mode)
(condition-case nil (funcall test-mode) (error nil))
(yas/expand-snippet (yas/template-content template)
(point-min)
(point-max)
@ -2684,7 +2693,7 @@ Otherwise throw exception."
(yas/throw (format "[yas] field only allows %s" possibilities))))
(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."
(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."
(setf (yas/snippet-fields snippet)
(sort (yas/snippet-fields snippet)
'(lambda (field1 field2)
(yas/snippet-field-compare field1 field2)))))
#'yas/snippet-field-compare)))
(defun yas/snippet-field-compare (field1 field2)
"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)))
(if n1
(if n2
(< n1 n2)
t)
(or (zerop n2) (and (not (zerop n1))
(< n1 n2)))
(not (zerop n1)))
(if n2
nil
(zerop n2)
(< (yas/field-start field1)
(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
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?
(yas/advance-end-maybe field (overlay-end overlay))
;;; primary field transform: normal calls to expression
(let ((saved-point (point)))
(yas/field-update-display field (car (yas/snippets-at-point)))
(goto-char saved-point))
;; 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)))
(yas/field-update-display field (car (yas/snippets-at-point)))
(goto-char saved-point)))
(yas/update-mirrors (car (yas/snippets-at-point))))
(field
(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)
"Indent current line according to mode, preserving
SNIPPET-MARKERS."
;; XXX: Here seems to be the indent problem:
;;; Apropos indenting problems....
;;
;; `indent-according-to-mode' uses whatever
;; `indent-line-function' is available. Some
;; implementations of these functions delete text
;; before they insert. If there happens to be a marker
;; just after the text being deleted, the insertion
;; actually happens after the marker, which misplaces
;; it.
;; `indent-according-to-mode' uses whatever `indent-line-function'
;; is available. Some implementations of these functions delete text
;; before they insert. If there happens to be a marker just after
;; the text being deleted, the insertion actually happens after the
;; marker, which misplaces it.
;;
;; This would also happen if we had used overlays with
;; the `front-advance' property set to nil.
;; This would also happen if we had used overlays with the
;; `front-advance' property set to nil.
;;
;; 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
@ -3817,7 +3830,8 @@ When multiple expressions are found, only the last one counts."
(not (save-match-data
(eq (string-match "$[ \t\n]*("
(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-marker (match-beginning 2))
(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)))))
(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)
(let ((number (string-to-number (match-string-no-properties 1))))
(cond ((zerop number)
@ -4053,16 +4067,17 @@ that the rest of `yas/post-command-handler' runs.")
(put 'yas/expand 'function-documentation '(yas/expand-from-trigger-key-doc))
(defun 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* ((yas/minor-mode nil)
(fallback (key-binding (read-kbd-macro yas/trigger-key))))
(or (and fallback
(format " call command `%s'." (pp-to-string fallback)))
" do nothing.")))
((eq yas/fallback-behavior 'return-nil)
", do nothing.")
(t
", defer to `yas/fallback-behaviour' :-)"))))
(let ((fallback-description
(cond ((eq yas/fallback-behavior 'call-other-command)
(let* ((yas/minor-mode nil)
(fallback (key-binding (read-kbd-macro yas/trigger-key))))
(or (and fallback
(format " call command `%s'." (pp-to-string fallback)))
" do nothing.")))
((eq yas/fallback-behavior 'return-nil)
", do nothing.")
(t
", defer to `yas/fallback-behaviour' :-)"))))
(concat "Expand a snippet before point. If no snippet
expansion is possible,"
fallback-description