Function: cfengine2-indent-line
cfengine2-indent-line is a byte-compiled function defined in
cfengine.el.gz.
Signature
(cfengine2-indent-line)
Documentation
Indent a line in Cfengine mode.
Intended as the value of indent-line-function.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cfengine.el.gz
;; Fixme: Should get an extra indent step in editfiles BeginGroup...s.
(defun cfengine2-indent-line ()
"Indent a line in Cfengine mode.
Intended as the value of `indent-line-function'."
(let ((pos (- (point-max) (point))))
(save-restriction
(narrow-to-defun)
(back-to-indentation)
(cond
;; Action selectors aren't indented; class selectors are
;; indented one step.
((looking-at "[[:alnum:]_().|!]+:\\(:\\)?")
(if (match-string 1)
(indent-line-to cfengine-indent)
(indent-line-to 0)))
;; Outdent leading close brackets one step.
((or (eq ?\} (char-after))
(eq ?\) (char-after)))
(condition-case ()
(indent-line-to (save-excursion
(forward-char)
(backward-sexp)
(current-column)))
(error nil)))
;; Inside brackets/parens: indent to start column of non-comment
;; token on line following open bracket or by one step from open
;; bracket's column.
((condition-case ()
(progn (indent-line-to (save-excursion
(backward-up-list)
(forward-char)
(skip-chars-forward " \t")
(if (looking-at "[^\n#]")
(current-column)
(skip-chars-backward " \t")
(+ (current-column) -1
cfengine-indent))))
t)
(error nil)))
;; Indent by two steps after a class selector.
((save-excursion
(re-search-backward "^[ \t]*[[:alnum:]_().|!]+::" nil t))
(indent-line-to (* 2 cfengine-indent)))
;; Indent by one step if we're after an action header.
((save-excursion
(goto-char (point-min))
(looking-at "[[:alpha:]]+:[ \t]*$"))
(indent-line-to cfengine-indent))
;; Else don't indent.
(t
(indent-line-to 0))))
;; If initial point was within line's indentation,
;; position after the indentation. Else stay at same point in text.
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))))