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,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)