extend multi-line matching to sections and keys

This commit is contained in:
Mark Oteiza 2017-09-11 09:25:09 -04:00
parent 5c9389dae3
commit a3d39214b7

View File

@ -253,14 +253,27 @@ file, defaulting to the link under point, if any."
(setq flag (memq (following-char) '(?# ?\;)))))) (setq flag (memq (following-char) '(?# ?\;))))))
flag)) flag))
(defun systemd-comment-matcher (limit) (defmacro define-systemd-matcher (name regexp &optional docstring)
"Matcher for comments. "Define a new function NAME that matches REGEXP in a multi-line construct.
Only matches comments on lines passing `systemd-construct-start-p'." Only returns matches of REGEXP on lines passing `systemd-construct-start-p'."
(let ((re "^[ \t]*?\\([#;]\\)\\(.*\\)$") (declare (debug (symbolp stringp &optional stringp))
match) (indent 2) (doc-string 3))
(while (and (setq match (re-search-forward re limit t)) `(defun ,name (limit)
(not (systemd-construct-start-p)))) ,docstring
match)) (let (match)
(while (and (setq match (re-search-forward ,regexp limit t))
(not (systemd-construct-start-p))))
match)))
(define-systemd-matcher systemd-comment-matcher "^[ \t]*?\\([#;]\\)\\(.*\\)$"
"Matcher for comments. ")
(define-systemd-matcher systemd-section-matcher
"^\\(\\[\\([[:upper:]][[:alnum:]]+\\|X-.*?\\)\\]\\)"
"Matcher for section titles.")
(define-systemd-matcher systemd-key-matcher "^\\([[:upper:]][[:alnum:]]+\\)="
"Matcher for keys (unit directives).")
(defun systemd-exec-prefix-anchored-matcher (limit) (defun systemd-exec-prefix-anchored-matcher (limit)
"Matcher for the exec prefix in anchored font-lock rule. "Matcher for the exec prefix in anchored font-lock rule.
@ -281,11 +294,8 @@ See `font-lock-keywords' and (info \"(elisp) Search-based Fontification\")."
`((systemd-comment-matcher `((systemd-comment-matcher
(1 'font-lock-comment-delimiter-face) (1 'font-lock-comment-delimiter-face)
(2 'font-lock-comment-face)) (2 'font-lock-comment-face))
;; sections (systemd-section-matcher 1 'font-lock-type-face)
("^\\(\\[\\([[:upper:]][[:alnum:]]+\\|X-.*?\\)\\]\\)" (systemd-key-matcher 1 'font-lock-keyword-face))
1 'font-lock-type-face)
;; keys
("^\\([[:upper:]][[:alnum:]]+\\)=" 1 'font-lock-keyword-face))
"Minimal expressions to highlight in `systemd-mode'.") "Minimal expressions to highlight in `systemd-mode'.")
(defconst systemd-font-lock-keywords-2 (defconst systemd-font-lock-keywords-2