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

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

[elpa] master a50f668 111/272: counsel.el (counsel-locate-options): Make


From: Oleh Krehel
Subject: [elpa] master a50f668 111/272: counsel.el (counsel-locate-options): Make obsolete
Date: Mon, 25 Apr 2016 10:13:20 +0000

branch: master
commit a50f668af9a70049c54b6c85683f375d64dfb3bb
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    counsel.el (counsel-locate-options): Make obsolete
    
    * counsel.el (counsel-locate-cmd): New defcustom that replaces
      `counsel-locate-options'.
    (counsel-locate-cmd-default): New defun. Corresponds to the default
    value of `counsel-locate-options' on linux.
    (counsel-locate-cmd-noregex): New defun. Corresponds to the default
    value of `counsel-locate-options' on darwin.
    (counsel-locate-function): Use `counsel-locate-cmd'.
    
    Fixes #385
---
 counsel.el |   63 +++++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 41 insertions(+), 22 deletions(-)

diff --git a/counsel.el b/counsel.el
index d3897d7..83eca7a 100644
--- a/counsel.el
+++ b/counsel.el
@@ -978,6 +978,33 @@ Update the minibuffer with the amount of lines collected 
every
       (delete-process process))))
 
 ;;* `counsel-locate'
+(defcustom counsel-locate-options nil
+  "Command line options for `locate`."
+  :group 'ivy
+  :type '(repeat string))
+
+(make-obsolete-variable 'counsel-locate-options 'counsel-locate-cmd "0.7.0")
+
+(defcustom counsel-locate-cmd (if (eq system-type 'darwin)
+                                  'counsel-locate-cmd-noregex
+                                '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."
+  :group 'ivy
+  :type '(choice
+          (const :tag "Default" counsel-locate-cmd-default)
+          (const :tag "No regex" counsel-locate-cmd-noregex)))
+
+(ivy-set-actions
+ 'counsel-locate
+ '(("x" counsel-locate-action-extern "xdg-open")
+   ("d" counsel-locate-action-dired "dired")))
+
+(defvar counsel-locate-history nil
+  "History for `counsel-locate'.")
+
 (defun counsel-locate-action-extern (x)
   "Use xdg-open shell command on X."
   (call-process shell-file-name nil
@@ -985,39 +1012,31 @@ Update the minibuffer with the amount of lines collected 
every
                 shell-command-switch
                 (format "%s %s"
                         (if (eq system-type 'darwin)
-                                    "open"
-                                  "xdg-open")
+                            "open"
+                          "xdg-open")
                         (shell-quote-argument x))))
 
 (declare-function dired-jump "dired-x")
+
 (defun counsel-locate-action-dired (x)
   "Use `dired-jump' on X."
   (dired-jump nil x))
 
-(defvar counsel-locate-history nil
-  "History for `counsel-locate'.")
-
-(defcustom counsel-locate-options (if (eq system-type 'darwin)
-                                      '("-i")
-                                    '("-i" "--regex"))
-  "Command line options for `locate`."
-  :group 'ivy
-  :type  '(repeat string))
-
-(ivy-set-actions
- 'counsel-locate
- '(("x" counsel-locate-action-extern "xdg-open")
-   ("d" counsel-locate-action-dired "dired")))
+(defun counsel-locate-cmd-default (input)
+  "Return a shell command based on INPUT."
+  (format "locate -i --regex '%s'"
+          (counsel-unquote-regex-parens
+           (ivy--regex input))))
 
+(defun counsel-locate-cmd-noregex (input)
+  "Return a shell command based on INPUT."
+  (format "locate -i '%s'" input))
 
-(defun counsel-locate-function (str)
-  (if (< (length str) 3)
+(defun counsel-locate-function (input)
+  (if (< (length input) 3)
       (counsel-more-chars 3)
     (counsel--async-command
-     (format "locate %s '%s'"
-             (mapconcat #'identity counsel-locate-options " ")
-             (counsel-unquote-regex-parens
-              (ivy--regex str))))
+     (funcall counsel-locate-cmd input))
     '("" "working...")))
 
 ;;;###autoload



reply via email to

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