[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: my-calculate-indent function
From: |
Stefan Monnier |
Subject: |
Re: my-calculate-indent function |
Date: |
Mon, 16 Apr 2007 23:06:38 -0400 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.97 (gnu/linux) |
> i'm working on a major mode for a simple script language.
> blocks are enclosed in {}, and i wrote this function:
> (defun tintin-calculate-indent ()
> (let ((opened (count-matches "{" 0 (point)))
> (closed (count-matches "}" 0 (point))))
> (max 0
> (if (equal (char-after) 125)
> (* tintin-indentation-step (- (- opened closed) 1))
> (* tintin-indentation-step (- opened closed))))))
(nth 0 (syntax-ppss <pos>)) returns more or less (- opened closed).
Stefan
PS: In Emacs<22, parse-partial-sexp can give you that info instead of
syntax-ppss.