improvements to autoload regexen

many thanks to @Lompik
* don't match empty unit names. AIUI unit names are alphanumeric with
  the exception of the group [-_.@], non ascii are backslash-escaped.
* more strictly match temp file names: .# prefix, [[:hexdigit:]]{16}
  suffix. the filenames are a unit name with a unit suffix (systemctl
  edit --full) or just override.conf (edit without --full option)
* add regex for dropin config files. This is just a file with ".conf"
  extension, with the added constraint that it's a file having some
  parent directory named "systemd"
This commit is contained in:
Mark Oteiza 2016-04-30 17:24:44 -04:00
parent bf39be20e4
commit a434645e76

View File

@ -199,7 +199,7 @@
(defconst systemd-autoload-regexp (defconst systemd-autoload-regexp
(eval-when-compile (eval-when-compile
(rx "." (rx (+? (or alphanumeric (any "-_.@\\"))) "."
(or "automount" "busname" "mount" "service" "slice" (or "automount" "busname" "mount" "service" "slice"
"socket" "swap" "target" "timer" "link" "netdev" "network") "socket" "swap" "target" "timer" "link" "netdev" "network")
string-end)) string-end))
@ -207,12 +207,20 @@
(defconst systemd-tempfn-autoload-regexp (defconst systemd-tempfn-autoload-regexp
(eval-when-compile (eval-when-compile
(rx (or "automount" "busname" "mount" "service" "slice" (rx ".#"
"socket" "swap" "target" "timer" "link" "netdev" "network" (or (and (+? (or alphanumeric (any "-_.@\\"))) "."
(or "automount" "busname" "mount" "service" "slice"
"socket" "swap" "target" "timer" "link" "netdev" "network"))
"override.conf") "override.conf")
(?? (= 16 (char hex-digit))) string-end)) (= 16 (char hex-digit)) string-end))
"Regexp for temp file buffers in which to autoload `systemd-mode'.") "Regexp for temp file buffers in which to autoload `systemd-mode'.")
(defconst systemd-dropin-autoload-regexp
(eval-when-compile
(rx "/systemd/" (+? anything) ".d/"
(+? (or alphanumeric (any "-_.@\\"))) ".conf" string-end))
"Regexp for dropin config file buffers in which to autoload `systemd-mode'.")
(defun systemd-get-value (start) (defun systemd-get-value (start)
"Return the value of the key whose value begins at position START. "Return the value of the key whose value begins at position START.
Lines ending in a backslash are concatenated with the next Lines ending in a backslash are concatenated with the next
@ -357,6 +365,8 @@ See systemd.unit(5) for details on unit file syntax.")
(add-to-list 'auto-mode-alist `(,systemd-autoload-regexp . systemd-mode)) (add-to-list 'auto-mode-alist `(,systemd-autoload-regexp . systemd-mode))
;;;###autoload ;;;###autoload
(add-to-list 'auto-mode-alist `(,systemd-tempfn-autoload-regexp . systemd-mode)) (add-to-list 'auto-mode-alist `(,systemd-tempfn-autoload-regexp . systemd-mode))
;;;###autoload
(add-to-list 'auto-mode-alist `(,systemd-dropin-autoload-regexp . systemd-mode))
;;;###autoload ;;;###autoload
(define-derived-mode systemd-mode conf-mode "Systemd" (define-derived-mode systemd-mode conf-mode "Systemd"