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
Preselect current file when showing list of files #1363
Conversation
counsel.el
Outdated
@@ -1695,6 +1695,14 @@ Skip some dotfiles unless `ivy-text' requires them." | |||
(defvar counsel-find-file-speedup-remote t | |||
"Speed up opening remote files by disabling `find-file-hook' for them.") | |||
|
|||
(defun preselect-file () |
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 should probably be called counsel--preselect-file
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.
Oh, right, fixing.
I think it would be good to make this optional in any case. |
95584b8
to
71a559b
Compare
@dieggsy, I added an option to turn my modification off. |
counsel.el
Outdated
(let ((f (ffap-guesser))) | ||
(when f (expand-file-name f)))) | ||
(when counsel-preselect-current-file | ||
(when buffer-file-name (file-name-nondirectory buffer-file-name))))) |
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 last operand of or
can be written as
(and counsel-preselect-current-file
buffer-file-name
(file-name-nondirectory buffer-file-name))
Either way, please add a docstring!
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.
Added docstring. I'm not convinced by (and x y z)
being more readable but if that's more idiomatic lisp I can change it.
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.
My opinion may not count for much, but since we're interested in the final expression's value and not control flow, doubly nested when
forms are a big no-no. Please use and
, which is not only more idiomatic Elisp but both logically and syntactically simpler.
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.
"big no-no" sounds very serious. I'll change it to and
, then. Thanks for adding some motivation as why this is.
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.
"big no-no" sounds very serious
I didn't intend for it to sound so serious/harmful, sorry about that. My argument can be summarised as "it's not idiomatic and it's more complex."
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.
No worries :-)
I appreciate your comments and will gladly learn from you.
counsel.el
Outdated
@@ -1654,6 +1654,11 @@ Does not list the currently checked out one." | |||
:type 'boolean | |||
:group 'ivy) | |||
|
|||
(defcustom counsel-preselect-current-file t | |||
"When non-nil, preselects current file in list of candidates." |
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.
Nitpick: "preselect" instead of "preselects", as this defcustom
is not the one performing the preselection.
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.
Fixed below.
Thanks, the change looks fine. Just make This change is over 15 lines. Are you willing to get an Emacs Copyright Assignment? See README for more info. |
I just sent an email to assign@gnu.org regarding Emacs Copyright Assignement. Do we have to wait until they reply to merge this PR? |
Yes, unfortunately. Hopefully, it won't take long. Thanks for the effort. |
Ping @abo-abo, I have the Emacs Copyright Assignment now. Can we get this PR merged? |
Thanks. Could you please resolve the merge conflict and update the PR? |
counsel.el
Outdated
@@ -1695,6 +1700,17 @@ Skip some dotfiles unless `ivy-text' requires them." | |||
(defvar counsel-find-file-speedup-remote t | |||
"Speed up opening remote files by disabling `find-file-hook' for them.") | |||
|
|||
(defun counsel--preselect-file () | |||
"Chooses the file to preselect in find-file like completions depending on customizations" |
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.
How about something like
"Return candidate to preselect during filename completion.
The preselect behaviour can be customized via user options
`counsel-find-file-at-point' and
`counsel-preselect-current-file', which see."
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.
My suggestion is basically to try and follow the conventions listed in (elisp) Documentation Tips
.
@basil-conto, @abo-abo, I updated the PR. Thanks! |
Thanks. |
Motivation is when you're browsing files in a directory one by one you want an easy way to go to the next one. With this change you only press ctrl-n.
Even without this example seems like a better default compared to
.
.This commit also does tiny refactor to remove duplicate code.