本文介绍了如何在emacs中将键绑定到indent / unindent区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
之前:我想要将缩排/未缩进区域的两个键绑定定义为4个空格。 h3>
hello
world
foo
bar
/ pre>
- 目视选择
world
和 foo 。
- 键入
:
hello
world
foo
bar
hello
world
foo
bar
/ pre> world
和 foo 。
hello
world
foo
bar
我也想绑定到unindent区域。 br>
我不熟悉 emacs
请帮助。
解决方案
已经有键盘快捷键:
缩进:
Unindent
如果您发现输入时间过长,可以将以下内容添加到.emacs文件:
(defun my-indent-region(N)
(互动p)
(if(use-region-p)
(progn(indent-rigidly(region-beginning)(region-end)(* N 4))
set $ n $)
(self-insert-command N))
(defun my-unindent-region(N)
(interactivep)
(if(use-region-p)
(progn(indent-rigidly(region-beginning)(region-end)(* N -4))
(setq deactivate-mark nil) )
(self-insert-command N))
(全局设置键>'我的缩进区域)
(全局设置键<'my-unindent-region)
使用这段代码, / em>()和小于()键将会将标记的区域缩进/取消标记4个空格。 p>
I want to define two key-bindings to indent/unindent region by 4 spaces.
Before:
hello
world
foo
bar
- Visually select
world
andfoo
. - Type
After:
hello
world
foo
bar
I also want to bind to unindent region.
I'm not familiar with emacs
, please help.
解决方案
There are already keyboard shortcuts for that:
Indent:
Unindent
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)
With this code the greater than () and less than () keys will indent/unindent a marked region by 4 spaces each.
这篇关于如何在emacs中将键绑定到indent / unindent区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!