From 46963566ce084c5644ed7630b85f76c93eccb95a Mon Sep 17 00:00:00 2001 From: nverno Date: Mon, 22 Jul 2019 00:48:58 -0400 Subject: [PATCH 1/5] added capf for env. variables --- systemd.el | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/systemd.el b/systemd.el index 6db0403..1d0838f 100644 --- a/systemd.el +++ b/systemd.el @@ -230,21 +230,22 @@ file, defaulting to the link under point, if any." (if sectionp systemd-network-sections systemd-network-directives)) (t (if sectionp systemd-unit-sections systemd-unit-directives))))) +(defun systemd-env-variable-table (&rest _ignore) + "Completion table with environment variables." + (mapcar (lambda (x) (substring x 0 (string-match "=" x))) process-environment)) + (defun systemd-complete-at-point () "Complete the symbol at point." - (let ((bounds (bounds-of-thing-at-point 'symbol))) - (list (or (car bounds) (point)) - (or (cdr bounds) (point)) - (completion-table-dynamic #'systemd-completion-table)))) - -(defun systemd-company-backend (command &optional arg &rest _ignored) - "Backend for `company-mode' in `systemd-mode' buffers." - (interactive (list 'interactive)) - (pcase command - (`interactive (company-begin-backend 'systemd-company-backend)) - (`prefix (and (eq major-mode 'systemd-mode) (company-grab-symbol))) - (`candidates (all-completions arg (systemd-completion-table nil))) - (`post-completion (if (not (systemd-buffer-section-p)) (insert "="))))) + (when-let* ((bounds (bounds-of-thing-at-point 'symbol))) + (list (car bounds) (cdr bounds) + (completion-table-in-turn + (completion-table-dynamic #'systemd-completion-table) + (completion-table-dynamic #'systemd-env-variable-table)) + :exit-function + (lambda (_ finished) + (when (and (not (systemd-buffer-section-p)) + (memq finished '(sole finished))) + (insert "=")))))) (defun systemd-construct-start-p () "Return non-nil if the current line is the first in a multi-line construct." @@ -407,6 +408,8 @@ Key bindings: (set-keymap-parent systemd-mode-map nil) (conf-mode-initialize systemd-comment-start) (setq-local auto-fill-inhibit-regexp "^[ \t]*?[^;#]") + (make-local-variable 'company-backends) + (cl-pushnew 'company-capf company-backends) (add-hook 'completion-at-point-functions #'systemd-complete-at-point nil t) (add-hook 'font-lock-extend-region-functions 'systemd-font-lock-extend-region nil t) From 3b1b55552bd8af0978b07791a9ac505da8dd7db1 Mon Sep 17 00:00:00 2001 From: Juergen Hoetzel Date: Sun, 16 Feb 2020 13:35:57 +0100 Subject: [PATCH 2/5] Add autoload for systemd.path unit --- systemd.el | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/systemd.el b/systemd.el index 1d0838f..4e11ae6 100644 --- a/systemd.el +++ b/systemd.el @@ -129,20 +129,22 @@ ;;;###autoload (defconst systemd-autoload-regexp - (rx (+? (any "a-zA-Z0-9-_.@\\")) "." - (or "automount" "busname" "mount" "service" "slice" - "socket" "swap" "target" "timer" "link" "netdev" "network") - string-end) + (eval-when-compile + (rx (+? (any "a-zA-Z0-9-_.@\\")) "." + (or "automount" "busname" "mount" "path" "service" "slice" + "socket" "swap" "target" "timer" "link" "netdev" "network") + string-end)) "Regexp for file buffers in which to autoload `systemd-mode'.") ;;;###autoload (defconst systemd-tempfn-autoload-regexp - (rx ".#" - (or (and (+? (any "a-zA-Z0-9-_.@\\")) "." - (or "automount" "busname" "mount" "service" "slice" - "socket" "swap" "target" "timer" "link" "netdev" "network")) - "override.conf") - (= 16 (char hex-digit)) string-end) + (eval-when-compile + (rx ".#" + (or (and (+? (any "a-zA-Z0-9-_.@\\")) "." + (or "automount" "busname" "mount" "path" "service" "slice" + "socket" "swap" "target" "timer" "link" "netdev" "network")) + "override.conf") + (= 16 (char hex-digit)) string-end)) "Regexp for temp file buffers in which to autoload `systemd-mode'.") ;;;###autoload From 929b052dcd4e082b684982dd34e5e53fd77882c8 Mon Sep 17 00:00:00 2001 From: Phil Brown Date: Sun, 30 Jan 2022 14:27:44 -0800 Subject: [PATCH 3/5] Fix txt file paths during native-compile-async When building systemd.el with async native compile, we can't rely on `load-file-name`, so fall back to the native relative path lookup performed in `insert-file-contents`. native-compile-async runs compilation in a subprocess launched by loading an elisp program from a temporary file: (native-compile-async "/home/phil/.emacs.d/systemd/systemd.el") => invokes emacs --batch -l /tmp/emacs-async-comp-systemd-BZ3kNs.el Inside the subprocess, `load-file-name` is /tmp/emacs-async-comp-systemd-BZ3kNs.el instead of .../systemd/systemd.el and the local txt resource files (unit-directives.txt etc) aren't resolvable from /tmp. --- systemd.el | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/systemd.el b/systemd.el index 4e11ae6..97c4ade 100644 --- a/systemd.el +++ b/systemd.el @@ -89,7 +89,9 @@ (with-temp-buffer (insert-file-contents (let ((f "unit-directives.txt")) - (if (null load-file-name) f + (if (or (null load-file-name) + (bound-and-true-p comp-async-compilation)) + f (expand-file-name f (file-name-directory load-file-name))))) (split-string (buffer-string)))) "Configuration directives for systemd.") @@ -108,7 +110,9 @@ (with-temp-buffer (insert-file-contents (let ((f "network-directives.txt")) - (if (null load-file-name) f + (if (or (null load-file-name) + (bound-and-true-p comp-async-compilation)) + f (expand-file-name f (file-name-directory load-file-name))))) (split-string (buffer-string)))) "Network configuration directives for systemd.") @@ -122,7 +126,9 @@ (with-temp-buffer (insert-file-contents (let ((f "nspawn-directives.txt")) - (if (null load-file-name) f + (if (or (null load-file-name) + (bound-and-true-p comp-async-compilation)) + f (expand-file-name f (file-name-directory load-file-name))))) (split-string (buffer-string)))) "Namespace container configuration directives for systemd.") From 4d7efddfb5c73f4326158bfc59c253f220850e7e Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Mon, 7 Aug 2023 23:44:00 -0700 Subject: [PATCH 4/5] Make complete function non-exclusive This will allow other completion at point functions to run to autocomplete things like file path. Figured this out from https://github.com/minad/cape/issues/24 --- systemd.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/systemd.el b/systemd.el index 97c4ade..1c353cf 100644 --- a/systemd.el +++ b/systemd.el @@ -253,7 +253,8 @@ file, defaulting to the link under point, if any." (lambda (_ finished) (when (and (not (systemd-buffer-section-p)) (memq finished '(sole finished))) - (insert "=")))))) + (insert "="))) + :exclusive 'no))) (defun systemd-construct-start-p () "Return non-nil if the current line is the first in a multi-line construct." From 105f4c7f1395112bc14a54dd45f27d8fff3765ad Mon Sep 17 00:00:00 2001 From: Abdelhak Bougouffa Date: Mon, 15 Jul 2024 20:44:59 +0200 Subject: [PATCH 5/5] Fix company integration (don't assume company is loaded/installed) --- systemd.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/systemd.el b/systemd.el index 1c353cf..4e7199b 100644 --- a/systemd.el +++ b/systemd.el @@ -417,8 +417,9 @@ Key bindings: (set-keymap-parent systemd-mode-map nil) (conf-mode-initialize systemd-comment-start) (setq-local auto-fill-inhibit-regexp "^[ \t]*?[^;#]") - (make-local-variable 'company-backends) - (cl-pushnew 'company-capf company-backends) + (with-eval-after-load 'company + (make-local-variable 'company-backends) + (cl-pushnew 'company-capf company-backends)) (add-hook 'completion-at-point-functions #'systemd-complete-at-point nil t) (add-hook 'font-lock-extend-region-functions 'systemd-font-lock-extend-region nil t)