编辑

编辑

在 Emacs 中,我可以使用C-x 5 C-fC-x 5 f来在新框架中查找文件。我想对书签执行类似操作。如何在新框架中跳转到书签?

答案1

您可以克隆并修改它bookmark-jump-other-window来创建函数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))

将该功能绑定到您喜欢的按键和弦,然后使用它在另一个框架中打开书签,例如:

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

请注意my-bookmark-jump-other-frame仍然需要bookmark.el及其功能。确保在启动文件中加载了适当的功能,例如:

(require 'bookmark)

或者

(autoload 'bookmark-completing-read "bookmark"
 "Prompting with PROMPT ...[rest of docstring (optional)]")

答案2

我想从书签菜单/列表中的书签跳转到新框架,无需提示

但 u-punkt 的解释对构建这个新功能很有帮助。我克隆了与 关联的现有命令RET,并将其绑定到未使用的C-RET本地 to 模式。

你可以用 来描述原始密钥C-h k RET。追踪 的代码bookmark-bmenu-this-window并不难,然后使用 u-punkt 的策略编写以下内容:

(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)))

对于键绑定,直到加载bookmark-bmenu-mode-map后才定义,因此我使用,bookmark+eval-after-load

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

编辑

bookmark+如果您需要在未安装时也能正常工作,请尝试以下操作,

(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))

相关内容