[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master b9bb7c6 140/184: ivy.el (ivy-configure): New function to c
From: |
Oleh Krehel |
Subject: |
[elpa] master b9bb7c6 140/184: ivy.el (ivy-configure): New function to configure many things at once |
Date: |
Wed, 16 Oct 2019 13:15:10 -0400 (EDT) |
branch: master
commit b9bb7c6e991c35c1d033db078b2492f7c36a9ac6
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
ivy.el (ivy-configure): New function to configure many things at once
- Reduce the amount of times `CALLER' has to be mentioned
- Reduce the amount of times "counsel" appears in ivy.el
---
counsel.el | 60 +++++++++++++++++++++++++++++++++++++++++++++---------------
ivy.el | 40 ++++++++++++++++++++++++++++------------
swiper.el | 25 +++++++++++++++++--------
3 files changed, 90 insertions(+), 35 deletions(-)
diff --git a/counsel.el b/counsel.el
index 633e958..12e30e4 100644
--- a/counsel.el
+++ b/counsel.el
@@ -564,6 +564,9 @@ Variables declared using `defcustom' are highlighted
according to
(funcall counsel-describe-variable-function (intern
x)))
:caller 'counsel-describe-variable)))
+(ivy-configure 'counsel-describe-variable
+ :initial-input "^")
+
;;** `counsel-describe-function'
(ivy-set-actions
'counsel-describe-function
@@ -614,6 +617,9 @@ to `ivy-highlight-face'."
(funcall counsel-describe-function-function (intern
x)))
:caller 'counsel-describe-function)))
+(ivy-configure 'counsel-describe-function
+ :initial-input "^")
+
;;** `counsel-set-variable'
(defvar counsel-set-variable-history nil
"Store history for `counsel-set-variable'.")
@@ -919,6 +925,9 @@ when available, in that order of precedence."
:initial-input initial-input
:caller 'counsel-M-x)))
+(ivy-configure 'counsel-M-x
+ :initial-input "^")
+
(ivy-set-actions
'counsel-M-x
`(("d" counsel--find-symbol "definition")
@@ -1267,6 +1276,9 @@ INITIAL-INPUT can be given as the initial minibuffer
input."
:action #'counsel-git-action
:caller 'counsel-git)))
+(ivy-configure 'counsel-git
+ :occur #'counsel-git-occur)
+
(defun counsel-git-action (x)
"Find file X in current Git repository."
(with-ivy-window
@@ -1311,8 +1323,6 @@ INITIAL-INPUT can be given as the initial minibuffer
input."
(forward-line 2)
(dired-move-to-filename)))))))
-(ivy-set-occur 'counsel-git 'counsel-git-occur)
-
;;** `counsel-git-grep'
(defvar counsel-git-grep-map
(let ((map (make-sparse-keymap)))
@@ -1323,7 +1333,6 @@ INITIAL-INPUT can be given as the initial minibuffer
input."
map))
(counsel-set-async-exit-code 'counsel-git-grep 1 "No matches found")
-(ivy-set-occur 'counsel-git-grep 'counsel-git-grep-occur)
(ivy-set-display-transformer 'counsel-git-grep 'counsel-git-grep-transformer)
(defvar counsel-git-grep-cmd-default "git --no-pager grep --full-name -n
--no-color -i -I -e \"%s\""
@@ -1507,6 +1516,9 @@ When CMD is non-nil, prompt for a specific \"git grep\"
command."
:unwind unwind-function
:history 'counsel-git-grep-history
:caller 'counsel-git-grep))))
+
+(ivy-configure 'counsel-git-grep
+ :occur #'counsel-git-grep-occur)
(cl-pushnew 'counsel-git-grep ivy-highlight-grep-commands)
(defun counsel-git-grep-proj-function (str)
@@ -1966,7 +1978,8 @@ When INITIAL-INPUT is non-nil, use it in the minibuffer
during completion."
#'counsel-find-file-action
'counsel-find-file))
-(ivy-set-occur 'counsel-find-file 'counsel-find-file-occur)
+(ivy-configure 'counsel-find-file
+ :occur #'counsel-find-file-occur)
(defvar counsel-find-file-occur-cmd "ls -a | %s | xargs -d '\\n' ls -d
--group-directories-first"
"Format string for `counsel-find-file-occur'.")
@@ -2546,6 +2559,9 @@ FZF-PROMPT, if non-nil, is passed as `ivy-read' prompt
argument."
:unwind #'counsel-delete-process
:caller 'counsel-fzf))
+(ivy-configure 'counsel-fzf
+ :occur #'counsel-fzf-occur)
+
(defun counsel-fzf-action (x)
"Find file X in current fzf directory."
(with-ivy-window
@@ -2561,8 +2577,6 @@ FZF-PROMPT, if non-nil, is passed as `ivy-read' prompt
argument."
"%s --print0 | xargs -0 ls"
(format counsel-fzf-cmd ivy-text)))))
-(ivy-set-occur 'counsel-fzf 'counsel-fzf-occur)
-
(ivy-set-actions
'counsel-fzf
'(("x" counsel-locate-action-extern "xdg-open")
@@ -2734,7 +2748,6 @@ regex string."
(defvar counsel--regex-look-around nil)
(counsel-set-async-exit-code 'counsel-ag 1 "No matches found")
-(ivy-set-occur 'counsel-ag 'counsel-ag-occur)
(ivy-set-display-transformer 'counsel-ag 'counsel-git-grep-transformer)
(defconst counsel--command-args-separator "-- ")
@@ -2832,6 +2845,9 @@ CALLER is passed to `ivy-read'."
(swiper--cleanup))
:caller (or caller 'counsel-ag))))
+(ivy-configure 'counsel-ag
+ :occur #'counsel-ag-occur)
+
(defun counsel-cd ()
"Change the directory for the currently running Ivy grep-like command.
Works for `counsel-git-grep', `counsel-ag', etc."
@@ -2923,7 +2939,6 @@ Note: don't use single quotes for the regex."
:type 'string)
(counsel-set-async-exit-code 'counsel-rg 1 "No matches found")
-(ivy-set-occur 'counsel-rg 'counsel-ag-occur)
(ivy-set-display-transformer 'counsel-rg 'counsel-git-grep-transformer)
(defun counsel--rg-targets ()
@@ -2963,6 +2978,9 @@ Example input with inclusion and exclusion file patterns:
switch))))
(counsel-ag initial-input initial-directory extra-rg-args rg-prompt
:caller 'counsel-rg)))
+
+(ivy-configure 'counsel-rg
+ :occur #'counsel-ag-occur)
(cl-pushnew 'counsel-rg ivy-highlight-grep-commands)
;;** `counsel-grep'
@@ -3038,7 +3056,6 @@ substituted by the search regexp and file, respectively.
Neither
(buffer-file-name
(ivy-state-buffer ivy-last)))))))
-(ivy-set-occur 'counsel-grep 'counsel-grep-occur)
(counsel-set-async-exit-code 'counsel-grep 1 "")
(defvar counsel-grep-history nil
@@ -3076,7 +3093,6 @@ When non-nil, INITIAL-INPUT is the initial search
pattern."
:keymap counsel-grep-map
:history 'counsel-grep-history
- :update-fn 'auto
:re-builder #'ivy--regex
:action #'counsel-grep-action
:unwind (lambda ()
@@ -3086,6 +3102,11 @@ When non-nil, INITIAL-INPUT is the initial search
pattern."
(unless res
(goto-char init-point)))))
+(ivy-configure 'counsel-grep
+ :update-fn 'auto
+ :occur #'counsel-grep-occur
+ :more-chars 2)
+
;;;###autoload
(defun counsel-grep-backward (&optional initial-input)
"Grep for a string in the file visited by the current buffer going
@@ -3604,6 +3625,9 @@ include attachments of other Org buffers."
(org-capture nil (car (split-string x))))
:caller 'counsel-org-capture))
+(ivy-configure 'counsel-org-capture
+ :initial-input "^")
+
(ivy-set-actions
'counsel-org-capture
`(("t" ,(lambda (x)
@@ -3803,7 +3827,6 @@ Obeys `widen-automatically', which see."
(if cands
(ivy-read "Mark: " cands
:require-match t
- :update-fn #'counsel--mark-ring-update-fn
:sort counsel-mark-ring-sort-selections
:action (lambda (cand)
(let ((pos (get-text-property 0 'point cand)))
@@ -3818,6 +3841,9 @@ Position of selected mark outside accessible part of
buffer")))
:caller 'counsel-mark-ring)
(message "Mark ring is empty"))))
+(ivy-configure 'counsel-mark-ring
+ :update-fn #'counsel--mark-ring-update-fn)
+
;;** `counsel-package'
(defvar package--initialized)
(defvar package-alist)
@@ -5486,9 +5512,11 @@ in the current window."
:keymap ivy-switch-buffer-map
:action #'ivy--switch-buffer-action
:matcher #'ivy--switch-buffer-matcher
- :caller 'counsel-switch-buffer
:unwind #'counsel--switch-buffer-unwind
- :update-fn 'counsel--switch-buffer-update-fn))
+ :caller 'counsel-switch-buffer))
+
+(ivy-configure 'counsel-switch-buffer
+ :update-fn #'counsel--switch-buffer-update-fn)
;;;###autoload
(defun counsel-switch-buffer-other-window ()
@@ -5500,9 +5528,11 @@ in the current window."
:preselect (buffer-name (other-buffer (current-buffer)))
:action #'ivy--switch-buffer-other-window-action
:matcher #'ivy--switch-buffer-matcher
- :caller 'counsel-switch-buffer-other-window
:unwind #'counsel--switch-buffer-unwind
- :update-fn 'counsel--switch-buffer-update-fn))
+ :caller 'counsel-switch-buffer-other-window))
+
+(ivy-configure 'counsel-switch-buffer-other-window
+ :update-fn #'counsel--switch-buffer-update-fn)
(defun counsel-open-buffer-file-externally (buffer)
"Open the file associated with BUFFER with an external program."
diff --git a/ivy.el b/ivy.el
index a85e8fa..f846610 100644
--- a/ivy.el
+++ b/ivy.el
@@ -677,8 +677,7 @@ functionality, e.g. as seen in `isearch'."
"Store the current overriding `case-fold-search'.")
(defvar ivy-more-chars-alist
- '((counsel-grep . 2)
- (t . 3))
+ '((t . 3))
"Map commands to their minimum required input length.
That is the number of characters prompted for before fetching
candidates. The special key t is used as a fallback.")
@@ -1873,18 +1872,15 @@ like.")
'((org-refile . "^")
(org-agenda-refile . "^")
(org-capture-refile . "^")
- (counsel-M-x . "^")
- (counsel-describe-function . "^")
- (counsel-describe-variable . "^")
- (counsel-org-capture . "^")
(Man-completion-table . "^")
(woman . "^"))
"An alist associating commands with their initial input.
Each cdr is either a string or a function called in the context
of a call to `ivy-read'."
- :type '(alist :key-type (symbol)
- :value-type (choice (string) (function))))
+ :type '(alist
+ :key-type (symbol)
+ :value-type (choice (string) (function))))
(defcustom ivy-hooks-alist nil
"An alist associating commands to setup functions.
@@ -1901,6 +1897,23 @@ May supersede `ivy-initial-inputs-alist'."
(const :tag "Off" nil)
(const :tag "Call action on change" auto))))
+(cl-defun ivy-configure (caller
+ &key
+ initial-input
+ occur
+ update-fn
+ more-chars)
+ "Configure `ivy-read' params for CALLER."
+ (declare (indent 1))
+ (when initial-input
+ (setf (alist-get caller ivy-initial-inputs-alist) initial-input))
+ (when occur
+ (ivy-set-occur caller occur))
+ (when update-fn
+ (setf (alist-get caller ivy-update-fns-alist) update-fn))
+ (when more-chars
+ (setf (alist-get caller ivy-more-chars-alist) more-chars)))
+
(defcustom ivy-sort-max-size 30000
"Sorting won't be done for collections larger than this."
:type 'integer)
@@ -2037,7 +2050,7 @@ customizations apply to the current completion session."
(not (window-minibuffer-p)))
(ivy-alist-setting ivy-display-functions-alist caller)))
result)
- (setq update-fn (ivy-alist-setting ivy-update-fns-alist caller))
+ (setq update-fn (or update-fn (ivy-alist-setting ivy-update-fns-alist
caller)))
(setq ivy-last
(make-ivy-state
:prompt prompt
@@ -4325,6 +4338,9 @@ Skip buffers that match `ivy-ignore-buffers'."
:matcher #'ivy--switch-buffer-matcher
:caller 'ivy-switch-buffer))
+(ivy-configure 'ivy-switch-buffer
+ :occur #'ivy-switch-buffer-occur)
+
;;;###autoload
(defun ivy-switch-view ()
"Switch to one of the window views stored by `ivy-push-view'."
@@ -4344,6 +4360,9 @@ Skip buffers that match `ivy-ignore-buffers'."
:keymap ivy-switch-buffer-map
:caller 'ivy-switch-buffer-other-window))
+(ivy-configure 'ivy-switch-buffer-other-window
+ :occur #'ivy-switch-buffer-occur)
+
(defun ivy--yank-handle-case-fold (text)
(if (and (> (length ivy-text) 0)
(string= (downcase ivy-text) ivy-text))
@@ -4713,9 +4732,6 @@ When `ivy-calling' isn't nil, call `ivy-occur-press'."
(setq ivy--occurs-list
(plist-put ivy--occurs-list cmd occur)))
-(ivy-set-occur 'ivy-switch-buffer 'ivy-switch-buffer-occur)
-(ivy-set-occur 'ivy-switch-buffer-other-window 'ivy-switch-buffer-occur)
-
(defun ivy--starts-with-dotslash (str)
(string-match-p "\\`\\.[/\\]" str))
diff --git a/swiper.el b/swiper.el
index c3c11c8..324ac6e 100644
--- a/swiper.el
+++ b/swiper.el
@@ -209,7 +209,7 @@ Treated as non-nil when searching backwards."
(ivy-read
(format "Query replace %s with: " from) nil
:def default
- :update-fn #'swiper--query-replace-updatefn)
+ :caller 'swiper-query-replace)
t)))
(swiper--cleanup)
(ivy-exit-with-action
@@ -221,6 +221,9 @@ Treated as non-nil when searching backwards."
t t nil))))))
(swiper--query-replace-cleanup)))))
+(ivy-configure 'swiper-query-replace
+ :update-fn #'swiper--query-replace-updatefn)
+
(defvar inhibit-message)
(defun swiper-all-query-replace ()
@@ -553,6 +556,10 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
(interactive)
(swiper--ivy (swiper--candidates) initial-input))
+(ivy-configure 'swiper
+ :occur #'swiper-occur
+ :update-fn #'swiper--update-input-ivy)
+
;;;###autoload
(defun swiper-backward (&optional initial-input)
"`isearch-backward' with an overview.
@@ -683,8 +690,6 @@ When capture groups are present in the input, print them
instead of lines."
(forward-line 4)
(setq-local next-error-function #'ivy-occur-next-error))))
-(ivy-set-occur 'swiper 'swiper-occur)
-
(declare-function evil-set-jump "ext:evil-jumps")
(defvar swiper--current-line nil)
@@ -796,7 +801,6 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
(ivy--filter initial-input candidates)))
preselect)
:require-match t
- :update-fn #'swiper--update-input-ivy
:unwind #'swiper--cleanup
:action #'swiper--action
:re-builder #'swiper--re-builder
@@ -1275,13 +1279,16 @@ See `ivy-format-functions-alist' for further
information."
(ivy-read "swiper-all: " 'swiper-all-function
:action #'swiper-all-action
:unwind #'swiper--cleanup
- :update-fn 'auto
:dynamic-collection t
:keymap swiper-all-map
:initial-input initial-input
- :caller 'swiper-multi)))
+ :caller 'swiper-all)))
+
+(ivy-configure 'swiper-all
+ :update-fn 'auto)
(add-to-list 'ivy-format-functions-alist '(swiper-multi .
swiper--all-format-function))
+(add-to-list 'ivy-format-functions-alist '(swiper-all .
swiper--all-format-function))
(defun swiper-all-action (x)
"Move to candidate X from `swiper-all'."
@@ -1602,7 +1609,6 @@ When not running `swiper-isearch' already, start it."
:dynamic-collection t
:require-match t
:action #'swiper-isearch-action
- :update-fn 'auto
:unwind #'swiper--cleanup
:re-builder #'swiper--re-builder
:history 'swiper-history
@@ -1615,6 +1621,10 @@ When not running `swiper-isearch' already, start it."
(unless (or res (string= ivy-text ""))
(cl-pushnew ivy-text swiper-history)))))
+(ivy-configure 'swiper-isearch
+ :occur #'swiper-occur
+ :update-fn 'auto)
+
;;;###autoload
(defun swiper-isearch-backward (&optional initial-input)
"Like `swiper-isearch' but the first result is before the point."
@@ -1623,7 +1633,6 @@ When not running `swiper-isearch' already, start it."
(swiper-isearch initial-input)))
(add-to-list 'ivy-format-functions-alist '(swiper-isearch .
swiper-isearch-format-function))
-(ivy-set-occur 'swiper-isearch 'swiper-occur)
(defun swiper-isearch-toggle ()
"Two-way toggle between `swiper-isearch' and isearch.
- [elpa] master c0aa563 112/184: ivy.el (ivy-occur): Set up next-error-function, (continued)
- [elpa] master c0aa563 112/184: ivy.el (ivy-occur): Set up next-error-function, Oleh Krehel, 2019/10/16
- [elpa] master 1a74a21 110/184: ivy-occur: setup for next-error., Oleh Krehel, 2019/10/16
- [elpa] master 30adc93 115/184: Add actions to counsel-switch-buffer, Oleh Krehel, 2019/10/16
- [elpa] master 892e44a 079/184: doc: Add full text of licences, Oleh Krehel, 2019/10/16
- [elpa] master 4645e89 121/184: swiper.el (swiper-action-copy): Add and bind to "M-o w", Oleh Krehel, 2019/10/16
- [elpa] master 77997ea 120/184: counsel.el (counsel-M-x-transformer): Handle read-only strings, Oleh Krehel, 2019/10/16
- [elpa] master 1984068 122/184: doc/ivy.org: Update GFDL license to no Invariant Sections, Oleh Krehel, 2019/10/16
- [elpa] master 881cbc5 130/184: counsel.el (counsel-google-function): Use request in async mode, Oleh Krehel, 2019/10/16
- [elpa] master b39f383 125/184: counsel.el (counsel-git-grep-occur): Re-use counsel-grep-like-occur, Oleh Krehel, 2019/10/16
- [elpa] master c9f1889 136/184: swiper.el (swiper--query-replace-setup): Fix "^$" issue, Oleh Krehel, 2019/10/16
- [elpa] master b9bb7c6 140/184: ivy.el (ivy-configure): New function to configure many things at once,
Oleh Krehel <=
- [elpa] master e3dabec 143/184: counsel.el: Use ivy-configure :unwind-fn, Oleh Krehel, 2019/10/16
- [elpa] master f16ac0e 148/184: ivy.el (ivy--format): Set case-fold-search, Oleh Krehel, 2019/10/16
- [elpa] master 501ac71 151/184: ivy.el (ivy-occur-revert-buffer): Re-use ivy-highlight-grep-commands, Oleh Krehel, 2019/10/16
- [elpa] master 6b0c41b 167/184: ivy.el (ivy-sort-file-function-using-ido): Make obsolete, Oleh Krehel, 2019/10/16
- [elpa] master 22cc602 160/184: counsel.el (counsel-find-symbol): Should not show up in counsel-M-x, Oleh Krehel, 2019/10/16
- [elpa] master b85f857 166/184: .github/FUNDING.yml: Add github, Oleh Krehel, 2019/10/16
- [elpa] master 722250c 162/184: counsel.el (counsel-imenu-action): Handle nil case, Oleh Krehel, 2019/10/16
- [elpa] master 9970ae6 180/184: counsel.el (counsel-read-directory-name): Add, Oleh Krehel, 2019/10/16
- [elpa] master 7054901 176/184: ivy.el (ivy-occur-revert-buffer): Make more generic, Oleh Krehel, 2019/10/16
- [elpa] master fcef913 023/184: swiper-isearch: Fix regexes in "ignore-order" case, Oleh Krehel, 2019/10/16