aboutsummaryrefslogtreecommitdiff
path: root/tw/services/files/emacs-packages/pam-env-mode.el
diff options
context:
space:
mode:
authorTimo Wilken2024-03-09 14:52:56 +0100
committerTimo Wilken2024-03-10 16:19:00 +0100
commitde20fc8d904643ffe6957febfc6a24e57c12b512 (patch)
tree8177459e40786bd432a37c5833f26350fb689356 /tw/services/files/emacs-packages/pam-env-mode.el
parentda5e9d5ee98dfc216eb7e3b1559c09f4bf868bf6 (diff)
Separate home service into PIM, dev env and graphical parts
This means we only instantiate Shepherd and mcron services if we really need them, to avoid annoyance on servers.
Diffstat (limited to 'tw/services/files/emacs-packages/pam-env-mode.el')
-rw-r--r--tw/services/files/emacs-packages/pam-env-mode.el45
1 files changed, 45 insertions, 0 deletions
diff --git a/tw/services/files/emacs-packages/pam-env-mode.el b/tw/services/files/emacs-packages/pam-env-mode.el
new file mode 100644
index 00000000..75b0bf94
--- /dev/null
+++ b/tw/services/files/emacs-packages/pam-env-mode.el
@@ -0,0 +1,45 @@
+;;; pam-env.el --- Major mode for pam_env.conf(5) files.
+
+;;; Commentary:
+
+;; This major mode font-locks files including ~/.pam_environment and
+;; /etc/security/pam_env.conf, but notably not /etc/environment. Their format is
+;; specified by the pam_env.conf(5) man page.
+
+;; TODO: Only apply font-lock-variable-name-face to variable declarations if
+;; the previous line didn't end with a backslash. The following case didn't
+;; work (some declarations that should've been font-locked weren't):
+;; '("\\(?:^$\\|[^\\\\]\\)[\r\n]\\([^[:blank:]]+\\)"
+;; 1 font-lock-variable-name-face keep)
+
+;; pam_env does not support escaped double quotes ("). Single-quoted strings are
+;; not used as string delimiters. We can only match against word chars in
+;; `pam-env-mode/font-lock-defaults', so make double quotes word chars.
+
+;;; Code:
+
+(defconst pam-env-mode/font-lock-defaults
+ '((("^#+" . font-lock-comment-delimiter-face)
+ ("^#+[[:blank:]]*\\(.*\\)$" 1 font-lock-comment-face)
+ ("\\\\[@$\\]" . font-lock-string-face) ; escaped $ @ \
+ ("@{[^}]+}" . font-lock-builtin-face) ; @{}-variable references
+ ("\\${[^}]+}" . font-lock-variable-name-face) ; ${}-variable references
+ ("\"[^\"]*\"" 0 font-lock-string-face keep) ; double-quoted strings; escaped " not supported
+ ("\\<\\(DEFAULT\\|OVERRIDE\\)=" . font-lock-keyword-face) ; DEFAULT= and OVERRIDE=
+ ("^[^[:blank:]]+" . font-lock-variable-name-face) ; variable declarations
+ ("[[:blank:]]+[^[:blank:]]+" . font-lock-warning-face)) ; stray whitespace
+ t nil ((?\' . "w") (?\" . "w")))
+ "Font lock settings for PAM-Environment mode. See `font-lock-defaults' for documentation.")
+
+(define-derived-mode pam-env-mode prog-mode "PAM-Environment"
+ "PAM-environment mode is used for pam_env.conf(5) files."
+ (set (make-local-variable 'comment-start) "#")
+ (set (make-local-variable 'comment-start-skip) "^#+[[:blank:]]*")
+ (set (make-local-variable 'comment-end) "")
+ (set (make-local-variable 'font-lock-defaults) pam-env-mode/font-lock-defaults))
+
+(let ((regexp "\\(\\`\\|/\\)\\(pam_env\\.conf\\|\\.pam_environment\\)\\'"))
+ (add-to-list 'auto-mode-alist `(,regexp . pam-env-mode)))
+
+(provide 'pam-env-mode)
+;;; pam-env.el ends here