]> code.delx.au - gnu-emacs-elpa/commitdiff
counsel.el (counsel-locate-options): Make obsolete
authorOleh Krehel <ohwoeowho@gmail.com>
Fri, 19 Feb 2016 14:29:36 +0000 (15:29 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Fri, 19 Feb 2016 14:43:50 +0000 (15:43 +0100)
* 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

index d3897d7fa32ef649b1d14358d59e1a89cf732985..83eca7a04dedfcdad9cfe3b4962863c4859b392f 100644 (file)
@@ -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