-
-
Notifications
You must be signed in to change notification settings - Fork 339
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
counsel-find-file: Support opening in other tab #2915
base: master
Are you sure you want to change the base?
Conversation
SGTM, thanks! |
Here's a pull request which adds other-tab actions on t to most commands for which I think they are relevant. Happy to work on any more that you can think of and add them to the commit though? The only command I haven't done is |
Thanks!
No need to worry about that. If you prefer to have such a command now, there's no need to wait for Emacs to acquire it as well. If and when Emacs acquires it, we can always adapt Counsel accordingly.
FWIW, my impression is that vanilla Emacs nowadays prioritises the more general idiom of |
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.
Native tabs are new in Emacs 27, but Ivy supports Emacs 24.5+. Should the addition of these "other tab" actions be conditional on the fboundp
/functionp
presence of the required underlying functions?
573f02f
to
42e7e9e
Compare
Yes, that sounds sensible to me. I very briefly had a look at ways of doing this. The simple way is to just use So to enforce the right position, I tried (ivy-set-actions
'counsel-find-file
`(("j" find-file-other-window "other window")
("f" find-file-other-frame "other frame")
,(when (fboundp 'find-file-other-tab)
'("t" find-file-other-tab "other tab"))
("b" counsel-find-file-cd-bookmark-action "cd bookmark")
("x" counsel-find-file-extern "open externally")
("r" counsel-find-file-as-root "open as root")
("R" find-file-read-only "read only")
("l" find-file-literally "open literally")
("k" counsel-find-file-delete "delete")
("c" counsel-find-file-copy "copy file")
("m" counsel-find-file-move "move or rename")
("d" counsel-find-file-mkdir-action "mkdir"))) This works fine if the test passes, but if it doesn't then the whole sexp ( There are a few solutions:
What do you think? EDIT: turns out it's pretty easy to code, at least I think it is. Here is my Very Simple amateur-elisp solution, just filtering out all the nil-evaluating values. Worked for me: (defun ivy-read-action ()
"Change the action to one of the available ones.
Return nil for `minibuffer-keyboard-quit' or wrong key during the
selection, non-nil otherwise."
(interactive)
(let ((actions (cl-remove-if 'byte-compile-nilconstp
(ivy-state-action ivy-last))))
(if (not (ivy--actionp actions))
t
(let ((ivy--directory ivy--directory))
(funcall ivy-read-action-function actions))))) |
If I understood correctly, I think you just need to splice, rather than unquote, the conditional part into the rest of the list, right? E.g.: (ivy-set-actions
'counsel-find-file
`(("j" find-file-other-window "other window")
("f" find-file-other-frame "other frame")
,@(and (fboundp 'find-file-other-tab)
'(("t" find-file-other-tab "other tab")))
("b" counsel-find-file-cd-bookmark-action "cd bookmark")
("x" counsel-find-file-extern "open externally")
("r" counsel-find-file-as-root "open as root")
("R" find-file-read-only "read only")
("l" find-file-literally "open literally")
("k" counsel-find-file-delete "delete")
("c" counsel-find-file-copy "copy file")
("m" counsel-find-file-move "move or rename")
("d" counsel-find-file-mkdir-action "mkdir"))) |
42e7e9e
to
d525b04
Compare
Thanks! I didn't know about the @ notation for splicing, haven't quite got round to reading the elisp manual yet. I've used that, and also added support for |
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.
Thanks!
I didn't know about the @ notation for splicing, haven't quite got round to reading the elisp manual yet.
If you're still interested, the relevant docs are under C-h v ` RET
and (info "(elisp) Backquote")
.
BTW, I think this PR is just large enough that I cannot merge it without a copyright assignment (CA) to the FSF. Do you already have a CA on file? If not, would you be willing to submit one?
If you're unfamiliar with this, see:
* ivy.el (ivy--switch-buffer-other-tab-action): New action function. (ivy-switch-buffer): * counsel.el (counsel-find-file, counsel-recentf) (counsel-buffer-or-recentf, counsel-bookmark) (counsel-switch-buffer): Add "other tab" actions, but only on the condition that the relevant features are available (because Ivy supports Emacsen before they were introduced) (abo-abo#2915).
* ivy.el (ivy--switch-buffer-elsewhere): New subroutine generalized from ivy--switch-buffer-other-window-action. (ivy--switch-buffer-other-window-action): Use it. Expand docstring. (ivy--switch-buffer-other-tab-action): Ditto. Define function only in Emacs 27+. (ivy-switch-buffer): * counsel.el (counsel-switch-buffer): Make "other tab" feature detection explicit. Re: abo-abo#2915.
d525b04
to
66a0f47
Compare
Not yet.
Happy to. I'm a student at a fairly well know university, so I might want to check with them first, but I can't them kicking up a fuss. I'll get on it. |
* ivy.el (ivy--switch-buffer-other-tab-action): New action function. (ivy-switch-buffer): * counsel.el (counsel-find-file, counsel-recentf) (counsel-buffer-or-recentf, counsel-bookmark) (counsel-switch-buffer): New action function (counsel--bookmark-jump-other-tab). Add "other tab" actions, but only on the condition that the relevant features are available (because Ivy supports Emacsen before they were introduced) (abo-abo#2915).
66a0f47
to
0616715
Compare
* ivy.el (ivy--switch-buffer-elsewhere): New subroutine generalized from ivy--switch-buffer-other-window-action. (ivy--switch-buffer-other-window-action): Use it. Expand docstring. (ivy--switch-buffer-other-tab-action): Ditto. Define function only in Emacs 27+. (ivy-switch-buffer): * counsel.el (counsel-switch-buffer): Make "other tab" feature detection explicit. Re: abo-abo#2915.
Great!
Thanks, just ping back here when the process is complete, or if you have any questions. |
So, I sent off the initial email to the FSF. I got a response with a form with a section for me and one for an FSF referee of some kind. I filled out my part (leaving the other blank) and absent any other instructions, emailed back to the person who sent it to me. Should I expect some sort of confirmation of my CA, or am I good to go? |
Thanks for working on this!
I think we need to wait until you've heard back from the copyright clerk and have received a copy of your CA (the text). |
My CA confirmation came through today, so this can be merged now |
I've been learning recently about tab-bar-mode, which is great. Like opening in the other window, or other frame, I think it would be useful for functions like
counsel-find-file
to have an action for opening in the other tab. I think t is currently free in the default actions list, and it would make sense for this. I would be happy to write up a PR if this seems like a good idea.