[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 0f05a75 14/42: Add yas-completing-read
From: |
Noam Postavsky |
Subject: |
[elpa] master 0f05a75 14/42: Add yas-completing-read |
Date: |
Sun, 22 Dec 2019 17:37:58 -0500 (EST) |
branch: master
commit 0f05a7555a5da7f9584cfbe32064c48ed42103b8
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>
Add yas-completing-read
* yasnippet.el (yas-completing-read): New function.
(yas-verify-value): Simplify with `member' instead of `cl-notany'.
* doc/snippet-development.org (Template Syntax): Show
`yas-completing-read' instead of `yas-choose-value' in the example.
---
doc/snippet-development.org | 14 ++++++++------
yasnippet.el | 12 +++++++++++-
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/doc/snippet-development.org b/doc/snippet-development.org
index 1a7ad49..e8c8701 100644
--- a/doc/snippet-development.org
+++ b/doc/snippet-development.org
@@ -412,15 +412,17 @@ the field, and with some useful variables bound, notably
can place a transformation in the primary field that lets you select
default values for it.
-The [[sym:yas-choose-value][=yas-choose-value=]] does this work for you. For
example:
+For example, the [[sym:yas-choose-value][=yas-completing-read=]] function is
version of
+=completing-read= which checks these variables. For example, asking
+the user for the initial value of a field:
#+BEGIN_SRC snippet
- <div align="${2:$$(yas-choose-value '("right" "center" "left"))}">
+ <div align="${2:$$(yas-completing-read "Alignment? " '("right" "center"
"left"))}">
$0
</div>
#+END_SRC
-See the definition of [[sym:yas-choose-value][=yas-choose-value=]] to see how
it was written
+See the definition of [[sym:yas-choose-value][=yas-completing-read=]] to see
how it was written
using the two variables. If you're really lazy :) and can't spare a
tab keypress, you can automatically move to the next field (or exit)
after choosing the value with [[sym:yas-auto-next][=yas-auto-next=]]. The
snippet above
@@ -428,7 +430,8 @@ becomes:
#+BEGIN_SRC snippet
<div align="${2:$$(yas-auto-next
- (yas-choose-value
+ (yas-completing-read
+ "Alignment? "
'("right" "center" "left")))}">
$0
</div>
@@ -440,8 +443,7 @@ enter snippet field 2. This one makes use of
[[sym:yas-modified-p][=yas-modified
#+BEGIN_SRC snippet
\section{${1:"Titel der Tour"}}%
\index{$1}%
- \label{{2:"waiting for reftex-label call..."$(unless yas-modified-p
(reftex-label nil 'dont-
- insert))}}%
+ \label{{2:"waiting for reftex-label call..."$(unless yas-modified-p
(reftex-label nil 'dont-insert))}}%
#+END_SRC
The function [[sym:yas-verify-value][=yas-verify-value=]] has another neat
trick, and makes use
diff --git a/yasnippet.el b/yasnippet.el
index dd8ca98..38b1a93 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -2987,6 +2987,16 @@ The last element of POSSIBILITIES may be a list of
strings."
(funcall fn "Choose: " possibilities))
yas-prompt-functions)))
+(defun yas-completing-read (&rest args)
+ "A snippet-aware version of `completing-read'.
+This can be used to query the user for the initial value of a
+snippet field. The arguments are the same as `completing-read'.
+
+\(fn PROMPT COLLECTION &optional PREDICATE REQUIRE-MATCH INITIAL-INPUT HIST
DEF INHERIT-INPUT-METHOD)"
+ (unless (or yas-moving-away-p
+ yas-modified-p)
+ (apply #'completing-read args)))
+
(defun yas--auto-next ()
"Helper for `yas-auto-next'."
(remove-hook 'post-command-hook #'yas--auto-next t)
@@ -3016,7 +3026,7 @@ The last element of POSSIBILITIES may be a list of
strings."
(defun yas-verify-value (possibilities)
"Verify that the current field value is in POSSIBILITIES.
Otherwise signal `yas-exception'."
- (when (and yas-moving-away-p (cl-notany (lambda (pos) (string= pos
yas-text)) possibilities))
+ (when (and yas-moving-away-p (not (member yas-text possibilities)))
(yas-throw (format "Field only allows %s" possibilities))))
(defun yas-field-value (number)
- [elpa] master 048d030 22/42: Fix line-relative snapshotting for org src blocks, (continued)
- [elpa] master 048d030 22/42: Fix line-relative snapshotting for org src blocks, Noam Postavsky, 2019/12/22
- [elpa] master bae20af 27/42: ; * doc/faq.org: Linkify bug reference., Noam Postavsky, 2019/12/22
- [elpa] master ffc733d 09/42: ; Debug code fixes, Noam Postavsky, 2019/12/22
- [elpa] master 1d96da2 18/42: Don't call before/after change-functions twice, Noam Postavsky, 2019/12/22
- [elpa] master 6a3619b 23/42: Fix additional corner case with org source block integration, Noam Postavsky, 2019/12/22
- [elpa] master 9cedd59 25/42: Allow disabling snippet keybindings from hook, Noam Postavsky, 2019/12/22
- [elpa] master 55c448b 32/42: Remove redundant arg to yas-expand-snippet, Noam Postavsky, 2019/12/22
- [elpa] master 189f737 26/42: * doc/faq.org: Note that Flyspell problem is (now fixed) Emacs bug., Noam Postavsky, 2019/12/22
- [elpa] master ffce236 30/42: Do auto indentation only in post command hook, Noam Postavsky, 2019/12/22
- [elpa] master 760f77a 12/42: Test for mirroring more than one field, Noam Postavsky, 2019/12/22
- [elpa] master 0f05a75 14/42: Add yas-completing-read,
Noam Postavsky <=
- [elpa] master 03aa561 19/42: * doc/snippet-organization.org: Fix typo., Noam Postavsky, 2019/12/22
- [elpa] master 9f51cf2 17/42: Register snippet movement comments for eldoc, Noam Postavsky, 2019/12/22
- [elpa] master 6a738b5 29/42: ; doc/faq.org: Fix example keybinding code., Noam Postavsky, 2019/12/22
- [elpa] master 476bc77 35/42: Fix snippet undo, Noam Postavsky, 2019/12/22
- [elpa] master c432e78 31/42: Fix field adjustment on deletion, Noam Postavsky, 2019/12/22
- [elpa] master f056a4d 33/42: Minor code shuffling and commenting, Noam Postavsky, 2019/12/22
- [elpa] master bd3572a 36/42: Handle multiple uses of yas-auto-next, Noam Postavsky, 2019/12/22
- [elpa] master e45e3de 34/42: * doc/faq.org: yas-prev should be yas-prev-field, Noam Postavsky, 2019/12/22
- [elpa] master a66f15e 38/42: Fix yas-insert-snippet for keyless snippets, Noam Postavsky, 2019/12/22
- [elpa] master d91dd66 37/42: * yasnippet.el (yas--extra-modes): Move alias before def, Noam Postavsky, 2019/12/22