Compare commits
10 Commits
dbd2c67ed8
...
e1fd3e0d37
| Author | SHA1 | Date | |
|---|---|---|---|
| e1fd3e0d37 | |||
| c5377aa0ac | |||
| 0bf9667e3a | |||
|
|
76876287c7 | ||
|
|
5e8a25456c | ||
|
|
8109776b2b | ||
|
|
1b809a0e8e | ||
|
|
08ac670328 | ||
|
|
75da27eeda | ||
|
|
43273c8fad |
51
krl-mode.el
51
krl-mode.el
@@ -4,6 +4,8 @@
|
|||||||
(define-key map "\C-j" 'newline-and-indent)
|
(define-key map "\C-j" 'newline-and-indent)
|
||||||
map)
|
map)
|
||||||
"Keymap for KRL major mode")
|
"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 '("\\.src\\'" . krl-mode))
|
||||||
(add-to-list 'auto-mode-alist '("\\.dat\\'" . krl-mode))
|
(add-to-list 'auto-mode-alist '("\\.dat\\'" . krl-mode))
|
||||||
@@ -70,6 +72,7 @@
|
|||||||
"ENDDAT"
|
"ENDDAT"
|
||||||
"DECL"
|
"DECL"
|
||||||
"GLOBAL"
|
"GLOBAL"
|
||||||
|
"CONST"
|
||||||
"PUBLIC"
|
"PUBLIC"
|
||||||
"THEN"
|
"THEN"
|
||||||
"ENUM"
|
"ENUM"
|
||||||
@@ -86,6 +89,10 @@
|
|||||||
"DO"
|
"DO"
|
||||||
"STEP"
|
"STEP"
|
||||||
"WHEN"
|
"WHEN"
|
||||||
|
"RETURN"
|
||||||
|
"STRUC"
|
||||||
|
"TO"
|
||||||
|
"SIGNAL"
|
||||||
))
|
))
|
||||||
|
|
||||||
(defconst krl-keywords
|
(defconst krl-keywords
|
||||||
@@ -106,17 +113,23 @@
|
|||||||
"WAIT"
|
"WAIT"
|
||||||
"TRIGGER"
|
"TRIGGER"
|
||||||
"!" ; Placeholder for positions.
|
"!" ; Placeholder for positions.
|
||||||
|
"ON_ERROR_PROCEED"
|
||||||
))
|
))
|
||||||
|
|
||||||
(defconst krl-types
|
(defconst krl-types
|
||||||
'(
|
'(
|
||||||
"CHAR"
|
"CHAR"
|
||||||
"INT"
|
"INT"
|
||||||
|
"BOOL"
|
||||||
"REAL"
|
"REAL"
|
||||||
"AXIS"
|
"AXIS"
|
||||||
"E6AXIS"
|
"E6AXIS"
|
||||||
"POS"
|
"POS"
|
||||||
"E6POS"
|
"E6POS"
|
||||||
|
"MODUS_T"
|
||||||
|
"STATE_T"
|
||||||
|
"DATE"
|
||||||
|
"TORQLIMITPARAM"
|
||||||
))
|
))
|
||||||
|
|
||||||
(defconst krl-constants
|
(defconst krl-constants
|
||||||
@@ -159,9 +172,13 @@
|
|||||||
"StrCopy"
|
"StrCopy"
|
||||||
"SWRITE"
|
"SWRITE"
|
||||||
"SREAD"
|
"SREAD"
|
||||||
|
; Torque
|
||||||
|
"SET_TORQUE_LIMITS"
|
||||||
|
"RESET_TORQUE_LIMITS"
|
||||||
; Magic
|
; Magic
|
||||||
"CWRITE"
|
"CWRITE"
|
||||||
"CREAD"
|
"CREAD"
|
||||||
|
"ERR_CLEAR"
|
||||||
))
|
))
|
||||||
|
|
||||||
(defconst krl-font-lock-keywords
|
(defconst krl-font-lock-keywords
|
||||||
@@ -252,22 +269,32 @@
|
|||||||
(setq ind 0))
|
(setq ind 0))
|
||||||
((looking-at krl-indent-regex-toplevel-block-open)
|
((looking-at krl-indent-regex-toplevel-block-open)
|
||||||
;(message "found tlb open")
|
;(message "found tlb open")
|
||||||
(setq ind (+ 2 (current-indentation))))
|
(setq ind (+ krl-indent-offset (current-indentation))))
|
||||||
((looking-at krl-indent-regex-nested-block-close)
|
((looking-at krl-indent-regex-nested-block-close)
|
||||||
;(message "found nb close")
|
;(message "found nb close")
|
||||||
(setq ind (current-indentation)))
|
(setq ind (current-indentation)))
|
||||||
((looking-at krl-indent-regex-nested-block-open)
|
((looking-at krl-indent-regex-nested-block-open)
|
||||||
;(message "found nb open")
|
;(message "found nb open")
|
||||||
(setq ind (+ 2 (current-indentation))))
|
(setq ind (+ krl-indent-offset (current-indentation))))
|
||||||
(t
|
(t
|
||||||
;(message "found other")
|
;(message "found other")
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
ind)))
|
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 ()
|
(defun krl-indent-line ()
|
||||||
"Indent current line as KRL."
|
"Indent current line as KRL."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(let ((ind nil))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(progn
|
(progn
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
@@ -278,25 +305,25 @@
|
|||||||
(cond ((looking-at krl-indent-regex-toplevel-block-open)
|
(cond ((looking-at krl-indent-regex-toplevel-block-open)
|
||||||
(progn
|
(progn
|
||||||
;(message "toplevel open")
|
;(message "toplevel open")
|
||||||
(indent-line-to 0)))
|
(setq ind 0)))
|
||||||
((looking-at krl-indent-regex-toplevel-block-close)
|
((looking-at krl-indent-regex-toplevel-block-close)
|
||||||
(progn
|
(progn
|
||||||
;(message "toplevel close")
|
;(message "toplevel close")
|
||||||
(indent-line-to 0)))
|
(setq ind 0)))
|
||||||
((looking-at "^ *&")
|
((looking-at "^ *&")
|
||||||
(progn
|
(progn
|
||||||
;(message "&")
|
;(message "&")
|
||||||
;; HMI editor crud.
|
;; HMI editor crud.
|
||||||
(indent-line-to 0)))
|
(setq ind 0)))
|
||||||
((looking-at krl-indent-regex-nested-block-close)
|
((looking-at krl-indent-regex-nested-block-close)
|
||||||
(progn
|
(progn
|
||||||
;(message "nested close")
|
;(message "nested close")
|
||||||
(indent-line-to (krl-indent-of-matching))))
|
(setq ind (krl-indent-of-matching))))
|
||||||
((looking-at krl-indent-regex-nested-block-middle)
|
((looking-at krl-indent-regex-nested-block-middle)
|
||||||
(progn
|
(progn
|
||||||
;(message "annoying stuff")
|
;(message "annoying stuff")
|
||||||
;; (indent-line-to (krl-indent-of-block-opener))))
|
;; (indent-line-to (krl-indent-of-block-opener))))
|
||||||
(indent-line-to (krl-indent-of-matching))))
|
(setq ind (krl-indent-of-matching))))
|
||||||
(t
|
(t
|
||||||
(progn
|
(progn
|
||||||
;(message "other")
|
;(message "other")
|
||||||
@@ -305,8 +332,9 @@
|
|||||||
(let ((hinted-indent (krl-find-hinted-indent)))
|
(let ((hinted-indent (krl-find-hinted-indent)))
|
||||||
(when (not hinted-indent)
|
(when (not hinted-indent)
|
||||||
(setq hinted-indent 0))
|
(setq hinted-indent 0))
|
||||||
(indent-line-to hinted-indent))))
|
(setq ind hinted-indent))))
|
||||||
)))))))
|
))))))
|
||||||
|
(indent-and-position ind)))
|
||||||
|
|
||||||
|
|
||||||
(defun krl-mode ()
|
(defun krl-mode ()
|
||||||
@@ -319,6 +347,9 @@
|
|||||||
(set (make-local-variable 'indent-line-function) 'krl-indent-line)
|
(set (make-local-variable 'indent-line-function) 'krl-indent-line)
|
||||||
(setq major-mode 'krl-mode)
|
(setq major-mode 'krl-mode)
|
||||||
(setq mode-name "KRL")
|
(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)
|
(provide 'krl-mode)
|
||||||
|
|||||||
Reference in New Issue
Block a user