update plantuml-mode

As plantuml.jar has added a new option “-language” which shows the keywords/builtins used in plantuml, the new plantuml-mode tries to take advantage of this feature. Here it is

;; plantuml-mode.el -- Major mode for plantuml

;; Author: Zhang Weize (zwz)
;; Keywords: uml ascii

;; You can redistribute this program and/or modify it under the terms
;; of the GNU General Public License as published by the Free Software
;; Foundation; either version 2, or (at your option) any later
;; version.

;;; DESCRIPTION

;; A major mode for plantuml, see: http://plantuml.sourceforge.net/
;; Plantuml is an open-source tool in java that allows to quickly write :
;;     - sequence diagram,
;;     - use case diagram,
;;     - class diagram,
;;     - activity diagram,
;;     - component diagram,
;;     - state diagram
;;     - object diagram
;; using a simple and intuitive language.

;;; HISTORY
;; version 0.2, 2010-09-20 Initialize the keywords from the -language output of plantuml.jar instead of the hard-coded way.
;; version 0.1, 2010-08-25 First version


(require 'thingatpt)

(defgroup plantuml-mode nil
  "Major mode for editing plantuml file."
  :group 'languages)

(defvar plantuml-jar-path (expand-file-name "~/plantuml.jar"))

(defvar plantuml-mode-hook nil "Standard hook for plantuml-mode.")

(defvar plantuml-mode-version nil "plantuml-mode version string.")

(defvar plantuml-mode-map nil "Keymap for plantuml-mode")

;;; syntax table
(defvar plantuml-mode-syntax-table
  (let ((synTable (make-syntax-table)))
    (modify-syntax-entry ?' "< b" synTable)
    (modify-syntax-entry ?\n "> b" synTable)
    (modify-syntax-entry ?! "w" synTable)
    (modify-syntax-entry ?@ "w" synTable)
    (modify-syntax-entry ?# "'" synTable)
    synTable)
  "Syntax table for `plantuml-mode'.")

(defvar plantuml-types nil)
(defvar plantuml-keywords nil)
(defvar plantuml-preprocessors nil)
(defvar plantuml-builtins nil)

;; keyword completion
(defvar plantuml-kwdList nil "plantuml keywords.")

;;; font-lock

(defun plantuml-init ()
  "Initialize the keywords or builtins from the cmdline language output"
  (unless (file-exists-p plantuml-jar-path)
    (error "Could not find plantuml.jar at %s" plantuml-jar-path))
  (with-temp-buffer
    (shell-command (concat "java -jar "
                           (shell-quote-argument plantuml-jar-path)
                           " -language") (current-buffer))
    (goto-char (point-min))
    (let ((found (search-forward ";" nil nil))
          (word "")
          (count 0)
          (pos 0))
      (while found
        (forward-char)
        (setq word (current-word))
        (if (string= word "EOF") (setq found nil)
            ;; else
            (forward-line)
            (setq count (string-to-number (current-word)))
            (beginning-of-line 2)
            (setq pos (point))
            (forward-line count)
            (cond ((string= word "type")
                   (setq plantuml-types
                     (split-string
                      (buffer-substring-no-properties pos (point)))))
                  ((string= word "keyword")
                   (setq plantuml-keywords
                     (split-string
                      (buffer-substring-no-properties pos (point)))))
                  ((string= word "preprocessor")
                   (setq plantuml-preprocessors
                     (split-string
                      (buffer-substring-no-properties pos (point)))))
                  (t (setq plantuml-builtins
                           (append
                            plantuml-builtins
                            (split-string
                             (buffer-substring-no-properties pos (point)))))))
;;                  ((string= word "skinparameter")
;;                  ((string= word "color")))
            (setq found (search-forward ";" nil nil)))))))

(unless plantuml-kwdList
  (plantuml-init)
  (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-keywords-regexp (concat "^\\s *" (regexp-opt plantuml-keywords 'words)  "\\|\\(<\\|<|\\|\\*\\|o\\)\\(\\.+\\|-+\\)\\|\\(\\.+\\|-+\\)\\(>\\||>\\|\\*\\|o\\)\\|\\.\\{2,\\}\\|-\\{2,\\}"))
  (defvar plantuml-builtins-regexp (regexp-opt plantuml-builtins 'words))
  (defvar plantuml-preprocessors-regexp (concat "^\\s *" (regexp-opt plantuml-preprocessors 'words)))

  (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))
  (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-builtins)
  (mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-preprocessors)
  (put 'plantuml-kwdList 'risky-local-variable t)

  ;; clear memory
  (setq plantuml-types nil)
  (setq plantuml-keywords nil)
  (setq plantuml-builtins nil)
  (setq plantuml-preprocessors nil)
  (setq plantuml-types-regexp nil)
  (setq plantuml-keywords-regexp nil)
  (setq plantuml-builtins-regexp nil)
  (setq plantuml-preprocessors-regexp nil))

(defun plantuml-complete-symbol ()
  "Perform keyword completion on word before cursor."
  (interactive)
  (let ((posEnd (point))
        (meat (thing-at-point 'symbol))
        maxMatchResult)

    (when (not meat) (setq meat ""))

    (setq maxMatchResult (try-completion meat plantuml-kwdList))
    (cond ((eq maxMatchResult t))
          ((null maxMatchResult)
           (message "Can't find completion for \"%s\"" meat)
           (ding))
          ((not (string= meat maxMatchResult))
           (delete-region (- posEnd (length meat)) posEnd)
           (insert maxMatchResult))
          (t (message "Making completion list...")
             (with-output-to-temp-buffer "*Completions*"
               (display-completion-list
                (all-completions meat plantuml-kwdList)
                meat))
             (message "Making completion list...%s" "done")))))

(add-to-list 'auto-mode-alist '("\\.plu$" . plantuml-mode))

;;;###autoload
(defun plantuml-mode ()
  "Major mode for plantuml.

Shortcuts             Command Name
\\[plantuml-complete-symbol]      `plantuml-complete-symbol'"

  (interactive)
  (kill-all-local-variables)

;;  (python-mode) ; for indentation
  (setq major-mode 'plantuml-mode
        mode-name "plantuml")
  (set-syntax-table plantuml-mode-syntax-table)
  (use-local-map plantuml-mode-map)

  (make-local-variable 'font-lock-defaults)
  (setq font-lock-defaults '((plantuml-font-lock-keywords) nil t))

  (run-mode-hooks 'plantuml-mode-hook))

(provide 'plantuml-mode)

Posted in Uncategorized | Tagged , , , , , , , , , , , | 4 Comments

A new version of ob-plantuml

Great news: ob-plantuml has been accepted as a part of org-babel in its git repository.

Here is the new version of it:

;;; ob-plantuml.el --- org-babel functions for plantuml evaluation

;; Author: Zhang Weize

;;; Commentary:

;; Org-Babel support for evaluating plantuml script.
;;
;; Inspired by Ian Yang's org-export-blocks-format-plantuml
;; http://www.emacswiki.org/emacs/org-export-blocks-format-plantuml.el

;;; Code:
(require 'ob)

(defvar org-babel-default-header-args:plantuml
  '((:results . "file") (:exports . "results"))
  "Default arguments for evaluating a plantuml source block.")

(defun org-babel-expand-body:plantuml (body params &optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body." body)

(defvar org-plantuml-jar-path)
(defun org-babel-execute:plantuml (body params)
  "Execute a block of plantuml code with org-babel.
This function is called by `org-babel-execute-src-block'."
  (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
        (out-file (cdr (assoc :file params)))
        (cmdline (cdr (assoc :cmdline params)))
        (in-file (make-temp-file "org-babel-plantuml")))
    (unless (file-exists-p org-plantuml-jar-path)
      (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
    (with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
    (message (concat "java -jar " org-plantuml-jar-path
                     " -p " cmdline " < " in-file " > " out-file))
    (shell-command (concat "java -jar " (shell-quote-argument org-plantuml-jar-path)
                           " -p " cmdline " < " in-file " > " out-file))
    ; The method below will produce error when exporting the buffer.
    ;; (with-temp-buffer
    ;;   (call-process-shell-command
    ;;    (concat "java -jar " org-plantuml-jar-path " -p " cmdline)
    ;;    in-file
    ;;    '(t nil))
    ;;   (write-region nil nil out-file))
    out-file))

(defun org-babel-prep-session:plantuml (session params)
  "Return an error because plantuml does not support sessions."
  (error "Plantuml does not support sessions"))

(provide 'ob-plantuml)

;;; ob-plantuml.el ends here
Posted in emacs | Tagged , , | 3 Comments

Creating uml images by using plantuml and org-babel in emacs

I came across Ian Yang’s org-export-blocks-format-plantuml a few days ago, which brought me in front of the great software Plantuml. It is an open-source tool in java that allows to quickly write:

  • sequence diagram,
  • use case diagram,
  • class diagram,
  • activity diagram,
  • component diagram,
  • state diagram
  • object diagram

using a simple and intuitive language.

Although Ian Yang’s code has incorporated plantuml in org-mode by #+BEGIN_UML and #+END_UML, I think it should be a good idea to introduce the plantuml as a new language into org-babel.

Here is the "ob-plantuml.el":

;;; ob-plantuml.el --- org-babel functions for plantuml evaluation

;; Author: Zhang Weize
;; Homepage: http://orgmode.org

;;; Commentary:

;; Org-Babel support for evaluating plantuml.
;;

;; Some code in ob-plantuml was adopted from
;; Ian Yang's org-export-blocks-format-plantuml
;; http://www.emacswiki.org/emacs/org-export-blocks-format-plantuml.el

;;; Code:
(require 'ob)

(defvar org-babel-default-header-args:plantuml
  '((:results . "file") (:exports . "results"))
  "Default arguments for evaluating a plantuml source block.")

(defun org-babel-expand-body:plantuml (body params &optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body." body)

(defvar org-plantuml-jar-path)
(defun org-babel-execute:plantuml (body params)
  "Execute a block of plantuml code with org-babel.
This function is called by `org-babel-execute-src-block'."
  (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
        (out-file (cdr (assoc :file params)))
        (cmdline (cdr (assoc :cmdline params)))
        (in-file (make-temp-file "org-babel-plantuml")))
    (unless (file-exists-p org-plantuml-jar-path)
      (error "Could not find plantuml.jar at %s" org-plantuml-jar-path))
    (with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml")))
    (message (concat "java -jar " org-plantuml-jar-path " -p " cmdline " " in-file))
    (with-temp-buffer
      (call-process-shell-command
       (concat "java -jar " org-plantuml-jar-path " -p " cmdline)
       in-file
       '(t nil))
      (write-region nil nil out-file))
    out-file))

(defun org-babel-prep-session:plantuml (session params)
  "Return an error because plantuml does not support sessions."
  (error "Plantuml does not support sessions"))

(provide 'ob-plantuml)

;;; ob-plantuml.el ends here

And a new major mode "plantuml-mode.el", which provides preliminary font-lock function for plantuml scripts:

;; plantuml-mode.el -- Major mode for plantuml

;; Author: Zhang Weize (zwz)
;; Keywords: uml ascii

;; You can redistribute this program and/or modify it under the terms
;; of the GNU General Public License as published by the Free Software
;; Foundation; either version 2, or (at your option) any later
;; version.

;;; DESCRIPTION

;; A major mode for plantuml, see: http://plantuml.sourceforge.net/
;; Plantuml is an open-source tool in java that allows to quickly write :
;;     - sequence diagram,
;;     - use case diagram,
;;     - class diagram,
;;     - activity diagram,
;;     - component diagram,
;;     - state diagram
;;     - object diagram
;; using a simple and intuitive language.

;;; HISTORY

;; version 0.1, 2010-08-25 First version


(require 'thingatpt)

(defgroup plantuml-mode nil
  "Major mode for editing plantuml file."
  :group 'languages)

(defvar plantuml-mode-hook nil "Standard hook for plantuml-mode.")

(defvar plantuml-mode-version nil "plantuml-mode version string.")

(defvar plantuml-mode-map nil "Keymap for plantuml-mode")

;;; syntax table
(defvar plantuml-mode-syntax-table
  (let ((synTable (make-syntax-table)))
    (modify-syntax-entry ?' "< b" synTable)
    (modify-syntax-entry ?\n "> b" synTable)
    (modify-syntax-entry ?! "w" synTable)
    (modify-syntax-entry ?@ "w" synTable)
    (modify-syntax-entry ?# "'" synTable)
    synTable)
  "Syntax table for `plantuml-mode'.")

;;; font-lock
(defvar plantuml-types '("participant" "actor" "usecase" "abstract" "abstract class" "interface" "enum" "package" "partition" "component" "state" "object" "title" "note" "end note" "end title" "end header" "end footer"
                         ;;"note left" "note right" "note top" "note bottom" "note left of" "note right of" "note top of" "note bottom of" "note over" "left header" "center header" "right header" "left footer" "center footer" "right footer"
))
(defvar plantuml-keywords '("\@startuml" "\@enduml" "as" "autonumber" "newpage" "alt" "else" "opt" "loop" "par" "break" "critical" "end" "create" "footbox off" "skin" "skinparam" "if" "then" "else" "endif" "rotate" "activate" "deactivate" "destroy"))

(defvar plantuml-preprocessors '("!include" "!define" "!undef" "!ifdef" "!endif" "!ifndef"))

(defvar plantuml-builtins '("backgroundColor"
                            "activityArrowColor"
                            "activityBackgroundColor"
                            "activityBorderColor"
                            "activityStartColor"
                            "activityEndColor"
                            "activityBarColor"
                            "usecaseArrowColor"
                            "actorBackgroundColor"
                            "actorBorderColor"
                            "usecaseBackgroundColor"
                            "usecaseBorderColor"
                            "classArrowColor"
                            "classBackgroundColor"
                            "classBorderColor"
                            "packageBackgroundColor"
                            "packageBorderColor"
                            "stereotypeCBackgroundColor"
                            "stereotypeABackgroundColor"
                            "stereotypeIBackgroundColor"
                            "stereotypeEBackgroundColor"
                            "componentArrowColor"
                            "componentBackgroundColor"
                            "componentBorderColor"
                            "interfaceBackgroundColor"
                            "interfaceBorderColor"
                            "noteBackgroundColor"
                            "noteBorderColor"
                            "stateBackgroundColor"
                            "stateBorderColor"
                            "stateArrowColor"
                            "sequenceArrowColor"
                            "sequenceActorBackgroundColor"
                            "sequenceActorBorderColor"
                            "sequenceGroupBackgroundColor"
                            "sequenceLifeLineBackgroundColor"
                            "sequenceLifeLineBorderColor"
                            "sequenceParticipantBackgroundColor"
                            "sequenceParticipantBorderColor"
                            "activityFontColor"
                            "activityFontSize"
                            "activityFontStyle"
                            "activityFontName"
                            "activityArrowFontColor"
                            "activityArrowFontSize"
                            "activityArrowFontStyle"
                            "activityArrowFontName"
                            "circledCharacterFontColor"
                            "circledCharacterFontSize"
                            "circledCharacterFontStyle"
                            "circledCharacterFontName"
                            "circledCharacterRadius"
                            "classArrowFontColor"
                            "classArrowFontSize"
                            "classArrowFontStyle"
                            "classArrowFontName"
                            "classAttributeFontColor"
                            "classAttributeFontSize"
                            "classAttributeIconSize"
                            "classAttributeFontStyle"
                            "classAttributeFontName"
                            "classFontColor"
                            "classFontSize"
                            "classFontStyle"
                            "classFontName"
                            "classStereotypeFontColor"
                            "classStereotypeFontSize"
                            "classStereotypeFontStyle"
                            "classStereotypeFontName"
                            "componentFontColor"
                            "componentFontSize"
                            "componentFontStyle"
                            "componentFontName"
                            "componentStereotypeFontColor"
                            "componentStereotypeFontSize"
                            "componentStereotypeFontStyle"
                            "componentStereotypeFontName"
                            "componentArrowFontColor"
                            "componentArrowFontSize"
                            "componentArrowFontStyle"
                            "componentArrowFontName"
                            "noteFontColor"
                            "noteFontSize"
                            "noteFontStyle"
                            "noteFontName"
                            "packageFontColor"
                            "packageFontSize"
                            "packageFontStyle"
                            "packageFontName"
                            "sequenceActorFontColor"
                            "sequenceActorFontSize"
                            "sequenceActorFontStyle"
                            "sequenceActorFontName"
                            "sequenceDividerFontColor"
                            "sequenceDividerFontSize"
                            "sequenceDividerFontStyle"
                            "sequenceDividerFontName"
                            "sequenceArrowFontColor"
                            "sequenceArrowFontSize"
                            "sequenceArrowFontStyle"
                            "sequenceArrowFontName"
                            "sequenceGroupingFontColor"
                            "sequenceGroupingFontSize"
                            "sequenceGroupingFontStyle"
                            "sequenceGroupingFontName"
                            "sequenceGroupingHeaderFontColor"
                            "sequenceGroupingHeaderFontSize"
                            "sequenceGroupingHeaderFontStyle"
                            "sequenceGroupingHeaderFontName"
                            "sequenceParticipantFontColor"
                            "sequenceParticipantFontSize"
                            "sequenceParticipantFontStyle"
                            "sequenceParticipantFontName"
                            "sequenceTitleFontColor"
                            "sequenceTitleFontSize"
                            "sequenceTitleFontStyle"
                            "sequenceTitleFontName"
                            "titleFontColor"
                            "titleFontSize"
                            "titleFontStyle"
                            "titleFontName"
                            "stateFontColor"
                            "stateFontSize"
                            "stateFontStyle"
                            "stateFontName"
                            "stateArrowFontColor"
                            "stateArrowFontSize"
                            "stateArrowFontStyle"
                            "stateArrowFontName"
                            "usecaseFontColor"
                            "usecaseFontSize"
                            "usecaseFontStyle"
                            "usecaseFontName"
                            "usecaseStereotypeFontColor"
                            "usecaseStereotypeFontSize"
                            "usecaseStereotypeFontStyle"
                            "usecaseStereotypeFontName"
                            "usecaseActorFontColor"
                            "usecaseActorFontSize"
                            "usecaseActorFontStyle"
                            "usecaseActorFontName"
                            "usecaseActorStereotypeFontColor"
                            "usecaseActorStereotypeFontSize"
                            "usecaseActorStereotypeFontStyle"
                            "usecaseActorStereotypeFontName"
                            "usecaseArrowFontColor"
                            "usecaseArrowFontSize"
                            "usecaseArrowFontStyle"
                            "usecaseArrowFontName"
                            "footerFontColor"
                            "footerFontSize"
                            "footerFontStyle"
                            "footerFontName"
                            "headerFontColor"
                            "headerFontSize"
                            "headerFontStyle"
                            "headerFontName"
                            "AliceBlue" "GhostWhite" "NavajoWhite"
                            "AntiqueWhite" "GoldenRod" "Navy"
                            "Aquamarine" "Gold" "OldLace"
                            "Aqua" "Gray" "OliveDrab"
                            "Azure" "GreenYellow" "Olive"
                            "Beige" "Green" "OrangeRed"
                            "Bisque" "HoneyDew" "Orange"
                            "Black" "HotPink" "Orchid"
                            "BlanchedAlmond" "IndianRed" "PaleGoldenRod"
                            "BlueViolet" "Indigo" "PaleGreen"
                            "Blue" "Ivory" "PaleTurquoise"
                            "Brown" "Khaki" "PaleVioletRed"
                            "BurlyWood" "LavenderBlush" "PapayaWhip"
                            "CadetBlue" "Lavender" "PeachPuff"
                            "Chartreuse" "LawnGreen" "Peru"
                            "Chocolate" "LemonChiffon" "Pink"
                            "Coral" "LightBlue" "Plum"
                            "CornflowerBlue" "LightCoral" "PowderBlue"
                            "Cornsilk" "LightCyan" "Purple"
                            "Crimson" "LightGoldenRodYellow" "Red"
                            "Cyan" "LightGreen" "RosyBrown"
                            "DarkBlue" "LightGrey" "RoyalBlue"
                            "DarkCyan" "LightPink" "SaddleBrown"
                            "DarkGoldenRod" "LightSalmon" "Salmon"
                            "DarkGray" "LightSeaGreen" "SandyBrown"
                            "DarkGreen" "LightSkyBlue" "SeaGreen"
                            "DarkKhaki" "LightSlateGray" "SeaShell"
                            "DarkMagenta" "LightSteelBlue" "Sienna"
                            "DarkOliveGreen" "LightYellow" "Silver"
                            "DarkOrchid" "LimeGreen" "SkyBlue"
                            "DarkRed" "Lime" "SlateBlue"
                            "DarkSalmon" "Linen" "SlateGray"
                            "DarkSeaGreen" "Magenta" "Snow"
                            "DarkSlateBlue" "Maroon" "SpringGreen"
                            "DarkSlateGray" "MediumAquaMarine" "SteelBlue"
                            "DarkTurquoise" "MediumBlue" "Tan"
                            "DarkViolet" "MediumOrchid" "Teal"
                            "Darkorange" "MediumPurple" "Thistle"
                            "DeepPink" "MediumSeaGreen" "Tomato"
                            "DeepSkyBlue" "MediumSlateBlue" "Turquoise"
                            "DimGray" "MediumSpringGreen" "Violet"
                            "DodgerBlue" "MediumTurquoise" "Wheat"
                            "FireBrick" "MediumVioletRed" "WhiteSmoke"
                            "FloralWhite" "MidnightBlue" "White"
                            "ForestGreen" "MintCream" "YellowGreen"
                            "Fuchsia" "MistyRose" "Yellow"
                            "Gainsboro" "Moccasin"
))
(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-keywords-regexp (concat "^\\s *" (regexp-opt plantuml-keywords 'words)  "\\|\\(<\\|<|\\|\\*\\|o\\)\\(\\.+\\|-+\\)\\|\\(\\.+\\|-+\\)\\(>\\||>\\|\\*\\|o\\)\\|\\.\\{2,\\}\\|-\\{2,\\}"))
(defvar plantuml-builtins-regexp (regexp-opt plantuml-builtins 'words))
(defvar plantuml-preprocessors-regexp (concat "^\\s *" (regexp-opt plantuml-preprocessors 'words)))

(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
        ))

;; keyword completion
(defvar plantuml-kwdList nil "plantuml keywords.")

(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-keywords)
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-builtins)
(mapc (lambda (x) (puthash x t plantuml-kwdList)) plantuml-preprocessors)
(put 'plantuml-kwdList 'risky-local-variable t)

(defun plantuml-complete-symbol ()
  "Perform keyword completion on word before cursor."
  (interactive)
  (let ((posEnd (point))
        (meat (thing-at-point 'symbol))
        maxMatchResult)

    (when (not meat) (setq meat ""))

    (setq maxMatchResult (try-completion meat plantuml-kwdList))
    (cond ((eq maxMatchResult t))
          ((null maxMatchResult)
           (message "Can't find completion for \"%s\"" meat)
           (ding))
          ((not (string= meat maxMatchResult))
           (delete-region (- posEnd (length meat)) posEnd)
           (insert maxMatchResult))
          (t (message "Making completion list...")
             (with-output-to-temp-buffer "*Completions*"
               (display-completion-list
                (all-completions meat plantuml-kwdList)
                meat))
             (message "Making completion list...%s" "done")))))

;; clear memory
(setq plantuml-types nil)
(setq plantuml-keywords nil)
(setq plantuml-builtins nil)
(setq plantuml-preprocessors nil)
(setq plantuml-types-regexp nil)
(setq plantuml-keywords-regexp nil)
(setq plantuml-builtins-regexp nil)
(setq plantuml-preprocessors-regexp nil)

(add-to-list 'auto-mode-alist '("\\.plu$" . plantuml-mode))

;;;###autoload
(defun plantuml-mode ()
  "Major mode for plantuml.

Shortcuts             Command Name
\\[plantuml-complete-symbol]      `plantuml-complete-symbol'"

  (interactive)
  (kill-all-local-variables)

;;  (python-mode) ; for indentation
  (setq major-mode 'plantuml-mode
        mode-name "plantuml")
  (set-syntax-table plantuml-mode-syntax-table)
  (use-local-map plantuml-mode-map)

  (make-local-variable 'font-lock-defaults)
  (setq font-lock-defaults '((plantuml-font-lock-keywords) nil t))

  (run-mode-hooks 'plantuml-mode-hook))

(provide 'plantuml-mode)
Posted in emacs | Tagged , , | 1 Comment

Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Posted in Uncategorized | 1 Comment