如何让 Emacs 显示空格(如空格、制表符、换行符等)。许多其他编辑器,如 Kate 和 Eclipse 都具有此功能,我发现查看代码何时因空格和制表符(尤其是 Python)的混合而出现缩进非常有用。
J. Pablo Fernández
问问题
40209 次
3 回答
70
WhiteSpace模式是 Emacs 次要模式,用于可视化当前缓冲区中的所有空白字符。它可以用 激活M-x whitespace-mode
。
这是直接取自 Emacs wiki 的 WhiteSpace 的截图,
注意:WhiteSpaceMode 现在已经取代了 BlankMode
于 2008-11-16T11:30:16.403 回答
5
此处(空白模式)和此处和此处(ShowWhiteSpace)似乎总结了所有可能的设置
还:
(if (>= emacs-major-version 22)
(progn
;; Mode to use with Emacs 22
;; http://emacswiki.org/cgi-bin/wiki/BlankMode
(require 'blank-mode)
;; Mode not active by default: let's activate it
(global-blank-mode t)
;; ... activate it when text mode where color syntax is not active by default
(add-hook 'text-mode-hook 'blank-mode-on)
;; All invisible chars are shown, except newline char.
(setq blank-chars '(tabs spaces trailing lines space-before-tab))
;; Show only for one color, no mark inserted
(setq blank-style '(color))
;; Use for normal space (not shown)
(set-face-background 'blank-space-face nil)
(set-face-foreground 'blank-space-face "black")
;; used for non breakable space
(set-face-background 'blank-hspace-face "PaleGreen")
(set-face-foreground 'blank-hspace-face "black")
;; Used for spaces left of a tab
(set-face-background 'blank-space-before-tab-face "orange")
(set-face-foreground 'blank-space-before-tab-face "black")
;; Used for tab
(set-face-background 'blank-tab-face "lemonchiffon")
(set-face-foreground 'blank-tab-face "black")
;; used for extra space at the end of a line
(set-face-background 'blank-trailing-face "gold")
(set-face-foreground 'blank-trailing-face "black")
;; Used for line too long
(set-face-background 'blank-line-face "snow2")
(set-face-foreground 'blank-line-face "black")
)
(progn
;; For older Emacs prior to version 22.
;; http://www.emacswiki.org/cgi-bin/wiki/show-wspace.el
(require 'show-wspace)
(add-hook 'font-lock-mode-hook 'show-ws-highlight-tabs)
(add-hook 'font-lock-mode-hook 'show-ws-highlight-hard-spaces)
(add-hook 'font-lock-mode-hook 'show-ws-highlight-trailing-whitespace)
)
)
于 2008-11-16T10:30:28.693 回答
4
缩进破坏?- 永远不要在代码中使用标签 - 现在磁盘空间很便宜。
放入(setq-default indent-tabs-mode nil)
您的 .emacs 文件。习惯于键入C-x h M-x untabify
以取消整个缓冲区的制表符。要搜索标签类型C-s C-i
。如果缓冲区中有模糊的控制字符,可以使用M-x hexl-mode
.
也C-x h M-x indent-region
将缩进整个缓冲区。某些模式(如 vhdl-mode)具有美化区域命令。
于 2008-11-16T22:20:07.807 回答