Use four different candidate lists:
Section vs directive, normal unit vs network configuration
This commit is contained in:
parent
57dcf5a90e
commit
0c871fc508
@ -27,6 +27,10 @@
|
|||||||
(declare-function company-begin-backend "company")
|
(declare-function company-begin-backend "company")
|
||||||
(declare-function company-grab-symbol "company")
|
(declare-function company-grab-symbol "company")
|
||||||
|
|
||||||
|
(defconst systemd-company-unit-sections
|
||||||
|
'("Unit" "Install" "Service")
|
||||||
|
"Configuration sections for systemd 224.")
|
||||||
|
|
||||||
(defconst systemd-company-unit-directives
|
(defconst systemd-company-unit-directives
|
||||||
;; TODO: keep a script of sorts for generating this list. systemd
|
;; TODO: keep a script of sorts for generating this list. systemd
|
||||||
;; source has a python script in tools/ for parsing the
|
;; source has a python script in tools/ for parsing the
|
||||||
@ -107,6 +111,12 @@
|
|||||||
"Where" "WorkingDirectory")
|
"Where" "WorkingDirectory")
|
||||||
"Configuration directives for systemd 224.")
|
"Configuration directives for systemd 224.")
|
||||||
|
|
||||||
|
(defconst systemd-company-network-sections
|
||||||
|
'("Match" "Link" "NetDev" "VLAN" "MACVLAN" "MACVTAP" "IPVLAN" "VXLAN"
|
||||||
|
"Tunnel" "Peer" "Tun" "Tap" "Bond" "Network" "Address" "Route" "DHCP"
|
||||||
|
"Bridge" "BridgeFDB")
|
||||||
|
"Network configuration sections for systemd 224.")
|
||||||
|
|
||||||
(defconst systemd-company-network-directives
|
(defconst systemd-company-network-directives
|
||||||
;; /Network directives/,/Journal fields/p
|
;; /Network directives/,/Journal fields/p
|
||||||
'("ARPAllTargets" "ARPIPTargets" "ARPIntervalSec" "ARPProxy" "ARPValidate"
|
'("ARPAllTargets" "ARPIPTargets" "ARPIntervalSec" "ARPProxy" "ARPValidate"
|
||||||
@ -133,16 +143,20 @@
|
|||||||
"WakeOnLan")
|
"WakeOnLan")
|
||||||
"Network configuration directives for systemd 224.")
|
"Network configuration directives for systemd 224.")
|
||||||
|
|
||||||
(defconst systemd-company-directives
|
|
||||||
(append systemd-company-unit-directives systemd-company-network-directives)
|
|
||||||
"Configuration directives for systemd.
|
|
||||||
Combination of `systemd-company-unit-directives' and
|
|
||||||
`systemd-company-network-directives'.")
|
|
||||||
|
|
||||||
(defun systemd-company--setup (enable)
|
(defun systemd-company--setup (enable)
|
||||||
(when (fboundp 'systemd-company--setup-company)
|
(when (fboundp 'systemd-company--setup-company)
|
||||||
(systemd-company--setup-company enable)))
|
(systemd-company--setup-company enable)))
|
||||||
|
|
||||||
|
(defun systemd-company-section-p ()
|
||||||
|
"Return t if current line begins with \"[\", otherwise nil"
|
||||||
|
(save-excursion
|
||||||
|
(beginning-of-line)
|
||||||
|
(looking-at "\\[")))
|
||||||
|
|
||||||
|
(defun systemd-company-network-p ()
|
||||||
|
"Return non-nil if `buffer-name' has a network-type extension, otherwise nil"
|
||||||
|
(string-match "\\.\\(link\\|netdev\\|network\\)\\'" (buffer-name)))
|
||||||
|
|
||||||
(with-eval-after-load "company"
|
(with-eval-after-load "company"
|
||||||
(defun systemd-company-backend (command &optional arg &rest ignored)
|
(defun systemd-company-backend (command &optional arg &rest ignored)
|
||||||
(interactive (list 'interactive))
|
(interactive (list 'interactive))
|
||||||
@ -151,8 +165,15 @@ Combination of `systemd-company-unit-directives' and
|
|||||||
(prefix (and (eq major-mode 'systemd-mode)
|
(prefix (and (eq major-mode 'systemd-mode)
|
||||||
(company-grab-symbol)))
|
(company-grab-symbol)))
|
||||||
(candidates
|
(candidates
|
||||||
(cl-remove-if-not (lambda (c) (string-prefix-p arg c))
|
(cl-remove-if-not
|
||||||
systemd-company-directives))))
|
(lambda (c) (string-prefix-p arg c))
|
||||||
|
(if (systemd-company-network-p)
|
||||||
|
(if (systemd-company-section-p)
|
||||||
|
systemd-company-network-sections
|
||||||
|
systemd-company-network-directives)
|
||||||
|
(if (systemd-company-section-p)
|
||||||
|
systemd-company-unit-sections
|
||||||
|
systemd-company-unit-directives))))))
|
||||||
(defun systemd-company--setup-company (enable)
|
(defun systemd-company--setup-company (enable)
|
||||||
(when enable
|
(when enable
|
||||||
(add-to-list (make-local-variable 'company-backends) 'systemd-company-backend))
|
(add-to-list (make-local-variable 'company-backends) 'systemd-company-backend))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user