Emacs更快的书签跳转? [英] Emacs quicker bookmark-jump?

查看:130
本文介绍了Emacs更快的书签跳转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的大部分书签都以一个字母的前缀,以
的第一个字母几乎总是唯一地确定书签。
这样,我可以通过这种方式,例如
跳转到我的源文件夹(以s:source的形式加入书签),使用 M-x书签跳转RET s RET
我有一个快捷方式,所以它实际上是〜s RET



我想摆脱 RET 最后,
ie get Mx书签 - 快速跳转RET s 〜s
执行上述任务。
我也喜欢它回到默认行为:向我显示所有书签
,从给定的字母开始,以防万一没有一个变体。



到目前为止,我已经有:

 (defun bookmark-do-quick-jump )
(let((completions(all-completions str bookmark-alist)))
(bookmark-jump
(if(eq 1(length completions))
(car completions )
(完成阅读跳到书签:bookmark-alist nil t str)))))

还有两个打嗝:



首先,我需要以某种方式跳入minibuffer,并坚持在这个地图(不知道该怎么做) :$($($($)

$ $ $ $ $ $ $ )
(mapcar(lambda(key)
(define-key map key
(lambda()
(interactive)
(bookmark-do-quic k-jump key))))
(循环为c从?a到?z
collect(string c)))
map))

其次,当我打电话时

  (bookmark-do-quick-jumpo)

它带有3种变体(org-捕获最后存储标记...)。
我现在在迷你缓存中,但是我仍然需要按 RET RET
来查看这3个变体。我想这样做是自动完成的。



感谢任何回应,直接回答我的两个子问题,
或完全不同的方法,只要我可以得到的行为和我描述的可用性



UPD:



我已经通过切换解决了第二件事从完成阅读 ido-completion-read

 (defun bookmark-do-quick-jump(str)
(let((Completions(all-completions str bookmark-alist)))
(bookmark-跳
(if(eq 1(length completions))
(car completions)
(ido-completion-read跳转到书签:completions nil t str))))

Btw,我忘了提到我使用书签+ 。我不知道是否跳转到
由默认的书签跳转支持。

解决方案

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

我最初使用了(或(minibuffer-complete-and-exit)(minibuffer-completion-help))乍看起来非常好,但正如评论中所指出的,当一个书签的名字是另一个书签的前缀时,它不太理想,因为它会立即接受较短的名称,因此使更长的一个无法访问。



调用 minibuffer-complete minibuffer-completion-help 一起打破完成功能,但是,我已将 minibuffer-complete-and-exit 的相关部分复制到新功能。

 (需要书签)

(defvar bookmark-do-quick-jump-map(copy-keymap minibuffer-local-must-match-map)
bookmark-do-quick-jump的键盘图

`minibuffer-local-must-match-map'在
REQUIRE-MATCH参数为t时被'completion-read'使用

在`bookmark-do-quick -jump'我们绑定这个修改的副本以使用它的位置。)

(定义键书签快速跳转映射
[remap self-insert-command] my-self-insert-complete-and-exit)

(defun bookmark-do-quick-jump()
自动完成和自动接受跳转到指定的书签。
(interactive)
(bookmark-maybe-load-default-file)
(let((minibuffer-local-must-match-map bookmark-do-quick-jump-map))
(书签跳转
(完成阅读跳转到书签:书签 - 主语nil t))))

(defun my-self-insert-com plete-and-exit(n)
插入字符,然后尝试完成当前字符串,
只有一个选项保留时自动退出,否则显示
完成选项。
(interactivep)
(self-insert-command n)
(my-minibuffer-complete)
(let((my-completions(completion-all-sorted- )
(if(和我的完成(eq 0(cdr my-completions)))
(exit-minibuffer)
(minibuffer-completion-help)))$

(defun my-minibuffer-complete()
从minibuffer-complete-and-exit复制
(interactive)
(条件状态为零
(完成 - do-completion nil'expect-exact)
(错误1)))






编辑:



我用另一个刺。有一点令人遗憾的是,你没有得到下一个重要角色,突出显示了您使用常规minibuffer完成的方式(因为这是下一步打下什么的好指标),但这似乎在其他方面很好地工作。

 (需要书签)
(require'ido)

(defvar bookmark-ido-quick-jump-map(copy-keymap minibuffer-local-map)
bookmark-ido-quick-jump的键盘图

每次ido-completion-read被称为重新初始化
`ido-common-completion-map'并将其父级设置为minibuffer-local-map

在bookmark-ido-quick-jump中,我们提供这个修改后的副本作为替换
父项。)

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

(defun bookmark-ido-quick-jump()
跳转到所选书签,使用自动完成和自动接受
(交互式)
(书签可能是加载默认文件)
(let((minibuffer-local-map bookmark-ido-quick-jump-map))
(ido-enable-prefix t))
(书签跳转
(ido-completion-read跳转到书签:
b)))))))

(defun my-self-insert-and-ido-complete(n)
插入字符,然后尝试完成当前字符串
$ b(interactivep)
(self-insert-command n)
;; ido使用缓冲区本地前后命令钩子,所以我们需要
;;与他们合作。我们附加我们的命令后功能,以便
;;在ido完成处理我们的自我插入后执行。
(add-hook'post-command-hook
'my-self-insert-and-ido-complete-post-command tt))

(defun my-self -insert-and-ido-complete-post-command()
(remove-hook'post-command-hook
'my-self-insert-and-ido-complete-post-command t)
;;现在,ido已经完成了对当前
;;命令的正常处理,我们模拟了一个后续的ido-complete命令
(ido-tidy);; pre-command -hook
(ido-complete)
(ido-exhibit));; post-command-hook


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.

So far, I've got:

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

There's still two hiccups:

Firstly, I need to jump into minibuffer somehow and stick in there this map (don't know how to do this):

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

Secondly, when I do a call

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

I'd appreciate any responses that either directly answer my two sub-problems, or an altogether different approach, as long as I can get the behavior and usability that I described.

UPD:

I've solved the second thing by switching from 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)))))

Btw, I forgot to mention that I use bookmark+. I'm not sure if jumping to dired is supported by the default bookmark-jump.

解决方案

We can remap self-insert-command during the completing-read to trigger the auto-completion and auto-acceptance behaviour.

I originally used (or (minibuffer-complete-and-exit) (minibuffer-completion-help)) which at first glance worked very nicely but, as noted in the comments, is less than ideal when one bookmark's name is the prefix of another, as it will immediately accept the shorter name, hence making the longer one inaccessible.

Calling minibuffer-complete and minibuffer-completion-help together breaks the completion functionality, however, so instead I've copied the relevant part of minibuffer-complete-and-exit to a new function. Using this resolves all of the earlier problems.

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

I took another stab at this using ido. It's a little unfortunate that you don't get the next 'important character' highlighted the way that you do with the regular minibuffer completion (as that was a nice indicator of what to type next), but this seems to work nicely in other respects.

(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

这篇关于Emacs更快的书签跳转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆