Compare commits
10 Commits
dbd2c67ed8
...
e1fd3e0d37
| Author | SHA1 | Date | |
|---|---|---|---|
| e1fd3e0d37 | |||
| c5377aa0ac | |||
| 0bf9667e3a | |||
|
|
76876287c7 | ||
|
|
5e8a25456c | ||
|
|
8109776b2b | ||
|
|
1b809a0e8e | ||
|
|
08ac670328 | ||
|
|
75da27eeda | ||
|
|
43273c8fad |
163
krl-mode.el
163
krl-mode.el
@@ -4,6 +4,8 @@
|
||||
(define-key map "\C-j" 'newline-and-indent)
|
||||
map)
|
||||
"Keymap for KRL major mode")
|
||||
(defvar krl-indent-offset 2
|
||||
"Indentation step for nested KRL blocks.")
|
||||
|
||||
(add-to-list 'auto-mode-alist '("\\.src\\'" . krl-mode))
|
||||
(add-to-list 'auto-mode-alist '("\\.dat\\'" . krl-mode))
|
||||
@@ -70,6 +72,7 @@
|
||||
"ENDDAT"
|
||||
"DECL"
|
||||
"GLOBAL"
|
||||
"CONST"
|
||||
"PUBLIC"
|
||||
"THEN"
|
||||
"ENUM"
|
||||
@@ -86,16 +89,20 @@
|
||||
"DO"
|
||||
"STEP"
|
||||
"WHEN"
|
||||
"RETURN"
|
||||
"STRUC"
|
||||
"TO"
|
||||
"SIGNAL"
|
||||
))
|
||||
|
||||
(defconst krl-keywords
|
||||
(append
|
||||
(mapcar (lambda (x) (rstrip (nth 0 x))) krl-keywords-toplevel-block-pairs)
|
||||
(mapcar (lambda (x) (rstrip (nth 1 x))) krl-keywords-toplevel-block-pairs)
|
||||
(mapcar (lambda (x) (rstrip (nth 0 x))) krl-keywords-nested-block-pairs)
|
||||
(mapcar (lambda (x) (rstrip (nth 1 x))) krl-keywords-nested-block-pairs)
|
||||
(mapcar (lambda (x) (rstrip (nth 2 x))) krl-keywords-nested-block-middle)
|
||||
krl-keywords-misc
|
||||
(mapcar (lambda (x) (rstrip (nth 0 x))) krl-keywords-toplevel-block-pairs)
|
||||
(mapcar (lambda (x) (rstrip (nth 1 x))) krl-keywords-toplevel-block-pairs)
|
||||
(mapcar (lambda (x) (rstrip (nth 0 x))) krl-keywords-nested-block-pairs)
|
||||
(mapcar (lambda (x) (rstrip (nth 1 x))) krl-keywords-nested-block-pairs)
|
||||
(mapcar (lambda (x) (rstrip (nth 2 x))) krl-keywords-nested-block-middle)
|
||||
krl-keywords-misc
|
||||
))
|
||||
|
||||
(defconst krl-warning-keywords
|
||||
@@ -106,17 +113,23 @@
|
||||
"WAIT"
|
||||
"TRIGGER"
|
||||
"!" ; Placeholder for positions.
|
||||
"ON_ERROR_PROCEED"
|
||||
))
|
||||
|
||||
(defconst krl-types
|
||||
'(
|
||||
"CHAR"
|
||||
"INT"
|
||||
"BOOL"
|
||||
"REAL"
|
||||
"AXIS"
|
||||
"E6AXIS"
|
||||
"POS"
|
||||
"E6POS"
|
||||
"MODUS_T"
|
||||
"STATE_T"
|
||||
"DATE"
|
||||
"TORQLIMITPARAM"
|
||||
))
|
||||
|
||||
(defconst krl-constants
|
||||
@@ -159,9 +172,13 @@
|
||||
"StrCopy"
|
||||
"SWRITE"
|
||||
"SREAD"
|
||||
; Torque
|
||||
"SET_TORQUE_LIMITS"
|
||||
"RESET_TORQUE_LIMITS"
|
||||
; Magic
|
||||
"CWRITE"
|
||||
"CREAD"
|
||||
"ERR_CLEAR"
|
||||
))
|
||||
|
||||
(defconst krl-font-lock-keywords
|
||||
@@ -188,24 +205,24 @@
|
||||
;; Get the string pair for the block we are currently on the end of.
|
||||
(defun krl-get-pair ()
|
||||
(let ((pairs (copy-sequence krl-keywords-nested-block-pairs)) (pair nil))
|
||||
(while (and (not pair) pairs)
|
||||
(when (looking-at (concat "^ *" (nth 1 (car pairs))))
|
||||
(setq pair (car pairs)))
|
||||
(setq pairs (cdr pairs)))
|
||||
;; FIXME: Hack for broken ELSE, CASE.
|
||||
(when (not pair)
|
||||
(let ((triples (copy-sequence krl-keywords-nested-block-middle)))
|
||||
(while (and (not pair) triples)
|
||||
(when (looking-at (concat "^ *" (nth 2 (car triples))))
|
||||
(setq pair (car triples)))
|
||||
(setq triples (cdr triples))
|
||||
(while (and (not pair) pairs)
|
||||
(when (looking-at (concat "^ *" (nth 1 (car pairs))))
|
||||
(setq pair (car pairs)))
|
||||
(setq pairs (cdr pairs)))
|
||||
;; FIXME: Hack for broken ELSE, CASE.
|
||||
(when (not pair)
|
||||
(let ((triples (copy-sequence krl-keywords-nested-block-middle)))
|
||||
(while (and (not pair) triples)
|
||||
(when (looking-at (concat "^ *" (nth 2 (car triples))))
|
||||
(setq pair (car triples)))
|
||||
(setq triples (cdr triples))
|
||||
)))
|
||||
pair))
|
||||
pair))
|
||||
|
||||
(defun krl-indent-of-matching ()
|
||||
(save-excursion
|
||||
(let ((balance 1) (pair (krl-get-pair)))
|
||||
;(message (nth 0 pair))
|
||||
;(message (nth 0 pair))
|
||||
(while (and (/= balance 0) (not (bobp)))
|
||||
(progn
|
||||
(forward-line -1)
|
||||
@@ -248,65 +265,76 @@
|
||||
(forward-line -1)
|
||||
(cond
|
||||
((looking-at krl-indent-regex-toplevel-block-close)
|
||||
;(message "found tlb close")
|
||||
;(message "found tlb close")
|
||||
(setq ind 0))
|
||||
((looking-at krl-indent-regex-toplevel-block-open)
|
||||
;(message "found tlb open")
|
||||
(setq ind (+ 2 (current-indentation))))
|
||||
;(message "found tlb open")
|
||||
(setq ind (+ krl-indent-offset (current-indentation))))
|
||||
((looking-at krl-indent-regex-nested-block-close)
|
||||
;(message "found nb close")
|
||||
;(message "found nb close")
|
||||
(setq ind (current-indentation)))
|
||||
((looking-at krl-indent-regex-nested-block-open)
|
||||
;(message "found nb open")
|
||||
(setq ind (+ 2 (current-indentation))))
|
||||
;(message "found nb open")
|
||||
(setq ind (+ krl-indent-offset (current-indentation))))
|
||||
(t
|
||||
;(message "found other")
|
||||
;(message "found other")
|
||||
)
|
||||
))
|
||||
ind)))
|
||||
|
||||
|
||||
(defun indent-and-position (col)
|
||||
(progn
|
||||
(save-excursion
|
||||
(indent-line-to col))
|
||||
(when (< (current-column) col)
|
||||
(move-to-column col))))
|
||||
|
||||
|
||||
(defun krl-indent-line ()
|
||||
"Indent current line as KRL."
|
||||
(interactive)
|
||||
(save-excursion
|
||||
(progn
|
||||
(beginning-of-line)
|
||||
(if (bobp)
|
||||
(indent-line-to 0)
|
||||
(let (indent-curr)
|
||||
(progn
|
||||
(cond ((looking-at krl-indent-regex-toplevel-block-open)
|
||||
(progn
|
||||
;(message "toplevel open")
|
||||
(indent-line-to 0)))
|
||||
((looking-at krl-indent-regex-toplevel-block-close)
|
||||
(progn
|
||||
;(message "toplevel close")
|
||||
(indent-line-to 0)))
|
||||
((looking-at "^ *&")
|
||||
(progn
|
||||
;(message "&")
|
||||
;; HMI editor crud.
|
||||
(indent-line-to 0)))
|
||||
((looking-at krl-indent-regex-nested-block-close)
|
||||
(progn
|
||||
;(message "nested close")
|
||||
(indent-line-to (krl-indent-of-matching))))
|
||||
((looking-at krl-indent-regex-nested-block-middle)
|
||||
(progn
|
||||
;(message "annoying stuff")
|
||||
;; (indent-line-to (krl-indent-of-block-opener))))
|
||||
(indent-line-to (krl-indent-of-matching))))
|
||||
(t
|
||||
(progn
|
||||
;(message "other")
|
||||
;; ;(message krl-indent-regex-toplevel-block-open)
|
||||
;; (indent-line-to (krl-find-hinted-indent))))
|
||||
(let ((hinted-indent (krl-find-hinted-indent)))
|
||||
(when (not hinted-indent)
|
||||
(setq hinted-indent 0))
|
||||
(indent-line-to hinted-indent))))
|
||||
)))))))
|
||||
(let ((ind nil))
|
||||
(save-excursion
|
||||
(progn
|
||||
(beginning-of-line)
|
||||
(if (bobp)
|
||||
(indent-line-to 0)
|
||||
(let (indent-curr)
|
||||
(progn
|
||||
(cond ((looking-at krl-indent-regex-toplevel-block-open)
|
||||
(progn
|
||||
;(message "toplevel open")
|
||||
(setq ind 0)))
|
||||
((looking-at krl-indent-regex-toplevel-block-close)
|
||||
(progn
|
||||
;(message "toplevel close")
|
||||
(setq ind 0)))
|
||||
((looking-at "^ *&")
|
||||
(progn
|
||||
;(message "&")
|
||||
;; HMI editor crud.
|
||||
(setq ind 0)))
|
||||
((looking-at krl-indent-regex-nested-block-close)
|
||||
(progn
|
||||
;(message "nested close")
|
||||
(setq ind (krl-indent-of-matching))))
|
||||
((looking-at krl-indent-regex-nested-block-middle)
|
||||
(progn
|
||||
;(message "annoying stuff")
|
||||
;; (indent-line-to (krl-indent-of-block-opener))))
|
||||
(setq ind (krl-indent-of-matching))))
|
||||
(t
|
||||
(progn
|
||||
;(message "other")
|
||||
;; ;(message krl-indent-regex-toplevel-block-open)
|
||||
;; (indent-line-to (krl-find-hinted-indent))))
|
||||
(let ((hinted-indent (krl-find-hinted-indent)))
|
||||
(when (not hinted-indent)
|
||||
(setq hinted-indent 0))
|
||||
(setq ind hinted-indent))))
|
||||
))))))
|
||||
(indent-and-position ind)))
|
||||
|
||||
|
||||
(defun krl-mode ()
|
||||
@@ -319,6 +347,9 @@
|
||||
(set (make-local-variable 'indent-line-function) 'krl-indent-line)
|
||||
(setq major-mode 'krl-mode)
|
||||
(setq mode-name "KRL")
|
||||
(run-hooks 'krl-mode-hook))
|
||||
(run-hooks 'krl-mode-hook)
|
||||
(setq-local comment-start ";")
|
||||
(setq-local comment-end "")
|
||||
(setq-local comment-start-skip ";+\\s-*"))
|
||||
|
||||
(provide 'krl-mode)
|
||||
|
||||
Reference in New Issue
Block a user