Indentation improvements (#117)

* Allow easier customization of indentation level

* correctly indent repeat construct

* Indent forks and loops for activity syntax. Test notes
This commit is contained in:
Joost Diepenmaat 2019-11-02 21:56:47 +01:00 committed by Carlo Sciolla
parent fec1d4fb9d
commit ea45a13707
4 changed files with 408 additions and 6 deletions

View File

@ -1,7 +1,7 @@
#!/bin/sh
# Where the script is executed
CURRENT_PATH="$(dirname "$(readlink -f "$0")")"
CURRENT_PATH="$(dirname "$0")"
# Where to download the file
OUTPUT_PATH="${CURRENT_PATH}/plantuml.jar"
@ -10,7 +10,7 @@ OUTPUT_PATH="${CURRENT_PATH}/plantuml.jar"
VERSIONS_URL='https://search.maven.org/solrsearch/select?q=g:net.sourceforge.plantuml+AND+a:plantuml&core=gav&start=0&rows=1&wt=xml'
# Only match the contents of the version (name="v") XML tag
LATEST_VERSION="$(curl -s "${VERSIONS_URL}" | grep -oP '(?<=<str name="v">).*(?=</str>)')"
LATEST_VERSION="$(curl -s "${VERSIONS_URL}" | grep '<str name="v">'| sed 's/.*<str name="v">//g'|sed 's/<\/str>.*//')"
# Compose the download link
DOWNLOAD_URL="https://search.maven.org/remotecontent?filepath=net/sourceforge/plantuml/plantuml/${LATEST_VERSION}/plantuml-${LATEST_VERSION}.jar"

View File

@ -143,6 +143,9 @@
:type 'boolean
:group 'plantuml)
(defcustom plantuml-indent-level 8
"Indentation level of PlantUML lines")
(defun plantuml-jar-render-command (&rest arguments)
"Create a command line to execute PlantUML with arguments (as ARGUMENTS)."
(let* ((cmd-list (append plantuml-java-args (list (expand-file-name plantuml-jar-path)) plantuml-jar-args arguments))
@ -583,6 +586,9 @@ or it is followed by line end.")
(defvar plantuml-indent-regexp-footer-start "^\s*\\(?:\\(?:center\\|left\\|right\\)\s+footer\\|footer\\)\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-legend-start "^\s*\\(?:legend\\|legend\s+\\(?:bottom\\|top\\)\\|legend\s+\\(?:center\\|left\\|right\\)\\|legend\s+\\(?:bottom\\|top\\)\s+\\(?:center\\|left\\|right\\)\\)\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-oldif-start "^.*if\s+\".*\"\s+then\s*\\('.*\\)?$" "used in current activity diagram, sometimes already mentioned as deprecated")
(defvar plantuml-indent-regexp-newif-start "^\s*\\(?:else\\)?if\s+(.*)\s+then\s*.*$")
(defvar plantuml-indent-regexp-loop-start "^\s*\\(?:repeat\s*\\|while\s+(.*).*\\)$")
(defvar plantuml-indent-regexp-fork-start "^\s*\\(?:fork\\|split\\)\\(?:\s+again\\)?\s*$")
(defvar plantuml-indent-regexp-macro-start "^\s*!definelong.*$")
(defvar plantuml-indent-regexp-user-control-start "^.*'.*\s*PLANTUML_MODE_INDENT_INCREASE\s*.*$")
(defvar plantuml-indent-regexp-start (list plantuml-indent-regexp-block-start
@ -592,7 +598,9 @@ or it is followed by line end.")
plantuml-indent-regexp-ref-start
plantuml-indent-regexp-legend-start
plantuml-indent-regexp-note-start
plantuml-indent-regexp-oldif-start
plantuml-indent-regexp-newif-start
plantuml-indent-regexp-loop-start
plantuml-indent-regexp-fork-start
plantuml-indent-regexp-title-start
plantuml-indent-regexp-header-start
plantuml-indent-regexp-footer-start
@ -610,6 +618,9 @@ or it is followed by line end.")
(defvar plantuml-indent-regexp-footer-end "^\s*endfooter\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-legend-end "^\s*endlegend\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-oldif-end "^\s*\\(endif\\|else\\)\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-newif-end "^\s*\\(endif\\|elseif\\|else\\)\s*.*$")
(defvar plantuml-indent-regexp-loop-end "^\s*\\(repeat\s*while\\|endwhile\\)\s*.*$")
(defvar plantuml-indent-regexp-fork-end "^\s*\\(\\(fork\\|split\\)\s+again\\|end\s+\\(fork\\|split\\)\\)\s*$")
(defvar plantuml-indent-regexp-macro-end "^\s*!enddefinelong\s*\\('.*\\)?$")
(defvar plantuml-indent-regexp-user-control-end "^.*'.*\s*PLANTUML_MODE_INDENT_DECREASE\s*.*$")
(defvar plantuml-indent-regexp-end (list plantuml-indent-regexp-block-end
@ -619,7 +630,9 @@ or it is followed by line end.")
plantuml-indent-regexp-ref-end
plantuml-indent-regexp-legend-end
plantuml-indent-regexp-note-end
plantuml-indent-regexp-oldif-end
plantuml-indent-regexp-newif-end
plantuml-indent-regexp-loop-end
plantuml-indent-regexp-fork-end
plantuml-indent-regexp-title-end
plantuml-indent-regexp-header-end
plantuml-indent-regexp-footer-end
@ -708,7 +721,7 @@ Restore point to same position in text of the line as before indentation."
(let ((original-position-eol (- (line-end-position) (point))))
(save-excursion
(beginning-of-line)
(indent-line-to (* tab-width (plantuml-current-block-depth))))
(indent-line-to (* plantuml-indent-level (plantuml-current-block-depth))))
;; restore position in text of line
(goto-char (- (line-end-position) original-position-eol))))

View File

@ -0,0 +1,389 @@
;;; plantuml-indentation-activity-old-test.el --- PlantUML Mode indentation tests -*- lexical-binding: t; -*-
;; Author: René Schmelzer
;; Maintainer: Carlo Sciolla (skuro)
;; URL: https://github.com/skuro/plantuml-mode
;;; Commentary:
;; Test indentation for activity (old version) diagrams.
;;; Code:
(ert-deftest plantuml-test-indentation/activity-new/start-stop ()
"Test correct indentation of plantuml activity-new diagram elements: start-stop.
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"@startuml
start
:Hello world;
:This is defined on
several **lines**;
end
@enduml"
"@startuml
start
:Hello world;
:This is defined on
several **lines**;
end
@enduml"))
(ert-deftest plantuml-test-indentation/activity-new/conditional ()
"Test correct indentation of plantuml activity-new diagram conditionals.
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"@startuml
start
if (condition A) then (yes)
:Text 1;
elseif (condition B) then (yes)
:Text 2;
stop
elseif (condition C) then (yes)
:Text 3;
elseif (condition D) then (yes)
:Text 4;
else (nothing)
:Text else;
endif
stop
@enduml"
"@startuml
start
if (condition A) then (yes)
:Text 1;
elseif (condition B) then (yes)
:Text 2;
stop
elseif (condition C) then (yes)
:Text 3;
elseif (condition D) then (yes)
:Text 4;
else (nothing)
:Text else;
endif
stop
@enduml"))
(ert-deftest plantuml-test-indentation/activity-new/repeat-loop ()
"Test correct indentation of plantuml activity-new repeat loop
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"@startuml
start
repeat
:read data;
:generate diagrams;
repeat while (more data?) is (yes)
->no;
stop
@enduml"
"@startuml
start
repeat
:read data;
:generate diagrams;
repeat while (more data?) is (yes)
->no;
stop
@enduml"))
(ert-deftest plantuml-test-indentation/activity-new/while-loop ()
"Test correct indentation of plantuml activity-new while loop
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"@startuml
start
while (data available?)
:read data;
:generate diagrams;
endwhile
stop
@enduml"
"@startuml
start
while (data available?)
:read data;
:generate diagrams;
endwhile
stop
@enduml")
(plantuml-test-indent-block
"@startuml
while (check filesize ?) is (not empty)
:read file;
endwhile (empty)
:close file;
@enduml"
"@startuml
while (check filesize ?) is (not empty)
:read file;
endwhile (empty)
:close file;
@enduml"))
(ert-deftest plantuml-test-indentation/activity-new/fork ()
"Test correct indentation of plantuml activity-new forks
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"@startuml
start
if (multiprocessor?) then (yes)
fork
:Treatment 1;
fork again
:Treatment 2;
end fork
else (monoproc)
:Treatment 1;
:Treatment 2;
endif
@enduml"
"@startuml
start
if (multiprocessor?) then (yes)
fork
:Treatment 1;
fork again
:Treatment 2;
end fork
else (monoproc)
:Treatment 1;
:Treatment 2;
endif
@enduml"))
(ert-deftest plantuml-test-indentation/activity-new/notes ()
"Test correct indentation of plantuml activity-new notes
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"@startuml
start
:foo1;
floating note left: This is a note
:foo2;
note right
This note is on several
//lines// and can
contain <b>HTML</b>
====
* Calling the method \"foo()\" is prohibited
end note
stop
@enduml"
"@startuml
start
:foo1;
floating note left: This is a note
:foo2;
note right
This note is on several
//lines// and can
contain <b>HTML</b>
====
* Calling the method \"foo()\" is prohibited
end note
stop
@enduml"))
(ert-deftest plantuml-test-indentation/activity-new/grouping ()
"Test correct indentation of plantuml activity-new grouping
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"@startuml
start
partition Initialization {
:read config file;
:init internal variable;
}
partition Running {
:wait for user interaction;
:print information;
}
stop
@enduml"
"@startuml
start
partition Initialization {
:read config file;
:init internal variable;
}
partition Running {
:wait for user interaction;
:print information;
}
stop
@enduml"))
(ert-deftest plantuml-test-indentation/activity-new/sdl+splits ()
"Test correct indentation of plantuml activity-new sdl rendering and splits
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"@startuml
:Ready;
:next(o)|
:Receiving;
split
:nak(i)<
:ack(o)>
split again
:ack(i)<
:next(o)
on several lines|
:i := i + 1]
:ack(o)>
split again
:err(i)<
:nak(o)>
split again
:foo/
split again
:i > 5}
stop
end split
:finish;
@enduml"
"@startuml
:Ready;
:next(o)|
:Receiving;
split
:nak(i)<
:ack(o)>
split again
:ack(i)<
:next(o)
on several lines|
:i := i + 1]
:ack(o)>
split again
:err(i)<
:nak(o)>
split again
:foo/
split again
:i > 5}
stop
end split
:finish;
@enduml"))
(ert-deftest plantuml-test-indentation/activity-new/complete ()
"Test correct indentation of plantuml activity-new complete example
These code examples are taken from www.plantuml.com"
(plantuml-test-indent-block
"@startuml
start
:ClickServlet.handleRequest();
:new page;
if (Page.onSecurityCheck) then (true)
:Page.onInit();
if (isForward?) then (no)
:Process controls;
if (continue processing?) then (no)
stop
endif
if (isPost?) then (yes)
:Page.onPost();
else (no)
:Page.onGet();
endif
:Page.onRender();
endif
else (false)
endif
if (do redirect?) then (yes)
:redirect process;
else
if (do forward?) then (yes)
:Forward request;
else (no)
:Render page template;
endif
endif
stop
@enduml"
"@startuml
start
:ClickServlet.handleRequest();
:new page;
if (Page.onSecurityCheck) then (true)
:Page.onInit();
if (isForward?) then (no)
:Process controls;
if (continue processing?) then (no)
stop
endif
if (isPost?) then (yes)
:Page.onPost();
else (no)
:Page.onGet();
endif
:Page.onRender();
endif
else (false)
endif
if (do redirect?) then (yes)
:redirect process;
else
if (do forward?) then (yes)
:Forward request;
else (no)
:Render page template;
endif
endif
stop
@enduml"))
(provide 'plantuml-indentation-activity-new-test)
;;; plantuml-indentation-activity-old-test.el ends here

View File

@ -61,7 +61,7 @@ Finally, the indented text in the buffer will be compared with AFTER."
(plantuml-mode)
;; use 2 spaces instead of one tab for indentation
(setq indent-tabs-mode nil)
(setq tab-width 2)
(setq plantuml-indent-level 2)
(indent-region (point-min) (point-max))
(should (equal (buffer-string) after))))