mirror of
https://github.com/correl/doom-modeline.git
synced 2024-11-23 11:09:54 +00:00
Refactor: rename doom-version-parser to doom-modeline-env.
This commit is contained in:
parent
3f5d13fc4c
commit
ea93d636f9
6 changed files with 59 additions and 56 deletions
|
@ -19,7 +19,7 @@ The `doom-modeline` was designed for minimalism, and offers:
|
|||
- A match count panel (for `anzu`, `iedit`, `multiple-cursors`, `symbol-overlay`,
|
||||
`evil-search` and `evil-substitute`)
|
||||
- An indicator for recording a macro
|
||||
- Local `python`/`ruby`/`perl`/`go`/`elixir` version in the major-mode
|
||||
- Current environment version (e.g. `python`, `ruby`, `go`, etc.) in the major-mode
|
||||
- A customizable mode-line height (see `doom-modeline-height`)
|
||||
- A minor modes segment which is compatible with `minions`
|
||||
- An error/warning count segment for `flymake`/`flycheck`
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
;;; doom-version-parser.el --- A version parser for doom-modeline -*- lexical-binding: t -*-
|
||||
;;; doom-modeline-env.el --- A environment parser for doom-modeline -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2019 Justin Barclay, Vincent Zhang
|
||||
|
||||
|
@ -29,19 +29,19 @@
|
|||
|
||||
(require 'subr-x)
|
||||
|
||||
(defun doom-version-parser--ruby (line)
|
||||
(defun doom-modeline-env--ruby (line)
|
||||
"Parse Ruby version from LINE."
|
||||
(car (split-string
|
||||
(cadr
|
||||
(split-string line))
|
||||
"p")))
|
||||
|
||||
(defun doom-version-parser--elixir (line)
|
||||
(defun doom-modeline-env--elixir (line)
|
||||
"Parse Elixir version from LINE."
|
||||
(cadr
|
||||
(split-string line)))
|
||||
|
||||
(defun doom-version-parser--rustc (line)
|
||||
(defun doom-modeline-env--rustc (line)
|
||||
"Parse Rust version from LINE."
|
||||
(car
|
||||
(split-string
|
||||
|
@ -49,7 +49,7 @@
|
|||
(split-string line))
|
||||
"-")))
|
||||
|
||||
(defun doom-version-parser--go (line)
|
||||
(defun doom-modeline-env--go (line)
|
||||
"Parse Go version from LINE."
|
||||
(cadr
|
||||
(split-string
|
||||
|
@ -59,7 +59,7 @@
|
|||
line)))
|
||||
"go")))
|
||||
|
||||
(defun doom-version-parser--perl (line)
|
||||
(defun doom-modeline-env--perl (line)
|
||||
"Parse Perl version from LINE."
|
||||
(cadr
|
||||
(split-string
|
||||
|
@ -70,17 +70,17 @@
|
|||
")"))
|
||||
"v")))
|
||||
|
||||
(defun doom-version-parser--python (line)
|
||||
(defun doom-modeline-env--python (line)
|
||||
"Parse Python version from LINE."
|
||||
(cadr
|
||||
(split-string line)))
|
||||
|
||||
(defun doom-version-parser--get (prog args callback)
|
||||
(defun doom-modeline-env--get (prog args callback)
|
||||
"Start a sub process using PROG and apply the ARGS to the sub process.
|
||||
Once it recieves information from STDOUT, it closes off the subprocess and
|
||||
passes on the information into the CALLBACK.
|
||||
Example:
|
||||
(doom-version-parser--get
|
||||
(doom-modeline-env--get
|
||||
\"ruby\"
|
||||
'(\"version\")
|
||||
(lambda (line)
|
||||
|
@ -101,6 +101,6 @@ Example:
|
|||
(funcall parser line)))
|
||||
nil))
|
||||
|
||||
(provide 'doom-version-parser)
|
||||
(provide 'doom-modeline-env)
|
||||
|
||||
;;; doom-version-parser.el ends here
|
||||
;;; doom-modeline-env.el ends here
|
|
@ -38,7 +38,7 @@
|
|||
;; - A match count panel (for anzu, iedit, multiple-cursors, symbol-overlay,
|
||||
;; evil-search and evil-substitute)
|
||||
;; - An indicator for recording a macro
|
||||
;; - Local python/ruby version in the major-mode
|
||||
;; - Current environment version (e.g. python, ruby, go, etc.) in the major-mode
|
||||
;; - A customizable mode-line height (see doom-modeline-height)
|
||||
;; - A minor modes segment which is compatible with minions
|
||||
;; - An error/warning count segment for flymake/flycheck
|
||||
|
@ -77,9 +77,9 @@
|
|||
(require 'eldoc-eval)
|
||||
(require 'shrink-path)
|
||||
(require 'subr-x)
|
||||
(require 'doom-version-parser)
|
||||
(when (>= emacs-major-version 26)
|
||||
(require 'project))
|
||||
(require 'doom-modeline-env)
|
||||
|
||||
|
||||
;;
|
||||
|
@ -544,7 +544,7 @@ If DEFAULT is non-nil, set the default mode-line for all buffers."
|
|||
|
||||
(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-version-parser--ruby")
|
||||
(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)
|
||||
|
@ -561,7 +561,7 @@ If DEFAULT is non-nil, set the default mode-line for all buffers."
|
|||
doom-modeline-env-command-args
|
||||
doom-modeline-env-parser)
|
||||
(let ((default-directory (doom-modeline-project-root)))
|
||||
(doom-version-parser--get doom-modeline-env-command
|
||||
(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)))))))
|
||||
|
@ -1579,6 +1579,19 @@ Returns \"\" to not break --no-window-system."
|
|||
doom-modeline--bar-inactive)
|
||||
""))
|
||||
|
||||
(defun doom-modeline-refresh-bars (&optional width height)
|
||||
"Refresh mode-line bars with `WIDTH' and `HEIGHT'."
|
||||
(setq doom-modeline--bar-active
|
||||
(doom-modeline--make-xpm 'doom-modeline-bar
|
||||
(or width doom-modeline-bar-width)
|
||||
(max (or height doom-modeline-height)
|
||||
(frame-char-height)))
|
||||
doom-modeline--bar-inactive
|
||||
(doom-modeline--make-xpm 'doom-modeline-inactive-bar
|
||||
(or width doom-modeline-bar-width)
|
||||
(max (or height doom-modeline-height)
|
||||
(frame-char-height)))))
|
||||
|
||||
(when (>= emacs-major-version 26)
|
||||
(add-variable-watcher
|
||||
'doom-modeline-height
|
||||
|
@ -2031,19 +2044,6 @@ mouse-1: Toggle Debug on Quit"
|
|||
;; Hooks
|
||||
;;
|
||||
|
||||
(defun doom-modeline-refresh-bars (&optional width height)
|
||||
"Refresh mode-line bars with `WIDTH' and `HEIGHT'."
|
||||
(setq doom-modeline--bar-active
|
||||
(doom-modeline--make-xpm 'doom-modeline-bar
|
||||
(or width doom-modeline-bar-width)
|
||||
(max (or height doom-modeline-height)
|
||||
(frame-char-height)))
|
||||
doom-modeline--bar-inactive
|
||||
(doom-modeline--make-xpm 'doom-modeline-inactive-bar
|
||||
(or width doom-modeline-bar-width)
|
||||
(max (or height doom-modeline-height)
|
||||
(frame-char-height)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom-modeline-init ()
|
||||
"Initialize doom mode-line."
|
||||
|
@ -2096,40 +2096,40 @@ mouse-1: Toggle Debug on Quit"
|
|||
(add-hook 'python-mode-hook
|
||||
(lambda ()
|
||||
(cond ((and (fboundp 'pipenv-project-p) (pipenv-project-p) (executable-find "pipenv"))
|
||||
(setq doom-modeline-env-parser 'doom-version-parser--python)
|
||||
(setq doom-modeline-env-parser 'doom-modeline-env--python)
|
||||
(setq doom-modeline-env-command "pipenv")
|
||||
(setq doom-modeline-env-command-args '("run" "python" "--version")))
|
||||
((and doom-modeline-python-executable
|
||||
(executable-find doom-modeline-python-executable))
|
||||
(setq doom-modeline-env-parser 'doom-version-parser--python)
|
||||
(setq doom-modeline-env-parser 'doom-modeline-env--python)
|
||||
(setq doom-modeline-env-command doom-modeline-python-executable)
|
||||
(setq doom-modeline-env-command-args '("--version"))))))
|
||||
(add-hook 'ruby-mode-hook
|
||||
(lambda ()
|
||||
(setq doom-modeline-env-command "ruby")
|
||||
(setq doom-modeline-env-command-args '("--version"))
|
||||
(setq doom-modeline-env-parser 'doom-version-parser--ruby)))
|
||||
(setq doom-modeline-env-parser 'doom-modeline-env--ruby)))
|
||||
(add-hook 'perl-mode-hook
|
||||
(lambda ()
|
||||
(setq doom-modeline-env-command "perl")
|
||||
(setq doom-modeline-env-command-args '("--version"))
|
||||
(setq doom-modeline-env-parser 'doom-version-parser--perl)))
|
||||
(setq doom-modeline-env-parser 'doom-modeline-env--perl)))
|
||||
(add-hook 'go-mode-hook
|
||||
(lambda ()
|
||||
(setq doom-modeline-env-command "go")
|
||||
(setq doom-modeline-env-command-args '("version"))
|
||||
(setq doom-modeline-env-parser 'doom-version-parser--go)))
|
||||
(setq doom-modeline-env-parser 'doom-modeline-env--go)))
|
||||
|
||||
(add-hook 'elixir-mode-hook
|
||||
(lambda ()
|
||||
(setq doom-modeline-env-command "iex")
|
||||
(setq doom-modeline-env-command-args '("--version"))
|
||||
(setq doom-modeline-env-parser 'doom-version-parser--elixir)))
|
||||
(setq doom-modeline-env-parser 'doom-modeline-env--elixir)))
|
||||
(add-hook 'rust-mode-hook
|
||||
(lambda ()
|
||||
(setq doom-modeline-env-command "rustc")
|
||||
(setq doom-modeline-env-command-args '("--version"))
|
||||
(setq doom-modeline-env-parser 'doom-version-parser--rustc)))
|
||||
(setq doom-modeline-env-parser 'doom-modeline-env--rustc)))
|
||||
|
||||
|
||||
;; Ensure modeline is inactive when Emacs is unfocused (and active otherwise)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
;;; doom-version-parser-test.el --- Unit tests for doom-version-parser -*- lexical-binding: t; -*-
|
||||
;;; doom-modeline-env-test.el --- Unit tests for doom-modeline-env -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2019 Justin Barclay
|
||||
|
||||
|
@ -23,33 +23,36 @@
|
|||
|
||||
;;; Commentary:
|
||||
;;
|
||||
;; Unit tests for doom-version-parser
|
||||
;; Unit tests for doom-modeline-env
|
||||
;;
|
||||
|
||||
;;; Code:
|
||||
(ert-deftest doom-version-parser--ruby/parse-ruby-version-string ()
|
||||
|
||||
(require 'doom-modeline-env)
|
||||
|
||||
(ert-deftest doom-modeline-env--ruby/parse-ruby-version-string ()
|
||||
(should
|
||||
(string= (doom-version-parser--ruby "ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]")
|
||||
(string= (doom-modeline-env--ruby "ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]")
|
||||
"2.3.3")))
|
||||
|
||||
(ert-deftest doom-version-parser--elixir/parse-elixr-version-string ()
|
||||
(ert-deftest doom-modeline-env--elixir/parse-elixr-version-string ()
|
||||
(should
|
||||
(string= (doom-version-parser--elixir "IEx 1.7.4 (compiled with Erlang/OTP 21)")
|
||||
(string= (doom-modeline-env--elixir "IEx 1.7.4 (compiled with Erlang/OTP 21)")
|
||||
"1.7.4")))
|
||||
|
||||
(ert-deftest doom-version-parser--rustc/parse-rustc-version-string ()
|
||||
(ert-deftest doom-modeline-env--rustc/parse-rustc-version-string ()
|
||||
(should
|
||||
(string= (doom-version-parser--rustc "rustc 1.32.0-nightly (14997d56a 2018-12-05)")
|
||||
(string= (doom-modeline-env--rustc "rustc 1.32.0-nightly (14997d56a 2018-12-05)")
|
||||
"1.32.0")))
|
||||
|
||||
(ert-deftest doom-version-parser--go/parse-go-version-string ()
|
||||
(ert-deftest doom-modeline-env--go/parse-go-version-string ()
|
||||
(should
|
||||
(string= (doom-version-parser--go "go version go1.11.4 darwin/amd64")
|
||||
(string= (doom-modeline-env--go "go version go1.11.4 darwin/amd64")
|
||||
"1.11.4")))
|
||||
|
||||
(ert-deftest doom-version-parser--perl/parse-perl-version-string ()
|
||||
(ert-deftest doom-modeline-env--perl/parse-perl-version-string ()
|
||||
(should
|
||||
(string= (doom-version-parser--perl
|
||||
(string= (doom-modeline-env--perl
|
||||
"This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level
|
||||
(with 2 registered patches, see perl -V for more detail)
|
||||
|
||||
|
@ -63,9 +66,9 @@ this system using \"man perl\" or \"perldoc perl\". If you have access to the
|
|||
Internet, point your browser at http://www.perl.org/, the Perl Home Page.")
|
||||
"5.18.2")))
|
||||
|
||||
(ert-deftest doom-version-parser--python/parse-python-version-string ()
|
||||
(ert-deftest doom-modeline-env--python/parse-python-version-string ()
|
||||
(should
|
||||
(string= (doom-version-parser--python "Python 2.7.15")
|
||||
(string= (doom-modeline-env--python "Python 2.7.15")
|
||||
"2.7.15")))
|
||||
|
||||
;;; doom-version-parser-test.el ends here
|
||||
;;; doom-modeline-env-test.el ends here
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
;;; Code:
|
||||
|
||||
(require 'doom-modeline)
|
||||
|
||||
(ert-deftest doom-modeline--buffer-file-name/truncate-upto-project ()
|
||||
(let ((default-directory "/home/user/project/")
|
||||
(file-path "/home/user/project/relative/test.txt")
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
|
||||
(add-to-list 'load-path (expand-file-name "."))
|
||||
|
||||
(require 'doom-modeline)
|
||||
|
||||
(defun strip-text-properties(txt)
|
||||
"Strip text properties of TXT."
|
||||
(set-text-properties 0 (length txt) nil txt)
|
||||
|
|
Loading…
Reference in a new issue