From adba2da2a1e00a5a2134131bdae964c659502ad6 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 | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/systemd.el b/systemd.el index 53f9a34..8f843c2 100644 --- a/systemd.el +++ b/systemd.el @@ -230,21 +230,32 @@ 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 "=")))))) + +;; Note: company-capf can take over here +;; (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 "="))))) (defun systemd-construct-start-p () "Return non-nil if the current line is the first in a multi-line construct." @@ -407,7 +418,9 @@ Key bindings: (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) + (make-local-variable 'company-backends) + (cl-pushnew 'company-capf company-backends) + ;; (add-hook 'company-backends #'systemd-company-backend) (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 ffef470208390f762f2cb29582b6c848f16776fe 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/systemd.el b/systemd.el index f544ed9..1e7bb86 100644 --- a/systemd.el +++ b/systemd.el @@ -130,7 +130,7 @@ (defconst systemd-autoload-regexp (eval-when-compile (rx (+? (any "a-zA-Z0-9-_.@\\")) "." - (or "automount" "busname" "mount" "service" "slice" + (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'.") @@ -140,7 +140,7 @@ (eval-when-compile (rx ".#" (or (and (+? (any "a-zA-Z0-9-_.@\\")) "." - (or "automount" "busname" "mount" "service" "slice" + (or "automount" "busname" "mount" "path" "service" "slice" "socket" "swap" "target" "timer" "link" "netdev" "network")) "override.conf") (= 16 (char hex-digit)) string-end)) From 39433d908eaf6467d8a1b0c4f32a43a99f0a7ae0 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 0505868..8aed374 100644 --- a/systemd.el +++ b/systemd.el @@ -88,7 +88,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.") @@ -107,7 +109,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.") @@ -121,7 +125,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 653f4f1bc4af904f9b889802fbfa22041caa4156 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 6db0403..921a2fa 100644 --- a/systemd.el +++ b/systemd.el @@ -235,7 +235,8 @@ file, defaulting to the link under point, if any." (let ((bounds (bounds-of-thing-at-point 'symbol))) (list (or (car bounds) (point)) (or (cdr bounds) (point)) - (completion-table-dynamic #'systemd-completion-table)))) + (completion-table-dynamic #'systemd-completion-table) + :exclusive 'no))) (defun systemd-company-backend (command &optional arg &rest _ignored) "Backend for `company-mode' in `systemd-mode' buffers." From 7193cc582b8fdec4f274dbba93ebb3d57f50d522 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)