Add customization group: doom-modeline-env.

This commit is contained in:
Vincent Zhang 2019-07-15 02:33:54 +08:00
parent 7541c31846
commit ce874ebc1d
2 changed files with 69 additions and 31 deletions

View file

@ -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-elixir t)
(setq doom-modeline-env-enable-rust 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. ;; Whether display mu4e notifications or not. Requires `mu4e-alert' package.
(setq doom-modeline-mu4e t) (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. ;; Function to stylize the irc buffer names.
(setq doom-modeline-irc-stylize 'identity) (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 ## FAQ

View file

@ -30,8 +30,59 @@
(require 'subr-x) (require 'subr-x)
(require 'doom-modeline-core) (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. ;; 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
@ -47,15 +98,6 @@ Example: '(\"--version\") ")
"A function that returns version number from a programs --version (or similar) command. "A function that returns version number from a programs --version (or similar) command.
Example: 'doom-modeline-env--ruby") 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 () (defun doom-modeline-update-env ()
"Update environment info on mode-line." "Update environment info on mode-line."
(when (and doom-modeline-env-version (when (and doom-modeline-env-version
@ -66,7 +108,7 @@ Example: 'doom-modeline-env--ruby")
(let ((default-directory (doom-modeline-project-root)) (let ((default-directory (doom-modeline-project-root))
(buffer (current-buffer))) (buffer (current-buffer)))
(run-hooks 'doom-modeline-before-update-env-hook) (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--get
doom-modeline-env--command doom-modeline-env--command
doom-modeline-env--command-args 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) :command (lambda () (cond ((and (fboundp 'pipenv-project-p)
(pipenv-project-p)) (pipenv-project-p))
(list "pipenv" "run" (list "pipenv" "run"
(or doom-modeline-env-python-executable doom-modeline-env-python-executable
python-shell-interpreter
"python")
"--version")) "--version"))
((list (or doom-modeline-env-python-executable ((list doom-modeline-env-python-executable
python-shell-interpreter
"python")
"--version")))) "--version"))))
:parser (lambda (line) (cadr (split-string line)))) :parser (lambda (line) (cadr (split-string line))))
;;;###autoload (autoload 'doom-modeline-env-setup-ruby "doom-modeline-env") ;;;###autoload (autoload 'doom-modeline-env-setup-ruby "doom-modeline-env")
(doom-modeline-def-env ruby (doom-modeline-def-env ruby
:hooks '(ruby-mode-hook enh-ruby-mode-hook) :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) :parser (lambda (line)
(car (split-string (car (split-string
(cadr (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") ;;;###autoload (autoload 'doom-modeline-env-setup-perl "doom-modeline-env")
(doom-modeline-def-env perl (doom-modeline-def-env perl
:hooks 'perl-mode-hook :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) :parser (lambda (line)
(cadr (cadr
(split-string (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") ;;;###autoload (autoload 'doom-modeline-env-setup-go "doom-modeline-env")
(doom-modeline-def-env go (doom-modeline-def-env go
:hooks 'go-mode-hook :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) :parser (lambda (line)
(cadr (cadr
(split-string (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") ;;;###autoload (autoload 'doom-modeline-env-setup-elixir "doom-modeline-env")
(doom-modeline-def-env elixir (doom-modeline-def-env elixir
:hooks 'elixir-mode-hook :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)))) :parser (lambda (line) (cadr (split-string line))))
;;;###autoload (autoload 'doom-modeline-env-setup-rust "doom-modeline-env") ;;;###autoload (autoload 'doom-modeline-env-setup-rust "doom-modeline-env")
(doom-modeline-def-env rust (doom-modeline-def-env rust
:hooks 'rust-mode-hook :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) :parser (lambda (line)
(car (car
(split-string (split-string