From 5d3080dee98538d20b9e3084fffb3a7850276000 Mon Sep 17 00:00:00 2001 From: nverno Date: Mon, 2 Mar 2020 14:30:57 -0500 Subject: [PATCH] extend rg-define-search :format to accept lisp form --- docs/configuration.org | 4 +++- rg.el | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/configuration.org b/docs/configuration.org index 699a780..67308e3 100644 --- a/docs/configuration.org +++ b/docs/configuration.org @@ -464,7 +464,9 @@ prompt the user for a string. Any form that evaluates to a string is allowed. Default is =ask=. - *:format* - Specifies if =:query= is interpreted literally - (=literal=) or as a regexp (=regexp=). Default is =regexp=. + (=literal=) or as a regexp (=regexp=). If it is a form, eg. + =(not current-prefix-arg)=, and is non-nil the =:query= is interpreted + literally, otherwise as a regexp. Default is =regexp=. - *:files* - Form that evaluates to a file alias or custom file glob. =current= means extract alias from current buffer file name, =ask= will prompt the user. Default is =ask=. diff --git a/rg.el b/rg.el index a83e598..9e5e038 100644 --- a/rg.el +++ b/rg.el @@ -554,6 +554,15 @@ the :query option is missing, set it to ASK" (cadr arg) arg))) +(eval-when-compile + ;; parse :format arg, default (non-nil) means to use regexp, otherwise + ;; do a literal search + (defsubst rg-parse-format-literal (format-opt) + (pcase format-opt + ('regexp nil) ; default to regexp search + ('literal t) + (_ format-opt)))) ; otherwise evaluate form + (eval-and-compile (defun rg-search-parse-local-bindings (search-cfg) "Parse local bindings for search functions from SEARCH-CFG." @@ -563,7 +572,7 @@ the :query option is missing, set it to ASK" (alias-opt (plist-get search-cfg :files)) (dir-opt (plist-get search-cfg :dir)) (flags-opt (plist-get search-cfg :flags)) - (binding-list `((literal ,(eq format-opt 'literal))))) + (binding-list `((literal ,(rg-parse-format-literal format-opt))))) ;; confirm binding (cond ((eq confirm-opt 'never) @@ -612,7 +621,7 @@ the :query option is missing, set it to ASK" "Parse interactive args from SEARCH-CFG for search functions." (let* ((query-opt (plist-get search-cfg :query)) (format-opt (plist-get search-cfg :format)) - (literal (eq format-opt 'literal)) + (literal (rg-parse-format-literal format-opt)) (dir-opt (plist-get search-cfg :dir)) (files-opt (plist-get search-cfg :files)) (flags-opt (plist-get search-cfg :flags)) @@ -674,7 +683,9 @@ specified default if left out. evaluates to a string is allowed. Default is `ask'. :format Specifies if :query is interpreted literally (`literal') - or as a regexp (`regexp'). + or as a regexp (`regexp'). If it is a form, eg. + (not `current-prefix-arg'), and is non-nil the :query is + interpreted literally, otherwise as a regexp. Default is `regexp'. :files Form that evaluates to a file alias or custom file glob. `current' means extract alias from current buffer file name,