]> code.delx.au - gnu-emacs-elpa/commitdiff
ivy.el (ivy-case-fold-search): New defvar
authorOleh Krehel <ohwoeowho@gmail.com>
Sat, 10 Oct 2015 11:09:24 +0000 (13:09 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Sat, 10 Oct 2015 11:09:24 +0000 (13:09 +0200)
* ivy.el (ivy--reset-state): Set `ivy-case-fold-search' to 'auto.
(ivy-toggle-case-fold): New command.
(ivy--filter): Use `ivy-case-fold-search' to determine `case-fold-search'.

* ivy-hydra.el (hydra-ivy): Bind "C" to `ivy-toggle-case-fold'.

Fixes #259

ivy-hydra.el
ivy.el

index 51b4c1aa7bf0426d59825d2f3d6e3cebcd365a0b..19deabb47393be7904a2d2eb896c0ee00eb2dd6d 100644 (file)
                    (byte-compile-file (buffer-file-name) t)))
              (error "Please install `hydra' and recompile/reinstall `ivy-hydra'")))))))
 
+(defun ivy--matcher-desc ()
+  (if (eq ivy--regex-function
+          'ivy--regex-fuzzy)
+      "fuzzy"
+    "ivy"))
+
 (defhydra hydra-ivy (:hint nil
                      :color pink)
   "
-^^^^^^          ^Yes^     ^No^     ^Maybe^            ^Action^
-^^^^^^^^^^^^^^---------------------------------------------------------------
-^ ^ _k_ ^ ^     _f_ollow  _i_nsert _c_: calling %-3s(if ivy-calling \"on\" \"off\")   _w_/_s_/_a_: %-14s(ivy-action-name)
-_h_ ^+^ _l_     _d_one    _o_ops   _m_: matcher %-27s(if (eq ivy--regex-function 'ivy--regex-fuzzy) \"fuzzy\" \"ivy\")
-^ ^ _j_ ^ ^     _g_o      ^ ^      _<_/_>_: shrink/grow _t_runcate: %-11`truncate-lines
+^^^^^^          ^Yes^     ^No^     ^Maybe^            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Action^               ^
+^^^^^^^^^^^^^^----------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------------
+^ ^ _k_ ^ ^     _f_ollow  _i_nsert _c_: calling %-5s(if ivy-calling \"on\" \"off\") _w_/_s_/_a_: %-14s(ivy-action-name)
+_h_ ^+^ _l_     _d_one    _o_ops   _m_: matcher %-5s(ivy--matcher-desc)^^^^^^^^^^^^ _C_ase-fold: %-10`ivy-case-fold-search
+^ ^ _j_ ^ ^     _g_o      ^ ^      _<_/_>_: shrink/grow^^^^^^^^^^^^^^^^^^^^^^^^^^^^ _t_runcate: %-11`truncate-lines
 "
   ;; arrows
   ("h" ivy-beginning-of-buffer)
@@ -75,7 +81,8 @@ _h_ ^+^ _l_     _d_one    _o_ops   _m_: matcher %-27s(if (eq ivy--regex-function
   ("w" ivy-prev-action)
   ("s" ivy-next-action)
   ("a" ivy-read-action)
-  ("t" (setq truncate-lines (not truncate-lines))))
+  ("t" (setq truncate-lines (not truncate-lines)))
+  ("C" ivy-toggle-case-fold))
 
 (provide 'ivy-hydra)
 
diff --git a/ivy.el b/ivy.el
index 71d80cda90f0108ba8b53bc9401cbe1b4ed8ff95..98f8eab7efb36134300b3585c7113d1e1e62dde0 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -252,6 +252,9 @@ When non-nil, it should contain one %d.")
 (defvar ivy--old-text ""
   "Store old `ivy-text' for dynamic completion.")
 
+(defvar ivy-case-fold-search 'auto
+  "Store the current overriding `case-fold-search'.")
+
 (defvar Info-current-file)
 
 (defmacro ivy-quit-and-run (&rest body)
@@ -1028,6 +1031,7 @@ This is useful for recursive `ivy-read'."
       (setq initial-input (cdr (assoc this-command
                                       ivy-initial-inputs-alist))))
     (setq ivy--directory nil)
+    (setq ivy-case-fold-search 'auto)
     (setq ivy--regex-function
           (or re-builder
               (and (functionp collection)
@@ -1558,6 +1562,22 @@ all of the text contained in the minibuffer."
 (eval-after-load 'flx
   '(setq ivy--flx-cache (flx-make-string-cache)))
 
+(defun ivy-toggle-case-fold ()
+  "Toggle the case folding between nil and auto.
+In any completion session, the case folding starts in auto:
+
+- when the input is all lower case, `case-fold-search' is t
+- otherwise it's nil.
+
+You can toggle this to make `case-fold-search' nil regardless of input."
+  (interactive)
+  (setq ivy-case-fold-search
+        (if ivy-case-fold-search
+            nil
+          'auto))
+  ;; reset cache so that the candidate list updates
+  (setq ivy--old-re nil))
+
 (defun ivy--filter (name candidates)
   "Return all items that match NAME in CANDIDATES.
 CANDIDATES are assumed to be static."
@@ -1568,7 +1588,9 @@ CANDIDATES are assumed to be static."
         ivy--old-cands
       (let* ((re-str (if (listp re) (caar re) re))
              (matcher (ivy-state-matcher ivy-last))
-             (case-fold-search (string= name (downcase name)))
+             (case-fold-search
+              (and ivy-case-fold-search
+                   (string= name (downcase name))))
              (cands (cond
                       (matcher
                        (funcall matcher re candidates))