emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ivy-hydra c76d797 370/395: Clean up some stuff around c


From: Basil L. Contovounesios
Subject: [elpa] externals/ivy-hydra c76d797 370/395: Clean up some stuff around counsel-locate
Date: Thu, 25 Feb 2021 08:32:40 -0500 (EST)

branch: externals/ivy-hydra
commit c76d79715f8bb3dd6308e4d2538c8fde149d28d4
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>

    Clean up some stuff around counsel-locate
    
    * counsel.el (counsel-require-program): Simplify and correct with
    string-prefix-p.
    (counsel-locate-cmd): Allow custom function values.
    (counsel-locate-cmd-default, counsel-locate-cmd-noregex)
    (counsel-locate-cmd-mdfind): Use shell-quote-argument.
    (counsel-locate-cmd-es): Localize defvar declaration.
    (counsel-locate-function, counsel-locate): Clarify docstring.
    (counsel-file-stale-p): Simplify.
    
    Re: #2766.
---
 counsel.el | 50 ++++++++++++++++++++++++--------------------------
 1 file changed, 24 insertions(+), 26 deletions(-)

diff --git a/counsel.el b/counsel.el
index 51c283e..5094be2 100644
--- a/counsel.el
+++ b/counsel.el
@@ -126,7 +126,7 @@ complex regexes."
   "Check system for program used in CMD, printing error if not found.
 CMD is either a string or a list of strings.
 To skip the `executable-find' check, start the string with a space."
-  (unless (and (stringp cmd) (string-match-p "^ " cmd))
+  (unless (and (stringp cmd) (string-prefix-p " " cmd))
     (let ((program (if (listp cmd)
                        (car cmd)
                      (car (split-string cmd)))))
@@ -2542,13 +2542,13 @@ can use `C-x r j i' to open that file."
 
 ;;** `counsel-locate'
 (defcustom counsel-locate-cmd (cond ((memq system-type '(darwin berkeley-unix))
-                                     'counsel-locate-cmd-noregex)
+                                     #'counsel-locate-cmd-noregex)
                                     ((and (eq system-type 'windows-nt)
                                           (executable-find "es.exe"))
-                                     'counsel-locate-cmd-es)
+                                     #'counsel-locate-cmd-es)
                                     (t
-                                     'counsel-locate-cmd-default))
-  "The function for producing a locate command string from the input.
+                                     #'counsel-locate-cmd-default))
+  "The function for producing a `locate' command string from the input.
 
 The function takes a string - the current input, and returns a
 string - the full shell command to run."
@@ -2556,7 +2556,8 @@ string - the full shell command to run."
           (const :tag "Default" counsel-locate-cmd-default)
           (const :tag "No regex" counsel-locate-cmd-noregex)
           (const :tag "mdfind" counsel-locate-cmd-mdfind)
-          (const :tag "everything" counsel-locate-cmd-es)))
+          (const :tag "everything" counsel-locate-cmd-es)
+          (function :tag "Custom")))
 
 (ivy-set-actions
  'counsel-locate
@@ -2591,33 +2592,33 @@ string - the full shell command to run."
   (dired-jump nil x))
 
 (defun counsel-locate-cmd-default (input)
-  "Return a shell command based on INPUT."
+  "Return a `locate' shell command based on regexp INPUT."
   (counsel-require-program "locate")
-  (format "locate -i --regex '%s'"
-          (counsel--elisp-to-pcre
-           (ivy--regex input))))
+  (format "locate -i --regex %s"
+          (shell-quote-argument
+           (counsel--elisp-to-pcre
+            (ivy--regex input)))))
 
 (defun counsel-locate-cmd-noregex (input)
-  "Return a shell command based on INPUT."
+  "Return a `locate' shell command based on INPUT."
   (counsel-require-program "locate")
-  (format "locate -i '%s'" input))
+  (format "locate -i %s" (shell-quote-argument input)))
 
 (defun counsel-locate-cmd-mdfind (input)
-  "Return a shell command based on INPUT."
+  "Return a `mdfind' shell command based on INPUT."
   (counsel-require-program "mdfind")
-  (format "mdfind -name '%s'" input))
-
-(defvar w32-ansi-code-page)
+  (format "mdfind -name %s" (shell-quote-argument input)))
 
 (defun counsel-locate-cmd-es (input)
-  "Return a shell command based on INPUT."
+  "Return a `es' shell command based on INPUT."
+  (defvar w32-ansi-code-page)
   (counsel-require-program "es.exe")
   (let ((raw-string (format "es.exe -i -p -r %s"
                             (counsel--elisp-to-pcre
                              (ivy--regex input t)))))
-    ;; W32 don't use Unicode by default, so we encode search command
-    ;; to local codepage to support searching filename contains non-ASCII
-    ;; characters.
+    ;; W32 doesn't use Unicode by default, so we encode search command
+    ;; to local codepage to support searching file names containing
+    ;; non-ASCII characters.
     (if (and (eq system-type 'windows-nt)
              (boundp 'w32-ansi-code-page))
         (encode-coding-string raw-string
@@ -2625,7 +2626,7 @@ string - the full shell command to run."
       raw-string)))
 
 (defun counsel-locate-function (input)
-  "Call the \"locate\" shell command with INPUT."
+  "Call a \"locate\" style shell command with INPUT."
   (or
    (ivy-more-chars)
    (progn
@@ -2639,10 +2640,7 @@ string - the full shell command to run."
 
 (defun counsel-file-stale-p (fname seconds)
   "Return non-nil if FNAME was modified more than SECONDS ago."
-  (> (time-to-seconds
-      (time-subtract
-       (current-time)
-       (nth 5 (file-attributes fname))))
+  (> (float-time (time-subtract nil (nth 5 (file-attributes fname))))
      seconds))
 
 (defun counsel--locate-updatedb ()
@@ -2657,7 +2655,7 @@ string - the full shell command to run."
 
 ;;;###autoload
 (defun counsel-locate (&optional initial-input)
-  "Call the \"locate\" shell command.
+  "Call a \"locate\" style shell command.
 INITIAL-INPUT can be given as the initial minibuffer input."
   (interactive)
   (counsel--locate-updatedb)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]