Don't create the process buffer while parsing env version.

This commit is contained in:
Vincent Zhang 2019-01-14 01:36:53 +08:00
parent ea93d636f9
commit 63875f89b0
2 changed files with 29 additions and 25 deletions

View file

@ -82,24 +82,17 @@ passes on the information into the CALLBACK.
Example:
(doom-modeline-env--get
\"ruby\"
'(\"version\")
'(\"--version\")
(lambda (line)
(message (doom-modeline-parser--ruby line)))"
(let ((proc (apply 'start-process
(append ;; Flaten process-args into a single list so we can handle variadic length args
(list "doom-modeline-prog" "doom-modeline-prog" prog)
(list "doom-modeline-env" nil prog)
args)))
(parser callback))
(set-process-filter
proc
(lambda (proc1 line)
(defvar old-buffer-query-functions kill-buffer-query-functions) ;; Store old query function
(setq kill-buffer-query-functions nil) ;; No need to query user when we kill this buffer and process
(kill-process proc1) ;; Clean up after ourselves
(kill-buffer "doom-modeline-prog")
(setq kill-buffer-query-functions old-buffer-query-functions) ;; let's restore everthing
(funcall parser line)))
nil))
(set-process-filter proc
(lambda (_proc line)
(funcall parser line)))))
(provide 'doom-modeline-env)

View file

@ -540,19 +540,19 @@ If DEFAULT is non-nil, set the default mode-line for all buffers."
(add-function :after after-focus-change-function #'doom-modeline-refresh-frame))))
;; Show version string for multi-version managers like rvm, rbenv, pyenv, etc.
(defvar-local doom-modeline-env-version nil)
(defvar-local doom-modeline-env-version nil
"The version to display with major-mode in mode-line.
Example: \"2.6.0\"")
(defvar-local doom-modeline-env-command nil
"A program that we're looking to extract version information from.
Example: \"ruby\"")
(defvar-local doom-modeline-env-command-args nil
"A list of arguments to pass to `doom-modeline-env-command` to extract the version from.
Example: '(\"--version\") ")
(defvar-local doom-modeline-env-parser nil
"A function that returns version number from a programs --version (or similar) command.
Example: 'doom-modeline-env--ruby")
(defvar-local doom-modeline-env-command nil "A program that we're looking to extract version information from. Ex: \"ruby\"")
(defvar-local doom-modeline-env-command-args nil "A list of arguments to pass to `doom-modeline-env-command` to extract the version from. Ex: '(\"--version\") ")
(defvar-local doom-modeline-env-parser nil "A function that returns version number from a programs --version (or similar) command. Ex: 'doom-modeline-env--ruby")
(add-hook 'find-file-hook #'doom-modeline-update-env)
(with-no-warnings
(if (boundp 'after-focus-change-function)
(add-function :after after-focus-change-function
(lambda ()
(if (frame-focus-state)
(doom-modeline-update-env))))
(add-hook 'focus-in-hook #'doom-modeline-update-env)))
(defun doom-modeline-update-env ()
"Update environment info on mode-line."
(when (and doom-modeline-version
@ -564,7 +564,18 @@ If DEFAULT is non-nil, set the default mode-line for all buffers."
(doom-modeline-env--get doom-modeline-env-command
doom-modeline-env-command-args
(lambda (prog-version)
(setq doom-modeline-env-version (funcall doom-modeline-env-parser prog-version)))))))
(setq doom-modeline-env-version
(funcall doom-modeline-env-parser prog-version)))))))
(add-hook 'find-file-hook #'doom-modeline-update-env)
(with-no-warnings
(if (boundp 'after-focus-change-function)
(add-function :after after-focus-change-function
(lambda ()
(if (frame-focus-state)
(doom-modeline-update-env))))
(add-hook 'focus-in-hook #'doom-modeline-update-env)))
;;
;; Modeline helpers