aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-06-13 23:24:28 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-06-13 23:24:28 +0200
commit5bacde1f77c96318a9d36e82d3d6646e91094228 (patch)
tree309740b2d5804427c3a05563c9b3a487a23b048f
parent47fc14590e0c3eb159b2f679c540844b414e0874 (diff)
downloadlightroff-5bacde1f77c96318a9d36e82d3d6646e91094228.tar.gz
xroff.el: Improve highlighting of troff escapes.
-rw-r--r--xroff.el50
1 files changed, 40 insertions, 10 deletions
diff --git a/xroff.el b/xroff.el
index 48ba533..54ae981 100644
--- a/xroff.el
+++ b/xroff.el
@@ -6,20 +6,50 @@
(not ?>))))
">"))
+(defvar xroff--single-escape-regexp
+ (rx "\\" any))
+
+(defvar xroff--identifier-escape-regexp
+ (rx "\\"
+ (any "FfgkmnOsYZ*$")
+ (? (any "+-"))
+ (or (not (any "([+-"))
+ (seq "(" any any)
+ (seq "[" (* (not "]")) "]"))))
+
+(defvar xroff--parameter-escape-regexp
+ (rx "\\"
+ (any "ABbCDHhLlMNoRSVvwXxz")
+ "'" (* (not "'")) "'"))
+
(defconst xroff-font-lock-keywords
`(("<!--.*-->"
(0 font-lock-comment-face))
- ("\\\\\\(.\\)"
- (1 font-lock-builtin-face))
(,(concat xroff--request-regexp)
(1 font-lock-keyword-face)
(2 font-lock-string-face))
(,(concat "\\\\" xroff--request-regexp)
(1 nil t)
(2 nil t))
- ;; ("<FS\\(?: \\(?:\\\\>\\|[^>]\\)*\\)?>\\(.*?\\)<FE\\(?: \\(?:\\\\>\\|[^>]\\)*\\)?>"
- ;; 1 font-lock-doc-string)
- ))
+ (,xroff--parameter-escape-regexp
+ (0 xroff-escape-face))
+ (,(concat "\\\\" xroff--parameter-escape-regexp)
+ (0 nil t))
+ (,xroff--identifier-escape-regexp
+ (0 xroff-escape-face))
+ (,(concat "\\\\" xroff--identifier-escape-regexp)
+ (0 nil t))
+ (,xroff--single-escape-regexp
+ (0 xroff-escape-face))
+ (,(concat "\\\\" xroff--single-escape-regexp)
+ (0 nil t))
+ (,"\\\\\\\\"
+ (0 xroff-escape-face t))))
+
+(defface xroff-escape
+ '((t (:foreground "gray")))
+ "`xroff-mode' face used to highlight backslash escapes.")
+(defvar xroff-escape-face 'xroff-escape)
(define-derived-mode xroff-mode text-mode "Xroff"
"Major mode for editing documents with xroff syntax."
@@ -29,19 +59,19 @@
(setq-local paragraph-start "<\\([^>]\\)+>")
(setq-local paragraph-separate "$\\|\\]>")
(setq-local adaptive-fill-regexp "[ \t]*")
- (add-hook 'fill-nobreak-predicate 'sgml-fill-nobreak nil t)
- (setq-local indent-line-function 'sgml-indent-line)
+ ;; (add-hook 'fill-nobreak-predicate 'sgml-fill-nobreak nil t)
+ ;; (setq-local indent-line-function 'sgml-indent-line)
(setq-local comment-start "<!-- ")
(setq-local comment-end " -->")
- (setq-local comment-indent-function 'sgml-comment-indent)
- (setq-local comment-line-break-function 'sgml-comment-indent-new-line)
+ ;; (setq-local comment-indent-function 'sgml-comment-indent)
+ ;; (setq-local comment-line-break-function 'sgml-comment-indent-new-line)
(setq-local skeleton-further-elements '((completion-ignore-case t)))
(setq-local skeleton-end-hook
(lambda ()
(or (eolp)
(not (or (eq v2 '\n) (eq (car-safe v2) '\n)))
(newline-and-indent))))
- (setq-local font-lock-defaults '((xroff-font-lock-keywords) nil t nil))
+ (setq-local font-lock-defaults '((xroff-font-lock-keywords)))
;; (setq-local font-lock-multiline t)
(setq-local comment-start-skip "<!--[ \t]*")
(setq-local comment-end-skip "[ \t]*--[ \t\n]*>")