reddit / emacs

Helm, bookmarks, and tab-bar-mode

granti128 · 2022-12-18 01:28
I’ve really gotten into using tabs in Emacs 28.2. I’ve also been checking out Helm more thoroughly. Although Helm has the feature `helm-filtered-bookmarks` (which is great for me), but when hitting the <tab> key, there are options for opening the bookmarked file in the current buffer, a buffer in a different window, and buffer in a different frame. I thought I’d dig a little to see if I could figure out how to add the ability to open a bookmark in a new tab. **NOTE: I’m just a hobbiest programmer.** I copied `bookmark-jump-other-buffer` and `helm-bookmark-jump-other-buffer` and modified them. I also used `customize-option` to add the line `("Jump to BM other tab" . my/helm-bookmark-jump-other-tab)` to `helm-type-bookmark-actions`. (require 'tab-bar) (require 'helm) (defun my/bookmark-jump-other-tab (bookmark) "Jump to BOOKMARK in another tab. See `bookmark-jump' for more." (interactive (list (bookmark-completing-read "Jump to bookmark (in another tab)" bookmark-current-bookmark))) (bookmark-jump bookmark 'switch-to-buffer-other-tab)) (defun my/helm-bookmark-jump-other-tab (candidate) "Jump to bookmark in other tab action." (let (non-essential) (my/bookmark-jump-other-tab candidate))) I don’t know if the first `require` statement is necessary, given that `tab-bar` is part of GNU Emacs, but I added it just in case. The code seems to be working, but if there’s anything I’ve missed, I would be grateful for input. Also I was wondering if this is something that I should send along to the Helm author for the sake of completeness.
helm05 · 2022-12-18 07:39
You don't have to provide completion on bookmarks in your action function as you already have completion in filtered bookmarks. I have pushed some changes in Helm to provide the feature. Thanks.
granti128 · 2022-12-19 03:07
Hello there. Thank you for your feedback! Sorry, I don't understand the term "action function". Could you please elaborate so I may learn? I would very much appreciate it!
helm05 · 2022-12-19 07:18
An action is a function that is in the :action slot of a source. It is called with a single argument 'candidate'. If you want to bind it to a key you have to make another function, interactive this time that call the action function, you can use the macro `helm-make-command-from-action` for this: ``` (helm-make-command-from-action helm-bookmark-run-jump-other-tab "Jump to bookmark other tab from keyboard." 'helm-bookmark-jump-other-tab) ```