Merge b4b8d082b4
into 06725c7ce7
This commit is contained in:
commit
e37cb965ee
|
@ -3,6 +3,7 @@ sudo: false
|
||||||
env:
|
env:
|
||||||
- EVM_EMACS=emacs-25.1-travis
|
- EVM_EMACS=emacs-25.1-travis
|
||||||
before_install:
|
before_install:
|
||||||
|
- unset _JAVA_OPTIONS
|
||||||
- curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw > x.sh && source ./x.sh
|
- curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw > x.sh && source ./x.sh
|
||||||
- evm install $EVM_EMACS --use --skip
|
- evm install $EVM_EMACS --use --skip
|
||||||
- cask
|
- cask
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import zlib
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# see https://github.com/dougn/python-plantuml
|
||||||
|
|
||||||
|
def encode(data):
|
||||||
|
"""encode the plantuml data which may be compresses in the proper
|
||||||
|
encoding for the plantuml server
|
||||||
|
"""
|
||||||
|
res = ""
|
||||||
|
for i in xrange(0,len(data), 3):
|
||||||
|
if (i+2==len(data)):
|
||||||
|
res += _encode3bytes(ord(data[i]), ord(data[i+1]), 0)
|
||||||
|
elif (i+1==len(data)):
|
||||||
|
res += _encode3bytes(ord(data[i]), 0, 0)
|
||||||
|
else:
|
||||||
|
res += _encode3bytes(ord(data[i]), ord(data[i+1]), ord(data[i+2]))
|
||||||
|
return res
|
||||||
|
|
||||||
|
def _encode3bytes(b1, b2, b3):
|
||||||
|
c1 = b1 >> 2;
|
||||||
|
c2 = ((b1 & 0x3) << 4) | (b2 >> 4);
|
||||||
|
c3 = ((b2 & 0xF) << 2) | (b3 >> 6);
|
||||||
|
c4 = b3 & 0x3F;
|
||||||
|
res = "";
|
||||||
|
res += _encode6bit(c1 & 0x3F);
|
||||||
|
res += _encode6bit(c2 & 0x3F);
|
||||||
|
res += _encode6bit(c3 & 0x3F);
|
||||||
|
res += _encode6bit(c4 & 0x3F);
|
||||||
|
return res;
|
||||||
|
|
||||||
|
def _encode6bit(b):
|
||||||
|
if b < 10:
|
||||||
|
return chr(48 + b)
|
||||||
|
b -= 10
|
||||||
|
if b < 26:
|
||||||
|
return chr(65 + b)
|
||||||
|
b -= 26
|
||||||
|
if b < 26:
|
||||||
|
return chr(97 + b);
|
||||||
|
b -= 26
|
||||||
|
if b == 0:
|
||||||
|
return '-'
|
||||||
|
if b == 1:
|
||||||
|
return '_'
|
||||||
|
return '?'
|
||||||
|
|
||||||
|
zlibbed_str = zlib.compress(sys.stdin.read())
|
||||||
|
compressed_string = zlibbed_str[2:-4]
|
||||||
|
sys.stdout.write(encode(compressed_string))
|
|
@ -87,6 +87,18 @@
|
||||||
(defcustom plantuml-java-command "java"
|
(defcustom plantuml-java-command "java"
|
||||||
"The java command used to execute PlantUML.")
|
"The java command used to execute PlantUML.")
|
||||||
|
|
||||||
|
(defcustom plantuml-server-url "http://www.plantuml.com/plantuml/"
|
||||||
|
"The PlantUML Server URL. Trailing slash is required.
|
||||||
|
|
||||||
|
Default server uses plain HTTP, so be careful not to send sensitive data."
|
||||||
|
:type '(string))
|
||||||
|
|
||||||
|
(defcustom plantuml-use-server nil
|
||||||
|
"Whether to use a PlantUML Server as a backend.
|
||||||
|
|
||||||
|
The feature requires Python."
|
||||||
|
:type '(boolean))
|
||||||
|
|
||||||
(eval-and-compile
|
(eval-and-compile
|
||||||
(defcustom plantuml-java-args '("-Djava.awt.headless=true" "-jar")
|
(defcustom plantuml-java-args '("-Djava.awt.headless=true" "-jar")
|
||||||
"The parameters passed to `plantuml-java-command' when executing PlantUML."))
|
"The parameters passed to `plantuml-java-command' when executing PlantUML."))
|
||||||
|
@ -244,14 +256,14 @@ 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)
|
(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)))
|
||||||
|
(if plantuml-use-server
|
||||||
|
(plantuml--preview-string-with-server prefix string imagep)
|
||||||
(let ((ps (plantuml-start-process buf)))
|
(let ((ps (plantuml-start-process buf)))
|
||||||
(process-send-string ps string)
|
(process-send-string ps string)
|
||||||
(process-send-eof ps)
|
(process-send-eof ps)
|
||||||
|
@ -259,6 +271,35 @@ to choose where to display it:
|
||||||
(lambda (_ps event)
|
(lambda (_ps event)
|
||||||
(unless (equal event "finished\n")
|
(unless (equal event "finished\n")
|
||||||
(error "PLANTUML Preview failed: %s" event))
|
(error "PLANTUML Preview failed: %s" event))
|
||||||
|
(plantuml--switch-to-preview-buffer prefix imagep)))))))
|
||||||
|
|
||||||
|
(defun plantuml--preview-string-with-server (prefix string imagep)
|
||||||
|
(let ((default-directory (file-name-directory (locate-library "plantuml-mode")))
|
||||||
|
(buffer (generate-new-buffer " *PlantUML Compress*")))
|
||||||
|
(let ((process (start-process "PLANTUML COMPRESS" buffer "python" "plantuml-compress.py")))
|
||||||
|
(set-process-sentinel process (lambda (ps _)
|
||||||
|
(plantuml--string-compress-handler ps prefix imagep)))
|
||||||
|
(process-send-string process (format "%s\n" string))
|
||||||
|
(process-send-eof process))))
|
||||||
|
|
||||||
|
(defun plantuml--string-compress-handler (process prefix imagep)
|
||||||
|
(let ((exit-status (process-exit-status process)))
|
||||||
|
(unless (= 0 exit-status)
|
||||||
|
(error "PLANTUML Preview failed: compression failed with %d" exit-status))
|
||||||
|
(with-current-buffer (process-buffer process)
|
||||||
|
(url-retrieve (format "%s%s/%s" plantuml-server-url plantuml-output-type (buffer-string))
|
||||||
|
(lambda (&rest _ignore)
|
||||||
|
(delete-region (point-min)
|
||||||
|
(search-forward "\n\n"))
|
||||||
|
(image-mode)
|
||||||
|
(let ((result (buffer-string)))
|
||||||
|
(with-current-buffer plantuml-preview-buffer
|
||||||
|
(erase-buffer)
|
||||||
|
(insert result)
|
||||||
|
(setq buffer-read-only t)))
|
||||||
|
(plantuml--switch-to-preview-buffer prefix imagep))))))
|
||||||
|
|
||||||
|
(defun plantuml--switch-to-preview-buffer (prefix imagep)
|
||||||
(cond
|
(cond
|
||||||
((= prefix 16)
|
((= prefix 16)
|
||||||
(switch-to-buffer-other-frame plantuml-preview-buffer))
|
(switch-to-buffer-other-frame plantuml-preview-buffer))
|
||||||
|
@ -267,7 +308,7 @@ to choose where to display it:
|
||||||
(t (switch-to-buffer plantuml-preview-buffer)))
|
(t (switch-to-buffer plantuml-preview-buffer)))
|
||||||
(when imagep
|
(when imagep
|
||||||
(image-mode)
|
(image-mode)
|
||||||
(set-buffer-multibyte t)))))))
|
(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.
|
||||||
|
|
Loading…
Reference in New Issue