[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/systemd b0c1d64 109/131: add multi-line comment highlighti
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/systemd b0c1d64 109/131: add multi-line comment highlighting |
Date: |
Sun, 29 Aug 2021 11:35:24 -0400 (EDT) |
branch: elpa/systemd
commit b0c1d64d62d9209d45fff813a35f917badc9f051
Author: Mark Oteiza <mvoteiza@udel.edu>
Commit: Mark Oteiza <mvoteiza@udel.edu>
add multi-line comment highlighting
between font-lock-keywords, the elisp manual, examples in the emacs
source (sh-mode is one) and the webernets, it is rather difficult to
find a way to properly deal with multi-line construct syntax
highlighting. this is a way leveraging anchored matching and
jit-lock.
---
systemd.el | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/systemd.el b/systemd.el
index 49cd290..5708ea3 100644
--- a/systemd.el
+++ b/systemd.el
@@ -24,7 +24,7 @@
;; Major mode for editing systemd units.
-;; Similar to `conf-mode' but with added highlighting; e.g. for
+;; Similar to `conf-mode' but with enhanced highlighting; e.g. for
;; specifiers and booleans. Employs strict regex for whitespace.
;; Features a facility for browsing documentation: use C-c C-o to open
;; links to documentation in a unit (cf. systemctl help).
@@ -258,8 +258,27 @@ See `font-lock-keywords' and (info \"(elisp) Search-based
Fontification\")."
(`candidates (all-completions arg (systemd-completion-table nil)))
(`post-completion (if (not (systemd-buffer-section-p)) (insert "=")))))
+(defun systemd-construct-start-p ()
+ "Return non-nil if the current line is the first in a multi-line construct."
+ (let ((flag t))
+ (save-excursion
+ (while (and (zerop (forward-line -1))
+ (eq ?\\ (char-before (line-end-position)))
+ (skip-chars-forward " \t")
+ (setq flag (memq (following-char) '(?# ?\;))))))
+ flag))
+
+(defun systemd-comment-matcher (limit)
+ "Matcher for comments.
+Only matches comments on lines passing `systemd-construct-start-p'."
+ (let ((re "^[ \t]*?\\([#;]\\)\\(.*\\)$")
+ match)
+ (while (and (setq match (re-search-forward re limit t))
+ (not (systemd-construct-start-p))))
+ match))
+
(defconst systemd-font-lock-keywords-1
- `(("^[[:space:]]*?\\([#;]\\)\\(.*\\)$"
+ `((systemd-comment-matcher
(1 'font-lock-comment-delimiter-face)
(2 'font-lock-comment-face))
;; sections
@@ -354,6 +373,7 @@ Key bindings:
(conf-mode-initialize systemd-comment-start)
(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)
(setq font-lock-defaults
'((systemd-font-lock-keywords
systemd-font-lock-keywords-1
- [nongnu] elpa/systemd bf39be2 062/131: assimilate systemd-company.el into systemd.el, (continued)
- [nongnu] elpa/systemd bf39be2 062/131: assimilate systemd-company.el into systemd.el, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 3580191 067/131: add autoload regex tests, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 16be183 084/131: don't indiscriminately use relative file name, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd f0b29ad 087/131: systemd v232 directives, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 7874a10 090/131: future flycheck has a checker for units, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd fa1277d 092/131: add reminder, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 59ce8ad 095/131: simpler while test, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 9693935 099/131: nix extra newline, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 7bb8f09 104/131: correct syntax?, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd a4f4096 107/131: moar keywords, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd b0c1d64 109/131: add multi-line comment highlighting,
ELPA Syncer <=
- [nongnu] elpa/systemd 5c9389d 110/131: move this matcher down with the other ones, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd a3d3921 111/131: extend multi-line matching to sections and keys, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd a9f82b1 124/131: add systemd-mode company backend buffer locally, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 401d71c 122/131: Add %E, %j, %J, %T, %V specifiers, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd ec8f6cf 128/131: happy new year, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd b6ae63a 131/131: add specifiers (leave obsoleted ones in for now), ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 0416fe4 130/131: drop some unneeded eval-when-compile, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 50c63c2 026/131: allow cycling completions in `systemd-doc-open`, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 612c3de 027/131: double bump, ELPA Syncer, 2021/08/29
- [nongnu] elpa/systemd 347c157 031/131: lexical binding, ELPA Syncer, 2021/08/29