Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Emacs I can do C-x 5 C-f or C-x 5 f to find a file in a new frame. I want to do something similar but for bookmarks. How can I jump to a bookmark in a new frame?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

There is bookmark-jump-other-window which you can clone and modify to create the function my-bookmark-jump-other-frame:

(defun my-bookmark-jump-other-frame (bookmark)
  "Jump to BOOKMARK in another frame.  See `bookmark-jump' for more."
  (interactive
   (list (bookmark-completing-read "Jump to bookmark (in another frame)"
                                   bookmark-current-bookmark)))
  (bookmark-jump bookmark 'switch-to-buffer-other-frame))

Bind that function to a key chord of your liking and use it to open bookmarks in another frame, e.g. like that:

(global-set-key (kbd "C-x C-5 b") 'my-bookmark-jump-other-frame)

Note that my-bookmark-jump-other-frame still needs bookmark.el and its functions. Make sure the appropriate functions are loaded in your startup file, e.g.:

(require 'bookmark)

or

(autoload 'bookmark-completing-read "bookmark"
 "Prompting with PROMPT ...[rest of docstring (optional)]")
share|improve this answer
    
That seems to work. Could you please include an appropriate way to bind a key for completeness? I figure that C-x C-5 b is an appropriate bind since it seems unbound and it is similar to the normal jump to bookmark, C-x r b, and also to find file in new frame. –  N.N. Jan 18 '12 at 9:55
    
You can e.g. use (global-set-key (kbd "C-x C-5 b") 'my-bookmark-jump-other-frame). –  u-punkt Jan 18 '12 at 10:51
    
I have encountered a problem with your solution. If I try to use it before I have used bookmarks in any other way during a session I get "list: Symbol's function definition is void: bookmark-completing-read". However, if I jump to a bookmark some other way, e.g. C-x r b and then try M-x my-bookmark-jump-other-frame it works. Can this be solved? –  N.N. Jan 18 '12 at 16:27
    
A (require 'bookmark) in your startup file should do. If you don't want to load bookmark.el unconditionally on each startup you could also use (autoload 'bookmark-completing-read "bookmark" "Prompting with PROMPT ... (plus rest of docstring from bookmark.el (optional))"). –  u-punkt Jan 19 '12 at 8:24
    
Could you please include that info and a full description of the autoload solution in the answer? I am unfamiliar with how to complete it. –  N.N. Jan 19 '12 at 8:33

I wanted to jump to a new frame, from a bookmark in the bookmark menu/list, without a prompt.

But u-punkt's explanation was helpful in constructing this new function. I cloned the existing command associated with RET, and bound it to the unused C-RET locally to mode.

You can describe the original key with C-h k RET. Tracking down the code for bookmark-bmenu-this-window is not hard, then use u-punkt's strategy to write the following:

(defun my-bookmark-bmenu-other-frame (&optional use-region-p) ; Bound to `C-RET' in bookmark list
  "Select this line's bookmark in a new frame.
See `bookmark-jump' for info about the prefix arg."
  (interactive "P")
  (bmkp-bmenu-barf-if-not-in-menu-list)
  (bookmark-bmenu-ensure-position)
  (let ((bookmark-name  (bookmark-bmenu-bookmark)))
    (bmkp-jump-1 bookmark-name 'switch-to-buffer-other-frame use-region-p)))

For the keybinding, bookmark-bmenu-mode-map is not defined until bookmark+ is loaded, so I use an eval-after-load,

(eval-after-load 'bookmark+ '(define-key bookmark-bmenu-mode-map 
                              (kbd "<C-return>") 
                              'my-bookmark-bmenu-other-frame))

EDIT

If you need something that works when bookmark+ is not installed, try the following,

(when (locate-library "bookmark+")
  '(eval-after-load 'bookmark 'bookmark+))

(if (locate-library "bookmark+")
    ;; then
    (defun my-bookmark-bmenu-other-frame (&optional use-region-p) ; Bound to `C-RET' in bookmark list
      "Select this line's bookmark in a new frame.
See `bookmark-jump' for info about the prefix arg."
      (interactive "P")
      (bmkp-bmenu-barf-if-not-in-menu-list)
      (bookmark-bmenu-ensure-position)
      (let ((bookmark-name  (bookmark-bmenu-bookmark)))
        (bmkp-jump-1 bookmark-name 'switch-to-buffer-other-frame use-region-p)))
  ;; else
  (defun my-bookmark-bmenu-other-frame ()
    "Select this line's bookmark in other frame."
    (interactive)
    (bookmark-jump (bookmark-bmenu-bookmark) 'switch-to-buffer-other-frame))
  )

(eval-after-load 'bookmark '(define-key bookmark-bmenu-mode-map 
                              (kbd "<C-return>") 
                              'my-bookmark-bmenu-other-frame))
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.