Skip to content

Instantly share code, notes, and snippets.

@gregoryg
Created June 13, 2014 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregoryg/4e4045ac25cd1210a0db to your computer and use it in GitHub Desktop.
Save gregoryg/4e4045ac25cd1210a0db to your computer and use it in GitHub Desktop.
First indentation code for Syncsort DTL
;; /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