Skip to content
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

Merged
merged 2 commits into from Jan 13, 2018

Conversation

neojski
Copy link
Contributor

@neojski neojski commented Dec 9, 2017

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.

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 ()
Copy link
Contributor

@dieggsy dieggsy Dec 9, 2017

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

Copy link
Contributor Author

@neojski neojski Dec 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right, fixing.

@dieggsy
Copy link
Contributor

@dieggsy dieggsy commented Dec 9, 2017

I think it would be good to make this optional in any case.

@neojski neojski force-pushed the preselect-current-file branch 2 times, most recently from 95584b8 to 71a559b Compare Dec 9, 2017
@neojski
Copy link
Contributor Author

@neojski neojski commented Dec 9, 2017

@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)))))
Copy link
Collaborator

@basil-conto basil-conto Dec 9, 2017

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!

Copy link
Contributor Author

@neojski neojski Dec 10, 2017

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.

Copy link
Collaborator

@basil-conto basil-conto Dec 10, 2017

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.

Copy link
Contributor Author

@neojski neojski Dec 10, 2017

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.

Copy link
Collaborator

@basil-conto basil-conto Dec 10, 2017

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."

Copy link
Contributor Author

@neojski neojski Dec 10, 2017

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."
Copy link
Collaborator

@basil-conto basil-conto Dec 9, 2017

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.

Copy link
Contributor Author

@neojski neojski Dec 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed below.

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Dec 10, 2017

Thanks, the change looks fine. Just make counsel-preselect-current-file off by default and add some small docstring to the new function.

This change is over 15 lines. Are you willing to get an Emacs Copyright Assignment? See README for more info.

@neojski neojski force-pushed the preselect-current-file branch from 71a559b to 4299558 Compare Dec 10, 2017
@neojski
Copy link
Contributor Author

@neojski neojski commented Dec 10, 2017

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?

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Dec 10, 2017

Do we have to wait until they reply to merge this PR?

Yes, unfortunately. Hopefully, it won't take long. Thanks for the effort.

@neojski neojski force-pushed the preselect-current-file branch from 4299558 to 293eea2 Compare Dec 10, 2017
@neojski
Copy link
Contributor Author

@neojski neojski commented Jan 9, 2018

Ping @abo-abo, I have the Emacs Copyright Assignment now. Can we get this PR merged?

@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Jan 9, 2018

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"
Copy link
Collaborator

@basil-conto basil-conto Jan 9, 2018

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."

Copy link
Collaborator

@basil-conto basil-conto Jan 9, 2018

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.

@neojski neojski force-pushed the preselect-current-file branch from 293eea2 to 5d9aedb Compare Jan 13, 2018
@neojski
Copy link
Contributor Author

@neojski neojski commented Jan 13, 2018

@basil-conto, @abo-abo, I updated the PR. Thanks!

@abo-abo abo-abo merged commit 5d9aedb into abo-abo:master Jan 13, 2018
1 check passed
@abo-abo
Copy link
Owner

@abo-abo abo-abo commented Jan 13, 2018

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants