update packages

This commit is contained in:
2025-07-05 20:36:47 +02:00
parent 4a4f30e3b1
commit 65dedd3df8
60 changed files with 15454 additions and 342 deletions

View File

@@ -1,9 +1,10 @@
;; -*- no-byte-compile: t; lexical-binding: nil -*-
(define-package "plantuml-mode" "20250613.1438"
(define-package "plantuml-mode" "20250705.1148"
"Major mode for PlantUML."
'((dash "2.0.0")
(emacs "25.0"))
'((dash "2.0.0")
(emacs "25.1")
(deflate "0.0.3"))
:url "https://github.com/skuro/plantuml-mode"
:commit "dc0f497a67ee9b3d2e437e16023011780d0e8b05"
:revdesc "dc0f497a67ee"
:keywords '("uml" "plantuml" "ascii"))
:commit "0a19d9988879c57b176dd4c03f59003644f9c9b0"
:revdesc "0a19d9988879"
:keywords '("files" "text" "processes" "tools"))

View File

@@ -5,10 +5,11 @@
;; Compatibility: Tested with Emacs 25 through 27 (current master)
;; Author: Zhang Weize (zwz)
;; Maintainer: Carlo Sciolla (skuro)
;; Keywords: uml plantuml ascii
;; Package-Version: 20250613.1438
;; Package-Revision: dc0f497a67ee
;; Package-Requires: ((dash "2.0.0") (emacs "25.0"))
;; Keywords: files text processes tools
;; Package-Version: 20250705.1148
;; Package-Revision: 0a19d9988879
;; Package-Requires: ((dash "2.0.0") (emacs "25.1") (deflate "0.0.3"))
;; Homepage: https://github.com/skuro/plantuml-mode
;; 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
@@ -37,6 +38,8 @@
;;; Change log:
;;
;; version 1.8.0, 2025-07-04 Support for `'hex' and `'deflate' modes for server URL encoding
;; version 1.7.0, 2025-05-24 Support for `completion-at-point'
;; version 1.6.0, 2025-05-15 Fix server exec mode; various indentation enhancements and bug fixes; better preview buffer management
;; version 1.5.0, 2025-05-14 Fixed warnings with new Java versions #157; updated versions to let CI work again
;; version 1.4.1, 2019-09-03 Better indentation; more bugfixing; actually adding `executable' mode
@@ -74,11 +77,13 @@
;; version 0.1, 2010-08-25 [from puml-mode] First version
;;; Code:
(require 'thingatpt)
(require 'cl-lib)
(require 'dash)
(require 'deflate)
(require 'thingatpt)
(require 'xml)
(defgroup plantuml-mode nil "Major mode for editing plantuml file."
(defgroup plantuml nil "Major mode for editing plantuml file."
:group 'languages)
(defcustom plantuml-jar-path
@@ -134,7 +139,15 @@
(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'"
- `jar': run PlantUML as a JAR file
- `server': contact the PlantUML server at `plantuml-server-url'
- `executable' run the PlantUML executable at `plantuml-executable-path'
The `jar' exec mode requires a local install of the PlantUML JAR file,
see `plantuml-jar-path'.
The `executable' exec mode requires a local install of the PlantUML JAR file,
see `plantuml-executable-path'."
:type 'symbol
:group 'plantuml
:options '(jar server executable))
@@ -145,14 +158,33 @@
:group 'plantuml)
(defcustom plantuml-indent-level 8
"Indentation level of PlantUML lines"
"Indentation level of PlantUML lines."
:type 'natnum
:group 'plantuml)
(defcustom plantuml-preview-default-theme nil
"Sets the default theme to use when rendering diagrams.
Works only if `!theme' does not appear in the diagram to be displayed."
:type 'string
:group 'plantuml
:safe #'stringp)
(defcustom plantuml-server-encode-mode 'deflate
"Whether to encode the server URL using HEX or DEFLATE."
:type 'symbol
:group 'plantuml
:options '(deflate hex))
(defcustom plantuml-svg-background nil
"The color SVG rendering will use as background.
Useful when the default transparent color makes the diagram hard to see."
:type 'string
:group 'plantuml)
(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))
(cmd (mapconcat 'identity cmd-list "|")))
(cmd (mapconcat #'identity cmd-list "|")))
(plantuml-debug (format "Command is [%s]" cmd))
cmd-list))
@@ -179,7 +211,8 @@
;; PlantUML execution mode
(defvar-local plantuml-exec-mode nil
"The Plantuml execution mode override. See `plantuml-default-exec-mode' for acceptable values.")
"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."
@@ -212,7 +245,7 @@
(setq plantuml-mode-debug-enabled nil))
(defun plantuml-debug (msg)
"Writes msg (as MSG) into the *PLANTUML Messages* buffer without annoying the user."
"Writes MSG into the *PLANTUML Messages* buffer without annoying the user."
(if plantuml-mode-debug-enabled
(let* ((log-buffer-name "*PLANTUML Messages*")
(log-buffer (get-buffer-create log-buffer-name)))
@@ -248,7 +281,8 @@
(message "Aborted.")))
(defun plantuml-jar-java-version ()
"Inspects the Java runtime version of the configured Java command in `plantuml-java-command'."
"Inspects the Java runtime version of the configured Java command.
The actual command is taken from in `plantuml-java-command'."
(save-excursion
(save-match-data
(with-temp-buffer
@@ -257,30 +291,34 @@
(string-to-number (match-string 2))))))
(defun plantuml-jar-get-language (buf)
"Retrieve the language specification from the PlantUML JAR file and paste it into BUF."
"Retrieve the language specification from the PlantUML JAR file.
The language spec is pasted into the buffer BUF."
(unless (or (eq system-type 'cygwin) (file-exists-p plantuml-jar-path))
(error "Could not find plantuml.jar at %s" plantuml-jar-path))
(with-current-buffer buf
(let ((cmd-args (append (list plantuml-java-command nil t nil)
(plantuml-jar-render-command "-language"))))
(apply 'call-process cmd-args)
(apply #'call-process cmd-args)
(goto-char (point-min)))))
(defun plantuml-server-get-language (buf)
"Retrieve the language specification from the PlantUML server and paste it into BUF."
"Retrieve the language specification from the PlantUML server.
The language spec is pasted into the buffer 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."
"Retrieve the language specification from the PlantUML executable.
The language spec is pasted into the buffer BUF."
(with-current-buffer buf
(let ((cmd-args (append (list plantuml-executable-path nil t nil) (list "-language"))))
(apply 'call-process cmd-args)
(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."
"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)
@@ -290,7 +328,8 @@
(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."
"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))
@@ -353,7 +392,7 @@
plantuml-output-type)))
(defun plantuml-set-output-type (type)
"Set the desired output type (as TYPE) for the current buffer.
"Set the desired output TYPE for the current buffer.
If the
major mode of the current buffer mode is not plantuml-mode, set the
default output type for new buffers."
@@ -361,7 +400,7 @@ default output type for new buffers."
(setq plantuml-output-type type))
(defun plantuml-is-image-output-p ()
"Return non-nil if the diagram output format is an image, false if it's text based."
"Return t if `plantuml-output-type' denotes an image, nil if it's text based."
(not (equal "txt" plantuml-output-type)))
(defun plantuml-jar-output-type-opt (output-type)
@@ -372,7 +411,7 @@ Note that output type `txt' is promoted to `utxt' for better rendering."
(_ output-type))))
(defun plantuml-jar-start-process (buf)
"Run PlantUML as an Emacs process and puts the output into the given buffer (as BUF)."
"Run the PlantUML JAR and puts the output into the given buffer BUF."
(let ((java-args (if (<= 8 (plantuml-jar-java-version))
(remove "--illegal-access=deny" plantuml-java-args)
plantuml-java-args)))
@@ -385,7 +424,7 @@ Note that output type `txt' is promoted to `utxt' for better rendering."
"-p"))))
(defun plantuml-executable-start-process (buf)
"Run PlantUML as an Emacs process and puts the output into the given buffer (as BUF)."
"Run the PlantUML executable and puts the output into the given buffer BUF."
(apply #'start-process
"PLANTUML" buf plantuml-executable-path
`(,@plantuml-executable-args
@@ -399,7 +438,10 @@ Window is selected according to PREFIX:
- 16 (when prefixing the command with C-u C-u) -> new frame.
- else -> new buffer"
(let ((imagep (and (display-images-p)
(plantuml-is-image-output-p))))
(plantuml-is-image-output-p)))
;; capture the output type before switching context to `buf'
;; as `plantuml-output-type' can be local
(output-type plantuml-output-type))
(cond
((= prefix 16) (switch-to-buffer-other-frame buf))
((= prefix 4) (switch-to-buffer-other-window buf))
@@ -407,7 +449,12 @@ Window is selected according to PREFIX:
(when imagep
(with-current-buffer buf
(image-mode)
(set-buffer-multibyte t)))
(set-buffer-multibyte t)
(when (and (equal "svg" output-type))
(let ((inhibit-read-only t)
(svg-data (buffer-string)))
(erase-buffer)
(insert-image (create-image svg-data 'svg t :background plantuml-svg-background))))))
(set-window-point (get-buffer-window buf 'visible) (point-min))))
(defun plantuml-jar-preview-string (prefix string buf)
@@ -426,14 +473,40 @@ Put the result into buffer BUF. Window is selected according to PREFIX:
(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."
(defun plantuml-server-hex-encode-url (string)
"HEX-encode STRING into a URL suitable for PlantUML server interactions."
(let* ((coding-system (or buffer-file-coding-system
"utf8"))
'utf-8))
(str (encode-coding-string string coding-system))
(encoded-string (mapconcat (lambda(x)(format "%02X" x)) str)))
(concat plantuml-server-url "/" plantuml-output-type "/~h" encoded-string)))
(defconst plantuml-server-base64-char-table
(let ((translation-table (make-char-table 'translation-table))
(base64-chars "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=")
(plantuml-chars "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_="))
(dotimes (i (length base64-chars))
(aset translation-table
(aref base64-chars i)
(aref plantuml-chars i)))
translation-table))
(defun plantuml-server-deflate-encode-url (string)
"DEFLATE-encode STRING into a URL suitable for PlantUML server interactions."
(let* ((compressed-bytes (deflate-zlib-compress string 'dynamic))
(base64-encoded (base64-encode-string (apply #'unibyte-string compressed-bytes))))
(with-temp-buffer
(insert base64-encoded)
(translate-region (point-min) (point-max) plantuml-server-base64-char-table)
(concat plantuml-server-url "/" plantuml-output-type "/~1" (buffer-string)))))
(defun plantuml-server-encode-url (string)
"Encode STRING into a URL suitable for PlantUML server interactions."
(let ((encode-mode (or plantuml-server-encode-mode 'deflate)))
(cl-case encode-mode
(deflate (plantuml-server-deflate-encode-url string))
(hex (plantuml-server-hex-encode-url 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:
@@ -441,18 +514,18 @@ Put the result into buffer BUF and place it according to PREFIX:
- 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)))))))
(let* ((response-buf (url-retrieve-synchronously url-request-location)))
(save-current-buffer
(save-match-data
(with-current-buffer response-buf
(set-buffer-multibyte t)
(decode-coding-region (point-min) (point-max) 'utf-8)
(goto-char (point-min))
(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.
@@ -484,9 +557,24 @@ Put the result into buffer BUF, selecting the window according to PREFIX:
(funcall preview-fn prefix string buf)
(error "Unsupported execution mode %s" mode))))
(defun plantuml-themed-p (string)
"Return non-nil if STRING is a PlantUML source with explicit theme directive."
;; check for beginning of line with word boundary
(string-match-p "^\\s-*!theme\\b" string))
(defun plantuml-set-theme (string theme)
"Add the THEME to the diagram STRING."
(replace-regexp-in-string "^@startuml"
(concat "@startuml\n!theme " theme)
string))
(defun plantuml-preview-string (prefix string)
"Preview diagram from PlantUML sources (as STRING), using prefix (as PREFIX)
to choose where to display it."
to choose where to display it.
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"
(when-let ((b (get-buffer plantuml-preview-buffer))
(inhibit-read-only t))
(with-current-buffer b
@@ -496,8 +584,19 @@ to choose where to display it."
(plantuml-is-image-output-p)))
(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-get-exec-mode) string buf)))
(coding-system-for-write (and imagep 'binary))
(themed (plantuml-themed-p string)))
(if (and (not (plantuml-themed-p string))
plantuml-preview-default-theme)
;; override the theme
(plantuml-exec-mode-preview-string prefix
(plantuml-get-exec-mode)
(plantuml-set-theme string plantuml-preview-default-theme)
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.
@@ -546,8 +645,20 @@ Uses prefix (as PREFIX) to choose where to display it:
(plantuml-preview-region prefix (region-beginning) (region-end))
(plantuml-preview-buffer prefix)))
(defun plantuml-deprecation-warning ()
"Warns the user about the deprecation of the `puml-mode' project."
(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 more at https://github.com/skuro/puml-mode/issues/26")))
(defun plantuml-init-once (&optional mode)
"Ensure initialization only happens once. Use exec mode MODE to load the language details or by first querying `plantuml-get-exec-mode'."
"Ensure initialization only happens once.
Use exec mode MODE to load the language details
or by first querying `plantuml-get-exec-mode'."
(plantuml-deprecation-warning)
(let ((mode (or mode (plantuml-get-exec-mode))))
(unless plantuml-kwdList
(plantuml-init mode)
@@ -582,7 +693,7 @@ The opening { has to be the last visible character in the line (whitespace
might follow).")
(defvar plantuml-indent-regexp-note-start "^\s*\\(floating\s+\\)?[hr]?note\s+\\(right\\|left\\|top\\|bottom\\|over\\|as\\)[^:]*\\(\\:\\:[^:]+\\)?$" "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+.+\\|$\\)"
"Indentation regex for plantuml group elements that are defined for sequence diagrams.
"Indentation regex for plantuml group elements defined for sequence diagrams.
Two variants for groups: keyword is either followed by whitespace and some text
or it is followed by line end.")
(defvar plantuml-indent-regexp-activate-start "^\s*activate\s+.+$")
@@ -592,7 +703,8 @@ or it is followed by line end.")
(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\\)\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-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*$")
@@ -699,12 +811,27 @@ or it is followed by line end.")
(all-completions meat plantuml-kwdList)))
(message "Making completion list...%s" "done")))))
(make-obsolete 'plantuml-complete-symbol
"Use `completion-at-point' (C-M-i) instead"
"1.7.0")
(defun plantuml-completion-at-point-function ()
"Complete symbol at point using `plantuml-kwdList'.
See `completion-at-point-functions'."
(let ((thing-start (beginning-of-thing 'symbol))
(thing-end (end-of-thing 'symbol)))
(list thing-start
thing-end
plantuml-kwdList
'(:exclusive no))))
;; indentation
(defun plantuml-current-block-depth ()
"Trace the current block indentation level by recursively looking back line by line."
"Trace the current block indentation level by looking back line by line."
(save-excursion
(let ((relative-depth 0))
;; current line
@@ -757,18 +884,9 @@ Shortcuts Command Name
(set (make-local-variable 'comment-multi-line) t)
(set (make-local-variable 'comment-style) 'extra-line)
(set (make-local-variable 'indent-line-function) 'plantuml-indent-line)
(setq font-lock-defaults '((plantuml-font-lock-keywords) nil t)))
(defun plantuml-deprecation-warning ()
"Warns the user about the deprecation of the `puml-mode' project."
(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 more at https://github.com/skuro/puml-mode/issues/26")))
(add-hook 'plantuml-mode-hook 'plantuml-deprecation-warning)
(make-local-variable 'plantuml-preview-default-theme)
(setq font-lock-defaults '((plantuml-font-lock-keywords) nil t))
(setq-local completion-at-point-functions (list #'plantuml-complete-symbol)))
(provide 'plantuml-mode)
;;; plantuml-mode.el ends here