我该如何让Emacs显示空格(如空格、制表符、换行等)?很多其他编辑器,比如Kate和Eclipse都有这个功能,我发现它非常有用,能够看到代码由于混合使用了空格和制表符而导致缩进出错的情况(特别是在Python中)。
我该如何让Emacs显示空格(如空格、制表符、换行等)?很多其他编辑器,比如Kate和Eclipse都有这个功能,我发现它非常有用,能够看到代码由于混合使用了空格和制表符而导致缩进出错的情况(特别是在Python中)。
WhiteSpace模式是一个Emacs小模式,可以可视化显示当前缓冲区中的所有空格字符。可以通过输入M-x whitespace-mode
激活它。
以下是从Emacs维基直接获取的WhiteSpace在运行中的屏幕截图:
注意:WhiteSpace模式已取代BlankMode。
(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)
)
)
indent-broken? - 在你的代码中不要使用制表符 - 如今磁盘空间便宜得多。
在你的 .emacs 文件中加入 (setq-default indent-tabs-mode nil)
。习惯性地输入C-x h M-x untabify
将整个缓冲区取消制表符。要搜索制表符,请键入 C-s C-i
。如果您的缓冲区中有不明确的控制字符,则可以使用 M-x hexl-mode
查看它们。
此外,C-x h M-x indent-region
将缩进整个缓冲区。某些模式(例如 vhdl-mode)具有美化区域命令。
C-h f untabify
而不是
C-x h M-x untabify
- To1neC-h f untabify
:关于 untabify
的帮助。C-x h M-x untabify
:标记整个缓冲区,然后运行 untabify
。 - user256434
M-x whitespace-mode
。) - bug