Added capability to automatically download the PlantUML jar path (#95)

* Added capability to automatically download the PlantUML jar path

As an effort to ease the first user setup, a new function is added to download the latest
PlantUML JAR release into `plantuml-jar-path` from Maven central.
This commit is contained in:
Carlo Sciolla 2019-05-09 22:04:51 +02:00 committed by GitHub
parent 9bd2dc86aa
commit c14684dc3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -26,6 +26,10 @@ Also, to enable preview you need to tell `plantuml-mode` where to locate the Pla
M-x customize-variable<RET>
plantuml-jar-path<RET>
You can also download the latest version of PlantUML straight into `plantuml-jar-path`:
M-x plantuml-download-jar<RET>
# Features
- Syntax highlight

View File

@ -69,6 +69,7 @@
;;; Code:
(require 'thingatpt)
(require 'dash)
(require 'xml)
(defgroup plantuml-mode nil
"Major mode for editing plantuml file."
@ -163,6 +164,31 @@
(insert msg)
(insert "\n"))))))
(defun plantuml-download-jar ()
"Download the latest PlantUML JAR file and install it into `plantuml-jar-path'."
(interactive)
(if (y-or-n-p (format "Download the latest PlantUML JAR file into %s? " plantuml-jar-path))
(if (or (not (file-exists-p plantuml-jar-path))
(y-or-n-p (format "The PlantUML jar file already exists at %s, overwrite? " plantuml-jar-path)))
(with-current-buffer (url-retrieve-synchronously "https://search.maven.org/solrsearch/select?q=g:net.sourceforge.plantuml+AND+a:plantuml&core=gav&start=0&rows=1&wt=xml")
(mkdir (file-name-directory plantuml-jar-path) t)
(let* ((parse-tree (xml-parse-region))
(doc (->> parse-tree
(assq 'response)
(assq 'result)
(assq 'doc)))
(strs (xml-get-children doc 'str))
(version (->> strs
(--filter (string-equal "v" (xml-get-attribute it 'name)))
(first)
(xml-node-children)
(first))))
(message (concat "Downloading PlantUML v" version " into " plantuml-jar-path))
(url-copy-file (format "https://search.maven.org/remotecontent?filepath=net/sourceforge/plantuml/plantuml/%s/plantuml-%s.jar" version version) plantuml-jar-path)
(kill-buffer))
(message "Aborted.")))
(message "Aborted.")))
(defun plantuml-init ()
"Initialize the keywords or builtins from the cmdline language output."
(unless (or (eq system-type 'cygwin) (file-exists-p plantuml-jar-path))