-
-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wordatpt dwim #1871
Wordatpt dwim #1871
Conversation
6d639de
to
fb94f60
Compare
it will probably get commented, so I'll address that here:
|
ivy.el
Outdated
@@ -4426,6 +4426,20 @@ EVENT gives the mouse position." | |||
(expand-file-name "doc/ivy-help.org")))) | |||
"The file for `ivy-help'.") | |||
|
|||
(defun ivy-word-at-point-dwim () | |||
"Extracts a meaningful part of the current buffer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The elevator pitch part of that docstring sucks. If anyone has a better proposal...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Return either text from region (if active) or `current-word'."
fb94f60
to
4ee1fdb
Compare
ivy.el
Outdated
@@ -4426,6 +4426,20 @@ EVENT gives the mouse position." | |||
(expand-file-name "doc/ivy-help.org")))) | |||
"The file for `ivy-help'.") | |||
|
|||
(defun ivy-word-at-point-dwim () | |||
"Extracts a meaningful part of the current buffer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Return either text from region (if active) or `current-word'."
ivy.el
Outdated
@@ -4424,6 +4426,20 @@ EVENT gives the mouse position." | |||
(expand-file-name "doc/ivy-help.org")))) | |||
"The file for `ivy-help'.") | |||
|
|||
(defun ivy-word-at-point-dwim () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ivy-region-text-or-current-word
.
ivy.el
Outdated
(defun ivy-word-at-point-dwim () | ||
"Extracts a meaningful part of the current buffer. | ||
|
||
This function tries to DWIM. It either uses the beginning of the region if activated, or the current word. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be superfluous given the above correction.
counsel.el
Outdated
(cons cmd 'ivy-word-at-point-dwim) | ||
nil | ||
(lambda (cell1 cell2) (eq (car cell1) (car cell2))))) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks ugly and also may result in side effects. Never do any logic on the top level apart from maybe
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.foo\\'" . foo-mode))
because you'd otherwise alter user's configuration in an unexpected way (see The Emacs Lisp Style Guide for a good summary). As a result, this code should really be part of defcustom
. I'd just let
a local list there, where I'd push
(or better add-to-list
as you said) in that loop, and then I'd nconc
it with '((org-refile . "^") ...
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fail to understand the difference between the last part of your answer and the current proposal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference will become visible if one setq-default
the ivy-initial-inputs-alist
to something custom before loading ivy
. That is the result would be custom value in ivy-initial-inputs-alist
plus whatever you now forcefully inject into it with add-to-list
on the top level upon load. These are side effects and are considered bad practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further problem is that if ivy
is loaded before counsel
, then ivy-highlight-grep-commands
is simply nil
and that modification of initial-inputs-alist
does nothing. Fragile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Further problem is that if
ivy
is loaded beforecounsel
, thenivy-highlight-grep-commands
is simplynil
and that modification ofinitial-inputs-alist
does nothing. Fragile.
I take back the last comment as I overlooked that you added this code to counsel
instead of ivy
. Forceful default initialization of ivy-initial-inputs-alist
still applies though.
The solution is good overall though it still does not fully address #1867 as it keeps on tampering with |
i am not that worried about that issue; someone else should feel free to implement it. |
Right, then your default initialization of (defcustom counsel-initial-input-default
#'ivy-region-text-or-current-word)
(defun counsel-set-initial-inputs-alist (symbol value)
(when (boundp symbol)
(dolist (entry (symbol-value symbol))
(setq ivy-initial-inputs-alist
(assq-delete-all (car entry) ivy-initial-inputs-alist))))
(dolist (entry value)
(add-to-list 'ivy-initial-inputs-alist
entry
nil
#'(lambda (entry-1 entry-2)
(eq (car entry-1) (car entry-2)))))
(set-default symbol value))
(defcustom counsel-initial-inputs-alist-default
nil)
(defcustom counsel-initial-inputs-alist
(when (and counsel-initial-inputs-alist-default
counsel-initial-input-default)
(let (alist)
(dolist (command ivy-highlight-grep-commands)
(push (cons command counsel-initial-input-default) alist))
alist))
:set #'counsel-set-initial-inputs-alist) This way, first of all, it is disabled by default thanks to |
I think that this is becoming too complicated. |
4ee1fdb
to
14e1412
Compare
I disagree. The point is that what you proposed is indeed a good "second-class" citizen default which, if not implemented in the form of the (tested) code, has to be be somehow documented in order to be advertised to the users. And we all know how much better it is to write actual self-documenting code rather than convoluted comments or docstrings. |
Why is this closed? I'm personally looking forward to this being merged. Do you plain to make a separate PR for this or? |
I'm also interested why it's closed. @mookid please ping if you still want this merged. |
@abo-abo @Alexander-Shukaev feel free to take some code from here, of course. I will be happy to see these features integrated. I just don't have the time to work on swiper at the moment. @abo-abo thanks again for the continuous work you are doing on emacs packages! |
@mookid Thanks for the explanation and for your past contributions. Feel free to reopen when you have more time. @Alexander-Shukaev If you're interested in this feature, feel free to take over testing the code and making sure it's integrated. Currently I have a backlog of 53 unread threads on Github (it was 100 around two weeks ago). I try to resolve those first, but new threads always keep coming up. I'm afraid if someone doesn't want to keep track this of PR, it will not be merged. |
@mookid Thanks, merged (there were other issues referencing this PR). I chose to extend |
This is a follow-up to #1868.
I propose this new default function for grep-like commands.
It provides a 'do what I mean' behaviour to get a meaningful initial input to search.
In particular, using the active region plays well with packages like expand-region.
To be discussed?