From ce874ebc1d26f1cac3de3d9bcc01cd7ab923f344 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 15 Jul 2019 02:33:54 +0800 Subject: [PATCH] Add customization group: doom-modeline-env. --- README.md | 16 ++++----- doom-modeline-env.el | 84 ++++++++++++++++++++++++++++++++------------ 2 files changed, 69 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 4c1db01..9c70dbf 100644 --- a/README.md +++ b/README.md @@ -223,14 +223,6 @@ Run `M-x customize-group RET doom-modeline RET` or set the variables. (setq doom-modeline-env-enable-elixir t) (setq doom-modeline-env-enable-rust t) -;; Change the executables to use for the language version string -(setq doom-modeline-env-python-executable "python") -(setq doom-modeline-env-ruby-executable "ruby") -(setq doom-modeline-env-perl-executable "perl") -(setq doom-modeline-env-go-executable "go") -(setq doom-modeline-env-elixir-executable "iex") -(setq doom-modeline-env-rust-executable "rustc") - ;; Whether display mu4e notifications or not. Requires `mu4e-alert' package. (setq doom-modeline-mu4e t) @@ -239,6 +231,14 @@ Run `M-x customize-group RET doom-modeline RET` or set the variables. ;; Function to stylize the irc buffer names. (setq doom-modeline-irc-stylize 'identity) + +;; Change the executables to use for the language version string +(setq doom-modeline-env-python-executable "python") ; or `python-shell-interpreter' +(setq doom-modeline-env-ruby-executable "ruby") +(setq doom-modeline-env-perl-executable "perl") +(setq doom-modeline-env-go-executable "go") +(setq doom-modeline-env-elixir-executable "iex") +(setq doom-modeline-env-rust-executable "rustc") ``` ## FAQ diff --git a/doom-modeline-env.el b/doom-modeline-env.el index 00836f5..453c193 100644 --- a/doom-modeline-env.el +++ b/doom-modeline-env.el @@ -30,8 +30,59 @@ (require 'subr-x) (require 'doom-modeline-core) -;; Externals -(defvar python-shell-interpreter) +;; +;; Customizations +;; + +(defgroup doom-modeline-env nil + "The environment parser for doom-modeline." + :group 'doom-modeline) + +(defcustom doom-modeline-env-python-executable "python" + "The executable to parse Python version." + :type 'string + :group 'doom-modeline-env) + +(defcustom doom-modeline-env-ruby-executable "ruby" + "The executable to parse Ruby version." + :type 'string + :group 'doom-modeline-env) + +(defcustom doom-modeline-env-perl-executable "perl" + "The executable to parse Perl version." + :type 'string + :group 'doom-modeline-env) + +(defcustom doom-modeline-env-go-executable "go" + "The executable to parse Golang version." + :type 'string + :group 'doom-modeline-env) + +(defcustom doom-modeline-env-elixir-executable "iex" + "The executable to parse Elixir version." + :type 'string + :group 'doom-modeline-env) + +(defcustom doom-modeline-env-rust-executable "rustc" + "The executable to parse Rust version." + :type 'string + :group 'doom-modeline-env) + +(defcustom doom-modeline-env-load-string "..." + "What to dispaly as the version while a new one is being loaded." + :type 'string + :group 'doom-modeline-env) + +(defcustom doom-modeline-after-update-env-hook nil + "Hooks that run after the modeline version string is updated." + :type 'hook + :group 'doom-modeline-env) + +(defcustom doom-modeline-before-update-env-hook nil + "Hooks that run before the modeline version string is updated." + :type 'hook + :group 'doom-modeline-env) + ;; Show version string for multi-version managers like rvm, rbenv, pyenv, etc. (defvar-local doom-modeline-env--version nil @@ -47,15 +98,6 @@ Example: '(\"--version\") ") "A function that returns version number from a programs --version (or similar) command. Example: 'doom-modeline-env--ruby") -(defvar doom-modeline-load-string "..." - "What to dispaly as the version while a new one is being loaded.") - -(defvar doom-modeline-after-update-env-hook nil - "Hooks that run after the modeline version string is updated.") - -(defvar doom-modeline-before-update-env-hook nil - "Hooks that run before the modeline version string is updated.") - (defun doom-modeline-update-env () "Update environment info on mode-line." (when (and doom-modeline-env-version @@ -66,7 +108,7 @@ Example: 'doom-modeline-env--ruby") (let ((default-directory (doom-modeline-project-root)) (buffer (current-buffer))) (run-hooks 'doom-modeline-before-update-env-hook) - (setq doom-modeline-env--version doom-modeline-load-string) + (setq doom-modeline-env--version doom-modeline-env-load-string) (doom-modeline-env--get doom-modeline-env--command doom-modeline-env--command-args @@ -179,20 +221,16 @@ PARSER should be a function for parsing COMMAND's output line-by-line, to :command (lambda () (cond ((and (fboundp 'pipenv-project-p) (pipenv-project-p)) (list "pipenv" "run" - (or doom-modeline-env-python-executable - python-shell-interpreter - "python") + doom-modeline-env-python-executable "--version")) - ((list (or doom-modeline-env-python-executable - python-shell-interpreter - "python") + ((list doom-modeline-env-python-executable "--version")))) :parser (lambda (line) (cadr (split-string line)))) ;;;###autoload (autoload 'doom-modeline-env-setup-ruby "doom-modeline-env") (doom-modeline-def-env ruby :hooks '(ruby-mode-hook enh-ruby-mode-hook) - :command (lambda () (list (or doom-modeline-env-ruby-executable "ruby") "--version")) + :command (lambda () (list doom-modeline-env-ruby-executable "--version")) :parser (lambda (line) (car (split-string (cadr @@ -202,7 +240,7 @@ PARSER should be a function for parsing COMMAND's output line-by-line, to ;;;###autoload (autoload 'doom-modeline-env-setup-perl "doom-modeline-env") (doom-modeline-def-env perl :hooks 'perl-mode-hook - :command (lambda () (list (or doom-modeline-env-perl-executable "perl") "--version")) + :command (lambda () (list doom-modeline-env-perl-executable "--version")) :parser (lambda (line) (cadr (split-string @@ -216,7 +254,7 @@ PARSER should be a function for parsing COMMAND's output line-by-line, to ;;;###autoload (autoload 'doom-modeline-env-setup-go "doom-modeline-env") (doom-modeline-def-env go :hooks 'go-mode-hook - :command (lambda () (list (or doom-modeline-env-go-executable "go") "version")) + :command (lambda () (list doom-modeline-env-go-executable "version")) :parser (lambda (line) (cadr (split-string @@ -228,13 +266,13 @@ PARSER should be a function for parsing COMMAND's output line-by-line, to ;;;###autoload (autoload 'doom-modeline-env-setup-elixir "doom-modeline-env") (doom-modeline-def-env elixir :hooks 'elixir-mode-hook - :command (lambda () (list (or doom-modeline-env-elixir-executable "iex") "--version")) + :command (lambda () (list doom-modeline-env-elixir-executable "--version")) :parser (lambda (line) (cadr (split-string line)))) ;;;###autoload (autoload 'doom-modeline-env-setup-rust "doom-modeline-env") (doom-modeline-def-env rust :hooks 'rust-mode-hook - :command (lambda () (list (or doom-modeline-env-rust-executable "rustc") "--version")) + :command (lambda () (list doom-modeline-env-rust-executable "--version")) :parser (lambda (line) (car (split-string