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) (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,16 +89,20 @@
"DO" "DO"
"STEP" "STEP"
"WHEN" "WHEN"
"RETURN"
"STRUC"
"TO"
"SIGNAL"
)) ))
(defconst krl-keywords (defconst krl-keywords
(append (append
(mapcar (lambda (x) (rstrip (nth 0 x))) krl-keywords-toplevel-block-pairs) (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 1 x))) krl-keywords-toplevel-block-pairs)
(mapcar (lambda (x) (rstrip (nth 0 x))) krl-keywords-nested-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 1 x))) krl-keywords-nested-block-pairs)
(mapcar (lambda (x) (rstrip (nth 2 x))) krl-keywords-nested-block-middle) (mapcar (lambda (x) (rstrip (nth 2 x))) krl-keywords-nested-block-middle)
krl-keywords-misc krl-keywords-misc
)) ))
(defconst krl-warning-keywords (defconst krl-warning-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
@@ -188,24 +205,24 @@
;; Get the string pair for the block we are currently on the end of. ;; Get the string pair for the block we are currently on the end of.
(defun krl-get-pair () (defun krl-get-pair ()
(let ((pairs (copy-sequence krl-keywords-nested-block-pairs)) (pair nil)) (let ((pairs (copy-sequence krl-keywords-nested-block-pairs)) (pair nil))
(while (and (not pair) pairs) (while (and (not pair) pairs)
(when (looking-at (concat "^ *" (nth 1 (car pairs)))) (when (looking-at (concat "^ *" (nth 1 (car pairs))))
(setq pair (car pairs))) (setq pair (car pairs)))
(setq pairs (cdr pairs))) (setq pairs (cdr pairs)))
;; FIXME: Hack for broken ELSE, CASE. ;; FIXME: Hack for broken ELSE, CASE.
(when (not pair) (when (not pair)
(let ((triples (copy-sequence krl-keywords-nested-block-middle))) (let ((triples (copy-sequence krl-keywords-nested-block-middle)))
(while (and (not pair) triples) (while (and (not pair) triples)
(when (looking-at (concat "^ *" (nth 2 (car triples)))) (when (looking-at (concat "^ *" (nth 2 (car triples))))
(setq pair (car triples))) (setq pair (car triples)))
(setq triples (cdr triples)) (setq triples (cdr triples))
))) )))
pair)) pair))
(defun krl-indent-of-matching () (defun krl-indent-of-matching ()
(save-excursion (save-excursion
(let ((balance 1) (pair (krl-get-pair))) (let ((balance 1) (pair (krl-get-pair)))
;(message (nth 0 pair)) ;(message (nth 0 pair))
(while (and (/= balance 0) (not (bobp))) (while (and (/= balance 0) (not (bobp)))
(progn (progn
(forward-line -1) (forward-line -1)
@@ -248,65 +265,76 @@
(forward-line -1) (forward-line -1)
(cond (cond
((looking-at krl-indent-regex-toplevel-block-close) ((looking-at krl-indent-regex-toplevel-block-close)
;(message "found tlb close") ;(message "found tlb close")
(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)
(save-excursion (let ((ind nil))
(progn (save-excursion
(beginning-of-line) (progn
(if (bobp) (beginning-of-line)
(indent-line-to 0) (if (bobp)
(let (indent-curr) (indent-line-to 0)
(progn (let (indent-curr)
(cond ((looking-at krl-indent-regex-toplevel-block-open) (progn
(progn (cond ((looking-at krl-indent-regex-toplevel-block-open)
;(message "toplevel open") (progn
(indent-line-to 0))) ;(message "toplevel open")
((looking-at krl-indent-regex-toplevel-block-close) (setq ind 0)))
(progn ((looking-at krl-indent-regex-toplevel-block-close)
;(message "toplevel close") (progn
(indent-line-to 0))) ;(message "toplevel close")
((looking-at "^ *&") (setq ind 0)))
(progn ((looking-at "^ *&")
;(message "&") (progn
;; HMI editor crud. ;(message "&")
(indent-line-to 0))) ;; HMI editor crud.
((looking-at krl-indent-regex-nested-block-close) (setq ind 0)))
(progn ((looking-at krl-indent-regex-nested-block-close)
;(message "nested close") (progn
(indent-line-to (krl-indent-of-matching)))) ;(message "nested close")
((looking-at krl-indent-regex-nested-block-middle) (setq ind (krl-indent-of-matching))))
(progn ((looking-at krl-indent-regex-nested-block-middle)
;(message "annoying stuff") (progn
;; (indent-line-to (krl-indent-of-block-opener)))) ;(message "annoying stuff")
(indent-line-to (krl-indent-of-matching)))) ;; (indent-line-to (krl-indent-of-block-opener))))
(t (setq ind (krl-indent-of-matching))))
(progn (t
;(message "other") (progn
;; ;(message krl-indent-regex-toplevel-block-open) ;(message "other")
;; (indent-line-to (krl-find-hinted-indent)))) ;; ;(message krl-indent-regex-toplevel-block-open)
(let ((hinted-indent (krl-find-hinted-indent))) ;; (indent-line-to (krl-find-hinted-indent))))
(when (not hinted-indent) (let ((hinted-indent (krl-find-hinted-indent)))
(setq hinted-indent 0)) (when (not hinted-indent)
(indent-line-to hinted-indent)))) (setq hinted-indent 0))
))))))) (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)