【发布时间】:2009-02-27 09:55:16
【问题描述】:
我使用ViewSourceWith 编辑我的 StackOverflow 答案和问题 和 Emacs。通常,我包含代码和StackOverflow formatting rules 说它必须缩进四个空格才能被识别为 这样的。手动甚至使用宏都是很痛苦的。
我搜索了 SO 以前的帖子,但一无所获。
从Python模式开始,我写了:
(defun text-shift-region (start end count)
"Indent lines from START to END by COUNT spaces."
(save-excursion
(goto-char end)
(beginning-of-line)
(setq end (point))
(goto-char start)
(beginning-of-line)
(setq start (point))
(indent-rigidly start end count)))
(defun text-shift-region-right (start end &optional count)
"Shift region of code to the right
Stolen from python-mode.
The lines from the line containing the start of the current region up
to (but not including) the line containing the end of the region are
shifted to the right, by `text-indent-offset' columns.
If a prefix argument is given, the region is instead shifted by that
many columns. With no active region, indent only the current line."
(interactive
(let ((p (point))
(m (mark))
(arg current-prefix-arg))
(if m
(list (min p m) (max p m) arg)
(list p (save-excursion (forward-line 1) (point)) arg))))
(text-shift-region start end (prefix-numeric-value
(or count text-indent-offset)))
)
;; Code in StackOverflow must be marked by four spaces at the
;; beginning of the line
(setq text-indent-offset 4)
(global-set-key "\C-c>" 'text-shift-region-right)
它似乎有效,但我欢迎建议、替代方案、错误报告, 等等
【问题讨论】:
-
是的,我希望能得到我速成解决方案的替代品,或者收到有趣的补丁。
-
另外,它似乎可能对某些人有所帮助,所以我用它来看看是否有足够的兴趣在某处要求文档。
-
冒着指出显而易见的风险,markdown 编辑器有一个工具栏按钮(也是 CTRL+K 键盘),它可以将文本缩进 4 个空格。
-
谢谢,但重点是使用 Emacs,而不是内置编辑器(使用 Emacs 的所有其他功能)。
-
@hackinwords:因为,正如我多次说过的,我更喜欢 Emacs 而不是 SO 的内置编辑器。