[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4f37afd 27/63: Let snippets expand in strings/comments by
From: |
Noam Postavsky |
Subject: |
[elpa] master 4f37afd 27/63: Let snippets expand in strings/comments by default |
Date: |
Mon, 17 Jul 2017 22:54:14 -0400 (EDT) |
branch: master
commit 4f37afd4936dfdc775c698ad6faf6b0308e48251
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
Let snippets expand in strings/comments by default
* yasnippet.el (yas-buffer-local-condition): Change default to t.
* doc/snippet-expansion.org: Update documentation.
---
doc/snippet-expansion.org | 35 ++++++++++++++++-------------------
yasnippet.el | 15 ++-------------
2 files changed, 18 insertions(+), 32 deletions(-)
diff --git a/doc/snippet-expansion.org b/doc/snippet-expansion.org
index 808a888..9b9f45b 100644
--- a/doc/snippet-expansion.org
+++ b/doc/snippet-expansion.org
@@ -178,32 +178,29 @@ In particular, the following things matter:
(yas-activate-extra-mode 'rails-mode)))
#+END_SRC
-- Buffer-local
- [[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]]
- variable
+- Buffer-local
[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]] variable
This variable provides finer grained control over what snippets can
- be expanded in the current buffer. The default value won't let you
- expand snippets inside comments or string literals for example. See
- The condition system\_ for more info.
+ be expanded in the current buffer. You could disable snippet
+ expansion inside comments or string literals for example. See
[[condition-system][the
+ condition system]] for more info.
-** The condition system
+** The condition system <<condition-system>>
Consider this scenario: you are an old Emacs hacker. You like the
abbrev-way and bind [[sym:yas-expand][=yas-expand=]] to =SPC=. However, you
don't want
=if= to be expanded as a snippet when you are typing in a comment
block or a string (e.g. in =python-mode=).
-If you use the =# condition := directive (see
-[[./snippet-development.org][Writing Snippets]]) you could just specify
-the condition for =if= to be =(not (python-syntax-comment-or-string-p))=. But
how
-about =while=, =for=, etc. ? Writing the same condition for all the
-snippets is just boring. So has a buffer local variable
-[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]]. You can set
this variable to
-=(not (python-syntax-comment-or-string-p))= in =python-mode-hook=.
+If you use the =# condition := directive (see
[[./snippet-development.org][Writing Snippets]]) you
+could just specify the condition for =if= to be =(not
+(python-syntax-comment-or-string-p))=. But how about =while=, =for=,
+etc? Writing the same condition for all the snippets is just boring.
+So you can instead set
[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]] to =(not
+(python-syntax-comment-or-string-p))= in =python-mode-hook=.
Then, what if you really want some particular snippet to expand even
-inside a comment? Set
[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]] like this
+inside a comment? Set
[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]] like this
#+BEGIN_SRC emacs-lisp
(add-hook 'python-mode-hook
@@ -214,10 +211,10 @@ inside a comment? Set
[[sym:yas-buffer-local-condition][=yas-buffer-local-condit
t))))
#+END_SRC
-... and specify the condition for a snippet that you're going to expand
-in comment to be evaluated to the symbol =force-in-comment=. Then it can
-be expanded as you expected, while other snippets like =if= still can't
-expanded in comment.
+... and for a snippet that you want to expand in comments, specify a
+condition which evaluates to the symbol =force-in-comment=. Then it
+can be expanded as you expected, while other snippets like =if= still
+can't expanded in comments.
For the full set of possible conditions, see the documentation for
[[sym:yas-buffer-local-condition][=yas-buffer-local-condition=]].
diff --git a/yasnippet.el b/yasnippet.el
index 715dce6..933f4ac 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -456,13 +456,7 @@ Attention: These hooks are not run when exiting
nested/stacked snippet expansion
'()
"Hooks to run just before expanding a snippet.")
-(defvar yas-buffer-local-condition
- '(if (and (let ((ppss (syntax-ppss)))
- (or (nth 3 ppss) (nth 4 ppss)))
- (memq this-command '(yas-expand yas-expand-from-trigger-key
- yas-expand-from-keymap)))
- '(require-snippet-condition . force-in-comment)
- t)
+(defvar yas-buffer-local-condition t
"Snippet expanding condition.
This variable is a Lisp form which is evaluated every time a
@@ -509,12 +503,7 @@ conditions.
(setq yas-buffer-local-condition
\\='(if (python-syntax-comment-or-string-p)
\\='(require-snippet-condition . force-in-comment)
- t))))
-
-The default value is similar, it filters out potential snippet
-expansions inside comments and string literals, unless the
-snippet itself contains a condition that returns the symbol
-`force-in-comment'.")
+ t))))")
;;; Internal variables
- [elpa] master 7b3c29d 13/63: * doc/faq.org: Typos and grammar., (continued)
- [elpa] master 7b3c29d 13/63: * doc/faq.org: Typos and grammar., Noam Postavsky, 2017/07/17
- [elpa] master 14819c9 28/63: Make yas-buffer-local-condition into a defcustom, Noam Postavsky, 2017/07/17
- [elpa] master f3d0e03 25/63: * yasnippet-tests.el (snippet-exit-hooks): New test., Noam Postavsky, 2017/07/17
- [elpa] master 4ee3835 08/63: Use expand-env for all snippet evaluations, Noam Postavsky, 2017/07/17
- [elpa] master 203df22 22/63: Use debug-on-error to simplify error handling, Noam Postavsky, 2017/07/17
- [elpa] master 9c9547a 21/63: Don't catch and rethrow yas-{-}exception, Noam Postavsky, 2017/07/17
- [elpa] master e878afb 12/63: Update handling of markers during indentation, Noam Postavsky, 2017/07/17
- [elpa] master 6c4fbb2 24/63: Fix snippet local exit hook, Noam Postavsky, 2017/07/17
- [elpa] master d0c6fec 16/63: Refactor snippet marker manipulating functions, Noam Postavsky, 2017/07/17
- [elpa] master e74f00e 18/63: Fix whitespace lossage between mirrors, Noam Postavsky, 2017/07/17
- [elpa] master 4f37afd 27/63: Let snippets expand in strings/comments by default,
Noam Postavsky <=
- [elpa] master cddb826 29/63: Merge: let snippets expand in strings/comments by default, Noam Postavsky, 2017/07/17
- [elpa] master 462f566 44/63: Don't leave unreadable objects in the undo list, Noam Postavsky, 2017/07/17
- [elpa] master 3949421 41/63: Fix problems with auto-fill-mode interaction, Noam Postavsky, 2017/07/17
- [elpa] master 0d9afb2 31/63: Fix mirror transformation error with expand-env, Noam Postavsky, 2017/07/17
- [elpa] master b4d2f9c 37/63: Update snippets submodule, Noam Postavsky, 2017/07/17
- [elpa] master c5fddf8 34/63: Restore syntax-propertize-function before indenting snippet, Noam Postavsky, 2017/07/17
- [elpa] master 5043a96 38/63: Correctly wrap auto-fill-function when it's toggled on later, Noam Postavsky, 2017/07/17
- [elpa] master 30913fd 35/63: Only update live snippets, Noam Postavsky, 2017/07/17
- [elpa] master 0f6d82f 46/63: * .travis.yml: Use Emacs 25.2, Noam Postavsky, 2017/07/17
- [elpa] master 6102ff5 50/63: Handle undo of snippet 1st line indent properly, Noam Postavsky, 2017/07/17