Emacs 书签跳转更快?

2023-11-29

I have most of my bookmarks prefixed by a letter in a way that the first letter almost always uniquely determines the bookmark. This way I can, for instance, jump to my source folder (bookmarked as "s: source") with M-x bookmark-jump RET s RET. I have it on a shortcut, so it's actually ~ s RET.

I'd like to get rid of RET in the end, i.e. get M-x bookmark-quick-jump RET s or ~ s to do the aforementioned job. I'd also like it to fall back to the default behavior: to show me all bookmarks that start with the given letter, in case there's not just one variant.

到目前为止,我已经得到:

(defun bookmark-do-quick-jump (str)
  (let ((completions (all-completions str bookmark-alist)))
    (bookmark-jump
     (if (eq 1 (length completions))
         (car completions)
       (completing-read "Jump to bookmark: " bookmark-alist nil t str)))))

还有两个问题:

首先,我需要以某种方式跳入迷你缓冲区并粘贴这张地图(不知道如何执行此操作):

(setq bookmark-quick-jump-map
      (let ((map (make-sparse-keymap)))
        (mapcar (lambda (key) 
                  (define-key map key 
                    (lambda()
                      (interactive)
                      (bookmark-do-quick-jump key))))
                (loop for c from ?a to ?z
                      collect (string c)))
        map))

其次,当我打电话时

(bookmark-do-quick-jump "o")

It comes back with 3 variants (org-capture-last-stored, org-capture-last-stored-marker...). I'm in minibuffer now, but I still need to press RET RET to see these 3 variants. I'd like this to be done automatically.

我很感激任何直接回答我的两个子问题的回复, 或者完全不同的方法,只要我能得到行为和可用性 我所描述的。

UPD:

我通过切换解决了第二件事completing-read to ido-completing-read:

(defun bookmark-do-quick-jump (str)
  (let ((completions (all-completions str bookmark-alist)))
    (bookmark-jump
     (if (eq 1 (length completions))
         (car completions)
       (ido-completing-read "Jump to bookmark: " completions nil t str)))))

顺便说一句,我忘了提及我使用bookmark+。我不确定是否跳到 dired 默认支持bookmark-jump.


我们可以重新映射self-insert-command在完成读取期间触发自动完成和自动接受行为。

我原来用的是(or (minibuffer-complete-and-exit) (minibuffer-completion-help))乍一看效果很好,但正如评论中所述,当一个书签的名称是另一个书签的前缀时,它不太理想,因为它会立即接受较短的名称,从而使较长的名称无法访问。

Calling minibuffer-complete and minibuffer-completion-help然而,一起破坏了完成功能,所以我复制了相关部分minibuffer-complete-and-exit到一个新函数。使用它可以解决所有先前的问题。

(require 'bookmark)

(defvar bookmark-do-quick-jump-map (copy-keymap minibuffer-local-must-match-map)
  "Keymap for `bookmark-do-quick-jump'.

`minibuffer-local-must-match-map' is used by `completing-read' when its
REQUIRE-MATCH argument is t.

In `bookmark-do-quick-jump' we bind this modified copy to use in its place.")

(define-key bookmark-do-quick-jump-map
  [remap self-insert-command] 'my-self-insert-complete-and-exit)

(defun bookmark-do-quick-jump ()
  "Jump to specified bookmark with auto-completion and auto-acceptance."
  (interactive)
  (bookmark-maybe-load-default-file)
  (let ((minibuffer-local-must-match-map bookmark-do-quick-jump-map))
    (bookmark-jump
     (completing-read "Jump to bookmark: " bookmark-alist nil t))))

(defun my-self-insert-complete-and-exit (n)
  "Insert the character, then attempt to complete the current string,
automatically exiting when only one option remains, and displaying the
completion options otherwise."
  (interactive "p")
  (self-insert-command n)
  (my-minibuffer-complete)
  (let ((my-completions (completion-all-sorted-completions)))
    (if (and my-completions (eq 0 (cdr my-completions)))
        (exit-minibuffer)
      (minibuffer-completion-help))))

(defun my-minibuffer-complete ()
  "Copied from `minibuffer-complete-and-exit'."
  (interactive)
  (condition-case nil
      (completion--do-completion nil 'expect-exact)
    (error 1)))

Edit:

我使用 ido 再次尝试了这一点。有点不幸的是,您没有像常规迷你缓冲区完成那样突出显示下一个“重要字符”(因为这是接下来要输入的内容的一个很好的指示器),但这似乎在其他方面工作得很好。

(require 'bookmark)
(require 'ido)

(defvar bookmark-ido-quick-jump-map (copy-keymap minibuffer-local-map)
  "Keymap for `bookmark-ido-quick-jump'.

Every time `ido-completing-read' is called it re-initializes
`ido-common-completion-map' and sets its parent to be `minibuffer-local-map'.

In `bookmark-ido-quick-jump' we provide this modified copy as a replacement
parent.")

(define-key bookmark-ido-quick-jump-map
  [remap self-insert-command] 'my-self-insert-and-ido-complete)

(defun bookmark-ido-quick-jump ()
  "Jump to selected bookmark, using auto-completion and auto-acceptance."
  (interactive)
  (bookmark-maybe-load-default-file)
  (let ((minibuffer-local-map bookmark-ido-quick-jump-map)
        (ido-enable-prefix t))
    (bookmark-jump
     (ido-completing-read "Jump to bookmark: " 
                          (loop for b in bookmark-alist collect (car b))))))

(defun my-self-insert-and-ido-complete (n)
  "Insert the character, then attempt to complete the current string,
automatically exiting when only one option remains."
  (interactive "p")
  (self-insert-command n)
  ;; ido uses buffer-local pre- and post-command hooks, so we need to
  ;; co-operate with those. We append our post-command function so that
  ;; it executes after ido has finished processing our self-insert.
  (add-hook 'post-command-hook
            'my-self-insert-and-ido-complete-post-command t t))

(defun my-self-insert-and-ido-complete-post-command ()
  (remove-hook 'post-command-hook
               'my-self-insert-and-ido-complete-post-command t)
  ;; Now that ido has finished its normal processing for the current
  ;; command, we simulate a subsequent `ido-complete' command.
  (ido-tidy) ;; pre-command-hook
  (ido-complete)
  (ido-exhibit)) ;; post-command-hook
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Emacs 书签跳转更快? 的相关文章

  • Org-Mode 中的 FlySpell 可以像 auctex 一样识别 Latex 语法

    原始回复 我试图弄清楚在 auctex 模式下乳胶如何在打开 Flyspell 的情况下似乎不会突出显示任何乳胶功能 这是一个自定义词典文件还是如何实现的 这可以很容易地合并到组织模式文件中 这样它就不会突出显示将导出的插入乳胶代码吗 编辑
  • 在多个 emacs 缓冲区上执行特定命令

    有没有办法在多个缓冲区上执行 emacs 命令 而不必单独选择它们并在每个单独的缓冲区上执行它 我通常打开与特定正则表达式匹配的多个文件 例如 py并希望启用特定模式 例如hs minor mode or glasses mode在每个上
  • ido-mode 绑定被全局设置键屏蔽

    堆栈溢出 在过去的几天里 我试图稍微定制一下我的 emacs 但我遇到了我不知道如何解决的问题 我想做的是定义一个全局键绑定和一个 ido 模式键绑定 它们将使用相同的键来做不同的事情 Ido 模式键绑定定义如下 defun ido my
  • Emacs 打字骨架对插入也许

    在 Eclipse 中 编辑 Java 代码时 如果我输入一个左括号 我会得到一对括号 如果我然后 输入 第二个括号 它不会插入额外的括号 我如何在 emacs 中得到它 Eclipse 编辑器足够聪明 当我输入闭括号时 它知道我刚刚完成了
  • Emacs 是否具有单词和行补全功能(如 Vim 的插入模式补全功能)?

    Vim 完成单词和行CTRL X P and CTRL L 有一个名为 Company mode 的 Emacs 插件 但该插件会干扰 Emacs 中的许多内容并导致冲突 与全局 linum 和 yasnippets 我知道我可以在 Ema
  • 基于扩展的 Emacs auto-minor-mode

    I found 这个问题 https stackoverflow com questions 1299193 in emacs how to automatically enable a minor mode based on buffer
  • 如何让Emacs显示与实际存储的不同的字符?

    我想使用Elisp为Emacs实现动态文本替换 仅替换显示 不替换实际存储的文件 例如 在 LaTeX 文档中 我想输入 alpha 然后让 Emacs 将其显示为 因此更容易阅读 但在结果中 tex文件 我还想要 alpha 代替 被拯救
  • 使用 slime 时如何跳转到 emacs 中的函数定义?

    我已经使用安装了史莱姆https github com thephoeron slime pack https github com thephoeron slime pack并想进一步探索 common lisp 如何访问 emacs 中
  • 如何使用 Emacs Lisp 检查文件是否存在?

    我希望 emacs 将打开时生成的文件标记为只读 我所缺少的难题部分是如何检查文件是否 存在 我目前有以下内容 get file extension defun get ext file name car cdr split string
  • 如何在 (emacs) shell 命令的输出中添加颜色?

    执行命令时shell命令 关联缓冲区中显示的输出未着色 当从 emacs 中调用测试框架 输出黄色 绿色 红色 时 这尤其令人烦恼 我如何配置或扩展 emacs 以便shell命令允许在 shell 中进行彩色输出并在表示该输出时保留颜色
  • Emacs Lisp 中函数名称中的“internal”是什么意思?

    有些人使用双破折号来表示该功能可能会发生变化 函数名称中的双减号 约定在 Emacs Lisp 中意味着什么 https stackoverflow com questions 3180390 what does the double mi
  • 在 emacs 的文件中不断出现的这些 ^M 是什么?

    我认为这可能与 TextMate 有关 但我们在一个小团队中工作 并且在 git 中几乎相同的文件的全文件冲突方面遇到了一些问题 在一个分支中 文件的每一行都附加了 M 这是什么神秘的事 M角色应该做什么 它从哪里来 我们的开发人员在 Wi
  • 如何在组织模式下关闭公司模式?

    我正在使用 spacemacs 并尝试在组织模式下关闭公司模式 同时将其保留在其他主要模式中 我尝试过以下方法 global company mode not org mode 但它不起作用 禁用自org mode hook 此方法几乎适用
  • Emacs 和 Anaconda。链接问题

    我有一个问题 为了运行Anaconda https store continuum io cshop anaconda 我需要unset LD LIBRARY PATH 为了运行 Emacs 以及其他程序 我需要set LD LIBRARY
  • 如何在 Visual Studio 中删除 Brief 书签?

    我已经为 Visual Studio 创建了绑定Edit BriefBookmarkDropx命令 Edit BriefBookmarkDrop1 Ctrl Shift 1 Edit BriefBookmarkDrop2 Ctrl Shif
  • 减少通过管道传输至 Emacs

    当查看 Less 的管道输出时 有时我希望能够在 Emacs 中查看它 以便获得语法突出显示并使用 emacs 命令进行搜索 标记 复制等 我看到 Less 有一个v可用于打开当前查看的文件的命令 EDITOR 不幸的是 这在查看管道输入时
  • Emacs cperl - 常量块中的缩进

    我正在运行基于 GNU Emacs 24 3 50 2 的 Aquamacs 3 0a cperl 版本是 6 2 当我编辑 Perl 常量块时 我得到了我不想要的额外缩进 use constant ONE gt 1 TWO gt 2 TH
  • Emacs java 模式:malabar、jdee 还是 eclim?

    我想使用 emacs 进行 java 编码 但我对使用什么模式进行 java 编码感到困惑 有 jdee 看起来像 ide malabar 据说他比 jdee 更精通 java 1 5 结构 和 emacs eclim 它是 emacs 的
  • 如何在 Emacs 中保存所有文件(或保存所有缓冲区)?

    C x C s saves only the current buffer 如何保存所有文件 或所有缓冲区 Press C x s and then choose for saving all buffers
  • 向上移动箭头不突出显示文本 emacs iterm2

    我最近有人帮忙修复M left等等 终端元箭头键绑定中的 emacs https stackoverflow com questions 10867199 emacs in terminal meta arrow keybindings 但

随机推荐