Emacs中的Multikeys快捷键 [英] Multikeys shortcuts in Emacs

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

问题描述

我使用以下解决方案来快速打开Emacs中的文件(感谢代码

I'm using the following solution to quickly open files in Emacs (thanks to lawlist for the code)

代码:OPTION#2 - 带有选项的功能: p>

The code : OPTION # 2 -- function with options:

(global-set-key (kbd "<f5>") 'lawlist-bookmark)

(defun lawlist-bookmark (choice)
  "Choices for directories and files."
  (interactive "c[D]ired | [v]ocab.org | [g]td.org | [d]iary.org | [n]otes.org")
    (cond
           ((eq choice ?D)
           (dired "/very/long/and/boring/path/which/make/me/use/tab/for/..."))
           ((eq choice ?v)
           (find-file "/Users/HOME/.0.data/vocab.org")
            (message "Opened:  %s" (buffer-name)))
          ((eq choice ?g)
           (find-file "/Users/HOME/.0.data/gtd.org")
            (message "Opened:  %s" (buffer-name)))
          ((eq choice ?d)
           (find-file "/Users/HOME/.0.data/diary.org")
            (message "Opened:  %s" (buffer-name)))
          ((eq choice ?n)
           (find-file "/Users/HOME/.0.data/notes.org")
            (message "Opened:  %s" (buffer-name)))
          (t (message "Quit"))))

它工作得很好。我按 F5 ,然后按另一个键打开我的文件。但是,现在我已经有很多的剪刀了,我想通过按两个(或更多)键来打电话给他们。

It works well. I press F5 and then another key to open my file. However, I have now a lot of shorcuts and I would like to call them by pressing two (or more) keys.

例如,我有一个名为网站-kate是包含两个主要文件 index.html stylesheet.css 的文件夹。我想要两个快捷键 ki (也就是说:按 F5 打开shorcut拨盘,然后按k,然后按kate和index)和< kbd> ks (对于kate和stylesheet)

For example, I have a project named "website-kate" which is a folder containing two main files index.html and stylesheet.css. I would like two shortcuts ki (that is to say: press F5 to open shorcut dial and press first k and then i for "kate" and "index") and ks (for "kate" and "stylesheet")

当然这个代码不起作用:

Of course this code doesn't work:

    ((eq choice ?ki)
    (find-file "/home/user/website-kate/index.html")
        (message "Opened:  %s" (buffer-name)))


推荐答案

使用字符串的交互式表单只能读取单个键,但 interactive 也可以使用表单进行评估而不是一个字符串,所以你可以实现自己的多键阅读表单。例如:

The interactive form using strings can only read a single key, but interactive can also take a form to evaluate instead of a string, so you can implement your own multi-key reading form. For example like this:

(interactive
 (list
  (let ((key (read-key "First key: ")))
    (cond
     ((equal key ?a)
      (message "a pressed"))
     ((equal key ?k)
      (let ((key (read-key "Second key: ")))
        (cond
         ((equal key ?i)
          (message "ki pressed"))
         (t
          (message "I don't know k%c" key)))))))))

这应该很容易扩展到你的全部用例。 (尽管这样做容易配置的方式稍微困难一些。)

This should be easy to extend to your full use case. (Doing it in a way that is easy to configure is slightly harder, though.)

在内部,(交互式cFoo:) code>只是使用 read-key ,所以你只是在同一个概念上扩展。

Internally, (interactive "cFoo: ") does simply use read-key, so you're just expanding on the same concept.

这篇关于Emacs中的Multikeys快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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