summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlutter <lutter@980ebf18-57e1-0310-9a29-db15c13687c0>2007-01-06 01:07:23 +0000
committerlutter <lutter@980ebf18-57e1-0310-9a29-db15c13687c0>2007-01-06 01:07:23 +0000
commitc35b44120684356bacc6d1e1c19cb202ad12bbc0 (patch)
treec51133bd6705745c60b70d4981c4cb5d59f839a6
parentf7d8350f97eeeb226d1d2c098452893537984107 (diff)
downloadpuppet-c35b44120684356bacc6d1e1c19cb202ad12bbc0.tar.gz
puppet-c35b44120684356bacc6d1e1c19cb202ad12bbc0.tar.xz
puppet-c35b44120684356bacc6d1e1c19cb202ad12bbc0.zip
Add indentation written by Mario Martelli
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2064 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--ext/emacs/puppet-mode.el47
1 files changed, 46 insertions, 1 deletions
diff --git a/ext/emacs/puppet-mode.el b/ext/emacs/puppet-mode.el
index a243204c1..472c386c0 100644
--- a/ext/emacs/puppet-mode.el
+++ b/ext/emacs/puppet-mode.el
@@ -89,6 +89,48 @@
(make-local-variable 'paragraph-ignore-fill-prefix)
(setq paragraph-ignore-fill-prefix t))
+(defun puppet-indent-line ()
+ "Indent current line as puppet code."
+ (interactive)
+ (beginning-of-line)
+ (if (bobp)
+ (indent-line-to 0) ; First line is always non-indented
+ (let ((not-indented t) cur-indent)
+ (if (looking-at "^.*}") ; If the line we are looking at is the end of a block, then decrease the indentation
+ (progn
+ (save-excursion
+ (forward-line -1)
+
+ (if (looking-at "^.*}")
+ (progn
+;; (setq cur-indent (current-indentation))
+ (setq cur-indent (- (current-indentation) 2))
+ (setq not-indented nil))
+ (setq cur-indent (- (current-indentation) 2))))
+ (if (< cur-indent 0) ; We can't indent past the left margin
+ (setq cur-indent 0)))
+ (save-excursion
+ (while not-indented ; Iterate backwards until we find an indentation hint
+ (forward-line -1)
+ (if (looking-at "^.*}") ; This hint indicates that we need to indent at the level of the END_ token
+ (progn
+ (setq cur-indent (current-indentation))
+ (setq not-indented nil))
+ (if (looking-at "^.*{") ; This hint indicates that we need to indent an extra level
+ (progn
+ (setq cur-indent (+ (current-indentation) 2)) ; Do the actual indenting
+ (setq not-indented nil))
+ (if (bobp)
+ (setq not-indented nil)))))))
+ (if cur-indent
+ (indent-line-to cur-indent)
+ (indent-line-to 0))))
+ (end-of-line)
+) ; If we didn't see an indentation hint, then allow no indentation
+
+
+
+
;;;###autoload
(defun puppet-mode ()
"Major mode for editing puppet manifests.
@@ -101,9 +143,12 @@ The variable puppet-indent-level controls the amount of indentation.
(setq mode-name "Puppet")
(setq major-mode 'puppet-mode)
(puppet-mode-variables)
-
+ ;; Register our indentation function
+ (set (make-local-variable 'indent-line-function) 'puppet-indent-line)
(run-hooks 'puppet-mode-hook))
+
+
(cond
((featurep 'font-lock)
(or (boundp 'font-lock-variable-name-face)