From 0ae3aed09521dc474be224715704ec77948dfda4 Mon Sep 17 00:00:00 2001 From: Carlo Sciolla Date: Sat, 3 Aug 2019 16:03:25 +0200 Subject: [PATCH 01/11] Avoid breaking long lines on base64 encoding Spotted by @alexvs11 as a solution to #101 --- plantuml-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index beb35a7..4c3c93f 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -379,7 +379,7 @@ Put the result into buffer BUF and place it according to PREFIX: - 4 (when prefixing the command with C-u) -> new window - 16 (when prefixing the command with C-u C-u) -> new frame. - else -> new buffer" - (let* ((url-request-location (concat plantuml-server-url "/" plantuml-output-type "/-base64-" (base64-encode-string string)))) + (let* ((url-request-location (concat plantuml-server-url "/" plantuml-output-type "/-base64-" (base64-encode-string string t)))) (save-current-buffer (save-match-data (url-retrieve url-request-location From d11bd57f3164647991968e4698165831b87f784d Mon Sep 17 00:00:00 2001 From: Carlo Sciolla Date: Mon, 12 Aug 2019 17:14:45 +0200 Subject: [PATCH 02/11] Removed broken link --- plantuml-mode.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index 4c3c93f..924d11f 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -621,8 +621,8 @@ Shortcuts Command Name (if (and plantuml-suppress-deprecation-warning (featurep 'puml-mode)) (display-warning :warning - "`puml-mode' is now deprecated and no longer updated, but it's still present in your system.\ -You should move your configuration to use `plantuml-mode'. See https://github.com/sytac/plantuml-mode. \ + "`puml-mode' is now deprecated and no longer updated, but it's still present in your system. \ +You should move your configuration to use `plantuml-mode'. \ See more at https://github.com/skuro/puml-mode/issues/26"))) (add-hook 'plantuml-mode-hook 'plantuml-deprecation-warning) From 1e5f8beedd940458d043832c7d972dbfe492155e Mon Sep 17 00:00:00 2001 From: Carlo Sciolla Date: Mon, 12 Aug 2019 17:40:00 +0200 Subject: [PATCH 03/11] Fix switching between modes (#104) Giving a default value to `plantuml-exec-mode` local var at startup time is wrong. This change keeps the local var to `nil` and resorts to the customizable `plantuml-default-exec-mode`. The local var can be set by users at will on a buffer local level, but without such an explicit opt-in then the default value is always used --- plantuml-mode.el | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index 924d11f..333510a 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -159,8 +159,8 @@ (defvar plantuml-kwdList nil "The plantuml keywords.") ;; PlantUML execution mode -(defvar-local plantuml-exec-mode plantuml-default-exec-mode - "The Plantuml execution mode. See `plantuml-default-exec-mode' for acceptable values.") +(defvar-local plantuml-exec-mode nil + "The Plantuml execution mode override. See `plantuml-default-exec-mode' for acceptable values.") (defun plantuml-set-exec-mode (mode) "Set the execution mode MODE for PlantUML." @@ -177,6 +177,11 @@ (setq plantuml-exec-mode (intern mode)) (error (concat "Unsupported mode:" mode)))) +(defun plantuml-get-exec-mode () + "Retrieves the currently active PlantUML exec mode." + (or plantuml-exec-mode + plantuml-default-exec-mode)) + (defun plantuml-enable-debug () "Enables debug messages into the *PLANTUML Messages* buffer." (interactive) @@ -418,7 +423,7 @@ to choose where to display it." (buf (get-buffer-create plantuml-preview-buffer)) (coding-system-for-read (and imagep 'binary)) (coding-system-for-write (and imagep 'binary))) - (plantuml-exec-mode-preview-string prefix plantuml-exec-mode string buf))) + (plantuml-exec-mode-preview-string prefix (plantuml-get-exec-mode) string buf))) (defun plantuml-preview-buffer (prefix) "Preview diagram from the PlantUML sources in the current buffer. @@ -467,8 +472,8 @@ Uses prefix (as PREFIX) to choose where to display it: (plantuml-preview-buffer prefix))) (defun plantuml-init-once (&optional mode) - "Ensure initialization only happens once. Use exec mode MODE to load the language details, which defaults to `plantuml-exec-mode'." - (let ((mode (or mode plantuml-exec-mode))) + "Ensure initialization only happens once. Use exec mode MODE to load the language details or by first querying `plantuml-get-exec-mode'." + (let ((mode (or mode (plantuml-get-exec-mode)))) (unless plantuml-kwdList (plantuml-init mode) (defvar plantuml-types-regexp (concat "^\\s *\\(" (regexp-opt plantuml-types 'words) "\\|\\<\\(note\\s +over\\|note\\s +\\(left\\|right\\|bottom\\|top\\)\\s +\\(of\\)?\\)\\>\\|\\<\\(\\(left\\|center\\|right\\)\\s +\\(header\\|footer\\)\\)\\>\\)")) From 9cba6835fd352462a86c17a57e555de1064414c8 Mon Sep 17 00:00:00 2001 From: Felix Weilbach Date: Mon, 19 Aug 2019 14:10:35 +0200 Subject: [PATCH 04/11] Added run mode EXECUTABLE (#102) --- README.md | 1 + plantuml-mode.el | 66 ++++++++++++++++++++++++++++++------ test/plantuml-config-test.el | 2 ++ 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 65ec16f..89b461b 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ As of `v1.3.0` support is added for switching execution mode. The following two - `jar` (default) to run PlantUML as a local JAR file. This is the traditional system used by `plantuml-mode` - `server` (experimental) to let an instance of [`plantuml-server`](https://github.com/plantuml/plantuml-server) render the preview +- `executable` to run PlantUML as a local executable file. This is useful if your package manager provides a executable for PlantUML. You can customize `plantuml-default-exec-mode` or run `plantuml-set-exec-mode` from a `plantuml-mode` buffer to switch modes. diff --git a/plantuml-mode.el b/plantuml-mode.el index 333510a..026e652 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -84,6 +84,12 @@ :type 'string :group 'plantuml) +(defcustom plantuml-executable-path + "plantuml" + "The location of the PlantUML executable." + :type 'string + :group 'plantuml) + (defvar plantuml-mode-hook nil "Standard hook for plantuml-mode.") (defconst plantuml-mode-version "1.3.1" "The plantuml-mode version string.") @@ -118,12 +124,17 @@ :type 'string :group 'plantuml) +(defcustom plantuml-executable-args (list "-headless") + "The parameters passed to plantuml executable when executing PlantUML." + :type '(repeat string) + :group 'plantuml) + (defcustom plantuml-default-exec-mode 'server "Default execution mode for PlantUML. Valid values are: - `jar': run PlantUML as a JAR file (requires a local install of the PlantUML JAR file, see `plantuml-jar-path'" :type 'symbol :group 'plantuml - :options '(jar server)) + :options '(jar server executable)) (defcustom plantuml-suppress-deprecation-warning t "To silence the deprecation warning when `puml-mode' is found upon loading." @@ -165,15 +176,15 @@ (defun plantuml-set-exec-mode (mode) "Set the execution mode MODE for PlantUML." (interactive (let* ((completion-ignore-case t) - (supported-modes '("jar" "server"))) + (supported-modes '("jar" "server" "executable"))) (list (completing-read (format "Exec mode [%s]: " plantuml-exec-mode) - supported-modes - nil - t - nil - nil - plantuml-exec-mode)))) - (if (member mode '("jar" "server")) + supported-modes + nil + t + nil + nil + plantuml-exec-mode)))) + (if (member mode '("jar" "server" "executable")) (setq plantuml-exec-mode (intern mode)) (error (concat "Unsupported mode:" mode)))) @@ -244,11 +255,19 @@ (with-current-buffer buf (url-insert-file-contents lang-url)))) +(defun plantuml-executable-get-language (buf) + "Retrieve the language specification from the PlantUML executable and paste it into BUF." + (with-current-buffer buf + (let ((cmd-args (append (list plantuml-executable-path nil t nil) (list "-language")))) + (apply 'call-process cmd-args) + (goto-char (point-min))))) + (defun plantuml-get-language (mode buf) "Retrieve the language spec using the preferred PlantUML execution mode MODE. Paste the result into BUF." (let ((get-fn (pcase mode ('jar #'plantuml-jar-get-language) - ('server #'plantuml-server-get-language)))) + ('server #'plantuml-server-get-language) + ('executable #'plantuml-executable-get-language)))) (if get-fn (funcall get-fn buf) (error "Unsupported execution mode %s" mode)))) @@ -345,6 +364,14 @@ Note that output type `txt' is promoted to `utxt' for better rendering." ,@plantuml-jar-args "-p"))) +(defun plantuml-executable-start-process (buf) + "Run PlantUML as an Emacs process and puts the output into the given buffer (as BUF)." + (apply #'start-process + "PLANTUML" buf plantuml-executable-path + `(,@plantuml-executable-args + ,(plantuml-jar-output-type-opt plantuml-output-type) + "-p"))) + (defun plantuml-update-preview-buffer (prefix buf) "Show the preview in the preview buffer BUF. Window is selected according to PREFIX: @@ -398,6 +425,22 @@ Put the result into buffer BUF and place it according to PREFIX: (copy-to-buffer buf (point-min) (point-max)) (plantuml-update-preview-buffer prefix buf))))))) +(defun plantuml-executable-preview-string (prefix string buf) + "Preview the diagram from STRING by running the PlantUML JAR. +Put the result into buffer BUF. Window is selected according to PREFIX: +- 4 (when prefixing the command with C-u) -> new window +- 16 (when prefixing the command with C-u C-u) -> new frame. +- else -> new buffer" + (let* ((process-connection-type nil) + (ps (plantuml-executable-start-process buf))) + (process-send-string ps string) + (process-send-eof ps) + (set-process-sentinel ps + (lambda (_ps event) + (unless (equal event "finished\n") + (error "PLANTUML Preview failed: %s" event)) + (plantuml-update-preview-buffer prefix buf))))) + (defun plantuml-exec-mode-preview-string (prefix mode string buf) "Preview the diagram from STRING using the execution mode MODE. Put the result into buffer BUF, selecting the window according to PREFIX: @@ -406,7 +449,8 @@ Put the result into buffer BUF, selecting the window according to PREFIX: - else -> new buffer" (let ((preview-fn (pcase mode ('jar #'plantuml-jar-preview-string) - ('server #'plantuml-server-preview-string)))) + ('server #'plantuml-server-preview-string) + ('executable #'plantuml-executable-preview-string)))) (if preview-fn (funcall preview-fn prefix string buf) (error "Unsupported execution mode %s" mode)))) diff --git a/test/plantuml-config-test.el b/test/plantuml-config-test.el index 0f0024c..d30be43 100644 --- a/test/plantuml-config-test.el +++ b/test/plantuml-config-test.el @@ -20,6 +20,8 @@ (should (equal 'server plantuml-exec-mode)) (plantuml-set-exec-mode "jar") (should (equal 'jar plantuml-exec-mode)) + (plantuml-set-exec-mode "executable") + (should (equal 'executable plantuml-exec-mode)) (setq plantuml-exec-mode orig-mode))) From a822c551b83c041b2085512f99a2e5e4d46b1eed Mon Sep 17 00:00:00 2001 From: Carlo Sciolla Date: Wed, 21 Aug 2019 10:52:15 +0200 Subject: [PATCH 05/11] Better version management --- README.md | 9 +++++++++ bin/set-version.sh | 33 +++++++++++++++++++++++++++++++++ plantuml-mode.el | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 bin/set-version.sh diff --git a/README.md b/README.md index 89b461b..ced20a5 100644 --- a/README.md +++ b/README.md @@ -139,11 +139,20 @@ the textual mode and see if the output is valid SVG. ## Development +Development happens mostly on the `develop` branch, which is released on MELPA at every commit. The `master` branch is used to generate tags which are then released to [MELPA +stable](https://stable.melpa.org). + In order to contribute to `plantuml-mode` make sure to: - agree with the [GPLv3+ licencing terms](#License) as they are mandated by Emacs - install [`cask`](https://github.com/cask/cask) - always test your code and run the full test suite with `cask exec ert-runner` (or just by `make`) +- ensure you always target `develop` in your pull requests + +For collaborators who have merge access to the repo: +- make sure [`set-version.sh`](./blob/develop/bin/set-version.sh) is run as part of your [`pre-commit` git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) +- always merge PRs on the command line +- when releasing a new stable version, add the proper entry in the changelog within `plantuml-mode.el` to ensure the right version is set for `plantuml-mode-version` # Credits diff --git a/bin/set-version.sh b/bin/set-version.sh new file mode 100755 index 0000000..c278854 --- /dev/null +++ b/bin/set-version.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Retrieves the version from the changelog in plantuml-mode.el +function grab_version(){ + grep ';; version' plantuml-mode.el | \ + head -n1 | \ + cut -f3 -d' ' | \ + tr -d ',' +} + +# Updates the version in-place +function update_version(){ + NEW_VERSION="${1}" + sed -i -E "s/plantuml-mode-version \"[1-9\.]+\"/plantuml-mode-version \"${1}\"/" plantuml-mode.el +} + +case "$(git rev-parse --abbrev-ref HEAD)" in + 'master') + VERSION="$(grab_version)" + update_version "${VERSION}" + git add plantuml-mode.el + ;; + + 'develop') + VERSION="$(date '+%Y%m%d.%H%M')" # MELPA style + update_version "${VERSION}" + git add plantuml-mode.el + ;; + + *) + ## do nothing + ;; +esac diff --git a/plantuml-mode.el b/plantuml-mode.el index 026e652..ec6b382 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -92,7 +92,7 @@ (defvar plantuml-mode-hook nil "Standard hook for plantuml-mode.") -(defconst plantuml-mode-version "1.3.1" "The plantuml-mode version string.") +(defconst plantuml-mode-version "20190821.1053" "The plantuml-mode version string.") (defvar plantuml-mode-debug-enabled nil) From 4a908c227939c39467014213b96ca645f3908727 Mon Sep 17 00:00:00 2001 From: Carlo Sciolla Date: Wed, 21 Aug 2019 11:19:37 +0200 Subject: [PATCH 06/11] Avoid zero-padding of hours to mimic MELPA --- bin/set-version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/set-version.sh b/bin/set-version.sh index c278854..19c7425 100755 --- a/bin/set-version.sh +++ b/bin/set-version.sh @@ -22,7 +22,7 @@ case "$(git rev-parse --abbrev-ref HEAD)" in ;; 'develop') - VERSION="$(date '+%Y%m%d.%H%M')" # MELPA style + VERSION="$(date '+%Y%m%d.%-H%M')" # MELPA style update_version "${VERSION}" git add plantuml-mode.el ;; From 5a6ed6c5a26f3b4c96b72a12daea033ad2a1e11e Mon Sep 17 00:00:00 2001 From: Carlo Sciolla Date: Wed, 21 Aug 2019 11:29:20 +0200 Subject: [PATCH 07/11] Use `car` instead of `first` --- plantuml-mode.el | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index ec6b382..94aaf40 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -178,12 +178,12 @@ (interactive (let* ((completion-ignore-case t) (supported-modes '("jar" "server" "executable"))) (list (completing-read (format "Exec mode [%s]: " plantuml-exec-mode) - supported-modes - nil - t - nil - nil - plantuml-exec-mode)))) + supported-modes + nil + t + nil + nil + plantuml-exec-mode)))) (if (member mode '("jar" "server" "executable")) (setq plantuml-exec-mode (intern mode)) (error (concat "Unsupported mode:" mode)))) @@ -230,9 +230,9 @@ (strs (xml-get-children doc 'str)) (version (->> strs (--filter (string-equal "v" (xml-get-attribute it 'name))) - (first) + (car) (xml-node-children) - (first)))) + (car)))) (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 t) (kill-buffer))) From 04110d0110afee9164d8b61dc64c9fc9b44493a2 Mon Sep 17 00:00:00 2001 From: Carlo Sciolla Date: Wed, 21 Aug 2019 12:06:38 +0200 Subject: [PATCH 08/11] Use UTC timezone when setting dates, to align with MELPA --- bin/set-version.sh | 4 ++-- plantuml-mode.el | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/set-version.sh b/bin/set-version.sh index 19c7425..dca53fc 100755 --- a/bin/set-version.sh +++ b/bin/set-version.sh @@ -11,7 +11,7 @@ function grab_version(){ # Updates the version in-place function update_version(){ NEW_VERSION="${1}" - sed -i -E "s/plantuml-mode-version \"[1-9\.]+\"/plantuml-mode-version \"${1}\"/" plantuml-mode.el + sed -i -E "s/plantuml-mode-version \"[0-9\.]+\"/plantuml-mode-version \"${1}\"/" plantuml-mode.el } case "$(git rev-parse --abbrev-ref HEAD)" in @@ -22,7 +22,7 @@ case "$(git rev-parse --abbrev-ref HEAD)" in ;; 'develop') - VERSION="$(date '+%Y%m%d.%-H%M')" # MELPA style + VERSION="$(TZ='UTC' date '+%Y%m%d.%-H%M')" # MELPA style update_version "${VERSION}" git add plantuml-mode.el ;; diff --git a/plantuml-mode.el b/plantuml-mode.el index ec6b382..c98af93 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -92,7 +92,7 @@ (defvar plantuml-mode-hook nil "Standard hook for plantuml-mode.") -(defconst plantuml-mode-version "20190821.1053" "The plantuml-mode version string.") +(defconst plantuml-mode-version "20190821.1011" "The plantuml-mode version string.") (defvar plantuml-mode-debug-enabled nil) From 08b783aee6a77702f04142e32d83f42b30a417c1 Mon Sep 17 00:00:00 2001 From: Carlo Sciolla Date: Wed, 21 Aug 2019 14:18:20 +0200 Subject: [PATCH 09/11] Ignore java warnings --- plantuml-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index 097e208..9fd9a8f 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -102,7 +102,7 @@ :type 'string :group 'plantuml) -(defcustom plantuml-java-args (list "-Djava.awt.headless=true" "-jar") +(defcustom plantuml-java-args (list "-Djava.awt.headless=true" "-jar" "--illegal-access=deny") "The parameters passed to `plantuml-java-command' when executing PlantUML." :type '(repeat string) :group 'plantuml) From beb4dfc7265ddd4a2fb6bfbee107a5a115f94e64 Mon Sep 17 00:00:00 2001 From: Carlo Sciolla Date: Wed, 21 Aug 2019 14:27:26 +0200 Subject: [PATCH 10/11] Fix tests --- plantuml-mode.el | 2 +- test/plantuml-mode-custom-jar-location-test.el | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index 7ab7db8..0bb0472 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -92,7 +92,7 @@ (defvar plantuml-mode-hook nil "Standard hook for plantuml-mode.") -(defconst plantuml-mode-version "20190821.1011" "The plantuml-mode version string.") +(defconst plantuml-mode-version "20190821.1227" "The plantuml-mode version string.") (defvar plantuml-mode-debug-enabled nil) diff --git a/test/plantuml-mode-custom-jar-location-test.el b/test/plantuml-mode-custom-jar-location-test.el index 77df757..0da9fc4 100644 --- a/test/plantuml-mode-custom-jar-location-test.el +++ b/test/plantuml-mode-custom-jar-location-test.el @@ -10,13 +10,13 @@ (ert-deftest custom-jar-location () (setq-local plantuml-jar-path "~/.plantuml/plantuml.jar") - (should (equal `("-Djava.awt.headless=true" "-jar" + (should (equal `("-Djava.awt.headless=true" "-jar" "--illegal-access=deny" ,(expand-file-name "~/.plantuml/plantuml.jar") "-charset" "UTF-8") (plantuml-jar-render-command))) (setq-local plantuml-jar-path "/path/with spaces/plantuml.jar") - (should (equal `("-Djava.awt.headless=true" "-jar" "/path/with spaces/plantuml.jar" "-charset" "UTF-8") + (should (equal `("-Djava.awt.headless=true" "-jar" "--illegal-access=deny" "/path/with spaces/plantuml.jar" "-charset" "UTF-8") (plantuml-jar-render-command)))) (provide 'plantuml-mode-custom-jar-location-test) From ae8593d66205ac8808f91658ea205f4f4e898089 Mon Sep 17 00:00:00 2001 From: Carlo Sciolla Date: Wed, 21 Aug 2019 14:34:02 +0200 Subject: [PATCH 11/11] Bump version --- plantuml-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index d6fa60f..876b211 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -92,7 +92,7 @@ (defvar plantuml-mode-hook nil "Standard hook for plantuml-mode.") -(defconst plantuml-mode-version "20190821.1227" "The plantuml-mode version string.") +(defconst plantuml-mode-version "20190821.1234" "The plantuml-mode version string.") (defvar plantuml-mode-debug-enabled nil)