2019-01-11 21:34:47 +00:00
|
|
|
;;; doom-version-parser.el --- A version parser for doom-modeline -*- lexical-binding: t -*-
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
(defun doom-version-parser--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")))
|
|
|
|
|
|
|
|
(defun doom-version-parser--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)))
|
|
|
|
|
|
|
|
(defun doom-version-parser--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))
|
|
|
|
"-")))
|
|
|
|
|
|
|
|
(defun doom-version-parser--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")))
|
|
|
|
|
|
|
|
(defun doom-version-parser--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")))
|
|
|
|
|
|
|
|
(defun doom-version-parser--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)))
|
|
|
|
|
|
|
|
(defun doom-version-parser--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.
|
|
|
|
Example:
|
|
|
|
(doom-version-parser--get
|
|
|
|
\"ruby\"
|
|
|
|
'(\"version\")
|
|
|
|
(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-11 21:34:47 +00:00
|
|
|
(list "doom-modeline-prog" "doom-modeline-prog" prog)
|
|
|
|
args)))
|
|
|
|
(parser callback))
|
2019-01-13 13:53:51 +00:00
|
|
|
(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)))
|
2019-01-11 21:34:47 +00:00
|
|
|
nil))
|
|
|
|
|
|
|
|
(provide 'doom-version-parser)
|
|
|
|
|
|
|
|
;;; doom-version-parser.el ends here
|