From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: my-calculate-indent function
Date: Mon, 16 Apr 2007 23:06:38 -0400 [thread overview]
Message-ID: <jwvirbvbt2l.fsf-monnier+gnu.emacs.help@gnu.org> (raw)
In-Reply-To: mailman.2156.1176768900.7795.help-gnu-emacs@gnu.org
> 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.
next parent reply other threads:[~2007-04-17 3:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.2156.1176768900.7795.help-gnu-emacs@gnu.org>
2007-04-17 3:06 ` Stefan Monnier [this message]
2007-04-20 2:21 ` my-calculate-indent function Tim X
2007-04-20 2:18 ` Tim X
2007-04-17 0:02 Pietro Giorgianni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvirbvbt2l.fsf-monnier+gnu.emacs.help@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).