emacs 自动高亮 *E *F 等并高亮到 EOL

emacs automatically highlight *E *F etc and highlight to EOL

我正在尝试构建我的主要模式,用于从某个工具流中突出显示日志文件的语法。 我一直在使用这个优秀的指南来开始 http://ergoemacs.org/emacs/elisp_syntax_coloring.html

但我想突出显示“*W”、“*E”和“*F” 但我无法让它工作

这是我的字体锁定关键字

(setq mylog-font-lock-keywords
  (let* (
         ;; define several category of keywords
        (x-warnings  '("UVM_ERROR" "UVM_FATAL" "^.*E" "F"))
        (x-keywords '("UVM_INFO" "NOTE" "Note"))
        (x-types '("UVM_WARNING" "*W," "xmsim"))
        (x-constants '("ACTIVE" "AGENT" "ALL_SIDES" "ATTACH_BACK"))
        (x-events '("at_rot_target" "at_target" "attach"))
        (x-functions '("llAbs" "llAcos" "llAddToLandBanList" "llAddToLandPassList"))



        ;; generate regex string for each category of keywords
        (x-keywords-regexp (regexp-opt x-keywords 'words))
        (x-types-regexp (regexp-opt x-types 'words))
        (x-constants-regexp (regexp-opt x-constants 'words))
        (x-events-regexp (regexp-opt x-events 'words))
        (x-functions-regexp (regexp-opt x-functions 'words))
        (x-warnings-regexp (regexp-opt x-warnings 'words))
        )

    `(
      (,x-types-regexp . font-lock-type-face)
      (,x-constants-regexp . font-lock-constant-face)
      (,x-events-regexp . font-lock-builtin-face)
      (,x-functions-regexp . font-lock-function-name-face)
      (,x-keywords-regexp . font-lock-keyword-face)
      (,x-warnings-regexp . font-lock-warning-face)
      ;; note: order above matters, because once colored, that part won't change.
      ;; in general, put longer words first
      )))

;;;###自动加载 (定义派生模式 mylog-mode verilog-mode "log mode" "Major mode for editing LOG FILES…"

;;语法高亮代码 (setq font-lock-defaults '((mylog-font-lock-keywords)))) (set-face-foreground 'font-lock-type-face "yellow")

;;将模式添加到“功能”列表 (提供'mylog-mode)

如您所见,我已经尝试了一些方法但没有成功。是否正确突出显示了其他单词?

作为最后一点,我想对所有出现的警告或错误进行突出显示,直到 EOL。

我找到了一些示例,但 none 显示了如何在主要模式 lisp 文件中突出显示直到 EOL

这是一个例子(取自我的init.el)。希望对你有帮助。

(font-lock-add-keywords nil
  '( ; high-light full line ending with "E" or "FATAL"
     ("^.*\(E\|FATAL\)$" . 'font-lock-function-name-face)
     ; high-light full line beginning with '*E' '*F' '*W'
     ("^\*[EFW]\b.*$" . 'font-lock-comment-face)
     ; high-light only ending part of the lines which contain "F"
     ("\b\w*F$" . 'font-lock-function-name-face)
     ; high-light from "UVM" to end of line
     ("\bUVM.*$" . 'font-lock-function-name-face)
     ; high-light only words that end with "G"
     ("\b\w*G\b" . 'font-lock-function-name-face)
     ; bold things between 2 **, like **bold**
     ("\*\*.+?\*\*" . 'bold)))