Function: doom-modeline-def-env

doom-modeline-def-env is a macro defined in doom-modeline-env.el.

Signature

(doom-modeline-def-env NAME &key HOOKS COMMAND PARSER)

Documentation

Define a handler for updating & displaying a version string for a language.

NAME is an unquoted symbol representing the handler's unique ID. HOOKS is a list of hook symbols where this handler should be triggered. COMMAND should be a function that returns a shell command and its arguments (as
  a list). It is run on HOOKS. It takes no arguments.
PARSER should be a function for parsing COMMAND's output line-by-line, to
  extract the version string.

Source Code

;; Defined in /nix/store/1lcicrdd2r4b8rkc91nnn74ymk1jl6yd-emacs-packages-deps/share/emacs/site-lisp/elpa/doom-modeline-20260928.1632/doom-modeline-env.el
(cl-defmacro doom-modeline-def-env (name &key hooks command parser)
  "Define a handler for updating & displaying a version string for a language.

NAME is an unquoted symbol representing the handler's unique ID.
HOOKS is a list of hook symbols where this handler should be triggered.
COMMAND should be a function that returns a shell command and its arguments (as
  a list). It is run on HOOKS. It takes no arguments.
PARSER should be a function for parsing COMMAND's output line-by-line, to
  extract the version string."
  (declare (indent defun))
  (unless (and hooks command parser)
    (error "'%s' env is missing either :hooks, :command or :parser" name))
  (let ((parse-fn  (intern (format "doom-modeline-env--%s-parse" name)))
        (action-fn (intern (format "doom-modeline-env--%s-args"  name)))
        (setup-fn  (intern (format "doom-modeline-env-setup-%s"  name)))
        (update-fn (intern (format "doom-modeline-env-update-%s" name)))
        (enable-var  (intern (format "doom-modeline-env-enable-%s" name)))
        (command-var (intern (format "doom-modeline-env-%s-command" name)))
        (parser-var  (intern (format "doom-modeline-env-%s-parser-fn" name)))
        (exe-var     (intern (format "doom-modeline-env-%s-executable" name))))
    (macroexp-progn
     `((defcustom ,enable-var t
         ,(format "Whether to display the version string for %s buffers." name)
         :type 'boolean
         :group 'doom-modeline-env)
       (defvar ,command-var ',action-fn
         ,(concat "A function that returns the shell command and arguments (as a list) to\n"
                  "produce a version string."))
       (defvar ,parser-var ',parse-fn
         ,(format "The function to parse each line of `%s'\'s output." command-var))
       (defcustom ,exe-var nil
         ,(format (concat "What executable to use for the version indicator in %s buffers.\n\n"
                          "If nil, the default binary for this language is used.")
                  name)
         :type 'string
         :group 'doom-modeline-env)
       (defalias ',parse-fn ,parser
         (format "The line parser for %s buffers.\n\nUsed by `%s'."
                 ',name ',update-fn))
       (defalias ',action-fn ,command
         (format "The command resolver for %s buffers.\n\nUsed by `%s'."
                 ',name ',update-fn))
       (defalias ',setup-fn
         (lambda ()
           (if enable-local-variables
               (add-hook 'hack-local-variables-hook #',update-fn nil t)
             (,update-fn)))
         (format "Prepares the modeline to later display the %s version string."
                 ',name))
       (defalias ',update-fn
         (lambda ()
           (when ,enable-var
             (when-let* ((command-list (funcall ,command-var))
                         (exe (executable-find (car command-list))))
               (setq doom-modeline-env--command exe
                     doom-modeline-env--command-args (cdr command-list)
                     doom-modeline-env--parser ,parser-var)
               (doom-modeline-update-env))))
         (format "Updates the %s version string in the modeline." ',name))
       (let ((hooks ',(eval hooks)))
         (dolist (hook (if (listp hooks) hooks (list hooks)))
           (add-hook hook #',setup-fn)))))))