diff --git a/extras/imported/ruby-mode/.yas-setup.el b/extras/imported/ruby-mode/.yas-setup.el index 7ef5312..2ae1fb2 100644 --- a/extras/imported/ruby-mode/.yas-setup.el +++ b/extras/imported/ruby-mode/.yas-setup.el @@ -17,11 +17,10 @@ ((string-match "_" fn) (replace-match "" nil nil fn)) (t fn)))) -(defun yas/ruby-in-interpolated-string-p () - (eq (fourth (syntax-ppss)) - ?\")) - -(defun yas/ruby-in-comment-p () - (fifth (syntax-ppss))) +;; conditions +;; +(yas/define-condition-cache yas/ruby-in-interpolated-string-p (eq (fourth (syntax-ppss)) ?\")) +(yas/define-condition-cache yas/ruby-in-comment-p (fifth (syntax-ppss))) +(yas/define-condition-cache yas/ruby-in-string-p (fourth (syntax-ppss))) diff --git a/extras/imported/ruby-mode/Blocks/open yield block ({).yasnippet b/extras/imported/ruby-mode/Blocks/open yield block ({).yasnippet index 3d40f34..3cc330c 100644 --- a/extras/imported/ruby-mode/Blocks/open yield block ({).yasnippet +++ b/extras/imported/ruby-mode/Blocks/open yield block ({).yasnippet @@ -1,9 +1,13 @@ # -*- mode: snippet -*- +# type: command # key: { # contributor: Translated from TextMate Snippet -# assumes some sort of autopairing of the braces such as autopair.el or ruby electric -# that would have added the closing brace. # name: Insert { |variable| … } -## condition: "source.ruby - string - comment" +# condition: (not (or (yas/ruby-in-comment-p) (yas/ruby-in-string-p))) # -- -{ ${1:$(if (string= yas/text "") "" "|")}${1:variable}${1:$(if (string= yas/text "") "" "|")}${2:`yas/selected-text`} \ No newline at end of file +(yas/expand-snippet (concat + "{ ${1:$(if (string= yas/text \"\") \"\" \"|\")}${1:variable}${1:$(if (string= yas/text \"\") \" \" \"| \")}`yas/selected-text`$0" + (save-excursion (if (search-forward-regexp "}" (line-end-position) t) + "" "}")))) + + diff --git a/extras/imported/ruby-mode/RDoc/RDoc documentation block.yasnippet b/extras/imported/ruby-mode/RDoc/RDoc documentation block.yasnippet index 1d5078b..75bc7e0 100644 --- a/extras/imported/ruby-mode/RDoc/RDoc documentation block.yasnippet +++ b/extras/imported/ruby-mode/RDoc/RDoc documentation block.yasnippet @@ -4,6 +4,6 @@ # name: New Block ## condition: "source.ruby" # -- -`[[ $TM_LINE_INDEX != 0 ]] && echo; echo`=begin rdoc +`(if (save-restriction (widen) (eq 1 (line-number-at-pos))) "\n\n" "\n")`=begin rdoc $0 =end \ No newline at end of file diff --git a/extras/imported/ruby-mode/RDoc/yields RDoc comment.yasnippet b/extras/imported/ruby-mode/RDoc/yields RDoc comment.yasnippet index 2344615..a2371c5 100644 --- a/extras/imported/ruby-mode/RDoc/yields RDoc comment.yasnippet +++ b/extras/imported/ruby-mode/RDoc/yields RDoc comment.yasnippet @@ -2,6 +2,6 @@ # key: y # contributor: Translated from TextMate Snippet # name: :yields: -## condition: "source.ruby comment" +# condition: (yas/ruby-in-comment-p) # -- - :yields: ${0:arguments} \ No newline at end of file + :yields: ${1:arguments} \ No newline at end of file diff --git a/yasnippet.el b/yasnippet.el index ae7d62e..bb74c32 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -447,13 +447,8 @@ Attention: These hooks are not run when exiting nested/stackd snippet expansion! "Hooks to run just before expanding a snippet.") (defvar yas/buffer-local-condition - '(if (and (not (bobp)) - (or (equal 'font-lock-comment-face - (get-char-property (1- (point)) - 'face)) - (equal 'font-lock-string-face - (get-char-property (1- (point)) - 'face)))) + '(if (or (fourth (syntax-ppss)) + (fifth (syntax-ppss))) '(require-snippet-condition . force-in-comment) t) "Snippet expanding condition. @@ -1052,11 +1047,9 @@ conditions to filter out potential expansions." (symbolp (cdr local-condition)) (cdr local-condition))))))) -(defun yas/template-can-expand-p (condition &optional requirement) +(defun yas/template-can-expand-p (condition requirement) "Evaluates CONDITION and REQUIREMENT and returns a boolean" - (let* ((requirement (or requirement - (yas/require-template-specific-condition-p))) - (result (or (null condition) + (let* ((result (or (null condition) (yas/eval-condition condition)))) (cond ((eq requirement t) result) @@ -1922,11 +1915,19 @@ will only be expanded when the condition evaluated to non-nil." ;;; (defvar yas/condition-cache-timestamp nil) (defmacro yas/define-condition-cache (func doc &rest body) - `(defun ,func () ,(when doc - (concat doc + "Define a function FUNC with doc DOC and body BODY, BODY is +executed at most once every snippet expansion attempt, to check +expansion conditions. + +It doesn't make any sense to call FUNC programatically." + `(defun ,func () ,(if (and doc + (stringp doc)) + (concat doc "\n\nFor use in snippets' conditions. Within each snippet-expansion routine like `yas/expand', computes actual -value for the first time then always returns a cached value.")) +value for the first time then always returns a cached value.") + (setq body (cons doc body)) + nil) (let ((timestamp-and-value (get ',func 'yas/condition-cache))) (if (equal (car timestamp-and-value) yas/condition-cache-timestamp) (cdr timestamp-and-value) @@ -3043,12 +3044,13 @@ will be deleted before inserting template." ;; them mostly to make the undo information ;; (setq yas/start-column (save-restriction (widen) (current-column))) - (insert template) (setq snippet (if expand-env (eval `(let ,expand-env + (insert template) (yas/snippet-create (point-min) (point-max)))) + (insert template) (yas/snippet-create (point-min) (point-max)))))) ;; stacked-expansion: This checks for stacked expansion, save the