Allow reinitialization of font lock regexps
In `plantuml-mode`, initialization of the font locking regular expressions is done by asking the current version of plantuml for its supported keywords, builtins, etc. Every so often, this might fail for any reason, leaving the current Emacs session with invalid font lock information for plantuml. Redoing the initialization process is tedious, as the corresponding function `plantuml-init-once` does not allow for that to be done easily (one would have to undefine a lot of global variables to do so). This commit introduces a force parameter for `plantuml-init-once` to conduct reinitialization of all font lock information. It also moves regular expressions meant for indentation out of `plantuml-init-once`, as those are initialized by literal values that do not depend on any runtime information.
This commit is contained in:
parent
ea45a13707
commit
d7721971f0
|
@ -539,16 +539,6 @@ Uses prefix (as PREFIX) to choose where to display it:
|
|||
(plantuml-preview-region prefix (region-beginning) (region-end))
|
||||
(plantuml-preview-buffer prefix)))
|
||||
|
||||
(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'."
|
||||
(let ((mode (or mode (plantuml-get-exec-mode))))
|
||||
(unless plantuml-kwdList
|
||||
(plantuml-init mode)
|
||||
(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)))
|
||||
|
||||
;; Below are the regexp's for indentation.
|
||||
;; Notes:
|
||||
;; - there is some control on what it is indented by overriding some of below
|
||||
|
@ -568,12 +558,14 @@ Uses prefix (as PREFIX) to choose where to display it:
|
|||
;; (Note: the line with the comment should not contain any text matching other indent
|
||||
;; regexp or this user-control instruction will be ignored; also at most will count
|
||||
;; per line ...)
|
||||
|
||||
(defvar plantuml-indent-regexp-block-start "^.*{\s*$"
|
||||
"Indentation regex for all plantuml elements that might define a {} block.
|
||||
Plantuml elements like skinparam, rectangle, sprite, package, etc.
|
||||
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\\)[^:]*?$" "simplyfied regex; note syntax is especially inconsistent across diagrams")
|
||||
(defvar plantuml-indent-regexp-note-start "^\s*\\(floating\s+\\)?[hr]?note\s+\\(right\\|left\\|top\\|bottom\\|over\\)[^:]*?$"
|
||||
"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.
|
||||
Two variants for groups: keyword is either followed by whitespace and some text
|
||||
|
@ -585,7 +577,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*$")
|
||||
|
@ -639,6 +632,27 @@ or it is followed by line end.")
|
|||
plantuml-indent-regexp-macro-end
|
||||
plantuml-indent-regexp-oldif-end
|
||||
plantuml-indent-regexp-user-control-end))
|
||||
|
||||
(defun plantuml-init-once (&optional mode force)
|
||||
"Initialize regular expressions for font locking.
|
||||
Use exec mode MODE to load the language details or by first
|
||||
querying `plantuml-get-exec-mode'. Ensure that initialization is
|
||||
only performed when not already done. To force reinitalization,
|
||||
provide a non-nil value for FORCE."
|
||||
(let ((mode (or mode (plantuml-get-exec-mode))))
|
||||
(when (or (not plantuml-kwdList)
|
||||
force)
|
||||
(plantuml-init mode)
|
||||
(let ((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\\)\\)\\>\\)"))
|
||||
(plantuml-keywords-regexp (concat "^\\s *"
|
||||
(regexp-opt plantuml-keywords 'words)
|
||||
"\\|\\(<\\|<|\\|\\*\\|o\\)\\(\\.+\\|-+\\)\\|\\(\\.+\\|-+\\)\\(>\\||>\\|\\*\\|o\\)\\|\\.\\{2,\\}\\|-\\{2,\\}"))
|
||||
(plantuml-builtins-regexp (regexp-opt plantuml-builtins 'words))
|
||||
(plantuml-preprocessors-regexp (concat "^\\s *"
|
||||
(regexp-opt plantuml-preprocessors 'words))))
|
||||
|
||||
(setq plantuml-font-lock-keywords
|
||||
`(
|
||||
(,plantuml-types-regexp . font-lock-type-face)
|
||||
|
@ -655,15 +669,10 @@ or it is followed by line end.")
|
|||
(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))))
|
||||
(setq plantuml-types nil
|
||||
plantuml-keywords nil
|
||||
plantuml-builtins nil
|
||||
plantuml-preprocessors nil)))))
|
||||
|
||||
(defun plantuml-complete-symbol ()
|
||||
"Perform keyword completion on word before cursor."
|
||||
|
|
Loading…
Reference in New Issue