如何在 emacs 中将键绑定到缩进/取消缩进区域? [英] How to bind keys to indent/unindent region in emacs?
本文介绍了如何在 emacs 中将键绑定到缩进/取消缩进区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想定义两个键绑定来缩进/取消缩进 4 个空格.
I want to define two key-bindings to indent/unindent region by 4 spaces.
hello
world
foo
bar
- 视觉选择
world
和foo
. - 输入>
hello
world
foo
bar
<小时>
我还想将 < 绑定到非缩进区域.
我对 emacs
不熟悉,请帮忙.
I also want to bind < to unindent region.
I'm not familiar with emacs
, please help.
推荐答案
已经有键盘快捷键:
缩进:C-u 4 C-x TAB
无缩进 C-u - 4 C-x TAB
如果您觉得太长而无法输入,您可以将以下内容放入您的 .emacs 文件中:
If you find that too long to type, you could put the following in your .emacs file:
(defun my-indent-region (N)
(interactive "p")
(if (use-region-p)
(progn (indent-rigidly (region-beginning) (region-end) (* N 4))
(setq deactivate-mark nil))
(self-insert-command N)))
(defun my-unindent-region (N)
(interactive "p")
(if (use-region-p)
(progn (indent-rigidly (region-beginning) (region-end) (* N -4))
(setq deactivate-mark nil))
(self-insert-command N)))
(global-set-key ">" 'my-indent-region)
(global-set-key "<" 'my-unindent-region)
使用此代码,大于(>)和小于(<)键将将标记区域缩进/取消缩进 4 个空格.
With this code the greater than (>) and less than (<) keys will indent/unindent a marked region by 4 spaces each.
这篇关于如何在 emacs 中将键绑定到缩进/取消缩进区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文