Compare commits

...

10 Commits

Author SHA1 Message Date
e1fd3e0d37 Formatting 2025-09-18 17:16:22 -04:00
c5377aa0ac Added default comment character 2025-09-18 17:13:43 -04:00
0bf9667e3a Added ajustable indentation 2025-09-18 17:13:19 -04:00
Tommy Olofsson
76876287c7 Added keyword CONST. 2015-12-01 14:34:34 +01:00
Tommy Olofsson
5e8a25456c Added a keyword. 2015-09-01 14:35:04 +02:00
Tommy Olofsson
8109776b2b Torque stuff. 2015-08-06 15:39:29 +02:00
Tommy Olofsson
1b809a0e8e Add primitive type. 2015-07-14 16:07:24 +02:00
Tommy Olofsson
08ac670328 Added type and (krl) error handling. 2015-07-10 20:35:02 +02:00
Tommy Olofsson
75da27eeda Better positioning after indentation. 2015-07-08 23:17:15 +02:00
Tommy Olofsson
43273c8fad Add some missing keywords. 2015-07-08 23:04:56 +02:00

View File

@@ -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,6 +89,10 @@
"DO"
"STEP"
"WHEN"
"RETURN"
"STRUC"
"TO"
"SIGNAL"
))
(defconst krl-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
@@ -252,22 +269,32 @@
(setq ind 0))
((looking-at krl-indent-regex-toplevel-block-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)
;(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))))
(setq ind (+ krl-indent-offset (current-indentation))))
(t
;(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)
(let ((ind nil))
(save-excursion
(progn
(beginning-of-line)
@@ -278,25 +305,25 @@
(cond ((looking-at krl-indent-regex-toplevel-block-open)
(progn
;(message "toplevel open")
(indent-line-to 0)))
(setq ind 0)))
((looking-at krl-indent-regex-toplevel-block-close)
(progn
;(message "toplevel close")
(indent-line-to 0)))
(setq ind 0)))
((looking-at "^ *&")
(progn
;(message "&")
;; HMI editor crud.
(indent-line-to 0)))
(setq ind 0)))
((looking-at krl-indent-regex-nested-block-close)
(progn
;(message "nested close")
(indent-line-to (krl-indent-of-matching))))
(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))))
(indent-line-to (krl-indent-of-matching))))
(setq ind (krl-indent-of-matching))))
(t
(progn
;(message "other")
@@ -305,8 +332,9 @@
(let ((hinted-indent (krl-find-hinted-indent)))
(when (not hinted-indent)
(setq hinted-indent 0))
(indent-line-to hinted-indent))))
)))))))
(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)