Comments (8)
Could you clarify what "better syntax" you're thinking of?
from yasnippet.
Just a repeat directive. Maybe a repeat hook (or just a function) could be implemented to run before yas-after-exit-snippet-hook
, repeating the snippet by name a number of times or indefinitely until the prefix argument is used.
# -*- mode: snippet -*-
# name:parameters
# key: p
# repeat: t (or a number)
# --
"$1, "
from yasnippet.
from yasnippet.
The left-over comma could be handled with the regular yas-after-exit-snippet-hook
.
The example is just a basic demonstration of the functionality, a more practical one would be a bunch of json fields. Other examples: css rules, html tags like list items, case statements. It is easier to just type without having to write and expand each snippet.
One could have a regular snippet and the repeatable version and use the more convenient one for each use case.
# -*- mode: snippet -*-
# name:json-fields
# key: jf
# repeat: t (or a number)
# --
"$1 ": $2,
from yasnippet.
from yasnippet.
That's not very satisfactory.
Yes I agree, but using yas-after-exit-snippet-hook
seems like the right thing to do (cleanup work after exiting the snippet), maybe there is another way I'm not familiar with.
Some alternatives: maybe a directive for yas-after-exit-snippet-hook
, or maybe a different hook that runs on a per snippet basis.
This suggests that instead of having the "repeat" be a property of the
template, maybe we should have a command to repeat a(ny) template.
This seems like a better solution than the initial proposal.
I looked for a "last snippet" variable in the yanippet code and could not find it. I think a possible implementation would be just adding it.
(defvar yas-last-snippet nil)
(make-variable-buffer-local 'yas-last-snippet)
(defun yas-expand-snippet (snippet &optional start end expand-env)
;;; omited code
(let ((content (if (yas--template-p snippet)
(yas--template-content snippet)
snippet)))
(setq yas-last-snippet snippet)
)
(defun my/expand-last-snippet ()
(interactive)
(yas-expand-snippet yas-last-snippet))
from yasnippet.
from yasnippet.
[ You can use
defvar-local
instead. ]
Thanks I was not aware of this.
But for the user that requires hitting a key for each repetition,
whereas your current approach requires hitting a key only for the
last repetition.
I don't think that this would be a problem for most snippets. It is probably a bit annoying for simple snippets with one or two fields but would otherwise work fine.
How do you start your repeated template?
In my approach I just use tab (or whatever yas-next-field is), using tab in the last field repeats the snippet.
The problem is how to stop repeating the snippet, I use the prefix argument C-u which is kind of cumbersome, I tried yas-abort-snippet
but it does not work, I believe it uses the exit hook.
Maybe we can provide a new command
yas-expand-repeatedly
?
Great!, I think this probably the best solution, and it would allow snippets already created to be repeatable.
I still think the previous expand-last command is useful for a different use case.
from yasnippet.
Related Issues (20)
- please tag new release for Emacs 29 compat (affects MELPA stable and others) HOT 7
- Tests failing under Emacs 29+ HOT 13
- unwanted prompt when pressing TAB HOT 1
- self-defined function `expand-from-key-p`(which check current expanding come from key or binding) not work anymore after update to newest master. HOT 3
- update latex snippets for use with text selection
- Documentation webage 404s HOT 1
- yas--all-parents can fail to find all parents if called before snippet directory is loaded HOT 5
- Some functions don't work in yasnippet HOT 3
- Multi-line embedded lisp-code HOT 7
- Template variables do not work in template lines starting with # HOT 3
- delete-numberless-inner-snippet-issue-562 test failure (non-deterministic) HOT 6
- Error in condition evaluation: Symbol’s function definition is void: js2-node-type HOT 3
- elpy-snippet-init-assignments - "Symbol’s value as variable is void: start-point" HOT 1
- Suggestion: not preceded by space HOT 4
- special character
- elisp evaluation move cursor on new line
- elisp evaluation move cursor on new line in snippet body
- Case sensitive major modes? HOT 1
- [FR/Q] How do I comment a line of the snippet from being included in the snippet? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yasnippet.