[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/mheerdegen-preview 5057b57 14/35: WIP [el-search] Discour
From: |
Michael Heerdegen |
Subject: |
[elpa] scratch/mheerdegen-preview 5057b57 14/35: WIP [el-search] Discourage using symbols as LPATS in `append' and `l' |
Date: |
Mon, 29 Oct 2018 22:24:06 -0400 (EDT) |
branch: scratch/mheerdegen-preview
commit 5057b57db4e79eed6c4674132b9bd55163745eba
Author: Michael Heerdegen <address@hidden>
Commit: Michael Heerdegen <address@hidden>
WIP [el-search] Discourage using symbols as LPATS in `append' and `l'
---
packages/el-search/el-search-x.el | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/packages/el-search/el-search-x.el
b/packages/el-search/el-search-x.el
index 03b3acf..30190c1 100644
--- a/packages/el-search/el-search-x.el
+++ b/packages/el-search/el-search-x.el
@@ -88,6 +88,14 @@ nil."
list2 (cons (car last-list1) list2)))))
match))
+(defun el-search-append--error-for-symbols (patterns &optional allowed-symbols)
+ (when-let ((symbol (cl-some (lambda (p) (and (symbolp p)
+ (not (keywordp p))
+ (not (memq p (append (list nil
t '_) allowed-symbols)))
+ p))
+ patterns)))
+ (user-error "Forbidden symbol binding: `%S'" symbol)))
+
(el-search-defpattern append (&rest patterns)
"Matches any list factorable into lists matched by PATTERNS in order.
@@ -97,16 +105,18 @@ equal to the concatenation of L1..Ln. Ln is allowed to be
no
list.
When different ways of matching are possible, it is unspecified
-which one is chosen.
+which one is chosen. There is no backtracking, and trying to
+create symbol bindings in an `append' pattern form is forbidden.
Example: the pattern
- (append '(1 2 3) x (app car-safe 7))
+ (append '(1 2 3) _ (app car-safe 7))
-matches the list (1 2 3 4 5 6 7 8 9), binding `x' to (4 5 6)."
+matches the list (1 2 3 4 5 6 7 8 9)."
(cond
((null patterns) '(pred null))
((equal patterns '(_)) '(pred listp))
+ ((el-search-append--error-for-symbols patterns))
(t
(pcase-let ((`(,pattern . ,more-patterns) patterns))
(cond
@@ -163,11 +173,9 @@ __ Matches any number (including zero) of list
elements.
$ Matches zero elements, but only at the end of a list.
Only allowed as the last of the LPATS.
PAT Anything else is interpreted as a standard pattern and
- matches one list element matched by it. Note: If
- matching PAT binds any symbols, occurrences in any
- following patterns are not turned into equivalence tests;
- the scope of symbol bindings is limited to the PAT
- itself.
+ matches one list element matched by it. Note: Since this
+ pattern type doesn't implement backtracking, binding
+ symbols in a PAT is discouraged.
Example: To match defuns that contain \"hl\" in the defined name
and have at least one mandatory, but also optional arguments, you
@@ -187,6 +195,7 @@ could use this pattern:
(_ (funcall (el-search-heuristic-matcher
(el-search--transform-nontrivial-lpat lpat))
file-name-or-buffer atoms-thunk))))
lpats)))))
+ (unless el-search-lazy-l (el-search-append--error-for-symbols lpats (list
'__ '_ '_? '^ '$)))
(let ((match-start nil) (match-end nil))
(when (eq (car-safe lpats) '^)
(setq match-start t)
- [elpa] scratch/mheerdegen-preview 9805060 02/35: WIP: [el-search] Fix nested match issues in *El Occur*, (continued)
- [elpa] scratch/mheerdegen-preview 9805060 02/35: WIP: [el-search] Fix nested match issues in *El Occur*, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview 220f349 04/35: WIP: Add package "sscell", Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview bef717d 06/35: WIP: New :key arg for "filename" and new pattern types "file" and "dir", Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview d2faca2 09/35: WIP: New command 'el-search-repository', Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview 2f72331 08/35: WIP: New file el-search/el-search-pp.el, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview f2ec15d 13/35: WIP [el-search] Fix more "redundant _ pattern" cases, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview f025458 12/35: WIP [el-search] Add quick help command, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview f23fe5e 17/35: WIP: Optimize caching, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview b4b94b0 11/35: WIP [el-search] Implement 'el-search-keyboard-quit', Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview 44715aa 05/35: WIP: New package "gnus-article-notes", Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview 5057b57 14/35: WIP [el-search] Discourage using symbols as LPATS in `append' and `l',
Michael Heerdegen <=
- [elpa] scratch/mheerdegen-preview 5e2aea1 20/35: WIP [el-search] Adjust prev/next match commands for search and occur, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview 38def8b 25/35: WIP: Test: Make mouse clicks not abort the search, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview feede7d 23/35: WIP: [el-search] Fine tune separator for splicing replace, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview 82abecf 16/35: WIP: Additions to "Mb hints", Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview df2132a 21/35: WIP: Improvements for change and changed, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview 2ec7a9e 22/35: WIP: More colorful match count, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview 91f5bd3 18/35: WIP [el-search] Fix C-j with numeric arg in error case, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview 237c2c6 33/35: WIP: [el-search] Enhance doc of el-search-occur-mode, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview 99782c3 19/35: WIP [el-search] Fix search setup when occur flag bound, Michael Heerdegen, 2018/10/29
- [elpa] scratch/mheerdegen-preview acc2594 24/35: WIP: Improvise eldoc support for search pattern prompt, Michael Heerdegen, 2018/10/29