Emacs Lisp 在 init 文件中对齐键绑定定义

发布于 2024-09-26 10:32:50 字数 143 浏览 0 评论 0原文

我的 Emacs 初始化文件中有以下行。

(global-set-key (kbd "C-x a r") 'align-regexp)

有没有办法在特定的正则表达式中进行硬编码,这样我就不必每次都指定它?

I have the following line in my Emacs init file.

(global-set-key (kbd "C-x a r") 'align-regexp)

Is there any way to hard-code in a particular regex so that I don't have to specify it every time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木格 2024-10-03 10:32:50

您可以使用硬编码的正则表达式创建自己的命令,如下所示:

(defun align-specific-regexp (beg end)
  "Call 'align-regexp with the regexp ..."
  (interactive "r")
  (align-regexp beg end "^some.*regexp\\(here\\)?"))

You could create your own command with the hard-coded regexp like so:

(defun align-specific-regexp (beg end)
  "Call 'align-regexp with the regexp ..."
  (interactive "r")
  (align-regexp beg end "^some.*regexp\\(here\\)?"))
掌心的温暖 2024-10-03 10:32:50

您可以将该按键序列绑定到键盘宏:

(fset 'my-align-regexp
   [?\M-x ?a ?l ?i ?g ?n ?- ?r ?e ?g ?e ?x ?p return ?f ?o ?o return])

(global-set-key (kbd "C-x a r") 'my-align-regexp)

使用 Mxalign-regexp 创建键盘宏,然后输入您的正则表达式。

然后使用 Mxinsert-kbd-macro return return 将宏插入到 .emacs 文件中

You could just bind that key-sequence to a keyboard-macro:

(fset 'my-align-regexp
   [?\M-x ?a ?l ?i ?g ?n ?- ?r ?e ?g ?e ?x ?p return ?f ?o ?o return])

(global-set-key (kbd "C-x a r") 'my-align-regexp)

Create a keyboard macro with M-xalign-regexp then enter your regex.

Then insert the macro into your .emacs file with M-xinsert-kbd-macro return return

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文