Create plantUML with emacs using plantuml-mode

投稿日:2017年10月30日 更新日:

Autumn leaves on wood table


Hello everyone it’s me candle.
In this time, we will introduce plantuml-mode of emacs supporting plantUML.
plantuml-mode has three functions.

  1. Syntax highlight
  2. Autocomplete
  3. Display UML preview

There are plenty of settings, so let’s do it patiently.


You had plantuml command
I installed plantuml with brew. but it is ok you prepare jar file.

If you don’t have it yet, please refer to here.
Build PlantUML environment on Mac using brew

Install plantuml-mode

The latest version of plant-mode is not yet registered in el-get packages, so we will get it from github directly.

For Mepla user, please see the official site and install it.

For el-get user, open the ~/.emacs.d/init.el

emacs ~/.emacs.d/init.el

Write this code.

(el-get-bundle plantuml-mode
:type github
:name plantuml-mode
:pkgname "skuro/plantuml-mode"
:branch "master")

Then restart emacs and install the plantum-mode.

Check installation either success or fail.
Run this command on emacs.

M-x plantuml-mode

If command exsist, installation is ok.

Confirm jar file path of plantuml which installed by brew

If you had installed plantuml command by “brew”, you need a bit preparation.
Since plantuml-mode tries to execute a jar file, alias plantuml command can not be used.

You’ll confirm plantuml.jar file path.

First go to the /usr/local/bin

cd /usr/local/bin

And show plantuml alias file with this command.

cat ./plantuml

The path of the jar file is displayed.

This is the path in my case.


Let’s keep to remember this.

Setting for plantuml-mode

Open ~/.emacs.d/init.el and write the below code.
You specify the absolute path of plantuml.jar to plantuml-jar-path.

;; Open the .pu extension file with plantuml-mode
(add-to-list ‘auto-mode-alist ‘("\.pu$" . plantuml-mode))
;; Write your absolute plantuml.jar path
(setq plantuml-jar-path "Here your plant.jar file path")
;; If you want to pass java options, write here.
(setq plantuml-java-options "")
;; Comment in here if you want to preview plantuml as svg, png
;; Display ASCII art by default
;;(setq plantuml-output-type "svg")
;; chart is utf-8
(setq plantuml-options "-charset UTF-8")

Setting is over.

Let’s use it.

Create a folder and create a file.

mkdir test
touch test/new.pu
emacs test/new.pu

Write this.


developer -> emacs: "Draw me a diagram"
emacs -> developer: "Here you are, sir"
developer -> world: "Woooooohooooo"


Type C-c C-c
A preview of plantuml is displayed at ASCII Art.

You can also open a preview with the below key bindings.

C-c C-c plantuml-preview: renders a PlantUML diagram from the current buffer in the best supported format

C-u C-c C-c plantuml-preview in other window

C-u C-u C-c C-c plantuml-preview in other frame

The basic usage is over.

Save png image in plantuml-mode

Although the preview can be displayed from the .pu file in the above method, it can not be saved with png.
When I saw the issue of github, developers are efforting to make it possible to save the image, so the next sentence may be unnecessary soon.

Edit ~/.emacs.d/init.el so that png can be saved.
I refer code from this site, I made it a little customise.

(ja lang)

Open ~/.emacs.d/init.el and write this.

;; Execute plantuml-save-png function with C-c C-s at plantuml-mode
(add-hook ‘plantuml-mode-hook
(lambda () (local-set-key (kbd "C-c C-s") ‘plantuml-save-png)))

;; If you want to save png file when saving .pu file, comment in here
;; (add-hook ‘plantuml-mode-hook
;; (lambda () (add-hook ‘after-save-hook ‘plantuml-save-png)))

;; Function to save plantuml as png
(defun plantuml-save-png ()
(when (buffer-modified-p)
(map-y-or-n-p "Save this buffer before executing PlantUML?"
‘save-buffer (list (current-buffer))))
(let ((code (buffer-string))
(when (string-match "^\\s-*@startuml\\s-+\\(\\S-+\\)\\s*$" code)
(setq out-file (match-string 1 code)))
(setq cmd (concat
"java -Djava.awt.headless=true -jar " plantuml-java-options " "
(shell-quote-argument plantuml-jar-path) " "
(and out-file (concat "-t" (file-name-extension out-file))) " "
plantuml-options " "
(message cmd)
(call-process-shell-command cmd nil 0)))

Save it.
Let’s reopen the new.pu and execute C-c C-s

The new.png is created in the same place, let’s open it.

It seems good!


Plantuml is now available in emacs.


If you think this article is good, share it please

-, ,



Your email address will not be published. Required fields are marked *


React Native slows down when debugging on Google Chrome

English 日本語 Abstract Hello everybody, It’s candle. This time, we will solve the problem that using simulator is going to slow down when debugging on the Google Chrome Anyway, It is solved in a simple way. we use Chromium instead of Google Chrome. Premise React development environment has been established

Ruby regex that does not match if there are keywords that you don’t want included in the string

Abstract Hello everyone it’s me candle. In this time I would like to create a regular expression that does not pass if keywords that I do not want included in the string match. This is such case like this. For example, the regex matches these words “Bitcoin” and “Bitcoin ~” but doesn’t match “BitcoinCash” and “Bitcoin Cash”. ○ Bitcoin ○ Bitcoin Core × BitcoinCash × Bitcoin Cash Condition Nothing Write the regex This is a regex that does not match if there are keywords that you do not want included in the string. /Keyword to include(?!Keywords you do not want …

How to change the language form “en-US” to “en” by wordpres bogo

English 日本語 Abstract Hello everyone, It’s me candle. In this time, I will show you to customize bogo plugins. The bogo is wonderful plugin which can adapt the wordpress site to many languages as a simple. but, there is a problem that you can’t choose general English. When writing English articles, you may not always have to write it limited to country. However, you can choose ‘en-UK’, ‘en-CA’ and ‘en-US’, but ‘en’ can not be chosen in bogo. I checked the source code. The bogo got a language list from wordpress function, and there is no general English in it. …

Tutorial to create a modal using react-modal

Abstract Hello everyone it’s me candle. In this time, let’s create a modal with react-modal. React-modal is a library which can create and handle a modal easily. But However, react-modal is not easy if you try to actually use it. it is necessary to incorporate state management, action, design etc. In this article, I will explain it like a tutorial and we will make a modal together. Condition You have a react knowledge. You installed create-react-app. Set up development env If you already have a some react project, you would use it. Otherwise, you don’t have a any project, please …

Lazy load image with react-lazyload

Abstract Hello everyoen it’s me candle. This time let’s make a delayed loading of images with react-lazyload. The problem of SPA is the delay at the time of initial loading. Among them, we feel that the site with many images is even late. Let’s try it. Condition Nothing Prepare If you have already developing react project, use it. But you don’t have yet or try to test. Generate it with this command. create-react-app imageloader-sample cd imageloader-sample We will prepare images for samples with Faker.js, so install it. yarn add faker Ready to develop. Make a sample code Open the src/App.js …

I work in the venture company as a CTO. I start to write program in University, first I learned java, C++ and PHP. In the company, I'm developing web services by Rails. I do like to automation.