If nil, the value of `case-fold-search' is decisive."
:type 'boolean)
+(defcustom el-search-use-sloppy-strings nil
+ "Whether to allow the usage of \"sloppy strings\".
+When this option is turned on, for faster typing you are allowed
+to specify symbols instead of strings as arguments to an
+\"el-search\" pattern type that would otherwise accept only
+strings, and their names will be used as input (with other words,
+this spares you to type the string delimiters in many cases).
+
+For example,
+
+ \(source ^cl\)
+
+is then equivalent to
+
+ \(source \"^cl\"\)
+
+When this option is off, the first form would just signal an
+error."
+ :type 'boolean)
+
;;;; Helpers
`(setf (alist-get ',name el-search--pcase-macros)
(lambda ,args ,@body)))
+(defun el-search--macroexpand-1 (pattern)
+ "Expand \"el-search\" PATTERN.
+This is like `pcase--macroexpand', but expands only patterns
+defined with `el-search-defpattern' and performs only one
+expansion step.
+
+Return PATTERN if this pattern type was not defined with
+`el-search-defpattern'."
+ (if-let ((expander (alist-get (car-safe pattern) el-search--pcase-macros)))
+ (apply expander (cdr pattern))
+ pattern))
(defmacro el-search--with-additional-pcase-macros (&rest body)
`(cl-letf ,(mapcar (pcase-lambda (`(,symbol . ,fun))
(,'\, ,(car more-patterns)))))))
(t `(append ,pattern (append ,@more-patterns)))))))
+(defun el-search--stringish-p (thing)
+ (or (stringp thing) (and el-search-use-sloppy-strings (symbolp thing))))
+
(el-search-defpattern string (&rest regexps)
"Matches any string that is matched by all REGEXPS."
- (el-search--check-pattern-args 'string regexps #'stringp)
- (let ((string (make-symbol "string"))
- (regexp (make-symbol "regexp")))
- `(and (pred stringp)
- (pred (lambda (,string)
- (cl-every
- (lambda (,regexp) (el-search--smart-string-match-p ,regexp ,string))
- ',regexps))))))
+ (el-search--check-pattern-args 'string regexps #'el-search--stringish-p
+ "Argument not a string")
+ `(and (pred stringp)
+ ,@(mapcar (lambda (thing) `(pred (el-search--smart-string-match-p
+ ,(if (symbolp thing) (symbol-name thing) thing))))
+ regexps)))
(el-search-defpattern symbol (&rest regexps)
"Matches any symbol whose name is matched by all REGEXPS."
- (el-search--check-pattern-args 'symbol regexps #'stringp)
+ (el-search--check-pattern-args 'symbol regexps #'el-search--stringish-p
+ "Argument not a string")
`(and (pred symbolp)
(app symbol-name (string ,@regexps))))
(concat \"^\" (symbol-name regexp) \"$\")
is used as regular expression."
- (el-search--check-pattern-args 'source (list regexp) #'stringp)
- `(pred (el-search--match-symbol-file ,regexp)))
+ (el-search--check-pattern-args 'source (list regexp) #'el-search--stringish-p
+ "Argument not a string")
+ `(pred (el-search--match-symbol-file ,(if (symbolp regexp) (symbol-name regexp) regexp))))
(defun el-search--match-key-sequence (keys expr)
(when-let ((expr-keys (pcase expr