Created
June 13, 2014 20:08
-
-
Save gregoryg/4e4045ac25cd1210a0db to your computer and use it in GitHub Desktop.
First indentation code for Syncsort DTL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; /DTL and /END are indent level 0 | |
;; default for everything following a /DTL is indent level 1 | |
;; if { appears in a previous line without a closing }, cur-indent += 1 | |
;; if } appears in current line without an opening {. cur-indent -= 1 | |
;; TODO: line continuations should indent past command (?) | |
(defun dtl-indent-line () | |
"Indent current line as DTL code." | |
(interactive) | |
(beginning-of-line) | |
(let ((cur-level 1) (not-indented t)) | |
(cond ((looking-at "^[ \t]*\\(/DTL\\|/END\\)") | |
(setq cur-level 0)) | |
((looking-at "^[^{\n]*}") | |
(setq cur-level 1)) | |
(t | |
(save-excursion | |
(while (and not-indented (not (bobp))) | |
(forward-line -1) | |
(cond | |
((looking-at "^[^{\n]*{[^}\n]*$") ;; opening brace without closing brace on line | |
(progn | |
(setq cur-level (+ cur-level 1)) | |
(setq not-indented nil))) | |
((looking-at "^[^{\n]*}") ;; closing brace without opening brace on line | |
(progn | |
;; (setq cur-level (- cur-level 1)) | |
(setq not-indented nil)))))))) | |
(if cur-level | |
(indent-line-to (* cur-level dtl-indent-level))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment