aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Zlatanov2013-03-12 11:49:26 -0400
committerTed Zlatanov2013-03-12 11:49:26 -0400
commitca68a22e6473d24f3aaca3d5ad26b78fad256560 (patch)
treebf550e935897597d1e6d2b1e239615a019dbe981
parent48b9bb83f2bec3692800cf007e85c284ba7b77e8 (diff)
downloademacs-ca68a22e6473d24f3aaca3d5ad26b78fad256560.tar.gz
emacs-ca68a22e6473d24f3aaca3d5ad26b78fad256560.zip
* progmodes/cfengine.el: add CFEngine 3-specific indentation.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/progmodes/cfengine.el90
2 files changed, 92 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a1a75d2b5aa..3b5051155ef 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12013-03-12 Teodor Zlatanov <tzz@lifelogs.com>
2
3 * progmodes/cfengine.el (cfengine-parameters-indent): New variable
4 for CFEngine 3-specific indentation.
5 (cfengine3-indent-line): Use it. Fix up category regex.
6 (cfengine3-font-lock-keywords): Add bundle and namespace characters.
7
12013-03-12 Stefan Monnier <monnier@iro.umontreal.ca> 82013-03-12 Stefan Monnier <monnier@iro.umontreal.ca>
2 9
3 * type-break.el (type-break-file-name): 10 * type-break.el (type-break-file-name):
diff --git a/lisp/progmodes/cfengine.el b/lisp/progmodes/cfengine.el
index 3e022c01f4a..74b81b0cd01 100644
--- a/lisp/progmodes/cfengine.el
+++ b/lisp/progmodes/cfengine.el
@@ -58,6 +58,70 @@
58 :group 'cfengine 58 :group 'cfengine
59 :type 'integer) 59 :type 'integer)
60 60
61(defcustom cfengine-parameters-indent '(promise pname 0)
62 "*Indentation of CFEngine3 promise parameters (hanging indent).
63
64For example, say you have this code:
65
66bundle x y
67{
68 section:
69 class::
70 promise ...
71 promiseparameter => ...
72}
73
74You can choose to indent promiseparameter from the beginning of
75the line (absolutely) or from the word \"promise\" (relatively).
76
77You can also choose to indent the start of the word
78\"promiseparameter\" or the arrow that follows it.
79
80Finally, you can choose the amount of the indent.
81
82The default is to anchor at promise, indent parameter name, and offset 0:
83
84bundle agent rcfiles
85{
86 files:
87 any::
88 \"/tmp/netrc\"
89 comment => \"my netrc\",
90 perms => mog(\"600\", \"tzz\", \"tzz\");
91}
92
93Here we anchor at beginning of line, indent arrow, and offset 10:
94
95bundle agent rcfiles
96{
97 files:
98 any::
99 \"/tmp/netrc\"
100 comment => \"my netrc\",
101 perms => mog(\"600\", \"tzz\", \"tzz\");
102}
103
104Some, including cfengine_stdlib.cf, like to anchor at promise, indent
105arrow, and offset 16 or so:
106
107bundle agent rcfiles
108{
109 files:
110 any::
111 \"/tmp/netrc\"
112 comment => \"my netrc\",
113 perms => mog(\"600\", \"tzz\", \"tzz\");
114}
115"
116
117 :group 'cfengine
118 :type '(list
119 (choice (const :tag "Anchor at beginning of promise" promise)
120 (const :tag "Anchor at beginning of line" bol))
121 (choice (const :tag "Indent parameter name" pname)
122 (const :tag "Indent arrow" arrow))
123 (integer :tag "Indentation amount from anchor")))
124
61(defvar cfengine-mode-debug nil 125(defvar cfengine-mode-debug nil
62 "Whether `cfengine-mode' should print debugging info.") 126 "Whether `cfengine-mode' should print debugging info.")
63 127
@@ -126,8 +190,8 @@ This includes those for cfservd as well as cfagent.")
126 ;; Defuns. This happens early so they don't get caught by looser 190 ;; Defuns. This happens early so they don't get caught by looser
127 ;; patterns. 191 ;; patterns.
128 (,(concat "\\<" cfengine3-defuns-regex "\\>" 192 (,(concat "\\<" cfengine3-defuns-regex "\\>"
129 "[ \t]+\\<\\([[:alnum:]_]+\\)\\>" 193 "[ \t]+\\<\\([[:alnum:]_.:]+\\)\\>"
130 "[ \t]+\\<\\([[:alnum:]_:]+\\)" 194 "[ \t]+\\<\\([[:alnum:]_.:]+\\)"
131 ;; Optional parentheses with variable names inside. 195 ;; Optional parentheses with variable names inside.
132 "\\(?:(\\([^)]*\\))\\)?") 196 "\\(?:(\\([^)]*\\))\\)?")
133 (1 font-lock-builtin-face) 197 (1 font-lock-builtin-face)
@@ -305,10 +369,10 @@ Intended as the value of `indent-line-function'."
305 ((looking-at (concat cfengine3-defuns-regex "\\>")) 369 ((looking-at (concat cfengine3-defuns-regex "\\>"))
306 (indent-line-to 0)) 370 (indent-line-to 0))
307 ;; Categories are indented one step. 371 ;; Categories are indented one step.
308 ((looking-at (concat cfengine3-category-regex "[ \t]*$")) 372 ((looking-at (concat cfengine3-category-regex "[ \t]*\\(#.*\\)*$"))
309 (indent-line-to cfengine-indent)) 373 (indent-line-to cfengine-indent))
310 ;; Class selectors are indented two steps. 374 ;; Class selectors are indented two steps.
311 ((looking-at (concat cfengine3-class-selector-regex "[ \t]*$")) 375 ((looking-at (concat cfengine3-class-selector-regex "[ \t]*\\(#.*\\)*$"))
312 (indent-line-to (* 2 cfengine-indent))) 376 (indent-line-to (* 2 cfengine-indent)))
313 ;; Outdent leading close brackets one step. 377 ;; Outdent leading close brackets one step.
314 ((or (eq ?\} (char-after)) 378 ((or (eq ?\} (char-after))
@@ -333,7 +397,23 @@ Intended as the value of `indent-line-function'."
333 ;; plus 2. That way, promises indent deeper than class 397 ;; plus 2. That way, promises indent deeper than class
334 ;; selectors, which in turn are one deeper than categories. 398 ;; selectors, which in turn are one deeper than categories.
335 ((= 1 (nth 0 parse)) 399 ((= 1 (nth 0 parse))
336 (indent-line-to (* (+ 2 (nth 0 parse)) cfengine-indent))) 400 (let ((p-anchor (nth 0 cfengine-parameters-indent))
401 (p-what (nth 1 cfengine-parameters-indent))
402 (p-indent (nth 2 cfengine-parameters-indent)))
403 ;; Do we have the parameter anchor and location and indent
404 ;; defined, and are we looking at a promise parameter?
405 (if (and p-anchor p-what p-indent
406 (looking-at "\\([[:alnum:]_]+[ \t]*\\)=>"))
407 (let* ((arrow-offset (* -1 (length (match-string 1))))
408 (extra-offset (if (eq p-what 'arrow) arrow-offset 0))
409 (base-offset (if (eq p-anchor 'promise)
410 (* (+ 2 (nth 0 parse)) cfengine-indent)
411 0)))
412 (indent-line-to (max 0 (+ p-indent base-offset extra-offset))))
413 ;; Else, indent to cfengine-indent times the nested depth
414 ;; plus 2. That way, promises indent deeper than class
415 ;; selectors, which in turn are one deeper than categories.
416 (indent-line-to (* (+ 2 (nth 0 parse)) cfengine-indent)))))
337 ;; Inside brackets/parens: indent to start column of non-comment 417 ;; Inside brackets/parens: indent to start column of non-comment
338 ;; token on line following open bracket or by one step from open 418 ;; token on line following open bracket or by one step from open
339 ;; bracket's column. 419 ;; bracket's column.