[英]Multikeys shortcuts in Emacs
I'm using the following solution to quickly open files in Emacs (thanks to lawlist for the code ) 我正在使用以下解决方案在Emacs中快速打开文件(感谢Lawlist提供的代码 )
The code : OPTION # 2 -- function with options: 代码 :OPTION#2-带有选项的功能:
(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"))))
It works well. 它运作良好。 I press F5 and then another key to open my file. 我按F5键,然后按另一个键打开文件。 However, I have now a lot of shorcuts and I would like to call them by pressing two (or more) keys. 但是,我现在有很多快捷方式,我想通过按两个(或更多)键来调用它们。
For example, I have a project named "website-kate" which is a folder containing two main files index.html
and stylesheet.css
. 例如,我有一个名为“ website-kate”的项目,该项目包含两个主文件index.html
和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") 我想要两个快捷键ki (即:按F5打开快捷拨号,然后先按k,然后按i表示“ kate”和“ index”)和ks (表示“ kate”和“ stylesheet”)
Of course this code doesn't work: 当然,此代码不起作用:
((eq choice ?ki)
(find-file "/home/user/website-kate/index.html")
(message "Opened: %s" (buffer-name)))
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. 使用字符串的interactive
形式只能读取一个键,但是interactive
也可以采用一种形式求值而不是字符串,因此您可以实现自己的多键读取形式。 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.) (不过,以易于配置的方式进行操作要困难一些。)
Internally, (interactive "cFoo: ")
does simply use read-key
, so you're just expanding on the same concept. 在内部, (interactive "cFoo: ")
仅使用read-key
,因此您只是在扩展相同的概念。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.