Regex 如何在Emacs Lisp中编写函数以突出显示语法?
我需要为Emacs添加Haskell语法高亮显示。我无法为函数定义高亮显示创建regexp,因为Emacs Lisp regexps不支持向前看(?=)和向后看(?)这里的“不工作”是什么意思?是否发生任何高亮显示?是否会因错误而崩溃?您希望发生什么?您似乎返回Regex 如何在Emacs Lisp中编写函数以突出显示语法?,regex,haskell,emacs,syntax-highlighting,Regex,Haskell,Emacs,Syntax Highlighting,我需要为Emacs添加Haskell语法高亮显示。我无法为函数定义高亮显示创建regexp,因为Emacs Lisp regexps不支持向前看(?=)和向后看(?)这里的“不工作”是什么意思?是否发生任何高亮显示?是否会因错误而崩溃?您希望发生什么?您似乎返回(nil)从高亮显示haskell函数,而不是nil。这给了我一个符号的函数定义是无效的错误。haskell模式是否正确高亮显示?AJFarmar,当我运行haskell模式时,没有任何变化,emacs会继续正常工作。我希望函数定义像so
(nil)
从高亮显示haskell函数
,而不是nil
。这给了我一个符号的函数定义是无效的
错误。haskell模式是否正确高亮显示?AJFarmar,当我运行haskell模式时,没有任何变化,emacs会继续正常工作。我希望函数定义像someFunc=un定义更改颜色。
(defun get-cur-character (pos)
(aref (buffer-substring (1- pos) pos) 0))
(defun find-equal-character (pos)
(let ((curchar ?0)
(result nil)
(max-pos (point-max)))
(while (and (not (equal curchar ?\n)) (< pos max-pos))
(setq curchar (get-cur-character pos))
(setq pos (1+ pos))
(if (equal curchar ?=)
(progn
(setq result t)
(setq curchar ?\n))))
result))
(defun highlight-haskell-function (limit)
(save-excursion
(if (not (null (re-search-forward "^\\([a-z]+\\w*\\)" limit t)))
(find-equal-character (match-end 0))
(nil))))
(provide 'haskell-mode)
(font-lock-add-keywords 'haskell-mode '((highlight-haskell-function . 'font-lock-keyword-face)))