[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/mheerdegen-preview ffd1bb1 13/33: WIP [el-search] Discour
From: |
Michael Heerdegen |
Subject: |
[elpa] scratch/mheerdegen-preview ffd1bb1 13/33: WIP [el-search] Discourage using symbols as LPATS in `append' and `l' |
Date: |
Wed, 24 Oct 2018 18:30:50 -0400 (EDT) |
branch: scratch/mheerdegen-preview
commit ffd1bb117d0b5a5c08beb24bba773b6e1ceb0804
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 c88c4c1 27/33: WIP: Include leading comments in occur defun context, (continued)
- [elpa] scratch/mheerdegen-preview c88c4c1 27/33: WIP: Include leading comments in occur defun context, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 3f656ab 11/33: WIP [el-search] Add quick help command, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 2d15aa7 22/33: WIP: [el-search] Fine tune separator for splicing replace, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 9cfe823 32/33: WIP: [el-search] Enhance doc of el-search-occur-mode, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview d774bfe 24/33: WIP: Test: Make mouse clicks not abort the search, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 1020ca9 16/33: WIP: Optimize caching, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview fadf6f9 05/33: WIP: New :key arg for "filename" and new pattern types "file" and "dir", Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 1fcb333 03/33: WIP: Add package "sscell", Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 35be4f8 12/33: WIP [el-search] Fix more "redundant _ pattern" cases, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview fa8dbb8 07/33: WIP: New file el-search/el-search-pp.el, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview ffd1bb1 13/33: WIP [el-search] Discourage using symbols as LPATS in `append' and `l',
Michael Heerdegen <=
- [elpa] scratch/mheerdegen-preview aca1cea 10/33: WIP [el-search] Implement 'el-search-keyboard-quit', Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 9773b43 18/33: WIP [el-search] Fix search setup when occur flag bound, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 35edf10 23/33: WIP: Improvise eldoc support for search pattern prompt, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 08e0d20 15/33: WIP: Additions to "Mb hints", Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 60fd31c 19/33: WIP [el-search] Adjust prev/next match commands for search and occur, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview fb5a73b 30/33: WIP: Small fix in 'el-search--reset-wrap-flag', Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 86f4f18 17/33: WIP [el-search] Fix C-j with numeric arg in error case, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 1d22a6c 14/33: WIP [el-search] Minibuffer hints when entering pattern, Fix case when search pattern fails for some sexps, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 0e37f94 28/33: WIP: Add alarm-clock.el, Michael Heerdegen, 2018/10/24
- [elpa] scratch/mheerdegen-preview 6a048a7 26/33: WIP: Don't initially fold occur buffer, Michael Heerdegen, 2018/10/24