Skip to content

Commit

Permalink
Add "other tab" actions to some commands
Browse files Browse the repository at this point in the history
* 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).
  • Loading branch information
Hugo-Heagren authored and basil-conto committed Sep 30, 2021
1 parent 5f49149 commit d295e0c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
19 changes: 15 additions & 4 deletions counsel.el
Original file line number Diff line number Diff line change
Expand Up @@ -1935,8 +1935,10 @@ choose between `yes-or-no-p' and `y-or-n-p'; otherwise default to

(ivy-set-actions
'counsel-find-file
'(("j" find-file-other-window "other window")
`(("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")
Expand Down Expand Up @@ -2331,6 +2333,8 @@ https://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec"))
'counsel-recentf
`(("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")))
("x" counsel-find-file-extern "open externally")
("d" ,(lambda (file) (setq recentf-list (delete file recentf-list)))
"delete from recentf")))
Expand Down Expand Up @@ -2439,8 +2443,10 @@ This function uses the `dom' library from Emacs 25.1 or later."

(ivy-set-actions
'counsel-buffer-or-recentf
'(("j" find-file-other-window "other window")
`(("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")))
("x" counsel-find-file-extern "open externally")))

(defun counsel-buffer-or-recentf-transformer (var)
Expand Down Expand Up @@ -2491,6 +2497,9 @@ By default `counsel-bookmark' opens a dired buffer for directories."
(ivy-set-actions
'counsel-bookmark
`(("j" bookmark-jump-other-window "other window")
,@(and (fboundp 'find-file-other-tab)
`(("t" ,(counsel--apply-bookmark-fn #'find-file-other-tab)
"other tab")))
("d" bookmark-delete "delete")
("e" bookmark-rename "edit")
("s" bookmark-set "overwrite")
Expand Down Expand Up @@ -6346,8 +6355,10 @@ in the current window."

(ivy-set-actions
'counsel-switch-buffer
'(("x" counsel-open-buffer-file-externally "open externally")
("j" ivy--switch-buffer-other-window-action "other window")))
`(("x" counsel-open-buffer-file-externally "open externally")
("j" ivy--switch-buffer-other-window-action "other window")
,@(and (fboundp 'find-file-other-tab)
'(("t" ivy--switch-buffer-other-tab-action "other tab")))))

;;** `counsel-compile'
(defvar counsel-compile-history nil
Expand Down
17 changes: 16 additions & 1 deletion ivy.el
Original file line number Diff line number Diff line change
Expand Up @@ -4441,6 +4441,17 @@ BUFFER may be a string or nil."
(find-file-other-window (cdr virtual))
(switch-to-buffer-other-window buffer)))))

(defun ivy--switch-buffer-other-tab-action (buffer)
"Switch to BUFFER in other tab.
BUFFER may be a string or nil."
(if (zerop (length buffer))
(switch-to-buffer-other-tab ivy-text)
(let ((virtual (assoc buffer ivy--virtual-buffers)))
(if (and virtual
(not (get-buffer buffer)))
(find-file-other-tab (cdr virtual))
(switch-to-buffer-other-tab buffer)))))

(defun ivy--rename-buffer-action (buffer)
"Rename BUFFER."
(let ((new-name (read-string "Rename buffer (to new name): ")))
Expand Down Expand Up @@ -4505,12 +4516,16 @@ Otherwise, forward to `ivy-kill-line'."

(ivy-set-actions
'ivy-switch-buffer
'(("f"
`(("f"
ivy--find-file-action
"find file")
("j"
ivy--switch-buffer-other-window-action
"other window")
,@(and (fboundp 'find-file-other-tab)
'(("t"
ivy--switch-buffer-other-tab-action
"other tab")))
("k"
ivy--kill-buffer-action
"kill")
Expand Down

0 comments on commit d295e0c

Please sign in to comment.