Michelson, Emacs: minor changes in emacs mode for annotations

And syntax highlightting in stack
This commit is contained in:
Alain Mebsout 2018-05-30 14:41:29 +02:00 committed by Benjamin Canou
parent 9993553a59
commit b229eace6b

View File

@ -66,18 +66,25 @@ Overrides `michelson-print-errors' and `michelson-highlight-errors'"
(defvar michelson-face-constant (defvar michelson-face-constant
'michelson-face-constant 'michelson-face-constant
"Face name for Michelson constants.") "Face name for Michelson constants.")
(defface michelson-face-constant (defface michelson-face-constant
'((t (:inherit font-lock-constant-face))) '((t (:inherit font-lock-constant-face)))
"Face for Michelson constants." "Face for Michelson constants."
:group 'michelson-faces) :group 'michelson-faces)
(defvar michelson-face-instruction (defvar michelson-face-var-annotation
'michelson-face-instruction 'michelson-face-var-annotation
"Face name for Michelson instructions.") "Face name for Michelson variable or binding annotations.")
(defface michelson-face-annotation (defface michelson-face-var-annotation
'((t (:inherit font-lock-variable-name-face)))
"Face for Michelson variable or binding annotations."
:group 'michelson-faces)
(defvar michelson-face-type-annotation
'michelson-face-type-annotation
"Face name for Michelson type or field annotations.")
(defface michelson-face-type-annotation
'((t (:inherit font-lock-string-face))) '((t (:inherit font-lock-string-face)))
"Face for Michelson annotations." "Face for Michelson type or field annotations."
:group 'michelson-faces) :group 'michelson-faces)
(defvar michelson-face-comment (defvar michelson-face-comment
@ -165,10 +172,11 @@ Overrides `michelson-print-errors' and `michelson-highlight-errors'"
(defconst michelson-font-lock-defaults (defconst michelson-font-lock-defaults
(list (list
(list (list
'("\\<[\$@][A-Za-z-_0-9\.]*\\>" . michelson-face-var-annotation)
'("\\<[%:][A-Za-z-_0-9\.]*\\>" . michelson-face-type-annotation)
'("\\<[0-9]+\\>" . michelson-face-constant) '("\\<[0-9]+\\>" . michelson-face-constant)
'("\\<[A-Z][a-z_0-9]+\\>" . michelson-face-constant) '("\\<[A-Z][a-z_0-9]+\\>" . michelson-face-constant)
'("\\<[A-Z][A-Z_0-9]*\\>" . michelson-face-instruction) '("\\<[A-Z][A-Z_0-9]*\\>" . michelson-face-instruction)
'("\\<\$[A-Za-z-_0-9]*\\>" . michelson-face-annotation)
;; This will have problems if users have whitespace in front of the declarations ;; This will have problems if users have whitespace in front of the declarations
'("^parameter\\|^return\\|^storage\\|^code" . michelson-face-declaration) '("^parameter\\|^return\\|^storage\\|^code" . michelson-face-declaration)
'("\\<[a-z][a-z_0-9]*\\>" . michelson-face-type)) '("\\<[a-z][a-z_0-9]*\\>" . michelson-face-type))
@ -178,6 +186,9 @@ Overrides `michelson-print-errors' and `michelson-highlight-errors'"
(defconst michelson-mode-syntax-table (defconst michelson-mode-syntax-table
(let ((michelson-mode-syntax-table (make-syntax-table))) (let ((michelson-mode-syntax-table (make-syntax-table)))
(modify-syntax-entry ?_ "w" michelson-mode-syntax-table) (modify-syntax-entry ?_ "w" michelson-mode-syntax-table)
(modify-syntax-entry ?@ "w" michelson-mode-syntax-table)
(modify-syntax-entry ?: "w" michelson-mode-syntax-table)
(modify-syntax-entry ?% "w" michelson-mode-syntax-table)
(modify-syntax-entry ?/ ". 1n4" michelson-mode-syntax-table) (modify-syntax-entry ?/ ". 1n4" michelson-mode-syntax-table)
(modify-syntax-entry ?* ". 23" michelson-mode-syntax-table) (modify-syntax-entry ?* ". 23" michelson-mode-syntax-table)
(modify-syntax-entry ?# "<b" michelson-mode-syntax-table) (modify-syntax-entry ?# "<b" michelson-mode-syntax-table)
@ -428,6 +439,18 @@ Overrides `michelson-print-errors' and `michelson-highlight-errors'"
map) map)
"Keymap for types buffer.") "Keymap for types buffer.")
(define-derived-mode michelson-stack-mode fundamental-mode "Michelson-stack"
"Major mode for visualizing the Michelson stack."
(interactive)
(use-local-map michelson-output-buffer-map)
(set-syntax-table michelson-mode-syntax-table)
(set
(make-local-variable 'font-lock-defaults)
michelson-font-lock-defaults)
(setq major-mode 'michelson-stack-mode)
(setq mode-name "Michelson-stack")
(setq indent-tabs-mode nil))
(defun michelson-write-output-buffer (data &optional do-not-overwrite) (defun michelson-write-output-buffer (data &optional do-not-overwrite)
"Write the given `DATA' to the output buffer. "Write the given `DATA' to the output buffer.
If `DATA' is a string, it is written directly, If `DATA' is a string, it is written directly,
@ -461,7 +484,7 @@ If `DO-NOT-OVERWRITE' is non-nil, the existing contents of the buffer are mainta
'face 'michelson-stack-highlight-face)) 'face 'michelson-stack-highlight-face))
(setq michelson-highlighting (not michelson-highlighting))))) (setq michelson-highlighting (not michelson-highlighting)))))
(insert data)) (insert data))
(use-local-map michelson-output-buffer-map) (with-current-buffer buffer (michelson-stack-mode))
(read-only-mode 1) (read-only-mode 1)
(goto-char (point-min)) (goto-char (point-min))
(while (not (eobp)) (while (not (eobp))