Complete the "env" directive in firejail-mode.el
This commit is contained in:
		@ -508,6 +508,21 @@ With NO-ABSOLUTE, don't complete absolute file names."
 | 
			
		||||
         (append (seq-take (nth ,index ,args) 2)
 | 
			
		||||
                 (list (seq-difference ,evaled-vals ,present)))))))
 | 
			
		||||
 | 
			
		||||
(defun firejail--get-all-env-keys ()
 | 
			
		||||
  "Return the name of every current environment variable."
 | 
			
		||||
  (mapcar (lambda (elt)
 | 
			
		||||
            (if-let ((sep (cl-position ?= elt)))
 | 
			
		||||
                (substring elt 0 sep)
 | 
			
		||||
              elt))
 | 
			
		||||
          process-environment))
 | 
			
		||||
 | 
			
		||||
(defun firejail--complete-env (index args _directive)
 | 
			
		||||
  "Complete the arg numbered INDEX in ARGS for an \"env\" directive."
 | 
			
		||||
  (cl-destructuring-bind (start _end text) (nth index args)
 | 
			
		||||
    (let ((sep-pos (or (cl-position ?= text) (length text))))
 | 
			
		||||
      (when (<= (point) (+ start sep-pos))
 | 
			
		||||
        (list start (+ start sep-pos) (firejail--get-all-env-keys))))))
 | 
			
		||||
 | 
			
		||||
(defconst firejail-profile--keyword-handlers
 | 
			
		||||
  (let ((ht (make-hash-table :test 'equal)))
 | 
			
		||||
    (cl-flet* ((complete (args fun dirs)
 | 
			
		||||
@ -583,7 +598,8 @@ With NO-ABSOLUTE, don't complete absolute file names."
 | 
			
		||||
      (complete-all (firejail--complete-many-from-set
 | 
			
		||||
                     '(mapcar 'number-to-string
 | 
			
		||||
                              (number-sequence 0 (firejail--get-num-cpus))))
 | 
			
		||||
                    "cpu"))
 | 
			
		||||
                    "cpu")
 | 
			
		||||
      (complete 1 #'firejail--complete-env "env"))
 | 
			
		||||
    ht)
 | 
			
		||||
  "Hash table mapping firejail profile directives to their handler.
 | 
			
		||||
Each handler is a function of three arguments.  The first is the index of the
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user