Compare commits
59 Commits
Author | SHA1 | Date |
---|---|---|
Carlo Sciolla | 5889166b6c | |
Carlo Sciolla | 7a1d7ab1ca | |
Carlo Sciolla | bea66129a9 | |
Carlo Sciolla | 4f899a4495 | |
Carlo Sciolla | 252e2c3ce8 | |
Carlo Sciolla | 11b78ff62e | |
Carlo Sciolla | 4349011ed7 | |
Carlo Sciolla | 2954c15322 | |
Carlo Sciolla | a6545435cd | |
Carlo Sciolla | 1a11576f4a | |
Carlo Sciolla | df0d718981 | |
Carlo Sciolla | 271f468edd | |
Carlo Sciolla | b0be4182fb | |
Carlo Sciolla | 76b14086e8 | |
Carlo Sciolla | f04480dcba | |
Carlo Sciolla | 2bd72f7ae6 | |
Carlo Sciolla | 914e0526d9 | |
Carlo Sciolla | 60e4d3ec6e | |
Felix Weilbach | 7eb6167eb8 | |
Carlo Sciolla | 19e268c0cb | |
Carlo Sciolla | 2f8170b30b | |
Carlo Sciolla | 14daefbb2f | |
Carlo Sciolla | 47156fac58 | |
Carlo Sciolla | 95428d2e2e | |
Carlo Sciolla | b43249e1aa | |
Carlo Sciolla | 39a109ffe6 | |
Carlo Sciolla | b39c310e9c | |
Carlo Sciolla | f7e3af35e8 | |
Carlo Sciolla | ae8593d662 | |
Carlo Sciolla | 36e0abac58 | |
Carlo Sciolla | beb4dfc726 | |
Carlo Sciolla | 7c1d6d3891 | |
Carlo Sciolla | 08b783aee6 | |
Carlo Sciolla | 04110d0110 | |
Carlo Sciolla | 5a6ed6c5a2 | |
Carlo Sciolla | 4a908c2279 | |
Carlo Sciolla | a822c551b8 | |
Felix Weilbach | 9cba6835fd | |
Michael Steiner | cbd7fa4c6b | |
Michael Steiner | 80b554e871 | |
Michael Steiner | c32493229d | |
Carlo Sciolla | 1e5f8beedd | |
Carlo Sciolla | d11bd57f31 | |
Carlo Sciolla | 0ae3aed095 | |
Carlo Sciolla | 648feb5b12 | |
Carlo Sciolla | 56bb65342a | |
Carlo Sciolla | 15ced4ae26 | |
Carlo Sciolla | e9c8e76ff2 | |
Carlo Sciolla | 27d48942a6 | |
Carlo Sciolla | 698a248549 | |
Carlo Sciolla | a2617017fd | |
Carlo Sciolla | b3cfafbf99 | |
Carlo Sciolla | 8503f9d96a | |
Carlo Sciolla | 8f12855be9 | |
Carlo Sciolla | c14684dc3a | |
Carlo Sciolla | 9bd2dc86aa | |
Carlo Sciolla | 689c6a6950 | |
Carlo Sciolla | 92c490d3fc | |
wailo | 56f5cf7276 |
|
@ -3,13 +3,18 @@ version: 2.0
|
||||||
# Default actions to perform on each Emacs version
|
# Default actions to perform on each Emacs version
|
||||||
default: &default-steps
|
default: &default-steps
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
|
||||||
- run:
|
- run:
|
||||||
name: Update APT packages
|
name: Update APT packages
|
||||||
command: apt-get update
|
command: apt-get update
|
||||||
- run:
|
- run:
|
||||||
name: Install prerequisites
|
name: Install prerequisites
|
||||||
command: apt-get install -y openjdk-8-jre make python git
|
command: apt-get install -y openjdk-11-jre make python git
|
||||||
|
- checkout
|
||||||
|
- run:
|
||||||
|
# Note: this makes it hard to reproduce builds but easier to spot incompatibilities with
|
||||||
|
# newer PlantUML releases. Current trade off seems acceptable.
|
||||||
|
name: Download the latest PlantUML release
|
||||||
|
command: sh ./bin/download-plantuml.sh
|
||||||
- run:
|
- run:
|
||||||
name: Install cask
|
name: Install cask
|
||||||
command: curl -fsSL https://raw.githubusercontent.com/cask/cask/master/go | python
|
command: curl -fsSL https://raw.githubusercontent.com/cask/cask/master/go | python
|
||||||
|
@ -30,7 +35,7 @@ jobs:
|
||||||
|
|
||||||
test-emacs-26:
|
test-emacs-26:
|
||||||
docker:
|
docker:
|
||||||
- image: silex/emacs:26.0
|
- image: silex/emacs:26
|
||||||
entrypoint: bash
|
entrypoint: bash
|
||||||
<<: *default-steps
|
<<: *default-steps
|
||||||
|
|
||||||
|
@ -48,4 +53,4 @@ workflows:
|
||||||
- test-emacs-25
|
- test-emacs-25
|
||||||
- test-emacs-26
|
- test-emacs-26
|
||||||
# Testing against master currently hangs on CircleCI
|
# Testing against master currently hangs on CircleCI
|
||||||
#- test-emacs-master
|
# - test-emacs-master
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Number of days of inactivity before an issue becomes stale
|
||||||
|
daysUntilStale: 90
|
||||||
|
# Number of days of inactivity before a stale issue is closed
|
||||||
|
daysUntilClose: 10
|
||||||
|
# Issues with these labels will never be considered stale
|
||||||
|
exemptLabels:
|
||||||
|
- help-wanted
|
||||||
|
- enhancement
|
||||||
|
# Label to use when marking an issue as stale
|
||||||
|
staleLabel: wontfix
|
||||||
|
# Comment to post when marking an issue as stale. Set to `false` to disable
|
||||||
|
markComment: >
|
||||||
|
This issue has been automatically marked as stale because it has not had
|
||||||
|
recent activity. It will be closed if no further activity occurs. Thank you
|
||||||
|
for your contributions.
|
||||||
|
# Comment to post when closing a stale issue. Set to `false` to disable
|
||||||
|
closeComment: false
|
7
Makefile
7
Makefile
|
@ -1,14 +1,15 @@
|
||||||
#
|
#
|
||||||
# Programs used in the make goals
|
# Programs used in the make goals
|
||||||
#
|
#
|
||||||
export CASK ?= cask
|
export CASK ?= cask
|
||||||
export EMACS ?= emacs
|
export EMACS ?= emacs
|
||||||
|
|
||||||
#
|
#
|
||||||
# General configuration
|
# General configuration
|
||||||
#
|
#
|
||||||
export CASK_DIR ?= `${CASK} package-directory`
|
export CASK_DIR ?= `${CASK} package-directory`
|
||||||
export BATCH = --batch -q -l .emacs/init.el
|
export BATCH = --batch -q -l .emacs/init.el
|
||||||
|
export COVERALLS_REPO_TOKEN = 61YFD7RG1RRJTs0kEuj1aZX7VBgUPiMNO
|
||||||
|
|
||||||
all: version test
|
all: version test
|
||||||
|
|
||||||
|
|
37
README.md
37
README.md
|
@ -1,6 +1,5 @@
|
||||||
[![MELPA](http://melpa.org/packages/plantuml-mode-badge.svg)](http://melpa.org/#/plantuml-mode) [![MELPA Stable](http://stable.melpa.org/packages/plantuml-mode-badge.svg)](http://stable.melpa.org/#/plantuml-mode) [![CircleCI](https://circleci.com/gh/skuro/plantuml-mode.svg?style=svg)](https://circleci.com/gh/skuro/plantuml-mode) [![Coverage Status](https://coveralls.io/repos/github/skuro/plantuml-mode/badge.svg?branch=HEAD)](https://coveralls.io/github/skuro/plantuml-mode?branch=HEAD)
|
[![MELPA](http://melpa.org/packages/plantuml-mode-badge.svg)](http://melpa.org/#/plantuml-mode) [![MELPA Stable](http://stable.melpa.org/packages/plantuml-mode-badge.svg)](http://stable.melpa.org/#/plantuml-mode) [![CircleCI](https://circleci.com/gh/skuro/plantuml-mode.svg?style=svg)](https://circleci.com/gh/skuro/plantuml-mode) [![Coverage Status](https://coveralls.io/repos/github/skuro/plantuml-mode/badge.svg?branch=HEAD)](https://coveralls.io/github/skuro/plantuml-mode?branch=HEAD)
|
||||||
|
|
||||||
|
|
||||||
# PlantUML mode for Emacs
|
# PlantUML mode for Emacs
|
||||||
|
|
||||||
<img src="https://raw.githubusercontent.com/skuro/plantuml-mode/master/banner.png"
|
<img src="https://raw.githubusercontent.com/skuro/plantuml-mode/master/banner.png"
|
||||||
|
@ -26,11 +25,16 @@ Also, to enable preview you need to tell `plantuml-mode` where to locate the Pla
|
||||||
M-x customize-variable<RET>
|
M-x customize-variable<RET>
|
||||||
plantuml-jar-path<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
|
# Features
|
||||||
|
|
||||||
- Syntax highlight
|
- Syntax highlight
|
||||||
- Autocompletion
|
- Autocompletion
|
||||||
- Preview of buffer or region
|
- Preview of buffer or region
|
||||||
|
- [EXPERIMENTAL] Use either local JAR or remote server for preview
|
||||||
|
|
||||||
# Enable the major mode
|
# Enable the major mode
|
||||||
|
|
||||||
|
@ -84,6 +88,28 @@ Then you can edit a `plantuml` code block with `plantuml-mode` by hitting `C-'`
|
||||||
|
|
||||||
When in the `plantuml-mode` buffer you can then hit again `C-'` to return to the original `org-mode` document.
|
When in the `plantuml-mode` buffer you can then hit again `C-'` to return to the original `org-mode` document.
|
||||||
|
|
||||||
|
# Execution modes
|
||||||
|
|
||||||
|
**EXPERIMENTAL**
|
||||||
|
|
||||||
|
As of `v1.3.0` support is added for switching execution mode. The following two modes are available:
|
||||||
|
|
||||||
|
- `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.
|
||||||
|
|
||||||
|
## Configure server rendering
|
||||||
|
|
||||||
|
When selecting `server` execution modes, you can customize the following variable to set the server to use for rendering:
|
||||||
|
|
||||||
|
```
|
||||||
|
plantuml-server-url
|
||||||
|
```
|
||||||
|
|
||||||
|
It defaults to `"https://www.plantuml.com/plantuml"`.
|
||||||
|
|
||||||
# Migration from `puml-mode`
|
# Migration from `puml-mode`
|
||||||
|
|
||||||
If you were previously using `puml-mode`, you should change any reference to a `puml-..` variable or function to its `plantuml-..` counterpart. Most notably, `puml-plantuml-jar-path` is now just `plantuml-jar-path`.
|
If you were previously using `puml-mode`, you should change any reference to a `puml-..` variable or function to its `plantuml-..` counterpart. Most notably, `puml-plantuml-jar-path` is now just `plantuml-jar-path`.
|
||||||
|
@ -112,11 +138,20 @@ the textual mode and see if the output is valid SVG.
|
||||||
|
|
||||||
## Development
|
## 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:
|
In order to contribute to `plantuml-mode` make sure to:
|
||||||
|
|
||||||
- agree with the [GPLv3+ licencing terms](#License) as they are mandated by Emacs
|
- agree with the [GPLv3+ licencing terms](#License) as they are mandated by Emacs
|
||||||
- install [`cask`](https://github.com/cask/cask)
|
- 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`)
|
- 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
|
# Credits
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Where the script is executed
|
||||||
|
CURRENT_PATH="$(dirname "$(readlink -f "$0")")"
|
||||||
|
|
||||||
|
# Where to download the file
|
||||||
|
OUTPUT_PATH="${CURRENT_PATH}/plantuml.jar"
|
||||||
|
|
||||||
|
# Retrieve the list of versions, in XML format, only one result (the latest)
|
||||||
|
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>)')"
|
||||||
|
|
||||||
|
# Compose the download link
|
||||||
|
DOWNLOAD_URL="https://search.maven.org/remotecontent?filepath=net/sourceforge/plantuml/plantuml/${LATEST_VERSION}/plantuml-${LATEST_VERSION}.jar"
|
||||||
|
|
||||||
|
# finally, download the JAR file
|
||||||
|
echo "Downloading PlantUML v${LATEST_VERSION} into ${OUTPUT_PATH}"
|
||||||
|
curl -so "${OUTPUT_PATH}" "${DOWNLOAD_URL}" 2>/dev/null
|
BIN
bin/plantuml.jar
BIN
bin/plantuml.jar
Binary file not shown.
|
@ -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 \"[0-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="$(TZ='UTC' date '+%Y%m%d.%-H%M')" # MELPA style
|
||||||
|
update_version "${VERSION}"
|
||||||
|
git add plantuml-mode.el
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
## do nothing
|
||||||
|
;;
|
||||||
|
esac
|
442
plantuml-mode.el
442
plantuml-mode.el
|
@ -8,7 +8,7 @@
|
||||||
;; Keywords: uml plantuml ascii
|
;; Keywords: uml plantuml ascii
|
||||||
;; Version: 1.2.9
|
;; Version: 1.2.9
|
||||||
;; Package-Version: 1.2.9
|
;; Package-Version: 1.2.9
|
||||||
;; Package-Requires: ((emacs "25.0"))
|
;; Package-Requires: ((dash "2.0.0") (emacs "25.0"))
|
||||||
|
|
||||||
;; This file is free software; you can redistribute it and/or modify
|
;; This file is free software; you can redistribute it and/or modify
|
||||||
;; it under the terms of the GNU General Public License as published by
|
;; it under the terms of the GNU General Public License as published by
|
||||||
|
@ -37,6 +37,12 @@
|
||||||
|
|
||||||
;;; Change log:
|
;;; Change log:
|
||||||
;;
|
;;
|
||||||
|
;; version 1.4.1, 2019-09-03 Better indentation; more bugfixing; actually adding `executable' mode
|
||||||
|
;; version 1.4.0, 2019-08-21 Added `executable' exec mode to use locally installed `plantuml' binaries, various bugfixes
|
||||||
|
;; version 1.3.1, 2019-08-02 Fixed interactive behavior of `plantuml-set-exec-mode'
|
||||||
|
;; version 1.3.0, 2019-05-31 Added experimental support for multiple rendering modes and, specifically, preview using a PlantUML server
|
||||||
|
;; version 1.2.11, 2019-04-09 Added `plantuml-download-jar'
|
||||||
|
;; version 1.2.10, 2019-04-03 Avoid messing with window layouts and buffers -- courtesy of https://github.com/wailo
|
||||||
;; version 1.2.9, Revamped indentation support, now working with a greater number of keywords
|
;; version 1.2.9, Revamped indentation support, now working with a greater number of keywords
|
||||||
;; version 1.2.8, 2019-01-07 Support indentation for activate / deactivate blocks; allow customization of `plantuml-java-args'
|
;; version 1.2.8, 2019-01-07 Support indentation for activate / deactivate blocks; allow customization of `plantuml-java-args'
|
||||||
;; version 1.2.7, 2018-08-15 Added support for indentation; Fixed the comiling error when installing with melpa
|
;; version 1.2.7, 2018-08-15 Added support for indentation; Fixed the comiling error when installing with melpa
|
||||||
|
@ -68,6 +74,7 @@
|
||||||
;;; Code:
|
;;; Code:
|
||||||
(require 'thingatpt)
|
(require 'thingatpt)
|
||||||
(require 'dash)
|
(require 'dash)
|
||||||
|
(require 'xml)
|
||||||
|
|
||||||
(defgroup plantuml-mode nil
|
(defgroup plantuml-mode nil
|
||||||
"Major mode for editing plantuml file."
|
"Major mode for editing plantuml file."
|
||||||
|
@ -79,9 +86,15 @@
|
||||||
:type 'string
|
:type 'string
|
||||||
:group 'plantuml)
|
: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.")
|
(defvar plantuml-mode-hook nil "Standard hook for plantuml-mode.")
|
||||||
|
|
||||||
(defconst plantuml-mode-version "1.2.9pre2" "The plantuml-mode version string.")
|
(defconst plantuml-mode-version "1.4.1" "The plantuml-mode version string.")
|
||||||
|
|
||||||
(defvar plantuml-mode-debug-enabled nil)
|
(defvar plantuml-mode-debug-enabled nil)
|
||||||
|
|
||||||
|
@ -98,7 +111,7 @@
|
||||||
:type 'string
|
:type 'string
|
||||||
:group 'plantuml)
|
: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."
|
"The parameters passed to `plantuml-java-command' when executing PlantUML."
|
||||||
:type '(repeat string)
|
:type '(repeat string)
|
||||||
:group 'plantuml)
|
:group 'plantuml)
|
||||||
|
@ -108,12 +121,29 @@
|
||||||
:type '(repeat string)
|
:type '(repeat string)
|
||||||
:group 'plantuml)
|
:group 'plantuml)
|
||||||
|
|
||||||
|
(defcustom plantuml-server-url "https://www.plantuml.com/plantuml"
|
||||||
|
"The base URL of the PlantUML server."
|
||||||
|
: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 executable))
|
||||||
|
|
||||||
(defcustom plantuml-suppress-deprecation-warning t
|
(defcustom plantuml-suppress-deprecation-warning t
|
||||||
"To silence the deprecation warning when `puml-mode' is found upon loading."
|
"To silence the deprecation warning when `puml-mode' is found upon loading."
|
||||||
:type 'boolean
|
:type 'boolean
|
||||||
:group 'plantuml)
|
:group 'plantuml)
|
||||||
|
|
||||||
(defun plantuml-render-command (&rest arguments)
|
(defun plantuml-jar-render-command (&rest arguments)
|
||||||
"Create a command line to execute PlantUML with arguments (as 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))
|
(let* ((cmd-list (append plantuml-java-args (list (expand-file-name plantuml-jar-path)) plantuml-jar-args arguments))
|
||||||
(cmd (mapconcat 'identity cmd-list "|")))
|
(cmd (mapconcat 'identity cmd-list "|")))
|
||||||
|
@ -141,6 +171,30 @@
|
||||||
;; keyword completion
|
;; keyword completion
|
||||||
(defvar plantuml-kwdList nil "The plantuml keywords.")
|
(defvar plantuml-kwdList nil "The plantuml keywords.")
|
||||||
|
|
||||||
|
;; PlantUML execution mode
|
||||||
|
(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."
|
||||||
|
(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))))
|
||||||
|
(if (member mode '("jar" "server" "executable"))
|
||||||
|
(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 ()
|
(defun plantuml-enable-debug ()
|
||||||
"Enables debug messages into the *PLANTUML Messages* buffer."
|
"Enables debug messages into the *PLANTUML Messages* buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
@ -162,15 +216,68 @@
|
||||||
(insert msg)
|
(insert msg)
|
||||||
(insert "\n"))))))
|
(insert "\n"))))))
|
||||||
|
|
||||||
(defun plantuml-init ()
|
(defun plantuml-download-jar ()
|
||||||
"Initialize the keywords or builtins from the cmdline language output."
|
"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)))
|
||||||
|
(car)
|
||||||
|
(xml-node-children)
|
||||||
|
(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)))
|
||||||
|
(message "Aborted."))
|
||||||
|
(message "Aborted.")))
|
||||||
|
|
||||||
|
(defun plantuml-jar-get-language (buf)
|
||||||
|
"Retrieve the language specification from the PlantUML JAR file and paste it into BUF."
|
||||||
(unless (or (eq system-type 'cygwin) (file-exists-p plantuml-jar-path))
|
(unless (or (eq system-type 'cygwin) (file-exists-p plantuml-jar-path))
|
||||||
(error "Could not find plantuml.jar at %s" plantuml-jar-path))
|
(error "Could not find plantuml.jar at %s" plantuml-jar-path))
|
||||||
(with-temp-buffer
|
(with-current-buffer buf
|
||||||
(let ((cmd-args (append (list plantuml-java-command nil t nil)
|
(let ((cmd-args (append (list plantuml-java-command nil t nil)
|
||||||
(plantuml-render-command "-language"))))
|
(plantuml-jar-render-command "-language"))))
|
||||||
(apply 'call-process cmd-args)
|
(apply 'call-process cmd-args)
|
||||||
(goto-char (point-min)))
|
(goto-char (point-min)))))
|
||||||
|
|
||||||
|
(defun plantuml-server-get-language (buf)
|
||||||
|
"Retrieve the language specification from the PlantUML server and paste it into BUF."
|
||||||
|
(let ((lang-url (concat plantuml-server-url "/language")))
|
||||||
|
(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)
|
||||||
|
('executable #'plantuml-executable-get-language))))
|
||||||
|
(if get-fn
|
||||||
|
(funcall get-fn buf)
|
||||||
|
(error "Unsupported execution mode %s" mode))))
|
||||||
|
|
||||||
|
(defun plantuml-init (mode)
|
||||||
|
"Initialize the keywords or builtins from the cmdline language output. Use exec mode MODE to load the language details."
|
||||||
|
(with-temp-buffer
|
||||||
|
(plantuml-get-language mode (current-buffer))
|
||||||
(let ((found (search-forward ";" nil t))
|
(let ((found (search-forward ";" nil t))
|
||||||
(word "")
|
(word "")
|
||||||
(count 0)
|
(count 0)
|
||||||
|
@ -208,10 +315,10 @@
|
||||||
|
|
||||||
(defvar plantuml-output-type
|
(defvar plantuml-output-type
|
||||||
(if (not (display-images-p))
|
(if (not (display-images-p))
|
||||||
"utxt"
|
"txt"
|
||||||
(cond ((image-type-available-p 'svg) "svg")
|
(cond ((image-type-available-p 'svg) "svg")
|
||||||
((image-type-available-p 'png) "png")
|
((image-type-available-p 'png) "png")
|
||||||
(t "utxt")))
|
(t "txt")))
|
||||||
"Specify the desired output type to use for generated diagrams.")
|
"Specify the desired output type to use for generated diagrams.")
|
||||||
|
|
||||||
(defun plantuml-read-output-type ()
|
(defun plantuml-read-output-type ()
|
||||||
|
@ -221,7 +328,7 @@
|
||||||
(append
|
(append
|
||||||
(and (image-type-available-p 'svg) '("svg"))
|
(and (image-type-available-p 'svg) '("svg"))
|
||||||
(and (image-type-available-p 'png) '("png"))
|
(and (image-type-available-p 'png) '("png"))
|
||||||
'("utxt"))))
|
'("txt"))))
|
||||||
(completing-read (format "Output type [%s]: " plantuml-output-type)
|
(completing-read (format "Output type [%s]: " plantuml-output-type)
|
||||||
available-types
|
available-types
|
||||||
nil
|
nil
|
||||||
|
@ -239,56 +346,137 @@ default output type for new buffers."
|
||||||
(setq plantuml-output-type type))
|
(setq plantuml-output-type type))
|
||||||
|
|
||||||
(defun plantuml-is-image-output-p ()
|
(defun plantuml-is-image-output-p ()
|
||||||
"Return true if the diagram output format is an image, false if it's text based."
|
"Return non-nil if the diagram output format is an image, false if it's text based."
|
||||||
(not (equal "utxt" plantuml-output-type)))
|
(not (equal "txt" plantuml-output-type)))
|
||||||
|
|
||||||
(defun plantuml-output-type-opt ()
|
(defun plantuml-jar-output-type-opt (output-type)
|
||||||
"Create the flag to pass to PlantUML to produce the selected output format."
|
"Create the flag to pass to PlantUML according to OUTPUT-TYPE.
|
||||||
(concat "-t" plantuml-output-type))
|
Note that output type `txt' is promoted to `utxt' for better rendering."
|
||||||
|
(concat "-t" (pcase output-type
|
||||||
|
("txt" "utxt")
|
||||||
|
(_ output-type))))
|
||||||
|
|
||||||
(defun plantuml-start-process (buf)
|
(defun plantuml-jar-start-process (buf)
|
||||||
"Run PlantUML as an Emacs process and puts the output into the given buffer (as BUF)."
|
"Run PlantUML as an Emacs process and puts the output into the given buffer (as BUF)."
|
||||||
(apply #'start-process
|
(apply #'start-process
|
||||||
"PLANTUML" buf plantuml-java-command
|
"PLANTUML" buf plantuml-java-command
|
||||||
`(,@plantuml-java-args
|
`(,@plantuml-java-args
|
||||||
,(expand-file-name plantuml-jar-path)
|
,(expand-file-name plantuml-jar-path)
|
||||||
,(plantuml-output-type-opt)
|
,(plantuml-jar-output-type-opt plantuml-output-type)
|
||||||
,@plantuml-jar-args
|
,@plantuml-jar-args
|
||||||
"-p")))
|
"-p")))
|
||||||
|
|
||||||
(defun plantuml-preview-string (prefix string)
|
(defun plantuml-executable-start-process (buf)
|
||||||
"Preview diagram from PlantUML sources (as STRING), using prefix (as PREFIX)
|
"Run PlantUML as an Emacs process and puts the output into the given buffer (as BUF)."
|
||||||
to choose where to display it:
|
(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:
|
||||||
- 4 (when prefixing the command with C-u) -> new window
|
- 4 (when prefixing the command with C-u) -> new window
|
||||||
- 16 (when prefixing the command with C-u C-u) -> new frame.
|
- 16 (when prefixing the command with C-u C-u) -> new frame.
|
||||||
- else -> new buffer"
|
- else -> new buffer"
|
||||||
|
(let ((imagep (and (display-images-p)
|
||||||
|
(plantuml-is-image-output-p))))
|
||||||
|
(cond
|
||||||
|
((= prefix 16) (switch-to-buffer-other-frame buf))
|
||||||
|
((= prefix 4) (switch-to-buffer-other-window buf))
|
||||||
|
(t (display-buffer buf)))
|
||||||
|
(when imagep
|
||||||
|
(with-current-buffer buf
|
||||||
|
(image-mode)
|
||||||
|
(set-buffer-multibyte t)))))
|
||||||
|
|
||||||
|
(defun plantuml-jar-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-jar-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-server-encode-url (string)
|
||||||
|
"Encode the string STRING into a URL suitable for PlantUML server interactions."
|
||||||
|
(let* ((coding-system (or buffer-file-coding-system
|
||||||
|
"utf8"))
|
||||||
|
(encoded-string (base64-encode-string (encode-coding-string string coding-system) t)))
|
||||||
|
(concat plantuml-server-url "/" plantuml-output-type "/-base64-" encoded-string)))
|
||||||
|
|
||||||
|
(defun plantuml-server-preview-string (prefix string buf)
|
||||||
|
"Preview the diagram from STRING as rendered by the PlantUML server.
|
||||||
|
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 (plantuml-server-encode-url string)))
|
||||||
|
(save-current-buffer
|
||||||
|
(save-match-data
|
||||||
|
(url-retrieve url-request-location
|
||||||
|
(lambda (status)
|
||||||
|
;; TODO: error check
|
||||||
|
(goto-char (point-min))
|
||||||
|
;; skip the HTTP headers
|
||||||
|
(while (not (looking-at "\n"))
|
||||||
|
(forward-line))
|
||||||
|
(kill-region (point-min) (+ 1 (point)))
|
||||||
|
(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:
|
||||||
|
- 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 ((preview-fn (pcase mode
|
||||||
|
('jar #'plantuml-jar-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))))
|
||||||
|
|
||||||
|
(defun plantuml-preview-string (prefix string)
|
||||||
|
"Preview diagram from PlantUML sources (as STRING), using prefix (as PREFIX)
|
||||||
|
to choose where to display it."
|
||||||
(let ((b (get-buffer plantuml-preview-buffer)))
|
(let ((b (get-buffer plantuml-preview-buffer)))
|
||||||
(when b
|
(when b
|
||||||
(kill-buffer b)))
|
(kill-buffer b)))
|
||||||
|
|
||||||
(let* ((imagep (and (display-images-p)
|
(let* ((imagep (and (display-images-p)
|
||||||
(plantuml-is-image-output-p)))
|
(plantuml-is-image-output-p)))
|
||||||
(process-connection-type nil)
|
|
||||||
(buf (get-buffer-create plantuml-preview-buffer))
|
(buf (get-buffer-create plantuml-preview-buffer))
|
||||||
(coding-system-for-read (and imagep 'binary))
|
(coding-system-for-read (and imagep 'binary))
|
||||||
(coding-system-for-write (and imagep 'binary)))
|
(coding-system-for-write (and imagep 'binary)))
|
||||||
|
(plantuml-exec-mode-preview-string prefix (plantuml-get-exec-mode) string buf)))
|
||||||
(let ((ps (plantuml-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))
|
|
||||||
(cond
|
|
||||||
((= prefix 16)
|
|
||||||
(switch-to-buffer-other-frame plantuml-preview-buffer))
|
|
||||||
((= prefix 4)
|
|
||||||
(switch-to-buffer-other-window plantuml-preview-buffer))
|
|
||||||
(t (switch-to-buffer plantuml-preview-buffer)))
|
|
||||||
(when imagep
|
|
||||||
(image-mode)
|
|
||||||
(set-buffer-multibyte t)))))))
|
|
||||||
|
|
||||||
(defun plantuml-preview-buffer (prefix)
|
(defun plantuml-preview-buffer (prefix)
|
||||||
"Preview diagram from the PlantUML sources in the current buffer.
|
"Preview diagram from the PlantUML sources in the current buffer.
|
||||||
|
@ -336,73 +524,121 @@ Uses prefix (as PREFIX) to choose where to display it:
|
||||||
(plantuml-preview-region prefix (region-beginning) (region-end))
|
(plantuml-preview-region prefix (region-beginning) (region-end))
|
||||||
(plantuml-preview-buffer prefix)))
|
(plantuml-preview-buffer prefix)))
|
||||||
|
|
||||||
(defun plantuml-init-once ()
|
(defun plantuml-init-once (&optional mode)
|
||||||
"Ensure initialization only happens once."
|
"Ensure initialization only happens once. Use exec mode MODE to load the language details or by first querying `plantuml-get-exec-mode'."
|
||||||
(unless plantuml-kwdList
|
(let ((mode (or mode (plantuml-get-exec-mode))))
|
||||||
(plantuml-init)
|
(unless plantuml-kwdList
|
||||||
(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\\)\\)\\>\\)"))
|
(plantuml-init mode)
|
||||||
(defvar plantuml-keywords-regexp (concat "^\\s *" (regexp-opt plantuml-keywords 'words) "\\|\\(<\\|<|\\|\\*\\|o\\)\\(\\.+\\|-+\\)\\|\\(\\.+\\|-+\\)\\(>\\||>\\|\\*\\|o\\)\\|\\.\\{2,\\}\\|-\\{2,\\}"))
|
(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\\)\\)\\>\\)"))
|
||||||
(defvar plantuml-builtins-regexp (regexp-opt plantuml-builtins 'words))
|
(defvar plantuml-keywords-regexp (concat "^\\s *" (regexp-opt plantuml-keywords 'words) "\\|\\(<\\|<|\\|\\*\\|o\\)\\(\\.+\\|-+\\)\\|\\(\\.+\\|-+\\)\\(>\\||>\\|\\*\\|o\\)\\|\\.\\{2,\\}\\|-\\{2,\\}"))
|
||||||
(defvar plantuml-preprocessors-regexp (concat "^\\s *" (regexp-opt plantuml-preprocessors 'words)))
|
(defvar plantuml-builtins-regexp (regexp-opt plantuml-builtins 'words))
|
||||||
|
(defvar plantuml-preprocessors-regexp (concat "^\\s *" (regexp-opt plantuml-preprocessors 'words)))
|
||||||
|
|
||||||
(defvar plantuml-indent-regexp-block-start "^.*{\s*$"
|
;; Below are the regexp's for indentation.
|
||||||
"Indentation regex for all plantuml elements that might define a {} block.
|
;; Notes:
|
||||||
|
;; - there is some control on what it is indented by overriding some of below
|
||||||
|
;; X-start and X-end regexp before plantuml-mode is loaded. E.g., to disable
|
||||||
|
;; indentation on activate, you might define in your .emacs something like
|
||||||
|
;; (setq plantuml-indent-regexp-activate-start
|
||||||
|
;; "NEVER MATCH THIS EXPRESSION"); define _before_ load plantuml-mode!
|
||||||
|
;; (setq plantuml-indent-regexp-activate-end
|
||||||
|
;; "NEVER MATCH THIS EXPRESSION"); define _before_ load plantuml-mode!
|
||||||
|
;; - due to the nature of using (context-insensitive) regexp, indentation have
|
||||||
|
;; following limitations
|
||||||
|
;; - commands commented out by /' ... '/ will _not_ be ignored
|
||||||
|
;; and potentially lead to miss-indentation
|
||||||
|
;; - you can though somewhat correct mis-indentation by adding in '-comment lines
|
||||||
|
;; PLANTUML_MODE_INDENT_INCREASE and/or PLANTUML_MODE_INDENT_DECREASE
|
||||||
|
;; to increase and/or decrease the level of indentation
|
||||||
|
;; (Note: the line with the comment should not contain any text matching other indent
|
||||||
|
;; regexp or this user-control instruction will be ignored; also at most will count
|
||||||
|
;; per line ...)
|
||||||
|
(defvar plantuml-indent-regexp-block-start "^.*{\s*$"
|
||||||
|
"Indentation regex for all plantuml elements that might define a {} block.
|
||||||
Plantuml elements like skinparam, rectangle, sprite, package, etc.
|
Plantuml elements like skinparam, rectangle, sprite, package, etc.
|
||||||
The opening { has to be the last visible character in the line (whitespace
|
The opening { has to be the last visible character in the line (whitespace
|
||||||
might follow).")
|
might follow).")
|
||||||
(defvar plantuml-indent-regexp-note-start "^\s*\\(floating\s+\\)?[hr]?note[^:]*?$" "simplyfied regex; note syntax is especially inconsistent across diagrams")
|
(defvar plantuml-indent-regexp-note-start "^\s*\\(floating\s+\\)?[hr]?note\s+\\(right\\|left\\|top\\|bottom\\|over\\)[^:]*?$" "simplyfied regex; note syntax is especially inconsistent across diagrams")
|
||||||
(defvar plantuml-indent-regexp-group-start "^\s*\\(alt\\|else\\|opt\\|loop\\|par\\|break\\|critical\\|group\\)\\(?:\s+.+\\|$\\)"
|
(defvar plantuml-indent-regexp-group-start "^\s*\\(alt\\|else\\|opt\\|loop\\|par\\|break\\|critical\\|group\\)\\(?:\s+.+\\|$\\)"
|
||||||
"Indentation regex for plantuml group elements that are defined for sequence diagrams.
|
"Indentation regex for plantuml group elements that are defined for sequence diagrams.
|
||||||
Two variants for groups: keyword is either followed by whitespace and some text
|
Two variants for groups: keyword is either followed by whitespace and some text
|
||||||
or it is followed by line end.")
|
or it is followed by line end.")
|
||||||
(defvar plantuml-indent-regexp-activate-start "^\s*activate\s+.+$")
|
(defvar plantuml-indent-regexp-activate-start "^\s*activate\s+.+$")
|
||||||
(defvar plantuml-indent-regexp-box-start "^\s*box\s+.+$")
|
(defvar plantuml-indent-regexp-box-start "^\s*box\s+.+$")
|
||||||
(defvar plantuml-indent-regexp-ref-start "^ref\s+over\s+[^:]+?$")
|
(defvar plantuml-indent-regexp-ref-start "^\s*ref\s+over\s+[^:]+?$")
|
||||||
(defvar plantuml-indent-regexp-title-start "^\s*title$")
|
(defvar plantuml-indent-regexp-title-start "^\s*title\s*\\('.*\\)?$")
|
||||||
(defvar plantuml-indent-regexp-header-start "^\s*\\(?:\\(?:center\\|left\\|right\\)\s+header\\|header\\)$")
|
(defvar plantuml-indent-regexp-header-start "^\s*\\(?:\\(?:center\\|left\\|right\\)\s+header\\|header\\)\s*\\('.*\\)?$")
|
||||||
(defvar plantuml-indent-regexp-footer-start "^\s*\\(?:\\(?:center\\|left\\|right\\)\s+footer\\|footer\\)$")
|
(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\\)\\)$")
|
(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$" "used in current activity diagram, sometimes already mentioned as deprecated")
|
(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-macro-start "^\s*!definelong.*$")
|
(defvar plantuml-indent-regexp-macro-start "^\s*!definelong.*$")
|
||||||
(defvar plantuml-indent-regexp-start (list plantuml-indent-regexp-block-start
|
(defvar plantuml-indent-regexp-user-control-start "^.*'.*\s*PLANTUML_MODE_INDENT_INCREASE\s*.*$")
|
||||||
plantuml-indent-regexp-group-start
|
(defvar plantuml-indent-regexp-start (list plantuml-indent-regexp-block-start
|
||||||
plantuml-indent-regexp-activate-start
|
plantuml-indent-regexp-group-start
|
||||||
plantuml-indent-regexp-box-start
|
plantuml-indent-regexp-activate-start
|
||||||
plantuml-indent-regexp-ref-start
|
plantuml-indent-regexp-box-start
|
||||||
plantuml-indent-regexp-legend-start
|
plantuml-indent-regexp-ref-start
|
||||||
plantuml-indent-regexp-note-start
|
plantuml-indent-regexp-legend-start
|
||||||
plantuml-indent-regexp-oldif-start
|
plantuml-indent-regexp-note-start
|
||||||
plantuml-indent-regexp-title-start
|
plantuml-indent-regexp-oldif-start
|
||||||
plantuml-indent-regexp-header-start
|
plantuml-indent-regexp-title-start
|
||||||
plantuml-indent-regexp-footer-start
|
plantuml-indent-regexp-header-start
|
||||||
plantuml-indent-regexp-macro-start
|
plantuml-indent-regexp-footer-start
|
||||||
plantuml-indent-regexp-oldif-start))
|
plantuml-indent-regexp-macro-start
|
||||||
(defvar plantuml-indent-regexp-end "^\s*\\(?:}\\|endif\\|else\s*.*\\|end\\|end\s+note\\|endhnote\\|endrnote\\|end\s+box\\|end\s+ref\\|deactivate\s+.+\\|end\s+title\\|endheader\\|endfooter\\|endlegend\\|!enddefinelong\\)$")
|
plantuml-indent-regexp-oldif-start
|
||||||
(setq plantuml-font-lock-keywords
|
plantuml-indent-regexp-user-control-start))
|
||||||
`(
|
(defvar plantuml-indent-regexp-block-end "^\s*\\(?:}\\|endif\\|else\s*.*\\|end\\)\s*\\('.*\\)?$")
|
||||||
(,plantuml-types-regexp . font-lock-type-face)
|
(defvar plantuml-indent-regexp-note-end "^\s*\\(end\s+note\\|end[rh]note\\)\s*\\('.*\\)?$")
|
||||||
(,plantuml-keywords-regexp . font-lock-keyword-face)
|
(defvar plantuml-indent-regexp-group-end "^\s*end\s*\\('.*\\)?$")
|
||||||
(,plantuml-builtins-regexp . font-lock-builtin-face)
|
(defvar plantuml-indent-regexp-activate-end "^\s*deactivate\s+.+$")
|
||||||
(,plantuml-preprocessors-regexp . font-lock-preprocessor-face)
|
(defvar plantuml-indent-regexp-box-end "^\s*end\s+box\s*\\('.*\\)?$")
|
||||||
;; note: order matters
|
(defvar plantuml-indent-regexp-ref-end "^\s*end\s+ref\s*\\('.*\\)?$")
|
||||||
))
|
(defvar plantuml-indent-regexp-title-end "^\s*end\s+title\s*\\('.*\\)?$")
|
||||||
|
(defvar plantuml-indent-regexp-header-end "^\s*endheader\s*\\('.*\\)?$")
|
||||||
|
(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-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
|
||||||
|
plantuml-indent-regexp-group-end
|
||||||
|
plantuml-indent-regexp-activate-end
|
||||||
|
plantuml-indent-regexp-box-end
|
||||||
|
plantuml-indent-regexp-ref-end
|
||||||
|
plantuml-indent-regexp-legend-end
|
||||||
|
plantuml-indent-regexp-note-end
|
||||||
|
plantuml-indent-regexp-oldif-end
|
||||||
|
plantuml-indent-regexp-title-end
|
||||||
|
plantuml-indent-regexp-header-end
|
||||||
|
plantuml-indent-regexp-footer-end
|
||||||
|
plantuml-indent-regexp-macro-end
|
||||||
|
plantuml-indent-regexp-oldif-end
|
||||||
|
plantuml-indent-regexp-user-control-end))
|
||||||
|
(setq plantuml-font-lock-keywords
|
||||||
|
`(
|
||||||
|
(,plantuml-types-regexp . font-lock-type-face)
|
||||||
|
(,plantuml-keywords-regexp . font-lock-keyword-face)
|
||||||
|
(,plantuml-builtins-regexp . font-lock-builtin-face)
|
||||||
|
(,plantuml-preprocessors-regexp . font-lock-preprocessor-face)
|
||||||
|
;; note: order matters
|
||||||
|
))
|
||||||
|
|
||||||
(setq plantuml-kwdList (make-hash-table :test 'equal))
|
(setq plantuml-kwdList (make-hash-table :test 'equal))
|
||||||
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-types)
|
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-types)
|
||||||
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-keywords)
|
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-keywords)
|
||||||
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-builtins)
|
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-builtins)
|
||||||
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-preprocessors)
|
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-preprocessors)
|
||||||
(put 'plantuml-kwdList 'risky-local-variable t)
|
(put 'plantuml-kwdList 'risky-local-variable t)
|
||||||
|
|
||||||
;; clear memory
|
;; clear memory
|
||||||
(setq plantuml-types nil)
|
(setq plantuml-types nil)
|
||||||
(setq plantuml-keywords nil)
|
(setq plantuml-keywords nil)
|
||||||
(setq plantuml-builtins nil)
|
(setq plantuml-builtins nil)
|
||||||
(setq plantuml-preprocessors nil)
|
(setq plantuml-preprocessors nil)
|
||||||
(setq plantuml-types-regexp nil)
|
(setq plantuml-types-regexp nil)
|
||||||
(setq plantuml-keywords-regexp nil)
|
(setq plantuml-keywords-regexp nil)
|
||||||
(setq plantuml-builtins-regexp nil)
|
(setq plantuml-builtins-regexp nil)
|
||||||
(setq plantuml-preprocessors-regexp nil)))
|
(setq plantuml-preprocessors-regexp nil))))
|
||||||
|
|
||||||
(defun plantuml-complete-symbol ()
|
(defun plantuml-complete-symbol ()
|
||||||
"Perform keyword completion on word before cursor."
|
"Perform keyword completion on word before cursor."
|
||||||
|
@ -437,13 +673,13 @@ or it is followed by line end.")
|
||||||
(let ((relative-depth 0))
|
(let ((relative-depth 0))
|
||||||
;; current line
|
;; current line
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(if (looking-at plantuml-indent-regexp-end)
|
(if (-any? 'looking-at plantuml-indent-regexp-end)
|
||||||
(setq relative-depth (1- relative-depth)))
|
(setq relative-depth (1- relative-depth)))
|
||||||
|
|
||||||
;; from current line backwards to beginning of buffer
|
;; from current line backwards to beginning of buffer
|
||||||
(while (not (bobp))
|
(while (not (bobp))
|
||||||
(forward-line -1)
|
(forward-line -1)
|
||||||
(if (looking-at plantuml-indent-regexp-end)
|
(if (-any? 'looking-at plantuml-indent-regexp-end)
|
||||||
(setq relative-depth (1- relative-depth)))
|
(setq relative-depth (1- relative-depth)))
|
||||||
(if (-any? 'looking-at plantuml-indent-regexp-start)
|
(if (-any? 'looking-at plantuml-indent-regexp-start)
|
||||||
(setq relative-depth (1+ relative-depth))))
|
(setq relative-depth (1+ relative-depth))))
|
||||||
|
@ -490,8 +726,8 @@ Shortcuts Command Name
|
||||||
(if (and plantuml-suppress-deprecation-warning
|
(if (and plantuml-suppress-deprecation-warning
|
||||||
(featurep 'puml-mode))
|
(featurep 'puml-mode))
|
||||||
(display-warning :warning
|
(display-warning :warning
|
||||||
"`puml-mode' is now deprecated and no longer updated, but it's still present in your system.\
|
"`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. \
|
You should move your configuration to use `plantuml-mode'. \
|
||||||
See more at https://github.com/skuro/puml-mode/issues/26")))
|
See more at https://github.com/skuro/puml-mode/issues/26")))
|
||||||
|
|
||||||
(add-hook 'plantuml-mode-hook 'plantuml-deprecation-warning)
|
(add-hook 'plantuml-mode-hook 'plantuml-deprecation-warning)
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
;;; plantuml-config-test.el --- tests for plantuml-mode configuration knobs -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
;; Author: Carlo Sciolla
|
||||||
|
;; Maintainer: Carlo Sciolla
|
||||||
|
;; URL: https://github.com/skuro/plantuml-mode
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
|
||||||
|
;; Test user-accessible configuration knobs
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(require 'plantuml-mode)
|
||||||
|
|
||||||
|
(ert-deftest plantuml-config-test/set-exec-mode-happy-path ()
|
||||||
|
"Test switching execution modes"
|
||||||
|
(let ((orig-mode plantuml-exec-mode))
|
||||||
|
;; happy flows:
|
||||||
|
(plantuml-set-exec-mode "server")
|
||||||
|
(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)))
|
||||||
|
|
||||||
|
(ert-deftest plantuml-config-test/set-exec-mode-wrong-mode ()
|
||||||
|
"Test setting the exec mode with the wrong text"
|
||||||
|
(should-error (plantuml-set-exec-mode "turing-machine")))
|
||||||
|
|
||||||
|
(provide 'plantuml-mode-config-test)
|
||||||
|
|
||||||
|
;;; plantuml-config-test.el ends here
|
|
@ -16,16 +16,16 @@
|
||||||
"Test correct indentation of a simple note block."
|
"Test correct indentation of a simple note block."
|
||||||
(plantuml-test-indent-block
|
(plantuml-test-indent-block
|
||||||
"
|
"
|
||||||
note: single line note
|
note right: single line note
|
||||||
|
|
||||||
note
|
note right
|
||||||
multi line note
|
multi line note
|
||||||
end note
|
end note
|
||||||
"
|
"
|
||||||
"
|
"
|
||||||
note: single line note
|
note right: single line note
|
||||||
|
|
||||||
note
|
note right
|
||||||
multi line note
|
multi line note
|
||||||
end note
|
end note
|
||||||
"
|
"
|
||||||
|
|
|
@ -10,14 +10,14 @@
|
||||||
|
|
||||||
(ert-deftest custom-jar-location ()
|
(ert-deftest custom-jar-location ()
|
||||||
(setq-local plantuml-jar-path "~/.plantuml/plantuml.jar")
|
(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")
|
,(expand-file-name "~/.plantuml/plantuml.jar")
|
||||||
"-charset" "UTF-8")
|
"-charset" "UTF-8")
|
||||||
(plantuml-render-command)))
|
(plantuml-jar-render-command)))
|
||||||
|
|
||||||
(setq-local plantuml-jar-path "/path/with spaces/plantuml.jar")
|
(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-render-command))))
|
(plantuml-jar-render-command))))
|
||||||
|
|
||||||
(provide 'plantuml-mode-custom-jar-location-test)
|
(provide 'plantuml-mode-custom-jar-location-test)
|
||||||
|
|
||||||
|
|
|
@ -8,16 +8,19 @@
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(defun assert-preview (puml output &optional format)
|
(defun assert-preview (puml output &optional format mode)
|
||||||
(if format
|
(if format
|
||||||
(setq plantuml-output-type format)
|
(setq plantuml-output-type format)
|
||||||
(setq plantuml-output-type "utxt"))
|
(setq plantuml-output-type "txt"))
|
||||||
|
(if mode
|
||||||
|
(setq plantuml-exec-mode mode)
|
||||||
|
(setq plantuml-exec-mode 'jar))
|
||||||
(plantuml-preview-string 42 (read-test-file puml))
|
(plantuml-preview-string 42 (read-test-file puml))
|
||||||
(sleep-for 3)
|
(sleep-for 3)
|
||||||
(should (equal (format-preview-output (replace-regexp-in-string " " "~" (read-test-file output)))
|
(should (equal (format-preview-output (replace-regexp-in-string " " "~" (read-test-file output)))
|
||||||
(format-preview-output (replace-regexp-in-string " " "~" (read-preview-buffer))))))
|
(format-preview-output (replace-regexp-in-string " " "~" (read-preview-buffer))))))
|
||||||
|
|
||||||
(ert-deftest preview-utxt-test ()
|
(ert-deftest preview-txt-test ()
|
||||||
(setq-local plantuml-jar-path plantuml-test-jar-path)
|
(setq-local plantuml-jar-path plantuml-test-jar-path)
|
||||||
(assert-preview "a-b.puml" "a-b.txt"))
|
(assert-preview "a-b.puml" "a-b.txt"))
|
||||||
|
|
||||||
|
|
|
@ -53,15 +53,15 @@ Finally, the indented text in the buffer will be compared with AFTER."
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
;; fix the JAR location prior to mode initialization
|
;; fix the JAR location prior to mode initialization
|
||||||
;; for some reason, plantuml-mode disregards the setq-local
|
;; for some reason, plantuml-mode disregards the setq-local
|
||||||
(setq-local plantuml-jar-path plantuml-test-jar-path)
|
(setq plantuml-jar-path plantuml-test-jar-path)
|
||||||
(plantuml-init-once)
|
(plantuml-init-once 'jar)
|
||||||
|
|
||||||
(insert before)
|
(insert before)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(plantuml-mode)
|
(plantuml-mode)
|
||||||
;; use 2 spaces instead of one tab for indentation
|
;; use 2 spaces instead of one tab for indentation
|
||||||
(setq-local indent-tabs-mode nil)
|
(setq indent-tabs-mode nil)
|
||||||
(setq-local tab-width 2)
|
(setq tab-width 2)
|
||||||
|
|
||||||
(indent-region (point-min) (point-max))
|
(indent-region (point-min) (point-max))
|
||||||
(should (equal (buffer-string) after))))
|
(should (equal (buffer-string) after))))
|
||||||
|
|
Loading…
Reference in New Issue