2019-01-13 16:48:54 +00:00
|
|
|
;;; doom-modeline-env.el --- A environment parser for doom-modeline -*- lexical-binding: t -*-
|
2019-01-11 21:34:47 +00:00
|
|
|
|
2019-01-13 13:53:51 +00:00
|
|
|
;; Copyright (C) 2019 Justin Barclay, Vincent Zhang
|
2019-01-11 21:34:47 +00:00
|
|
|
|
2019-01-13 13:55:50 +00:00
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
|
2019-01-11 21:34:47 +00:00
|
|
|
;;
|
|
|
|
;; This program is free software; you can redistribute it and/or
|
|
|
|
;; modify it under the terms of the GNU General Public License as
|
|
|
|
;; published by the Free Software Foundation; either version 2, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
;;
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
;; General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program; see the file COPYING. If not, write to
|
|
|
|
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
|
|
|
;; Floor, Boston, MA 02110-1301, USA.
|
|
|
|
;;
|
2019-01-13 13:53:51 +00:00
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; Parse programming environment version.
|
|
|
|
;;
|
|
|
|
|
|
|
|
;;; Code:
|
2019-01-11 21:34:47 +00:00
|
|
|
|
|
|
|
(require 'subr-x)
|
|
|
|
|
2019-01-13 16:48:54 +00:00
|
|
|
(defun doom-modeline-env--ruby (line)
|
2019-01-13 13:53:51 +00:00
|
|
|
"Parse Ruby version from LINE."
|
2019-01-11 21:34:47 +00:00
|
|
|
(car (split-string
|
|
|
|
(cadr
|
|
|
|
(split-string line))
|
|
|
|
"p")))
|
|
|
|
|
2019-01-13 16:48:54 +00:00
|
|
|
(defun doom-modeline-env--elixir (line)
|
2019-01-13 13:53:51 +00:00
|
|
|
"Parse Elixir version from LINE."
|
2019-01-11 21:34:47 +00:00
|
|
|
(cadr
|
|
|
|
(split-string line)))
|
|
|
|
|
2019-01-13 16:48:54 +00:00
|
|
|
(defun doom-modeline-env--rustc (line)
|
2019-01-13 13:53:51 +00:00
|
|
|
"Parse Rust version from LINE."
|
2019-01-11 21:34:47 +00:00
|
|
|
(car
|
|
|
|
(split-string
|
|
|
|
(cadr
|
|
|
|
(split-string line))
|
|
|
|
"-")))
|
|
|
|
|
2019-01-13 16:48:54 +00:00
|
|
|
(defun doom-modeline-env--go (line)
|
2019-01-13 13:53:51 +00:00
|
|
|
"Parse Go version from LINE."
|
2019-01-11 21:34:47 +00:00
|
|
|
(cadr
|
|
|
|
(split-string
|
|
|
|
(cadr
|
|
|
|
(cdr
|
|
|
|
(split-string
|
|
|
|
line)))
|
|
|
|
"go")))
|
|
|
|
|
2019-01-13 16:48:54 +00:00
|
|
|
(defun doom-modeline-env--perl (line)
|
2019-01-13 13:53:51 +00:00
|
|
|
"Parse Perl version from LINE."
|
2019-01-11 21:34:47 +00:00
|
|
|
(cadr
|
|
|
|
(split-string
|
|
|
|
(car
|
|
|
|
(split-string
|
|
|
|
(cadr
|
|
|
|
(split-string line "("))
|
|
|
|
")"))
|
|
|
|
"v")))
|
|
|
|
|
2019-01-13 16:48:54 +00:00
|
|
|
(defun doom-modeline-env--python (line)
|
2019-01-13 13:53:51 +00:00
|
|
|
"Parse Python version from LINE."
|
2019-01-11 21:34:47 +00:00
|
|
|
(cadr
|
|
|
|
(split-string line)))
|
|
|
|
|
2019-01-13 16:48:54 +00:00
|
|
|
(defun doom-modeline-env--get (prog args callback)
|
2019-01-13 13:53:51 +00:00
|
|
|
"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.
|
2019-01-13 15:32:30 +00:00
|
|
|
Example:
|
2019-01-13 16:48:54 +00:00
|
|
|
(doom-modeline-env--get
|
2019-01-13 15:32:30 +00:00
|
|
|
\"ruby\"
|
2019-01-13 17:36:53 +00:00
|
|
|
'(\"--version\")
|
2019-01-13 15:32:30 +00:00
|
|
|
(lambda (line)
|
|
|
|
(message (doom-modeline-parser--ruby line)))"
|
2019-01-11 21:34:47 +00:00
|
|
|
(let ((proc (apply 'start-process
|
2019-01-13 13:53:51 +00:00
|
|
|
(append ;; Flaten process-args into a single list so we can handle variadic length args
|
2019-01-13 17:36:53 +00:00
|
|
|
(list "doom-modeline-env" nil prog)
|
2019-01-11 21:34:47 +00:00
|
|
|
args)))
|
|
|
|
(parser callback))
|
2019-01-13 17:36:53 +00:00
|
|
|
(set-process-filter proc
|
|
|
|
(lambda (_proc line)
|
2019-01-13 18:05:29 +00:00
|
|
|
(ignore-errors
|
|
|
|
(funcall parser line))))))
|
2019-01-11 21:34:47 +00:00
|
|
|
|
2019-01-13 16:48:54 +00:00
|
|
|
(provide 'doom-modeline-env)
|
2019-01-11 21:34:47 +00:00
|
|
|
|
2019-01-13 16:48:54 +00:00
|
|
|
;;; doom-modeline-env.el ends here
|