How can I make emacs highlight lines that go over 80 chars?

后端 未结 8 1541
不思量自难忘°
不思量自难忘° 2020-12-01 02:18

I know there are solutions to making emacs show the 80 line column, but I don\'t want that sort of visual disturbance. I\'d just like to make it highlight a line if it\'s ov

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 02:37

    Here is some example code which will highlight text that lies beyond column 80 with the current 'warning' face, and a line to enable it for C++ mode.

    ;; 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))
    

    It doesn't highlight the whole line, but I find it is reasonably helpful.

提交回复
热议问题