问题描述
|
我知道有一些解决方法可以使emacs显示80行列,但是我不希望这种视觉干扰。如果字符超过80个字符,我想使其突出显示。
解决方法
另一个简单的选择是在表达式
.\\{81\\}
上运行highlight-lines-matching-regexp
。
每行81个字符或更多的字符将以您选择的颜色突出显示。
, 参见whitespace-mode
-它现在是Emacs的一部分,除了突出显示长行以外,还可以做更多的事情。 (但是,当然只能用于此操作。)
, 这是来自Emacs Dev Kit的配置:
;; whitespace-mode
;; free of trailing whitespace and to use 80-column width,standard indentation
(setq whitespace-style \'(trailing lines space-before-tab
indentation space-after-tab)
whitespace-line-column 80)
基本上,您只需要最后一点,但是我发现其他设置非常有用(我讨厌制表符和尾随空格)。
, 尝试highlight-80+.el
。您可以从这里获取。
要安装它,只需将以下内容添加到您的.emacs
中:
(add-to-list \'load-path \"/path/to/highlight-80+\")
(require \'highlight-80+)
然后,您可以通过以下方式启用它:
M-xhighlight-80+-mode
, 这是一些示例代码,该代码将突出显示第80列以外的带有当前\'warning \'面的文本,以及一行将其启用为C ++模式的行。
;; Turn on warn highlighting for characters outside of the \'width\' char limit
(defun font-lock-width-keyword (width)
\"Return a font-lock style keyword for a string beyond width WIDTH
that uses \'font-lock-warning-face\'.\"
`((,(format \"^%s\\\\(.+\\\\)\" (make-string width ?.))
(1 font-lock-warning-face t))))
(font-lock-add-keywords \'c++-mode (font-lock-width-keyword 80))
它并没有突出显示整条线,但是我发现它是相当有用的。
, 这并不是您想要的,但是我遇到了类似的问题,并找到了这个问题/答案。我只想在需要时插入视觉指南。这是我最终得到的结果:
(defun insert-80 ()
\"Insert an 80-character-wide guide at beginning of line.\"
(interactive)
(beginning-of-line)
(insert \"0 1 2 3 4 5 6 7 |\")
(newline)
(insert \"01234567890123456789012345678901234567890123456789012345678901234567890123456789|\")
(newline)
)
超级简单,但有时非常有效。
, emacs-goodies-el
(建议将其安装在终端中)中有一个内置软件包,称为highlight-beyond-fill-column.el,请将其添加到your5ѭ或init.el
中:
(setq-default fill-column 80)
(add-hook \'prog-mode-hook \'highlight-beyond-fill-column)
(custom-set-faces \'(highlight-beyond-fill-column-face
((t (:foreground \"red\" )))))
摘录中8080之后的fill-column
文本将以be15ѭ的颜色突出显示。您可以根据需要设置脸部。
, 这与此处的其他答案类似,不同之处在于使用fill-column
,并且在模式切换后运行。因此,每种模式都可以具有自己的线宽,突出显示会适当地考虑它。
(add-hook \'after-change-major-mode-hook
(lambda ()
(when (derived-mode-p \'prog-mode)
(let ((column-re (format \"^[^\\n]\\\\{%d\\\\}\\\\(.*\\\\)$\" fill-column)))
(font-lock-add-keywords nil
`((,column-re 1 font-lock-warning-face prepend)))))))
如果您也希望对文本文件启用prog-mode
检查,则可能不希望删除。