mirror of
https://github.com/correl/doom-modeline.git
synced 2024-11-27 19:19:53 +00:00
Don't create the process buffer while parsing env version.
This commit is contained in:
parent
ea93d636f9
commit
63875f89b0
2 changed files with 29 additions and 25 deletions
|
@ -82,24 +82,17 @@ passes on the information into the CALLBACK.
|
||||||
Example:
|
Example:
|
||||||
(doom-modeline-env--get
|
(doom-modeline-env--get
|
||||||
\"ruby\"
|
\"ruby\"
|
||||||
'(\"version\")
|
'(\"--version\")
|
||||||
(lambda (line)
|
(lambda (line)
|
||||||
(message (doom-modeline-parser--ruby line)))"
|
(message (doom-modeline-parser--ruby line)))"
|
||||||
(let ((proc (apply 'start-process
|
(let ((proc (apply 'start-process
|
||||||
(append ;; Flaten process-args into a single list so we can handle variadic length args
|
(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)))
|
args)))
|
||||||
(parser callback))
|
(parser callback))
|
||||||
(set-process-filter
|
(set-process-filter proc
|
||||||
proc
|
(lambda (_proc line)
|
||||||
(lambda (proc1 line)
|
(funcall parser 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))
|
|
||||||
|
|
||||||
(provide 'doom-modeline-env)
|
(provide 'doom-modeline-env)
|
||||||
|
|
||||||
|
|
|
@ -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))))
|
(add-function :after after-focus-change-function #'doom-modeline-refresh-frame))))
|
||||||
|
|
||||||
;; Show version string for multi-version managers like rvm, rbenv, pyenv, etc.
|
;; 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 ()
|
(defun doom-modeline-update-env ()
|
||||||
"Update environment info on mode-line."
|
"Update environment info on mode-line."
|
||||||
(when (and doom-modeline-version
|
(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--get doom-modeline-env-command
|
||||||
doom-modeline-env-command-args
|
doom-modeline-env-command-args
|
||||||
(lambda (prog-version)
|
(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
|
;; Modeline helpers
|
||||||
|
|
Loading…
Reference in a new issue