[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/systemd 47ae79a 112/131: Use syntax-propertize and font-lo
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/systemd 47ae79a 112/131: Use syntax-propertize and font-lock-extend-region-functions |
Date: |
Sun, 29 Aug 2021 11:35:25 -0400 (EDT) |
branch: elpa/systemd
commit 47ae79aed03e175bf7e2362a88d53bb776a58043
Author: Mark Oteiza <mvoteiza@udel.edu>
Commit: Mark Oteiza <mvoteiza@udel.edu>
Use syntax-propertize and font-lock-extend-region-functions
---
systemd.el | 44 ++++++++++++++++++++++++++++++++++----------
1 file changed, 34 insertions(+), 10 deletions(-)
diff --git a/systemd.el b/systemd.el
index 7cce5d5..f83a072 100644
--- a/systemd.el
+++ b/systemd.el
@@ -44,6 +44,9 @@
(declare-function company-begin-backend "company")
(declare-function company-grab-symbol "company")
+(defvar font-lock-beg)
+(defvar font-lock-end)
+
(defgroup systemd ()
"Major mode for editing systemd units."
:link '(url-link "http://www.freedesktop.org/wiki/Software/systemd/")
@@ -253,6 +256,30 @@ file, defaulting to the link under point, if any."
(setq flag (memq (following-char) '(?# ?\;))))))
flag))
+(defun systemd-syntax-propertize (start end)
+ "`systemd-propertize-function' for `systemd-mode' buffers."
+ (let ((case-fold-search nil))
+ (goto-char start)
+ (funcall
+ (syntax-propertize-rules
+ ("^[ \t]*\\([;#]\\)$?"
+ (1 (when (systemd-construct-start-p) (string-to-syntax "<")))))
+ start end)))
+
+(defun systemd-font-lock-extend-region ()
+ (goto-char font-lock-beg)
+ (while (and (zerop (forward-line -1))
+ (= (char-before (line-end-position)) ?\\)
+ (skip-chars-forward " \t")
+ (not (memq (following-char) '(?# ?\;)))))
+ (setq font-lock-beg (point-marker))
+ (goto-char font-lock-end)
+ (while (and (= (char-before (line-end-position)) ?\\)
+ (skip-chars-forward " \t")
+ (not (memq (following-char) '(?# ?\;)))
+ (zerop (forward-line))))
+ (setq font-lock-end (line-end-position)))
+
(defmacro define-systemd-matcher (name regexp &optional docstring)
"Define a new function NAME that matches REGEXP in a multi-line construct.
Only returns matches of REGEXP on lines passing `systemd-construct-start-p'."
@@ -265,9 +292,6 @@ Only returns matches of REGEXP on lines passing
`systemd-construct-start-p'."
(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.")
@@ -291,10 +315,7 @@ See `font-lock-keywords' and (info \"(elisp) Search-based
Fontification\")."
(set-match-data res)))))
(defconst systemd-font-lock-keywords-1
- `((systemd-comment-matcher
- (1 'font-lock-comment-delimiter-face)
- (2 'font-lock-comment-face))
- (systemd-section-matcher 1 'font-lock-type-face)
+ `((systemd-section-matcher 1 'font-lock-type-face)
(systemd-key-matcher 1 'font-lock-keyword-face))
"Minimal expressions to highlight in `systemd-mode'.")
@@ -345,6 +366,7 @@ See systemd.unit(5) for details on unit file syntax.")
(let ((table (make-syntax-table)))
(modify-syntax-entry ?% "/" table)
(modify-syntax-entry ?$ "'" table)
+ (modify-syntax-entry ?\; "." table)
table)
"Syntax table used in `systemd-mode' buffers.")
@@ -381,15 +403,17 @@ Key bindings:
\\{systemd-mode-map}"
(set-keymap-parent systemd-mode-map nil)
(conf-mode-initialize systemd-comment-start)
+ (setq-local auto-fill-inhibit-regexp "^[ \t]*?[^;#]")
(add-hook 'company-backends #'systemd-company-backend)
(add-hook 'completion-at-point-functions #'systemd-complete-at-point nil t)
- (setq-local jit-lock-contextually t)
+ (add-hook 'font-lock-extend-region-functions
+ 'systemd-font-lock-extend-region nil t)
+ (setq-local syntax-propertize-function #'systemd-syntax-propertize)
(setq font-lock-defaults
'((systemd-font-lock-keywords
systemd-font-lock-keywords-1
systemd-font-lock-keywords-2
- systemd-font-lock-keywords-3)
- t)))
+ systemd-font-lock-keywords-3))))
(provide 'systemd)
- [nongnu] elpa/systemd 6f2e31e 048/131: add a mode menu, (continued)
- [nongnu] elpa/systemd 6f2e31e 048/131: add a mode menu, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 1a7af12 051/131: no strings with single quotes either, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 26de1dd 056/131: don't turn on company by default, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd cd22a2c 065/131: use a-zA-Z0-9, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd bd1b86e 072/131: woops!, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd f74f3c8 075/131: add to buffer-local hooks, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 921f8d0 074/131: nix systemd-use-company-p, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd a73c16a 085/131: nix LOCAL argument for adding to company-backends, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd bf7b281 088/131: nix unneeded arg, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd b561c6b 093/131: happy new year, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 47ae79a 112/131: Use syntax-propertize and font-lock-extend-region-functions,
ELPA Syncer <=
- [nongnu] elpa/systemd 22f024f 118/131: systemd 235, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd c6e06df 123/131: happy new year, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 5b68986 024/131: add C-c C-d for opening systemd.directives(7), ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 09bfb67 030/131: explicitly require cl-lib, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 077b294 036/131: no change in systemd 220, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd f69d903 040/131: add missing network directives, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 1513dd0 054/131: systemd 228, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd dbf7830 057/131: happy new year, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd a434645 063/131: improvements to autoload regexen, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 4121a9a 064/131: section names can be prefixed with X-, ELPA Syncer, 2021/08/29