branch: master commit 877648a227fe34e1456776a4e6019029d65fc734 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
ivy.el (ivy-case-fold-search): New defvar * 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 | 19 +++++++++++++------ ivy.el | 24 +++++++++++++++++++++++- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/ivy-hydra.el b/ivy-hydra.el index 51b4c1a..19deabb 100644 --- a/ivy-hydra.el +++ b/ivy-hydra.el @@ -44,14 +44,20 @@ (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 71d80cd..98f8eab 100644 --- 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))