Oleh Krehel [Fri, 1 May 2015 20:01:30 +0000 (22:01 +0200)]
ivy-resume now works for functions that supply action
ivy.el (ivy-resume): Use action
Functions like `counsel-describe-funtion' and `counsel-describe-varible'
are now resume-able: after finishing with "RET" or breaking out with
"C-g" it's possible to resume the query in the same state as it
was (same collection, input, index).
With:
(global-set-key (kbd "C-c C-r") 'ivy-resume)
it's possible to e.g.:
- "F1 f" info read "RET" to describe Info-breadcrumbs
- "C-c C-r" "C-n" to describe Info-read-node-name
- "C-c C-r" "C-n" to describe Info-read-node-name-1
...
Oleh Krehel [Fri, 1 May 2015 19:49:25 +0000 (21:49 +0200)]
Merge ivy--action into ivy-last
* ivy.el (ivy-state): Add action field.
(ivy-set-action): New defun. Just a shortcut to set action.
(ivy--action): Remove defvar.
(ivy-read): Add action argument. Check (ivy-state-action ivy-last) in
the end and call it, since the action can change during the completion.
(ivy--insert-prompt): Add `counsel-find-symbol' to the list.
(ivy--format): If there are no matches, set `ivy--current' to "".
Oleh Krehel [Fri, 1 May 2015 18:01:08 +0000 (20:01 +0200)]
Add ivy-state struct
* ivy.el (ivy-state): New defstruct.
(ivy-last): A single global to store an `ivy-state' struct.
(ivy-require-match): Move into `ivy-last'.
(ivy-done): Update.
(ivy-resume): New defun. Initial draft, kind of works for swiper. Need
to add a callback of what to do with the result as an argument.
(ivy-read): Store all arguments into `ivy-last'.
(ivy-completing-read): Update doc.
Oleh Krehel [Wed, 29 Apr 2015 15:00:54 +0000 (17:00 +0200)]
Update and improve faces
* ivy.el (ivy-subdir): Inherit from dired-directory.
* swiper.el (swiper-match-face-1): Update doc.
(swiper-match-face-2): Update doc.
(swiper-match-face-3): Update doc.
(swiper-match-face-4): Inherit from isearch-fail.
(swiper--add-overlays): Fix the faces order swapping on the second
match.
Now it finally works as planned: face-1 is the background (re group 0),
next it cycles: face-2, face-3, face-4, face-2, face-3, face-4.
Oleh Krehel [Wed, 29 Apr 2015 10:10:09 +0000 (12:10 +0200)]
ivy.el (ivy--exhibit): Fixup last commit
* ivy.el (ivy--old-text): Should always be a string.
(ivy-read): Update.
(ivy--exhibit): Recompute candidates on flip, always set `ivy--old-re'
to nil.
Oleh Krehel [Tue, 28 Apr 2015 08:46:28 +0000 (10:46 +0200)]
Store the preselect and use it for empty ivy-text
* ivy.el (ivy-def): New defvar.
(ivy-read): Store `ivy-def'.
(ivy-completing-read): Update.
(ivy--filter): When the input is empty, set `ivy--index' to select
`ivy-def'.
Oleh Krehel [Sat, 25 Apr 2015 11:44:52 +0000 (13:44 +0200)]
Improve completion history using the propertize trick
* ivy.el (ivy-previous-history-element): Update.
(ivy-next-history-element): Update.
(ivy--maybe-scroll-history): New defun. When the history element string
has ivy-index property, set `ivy--index' to that.
Oleh Krehel [Fri, 24 Apr 2015 10:52:40 +0000 (12:52 +0200)]
Improve the match confirm while completing files
* ivy.el (ivy-confirm-face): New face.
(ivy-match-required-face): New face.
(ivy--prompt-extra): New defvar, the prompt is concatenaded with this.
(ivy--extend-prompt): Remove.
(ivy-done): Update.
(ivy--insert-prompt): Use `ivy--prompt-extra'. Reset it unless the
`this-command' is appropriate.
(ivy--set-match-props): New defun.
Oleh Krehel [Wed, 22 Apr 2015 13:37:11 +0000 (15:37 +0200)]
ivy.el (ivy--exhibit): Wrap in `while-no-input'
* ivy.el (ivy--exhibit): `ivy--dynamic-function' will sometimes use
`call-process'. Adding `while-no-input' speeds up things a lot, at the
cost of a small message interrupting the minibuffer when
`call-process' takes too long or the user types too fast.
This message is not an issue for emacs-snapshot.
Oleh Krehel [Wed, 22 Apr 2015 13:36:46 +0000 (15:36 +0200)]
Bind "M-q" to `ivy-toggle-regexp-quote'
* ivy.el (ivy-minibuffer-map): Update.
(ivy--regexp-quote): New defvar.
(ivy-toggle-regexp-quote): New command, toggle `ivy--regex-function'
between the value selected in `ivy-read' and `ivy--regexp-quote'.
(ivy-read): Reset `ivy--regexp-quote' to 'regexp-quote.
Oleh Krehel [Wed, 22 Apr 2015 10:59:21 +0000 (12:59 +0200)]
ivy.el (ivy-done): Be more strict for `require-match'
When `require-match' isn't in (nil confirm confirm-after-completion),
don't allow to exit if there isn't a match. Instead, amend the prompt
with "(match required)".
Oleh Krehel [Wed, 22 Apr 2015 10:56:19 +0000 (12:56 +0200)]
Change `ivy-read' to a cl-defun
* ivy.el (ivy-read): All args but PROMPT and COLLECTION are now keys.
The existing basic calls to `ivy-read' should still work, the others
need to be updated. It's best to try to use `ivy-completing-read' if
possible, since it conforms to the `completing-read' arguments.
New arguments: REQUIRE-MATCH and HISTORY. If HISTORY is nil, `ivy-history'
is used.
(ivy--sorted-files): Don't try to extend the collection.
(ivy-completing-read): Update.
* swiper.el (swiper--ivy): Update.
* counsel.el (counsel-describe-symbol-history): New defvar.
(counsel-describe-variable): Update the call, require match, use
`counsel-describe-symbol-history'.
(counsel-describe-function): Update the call, require match, use
`counsel-describe-symbol-history'.
* ivy-test.el: Update tests, since zero and one length input doesn't
return immediately any more.
Oleh Krehel [Tue, 21 Apr 2015 15:01:58 +0000 (17:01 +0200)]
Add a way to exit ignoring the candidates
* ivy.el (ivy-immediate-done): New commad, currently unbound.
Exit the minibuffer, ignoring the candidates. Solves the same problem as
"C-f" in `ido-mode'.
(ivy-alt-done): With a prefix arg, e.g. "C-u C-j", forward to `ivy-immediate-done'.
* counsel.el (counsel-describe-variable): Don't describe variable if
jump-to-symbol action was chosen.
(counsel-describe-function): Don't describe variable if
jump-to-symbol action was chosen.
I should handle this more gracefully if multiple actions become a
pattern.
Oleh Krehel [Tue, 21 Apr 2015 11:33:18 +0000 (13:33 +0200)]
counsel.el: Add awesome swiper highlighting to git grep
* counsel.el (swiper): Require.
(counsel-git-grep-function): Use `swiper--add-overlays'. Remember to set
`swiper--window', and call `swiper--cleanup'. Use `ivy--regex' in all
cases to build the regex.
Oleh Krehel [Tue, 21 Apr 2015 11:30:35 +0000 (13:30 +0200)]
ivy.el (ivy--regex): Add optional greedy arg
* ivy.el (ivy--regex): When optional greedy arg is t, be greedy. Don't
wrap a sub-expr in a group if it's already a group, for instance
"forward \(char\|list\)".
Greedy is needed, for instance, for "git grep", which doesn't work great
with non-greedy regex.
Oleh Krehel [Tue, 21 Apr 2015 09:49:46 +0000 (11:49 +0200)]
Add an option to call the completion action without exiting
* ivy.el (ivy--persistent-action): New defvar. This is a lambda that the
caller sets if the caller has a plan for persistent actions.
(ivy-next-line-and-call): Add and bind to "C-M-n". Identical to "C-n",
except calls `ivy--persistent-action' when it's not nil.
Add and bind to "C-M-p". Identical to "C-p",
except calls `ivy--persistent-action' when it's not nil.
(ivy-window): New defvar.
(ivy-read): Store `ivy-window'.
* counsel.el (counsel-git-grep): Use `ivy--persistent-action'.
For `counsel-git-grep', as an example, it's possible to move to the
matched place without exiting the completion with "C-M-n" and "C-M-p".
This is a nice advantage, since it gives a full context to each one-line
git grep match.
Oleh Krehel [Tue, 21 Apr 2015 08:44:52 +0000 (10:44 +0200)]
Allow to customize the sorting methods
* ivy.el (ivy-sort-functions-alist): New defvar, stores sorting
functions for various function collection types.
(ivy-sort-file-function): Remove, merge into `ivy-sort-functions-alist'.
(ivy-sort-max-size): Don't sort candidate lists larger than this size.
(ivy--sorted-files): Update.
(ivy-read): Add an argument SORT. When it's t, sort the candidates
according to `ivy-sort-functions-alist'. It's assumed that if
COLLECTION is a function it's OK to `cl-sort' it without making a copy.
(ivy-completing-read): Call with SORT t.
* counsel.el (counsel-describe-variable): Call with SORT t.
(counsel-describe-function): Call with SORT t.
Oleh Krehel [Mon, 20 Apr 2015 16:34:43 +0000 (18:34 +0200)]
`counsel-git-grep' can now handle huge git repos
* counsel.el (counsel-git-grep-count): Return a number instead of a
string. Apply `ivy--regex' on the input.
(counsel--git-grep-count): New defvar.
(counsel-git-grep-function): If the repo has >20000 lines, use `head' 5000
instead, but still display the true amount of matches.
(counsel-git-grep): Set `ivy--dynamic-function'.
(counsel-locate-function): Update.
* ivy.el (ivy--dynamic-function): New defvar. When this isn't nil, it
will be called to get a new batch of candidates in case the `ivy-text'
was changed.
(ivy--full-length): The true candidates length in case of `head' shenanigans.
(ivy--old-text): Store the old text for when `ivy--dynamic-function' was
called last.
(ivy--insert-prompt): Update.
(ivy--exhibit): Don't do filtering for non-nil `ivy--dynamic-function' -
let the caller (usually a shell tool) do the filtering.
(ivy--insert-minibuffer): New defun, created from a part of
`ivy--exhibit'.
Turns out that calling `file-directory-p' in `cl-sort' is too expensive.
So when `ivy-sort-file-function' is `ivy-sort-file-function-default',
propertize all strings with whether they are directories or not.
When `ivy-sort-file-function' is something different,
e.g. `string-lessp', don't do propertizing since it also can be slow.
Oleh Krehel [Mon, 20 Apr 2015 08:55:18 +0000 (10:55 +0200)]
Allow "C-." to jump to current symbol definition
* counsel.el (counsel-describe-map): New defvar.
(counsel-find-symbol): New defun.
(counsel--find-symbol): New defun - jump to definition of function or
symbol or library.
(counsel-describe-variable): Use `counsel-describe-map'.
(counsel-describe-function): Use `counsel-describe-map'.