[Emacs] Allow haml-indent-function to be more powerful.

This commit is contained in:
Nathan Weizenbaum 2009-03-06 11:04:45 -08:00
parent 0e5c7e1c97
commit 317e2dd787
2 changed files with 12 additions and 6 deletions

View File

@ -55,8 +55,11 @@ line itself."
:group 'haml) :group 'haml)
(defvar haml-indent-function 'haml-indent-p (defvar haml-indent-function 'haml-indent-p
"This function should look at the current line and return true "This function should look at the current line and return t
if the next line could be nested within this line.") if the next line could be nested within this line.
The function can also return a positive integer to indicate
a specific level to which the current line could be indented.")
(defvar haml-block-openers (defvar haml-block-openers
`("^ *\\([%\\.#][^ \t]*\\)\\(\\[.*\\]\\)?\\({.*}\\)?\\(\\[.*\\]\\)?[ \t]*$" `("^ *\\([%\\.#][^ \t]*\\)\\(\\[.*\\]\\)?\\({.*}\\)?\\(\\[.*\\]\\)?[ \t]*$"
@ -387,7 +390,7 @@ character of the next line."
;; Indentation and electric keys ;; Indentation and electric keys
(defun haml-indent-p () (defun haml-indent-p ()
"Returns true if the current line can have lines nested beneath it." "Returns t if the current line can have lines nested beneath it."
(loop for opener in haml-block-openers (loop for opener in haml-block-openers
if (looking-at opener) return t if (looking-at opener) return t
finally return nil)) finally return nil))
@ -399,8 +402,11 @@ character of the next line."
(if (bobp) 0 (if (bobp) 0
(haml-forward-through-whitespace t) (haml-forward-through-whitespace t)
(+ (current-indentation) (+ (current-indentation)
(if (funcall haml-indent-function) haml-indent-offset (let ((indent (funcall haml-indent-function)))
0))))) (cond
((integerp indent) indent)
(indent haml-indent-offset)
(t 0)))))))
(defun haml-indent-region (start end) (defun haml-indent-region (start end)
"Indent each nonblank line in the region. "Indent each nonblank line in the region.

View File

@ -85,7 +85,7 @@ text nested beneath them.")
;; Indentation ;; Indentation
(defun sass-indent-p () (defun sass-indent-p ()
"Returns true if the current line can have lines nested beneath it." "Returns t if the current line can have lines nested beneath it."
(loop for opener in sass-non-block-openers (loop for opener in sass-non-block-openers
unless (looking-at opener) return t unless (looking-at opener) return t
return nil)) return nil))