Add indent-line implementation
This commit is contained in:
parent
cfb408fc84
commit
1162d9de46
|
@ -373,6 +373,40 @@ Uses prefix (as PREFIX) to choose where to display it:
|
|||
(all-completions meat plantuml-kwdList)))
|
||||
(message "Making completion list...%s" "done")))))
|
||||
|
||||
|
||||
;; indentation
|
||||
(defvar plantuml-indent-regexp-start "^[ \t]*\\(\\(?:.*\\)?\s*\\(?:[<>.*a-z-|]+\\)?\s*\\(?:\\[[a-zA-Z]+\\]\\)?\s+if\\|alt\\|else\\|note\s+over\\|note\sas\s.*\\|note\s+\\(\\(?:\\(?:buttom\\|left\\|right\\|top\\)\\)\\)\\(?:\s+of\\)?\\|\\(?:class\\|enum\\|package\\)\s+.*{\\)")
|
||||
|
||||
(defvar plantuml-indent-regexp-end "^[ \t]*\\(endif\\|else\\|end\\|end\s+note\\|.*}\\)")
|
||||
|
||||
(defun plantuml-current-block-indentation ()
|
||||
(save-excursion
|
||||
(let ((relative-depth 0))
|
||||
(while (>= relative-depth 0)
|
||||
;; (message (concat "got: " (number-to-string relative-depth)))
|
||||
(forward-line -1)
|
||||
(if (bobp)
|
||||
(setq relative-depth -2)) ;end fast
|
||||
(if (looking-at plantuml-indent-regexp-end)
|
||||
(setq relative-depth (1+ relative-depth)))
|
||||
(if (looking-at plantuml-indent-regexp-start)
|
||||
(setq relative-depth (1- relative-depth))))
|
||||
|
||||
(if (= -2 relative-depth)
|
||||
0
|
||||
(+ 2 (current-indentation))))))
|
||||
|
||||
(defun plantuml-indent-line ()
|
||||
(interactive)
|
||||
(beginning-of-line)
|
||||
(if (bobp)
|
||||
(indent-line-to 0)
|
||||
(let ((offset (plantuml-current-block-indentation)))
|
||||
(when (looking-at plantuml-indent-regexp-end)
|
||||
(setq offset (max (- offset 2) 0)))
|
||||
(indent-line-to offset))))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
(add-to-list 'auto-mode-alist '("\\.\\(plantuml\\|pum\\|plu\\)\\'" . plantuml-mode))
|
||||
|
||||
|
@ -389,6 +423,7 @@ Shortcuts Command Name
|
|||
(set (make-local-variable 'comment-end) "'/")
|
||||
(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 ()
|
||||
|
|
Loading…
Reference in New Issue