From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Pietro Giorgianni Newsgroups: gmane.emacs.help Subject: my-calculate-indent function Date: Tue, 17 Apr 2007 02:02:41 +0200 Message-ID: <87odlnq34u.fsf@giorgian.widge.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1176768629 8030 80.91.229.12 (17 Apr 2007 00:10:29 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 17 Apr 2007 00:10:29 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Apr 17 02:10:23 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HdbH5-00019w-7k for geh-help-gnu-emacs@m.gmane.org; Tue, 17 Apr 2007 02:10:23 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HdbLk-0000qA-0v for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Apr 2007 20:15:12 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HdbLX-0000q3-3S for help-gnu-emacs@gnu.org; Mon, 16 Apr 2007 20:14:59 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HdbLW-0000pr-Mn for help-gnu-emacs@gnu.org; Mon, 16 Apr 2007 20:14:58 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HdbLW-0000pn-Hs for help-gnu-emacs@gnu.org; Mon, 16 Apr 2007 20:14:58 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HdbGq-0000aF-TS for help-gnu-emacs@gnu.org; Mon, 16 Apr 2007 20:10:09 -0400 Original-Received: from root by ciao.gmane.org with local (Exim 4.43) id 1HdbGk-0000VN-Cu for help-gnu-emacs@gnu.org; Tue, 17 Apr 2007 02:10:02 +0200 Original-Received: from host15-98-dynamic.10-87-r.retail.telecomitalia.it ([87.10.98.15]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 17 Apr 2007 02:10:02 +0200 Original-Received: from giorgian by host15-98-dynamic.10-87-r.retail.telecomitalia.it with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 17 Apr 2007 02:10:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 26 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: host15-98-dynamic.10-87-r.retail.telecomitalia.it User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.95 (gnu/linux) Cancel-Lock: sha1:eK/x5lXFXCuqol8MHhLg4we/GNU= X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:42741 Archived-At: hi, 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)))))) which works, but is ugly. questions: 1) is there already a function that does this? 2) if not, how can i do it better? thanks giorgian