From 63875f89b0ee3dc293a732c6f879753b97b7c8ca Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 14 Jan 2019 01:36:53 +0800 Subject: [PATCH] Don't create the process buffer while parsing env version. --- doom-modeline-env.el | 17 +++++------------ doom-modeline.el | 37 ++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/doom-modeline-env.el b/doom-modeline-env.el index 5cd5f68..dfe2687 100644 --- a/doom-modeline-env.el +++ b/doom-modeline-env.el @@ -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) diff --git a/doom-modeline.el b/doom-modeline.el index 934fc1b..881a15a 100644 --- a/doom-modeline.el +++ b/doom-modeline.el @@ -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