mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-01-05 11:45:45 +00:00
* progmodes/cfengine.el: add CFEngine 3-specific indentation.
This commit is contained in:
parent
48b9bb83f2
commit
ca68a22e64
@ -1,3 +1,10 @@
|
|||||||
|
2013-03-12 Teodor Zlatanov <tzz@lifelogs.com>
|
||||||
|
|
||||||
|
* progmodes/cfengine.el (cfengine-parameters-indent): New variable
|
||||||
|
for CFEngine 3-specific indentation.
|
||||||
|
(cfengine3-indent-line): Use it. Fix up category regex.
|
||||||
|
(cfengine3-font-lock-keywords): Add bundle and namespace characters.
|
||||||
|
|
||||||
2013-03-12 Stefan Monnier <monnier@iro.umontreal.ca>
|
2013-03-12 Stefan Monnier <monnier@iro.umontreal.ca>
|
||||||
|
|
||||||
* type-break.el (type-break-file-name):
|
* type-break.el (type-break-file-name):
|
||||||
|
@ -58,6 +58,70 @@
|
|||||||
:group 'cfengine
|
:group 'cfengine
|
||||||
:type 'integer)
|
:type 'integer)
|
||||||
|
|
||||||
|
(defcustom cfengine-parameters-indent '(promise pname 0)
|
||||||
|
"*Indentation of CFEngine3 promise parameters (hanging indent).
|
||||||
|
|
||||||
|
For example, say you have this code:
|
||||||
|
|
||||||
|
bundle x y
|
||||||
|
{
|
||||||
|
section:
|
||||||
|
class::
|
||||||
|
promise ...
|
||||||
|
promiseparameter => ...
|
||||||
|
}
|
||||||
|
|
||||||
|
You can choose to indent promiseparameter from the beginning of
|
||||||
|
the line (absolutely) or from the word \"promise\" (relatively).
|
||||||
|
|
||||||
|
You can also choose to indent the start of the word
|
||||||
|
\"promiseparameter\" or the arrow that follows it.
|
||||||
|
|
||||||
|
Finally, you can choose the amount of the indent.
|
||||||
|
|
||||||
|
The default is to anchor at promise, indent parameter name, and offset 0:
|
||||||
|
|
||||||
|
bundle agent rcfiles
|
||||||
|
{
|
||||||
|
files:
|
||||||
|
any::
|
||||||
|
\"/tmp/netrc\"
|
||||||
|
comment => \"my netrc\",
|
||||||
|
perms => mog(\"600\", \"tzz\", \"tzz\");
|
||||||
|
}
|
||||||
|
|
||||||
|
Here we anchor at beginning of line, indent arrow, and offset 10:
|
||||||
|
|
||||||
|
bundle agent rcfiles
|
||||||
|
{
|
||||||
|
files:
|
||||||
|
any::
|
||||||
|
\"/tmp/netrc\"
|
||||||
|
comment => \"my netrc\",
|
||||||
|
perms => mog(\"600\", \"tzz\", \"tzz\");
|
||||||
|
}
|
||||||
|
|
||||||
|
Some, including cfengine_stdlib.cf, like to anchor at promise, indent
|
||||||
|
arrow, and offset 16 or so:
|
||||||
|
|
||||||
|
bundle agent rcfiles
|
||||||
|
{
|
||||||
|
files:
|
||||||
|
any::
|
||||||
|
\"/tmp/netrc\"
|
||||||
|
comment => \"my netrc\",
|
||||||
|
perms => mog(\"600\", \"tzz\", \"tzz\");
|
||||||
|
}
|
||||||
|
"
|
||||||
|
|
||||||
|
:group 'cfengine
|
||||||
|
:type '(list
|
||||||
|
(choice (const :tag "Anchor at beginning of promise" promise)
|
||||||
|
(const :tag "Anchor at beginning of line" bol))
|
||||||
|
(choice (const :tag "Indent parameter name" pname)
|
||||||
|
(const :tag "Indent arrow" arrow))
|
||||||
|
(integer :tag "Indentation amount from anchor")))
|
||||||
|
|
||||||
(defvar cfengine-mode-debug nil
|
(defvar cfengine-mode-debug nil
|
||||||
"Whether `cfengine-mode' should print debugging info.")
|
"Whether `cfengine-mode' should print debugging info.")
|
||||||
|
|
||||||
@ -126,8 +190,8 @@ This includes those for cfservd as well as cfagent.")
|
|||||||
;; Defuns. This happens early so they don't get caught by looser
|
;; Defuns. This happens early so they don't get caught by looser
|
||||||
;; patterns.
|
;; patterns.
|
||||||
(,(concat "\\<" cfengine3-defuns-regex "\\>"
|
(,(concat "\\<" cfengine3-defuns-regex "\\>"
|
||||||
"[ \t]+\\<\\([[:alnum:]_]+\\)\\>"
|
"[ \t]+\\<\\([[:alnum:]_.:]+\\)\\>"
|
||||||
"[ \t]+\\<\\([[:alnum:]_:]+\\)"
|
"[ \t]+\\<\\([[:alnum:]_.:]+\\)"
|
||||||
;; Optional parentheses with variable names inside.
|
;; Optional parentheses with variable names inside.
|
||||||
"\\(?:(\\([^)]*\\))\\)?")
|
"\\(?:(\\([^)]*\\))\\)?")
|
||||||
(1 font-lock-builtin-face)
|
(1 font-lock-builtin-face)
|
||||||
@ -305,10 +369,10 @@ Intended as the value of `indent-line-function'."
|
|||||||
((looking-at (concat cfengine3-defuns-regex "\\>"))
|
((looking-at (concat cfengine3-defuns-regex "\\>"))
|
||||||
(indent-line-to 0))
|
(indent-line-to 0))
|
||||||
;; Categories are indented one step.
|
;; Categories are indented one step.
|
||||||
((looking-at (concat cfengine3-category-regex "[ \t]*$"))
|
((looking-at (concat cfengine3-category-regex "[ \t]*\\(#.*\\)*$"))
|
||||||
(indent-line-to cfengine-indent))
|
(indent-line-to cfengine-indent))
|
||||||
;; Class selectors are indented two steps.
|
;; Class selectors are indented two steps.
|
||||||
((looking-at (concat cfengine3-class-selector-regex "[ \t]*$"))
|
((looking-at (concat cfengine3-class-selector-regex "[ \t]*\\(#.*\\)*$"))
|
||||||
(indent-line-to (* 2 cfengine-indent)))
|
(indent-line-to (* 2 cfengine-indent)))
|
||||||
;; Outdent leading close brackets one step.
|
;; Outdent leading close brackets one step.
|
||||||
((or (eq ?\} (char-after))
|
((or (eq ?\} (char-after))
|
||||||
@ -333,7 +397,23 @@ Intended as the value of `indent-line-function'."
|
|||||||
;; plus 2. That way, promises indent deeper than class
|
;; plus 2. That way, promises indent deeper than class
|
||||||
;; selectors, which in turn are one deeper than categories.
|
;; selectors, which in turn are one deeper than categories.
|
||||||
((= 1 (nth 0 parse))
|
((= 1 (nth 0 parse))
|
||||||
(indent-line-to (* (+ 2 (nth 0 parse)) cfengine-indent)))
|
(let ((p-anchor (nth 0 cfengine-parameters-indent))
|
||||||
|
(p-what (nth 1 cfengine-parameters-indent))
|
||||||
|
(p-indent (nth 2 cfengine-parameters-indent)))
|
||||||
|
;; Do we have the parameter anchor and location and indent
|
||||||
|
;; defined, and are we looking at a promise parameter?
|
||||||
|
(if (and p-anchor p-what p-indent
|
||||||
|
(looking-at "\\([[:alnum:]_]+[ \t]*\\)=>"))
|
||||||
|
(let* ((arrow-offset (* -1 (length (match-string 1))))
|
||||||
|
(extra-offset (if (eq p-what 'arrow) arrow-offset 0))
|
||||||
|
(base-offset (if (eq p-anchor 'promise)
|
||||||
|
(* (+ 2 (nth 0 parse)) cfengine-indent)
|
||||||
|
0)))
|
||||||
|
(indent-line-to (max 0 (+ p-indent base-offset extra-offset))))
|
||||||
|
;; Else, indent to cfengine-indent times the nested depth
|
||||||
|
;; plus 2. That way, promises indent deeper than class
|
||||||
|
;; selectors, which in turn are one deeper than categories.
|
||||||
|
(indent-line-to (* (+ 2 (nth 0 parse)) cfengine-indent)))))
|
||||||
;; Inside brackets/parens: indent to start column of non-comment
|
;; Inside brackets/parens: indent to start column of non-comment
|
||||||
;; token on line following open bracket or by one step from open
|
;; token on line following open bracket or by one step from open
|
||||||
;; bracket's column.
|
;; bracket's column.
|
||||||
|
Loading…
Reference in New Issue
Block a user