[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/urgrep 98e20f0630 021/115: Use pcase macros for filling
|
From: |
ELPA Syncer |
|
Subject: |
[elpa] externals/urgrep 98e20f0630 021/115: Use pcase macros for filling in optional arguments |
|
Date: |
Wed, 10 May 2023 03:00:39 -0400 (EDT) |
branch: externals/urgrep
commit 98e20f0630dff4d6010e4e37ad63d4dae0ba6828
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Jim Porter <jporterbugs@gmail.com>
Use pcase macros for filling in optional arguments
---
urgrep.el | 72 +++++++++++++++++++++++++++++++--------------------------------
1 file changed, 35 insertions(+), 37 deletions(-)
diff --git a/urgrep.el b/urgrep.el
index 3072e8960e..78965ec16f 100644
--- a/urgrep.el
+++ b/urgrep.el
@@ -81,10 +81,15 @@
;; Urgrep tools
(cl-defun urgrep-rgrep--command (query &key &allow-other-keys)
- ;; XXX: Support literal/regexp and context settings.
+ ;; XXX: Support literal/regexp and context settings. Perhaps let-bind
+ ;; `grep-find-template' to include these options?
(grep-compute-defaults)
(rgrep-default-command query "*" nil))
+(defconst urgrep--context-arguments
+ '(((and (pred integerp) n (guard (> n 0)))
+ (list (format "-C%d" n)))))
+
(defvar urgrep-tools
`(("ripgrep"
(executable-name "rg")
@@ -92,28 +97,28 @@
(pre-arguments ("--color" "always" "--colors" "path:fg:magenta"
"--colors" "match:fg:red" "--colors" "match:style:bold"))
(post-arguments ("--"))
- (group-arguments ((t ("--heading"))
- (nil ("--no-heading"))))
- (regexp-arguments ((nil ("-F"))))
- (context-arguments "-C%d"))
+ (group-arguments (('nil '("--no-heading"))
+ (_ '("--heading"))))
+ (regexp-arguments (('nil '("-F"))))
+ (context-arguments ,urgrep--context-arguments))
("ag"
(executable-name "ag")
(regexp-syntax (pcre))
(pre-arguments ("--color-path" "35" "--color-match" "1;31"))
(post-arguments ("--"))
- (group-arguments ((t ("--group"))
- (nil ("--nogroup"))))
- (regexp-arguments ((nil ("-Q"))))
- (context-arguments "-C%d"))
+ (group-arguments (('nil '("--nogroup"))
+ (_ '("--group"))))
+ (regexp-arguments (('nil '("-Q"))))
+ (context-arguments ,urgrep--context-arguments))
("ack"
(executable-name "ack")
(regexp-syntax (pcre))
(pre-arguments ("--color-filename" "magenta" "--color-match" "bold red"))
(post-arguments ("--"))
- (group-arguments ((t ("--group"))
- (nil ("--nogroup"))))
- (regexp-arguments ((nil ("-Q"))))
- (context-arguments "-C%d"))
+ (group-arguments (('nil '("--nogroup"))
+ (_ '("--group"))))
+ (regexp-arguments (('nil '("-Q"))))
+ (context-arguments ,urgrep--context-arguments))
("git-grep"
(executable-name "git")
(vc-backend "Git")
@@ -122,12 +127,12 @@
"-c" "color.grep.match=bold red" "grep" "--color" "-n"
"--recurse-submodules"))
(post-arguments ("-e"))
- (group-arguments ((t ("--heading" "--break"))))
- (regexp-arguments ((bre ("-G"))
- (ere ("-E"))
- (pcre ("-P"))
- (nil ("-F"))))
- (context-arguments "-C%d"))
+ (group-arguments (('t '("--heading" "--break"))))
+ (regexp-arguments (('bre '("-G"))
+ ('ere '("-E"))
+ ('pcre '("-P"))
+ (_ '("-F"))))
+ (context-arguments ,urgrep--context-arguments))
("grep"
(executable-name "grep")
(command-function ,#'urgrep-rgrep--command)))
@@ -138,11 +143,11 @@
(when-let ((prop-entry (assoc prop (cdr tool))))
(cadr prop-entry)))
-(defun urgrep-get-property-assoc (tool prop key)
- "Get a given property PROP from TOOL, selecting a KEY from the alist value."
- (when-let ((prop-value (urgrep-get-property tool prop))
- (assoc-value (assoc key prop-value)))
- (cadr assoc-value)))
+(defun urgrep-get-property-pcase (tool prop value)
+ "Get a given property PROP from TOOL and use it as a `pcase' macro for
VALUE."
+ (when-let ((cases (urgrep-get-property tool prop))
+ (block (append `(,#'pcase ',value) cases)))
+ (eval block t)))
(defun urgrep-get-tool ()
"Get the preferred urgrep tool from `urgrep-tools'."
@@ -200,19 +205,12 @@ for MS shells."
(executable (urgrep-get-property tool 'executable-name))
(pre-args (or (urgrep-get-property tool 'pre-arguments) '()))
(arguments (or (urgrep-get-property tool 'post-arguments) '())))
- ;; Fill in group arguments. XXX: Maybe figure out a more flexible way to
- ;; do this?
- (when-let ((x (urgrep-get-property-assoc tool 'group-arguments group)))
- (setq arguments (append x arguments)))
- ;; Fill in regexp/literal arguments.
- (when-let ((x (urgrep-get-property-assoc tool 'regexp-arguments
- tool-re-syntax)))
- (setq arguments (append x arguments)))
- ;; Fill in context arguments.
- (when-let (((> context 0))
- (prop (urgrep-get-property tool 'context-arguments))
- (context-arg (format prop context)))
- (setq arguments (append (list context-arg) arguments)))
+ ;; Fill in various options according to the tool's argument syntax.
+ (dolist (i `((group-arguments . ,group)
+ (regexp-arguments . ,tool-re-syntax)
+ (context-arguments . ,context)))
+ (when-let ((args (urgrep-get-property-pcase tool (car i) (cdr i))))
+ (setq arguments (append args arguments))))
;; FIXME: Inside compile and dired buffers, `shell-quote-argument'
;; doesn't handle TRAMP right...
(mapconcat #'urgrep--maybe-shell-quote-argument
- [elpa] externals/urgrep d93a565190 060/115: Simplify implementation of 'urgrep', (continued)
- [elpa] externals/urgrep d93a565190 060/115: Simplify implementation of 'urgrep', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 0270e11849 072/115: Allow directory for `urgrep' and `urgrep-run-command' to be relative, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 86e7055ce5 063/115: Typo, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 5aabe4ffa9 066/115: Remove debug code, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 7fd67f1db5 092/115: Run CI against Emacs 28.2, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 2ef7daa448 093/115: Reorganize tests a bit, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 500c01092d 086/115: Fix display override for null character in context lines, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 229ae0bfb5 110/115: Use a version identifier compatible with 'version-to-string', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 6aefc895bc 113/115: Set system-type to gnu/linux when making the Urgrep command for Eshell, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 83e62357da 018/115: Provide a friendly default value when searching, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 98e20f0630 021/115: Use pcase macros for filling in optional arguments,
ELPA Syncer <=
- [elpa] externals/urgrep bf24dac2ac 025/115: Allow for separate before/after contexts, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep f2ba643f35 028/115: Typo, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep c26ff9b22b 029/115: Add note about grep issues on MS Windows, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 6f50ef99d3 032/115: Remove urgrep--to-command, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 3599ad1a56 033/115: Update comment, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep ba2b01b91b 042/115: Remove no-longer-needed `post-arguments', ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 3643c933c4 055/115: Add support for ugrep, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 0de93bfdb9 068/115: Fix use of wgrep on long urgrep results, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep e2e8898ab2 074/115: Update copyright, ELPA Syncer, 2023/05/10
- [elpa] externals/urgrep 0c966b2001 075/115: Ensure `default-directory' stays in sync, ELPA Syncer, 2023/05/10