From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Paulo J. Matos" Newsgroups: gmane.emacs.help Subject: Indent goes to beginning of line Date: Fri, 07 Aug 2009 14:22:51 +0100 Message-ID: <1249651371.16381.2.camel@drserver> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1249651410 4196 80.91.229.12 (7 Aug 2009 13:23:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 7 Aug 2009 13:23:30 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Aug 07 15:23:23 2009 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 1MZPPm-0002Vb-Qv for geh-help-gnu-emacs@m.gmane.org; Fri, 07 Aug 2009 15:23:23 +0200 Original-Received: from localhost ([127.0.0.1]:42920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MZPPj-0006tl-M4 for geh-help-gnu-emacs@m.gmane.org; Fri, 07 Aug 2009 09:23:19 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MZPPN-0006rP-4Z for help-gnu-emacs@gnu.org; Fri, 07 Aug 2009 09:22:57 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MZPPL-0006r5-Lf for help-gnu-emacs@gnu.org; Fri, 07 Aug 2009 09:22:55 -0400 Original-Received: from [199.232.76.173] (port=41443 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MZPPL-0006r2-HT for help-gnu-emacs@gnu.org; Fri, 07 Aug 2009 09:22:55 -0400 Original-Received: from ey-out-1920.google.com ([74.125.78.150]:64703) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MZPPL-0003e5-34 for help-gnu-emacs@gnu.org; Fri, 07 Aug 2009 09:22:55 -0400 Original-Received: by ey-out-1920.google.com with SMTP id 5so566423eyb.24 for ; Fri, 07 Aug 2009 06:22:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:content-type :date:message-id:mime-version:x-mailer:content-transfer-encoding; bh=nhtUPRxLLawI+MDrxI57CnyixhBNjKF03VSfegO07Qk=; b=DGBmtK4axrLJY1o5oljviiRvT5jPAgwC8oYKYwSlRjKHMYLF5jQBCGpXd1oicy+8jy x5em5LglIWM/rHY+XIIvWeG1XDxDNJHABkf6Jq419uGcGQrtzlP6HbRcWKVe0EEGmVl3 GWgBq7Nu6+TuKYtQEj4W/gBiaGEvnLp0/1TbM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; b=p3E1AhXOBcGdU5uvGcNlt1F6LBl7ym8yBHSsapot7esRnWVgvBjmCbeDETcZCkiDZt Rz4Ora3hF62D3XnzntXMrnpoqEoyGbL12qWwUadLuhXb+Tb42Zv02e7xddnNg6MM8RiA GDXyQBy/vYiSKch29haNXQ1CuTx98V34dCHpw= Original-Received: by 10.210.30.10 with SMTP id d10mr960913ebd.60.1249651373640; Fri, 07 Aug 2009 06:22:53 -0700 (PDT) Original-Received: from ?192.168.1.2? ([78.149.171.162]) by mx.google.com with ESMTPS id 5sm2851903eyh.16.2009.08.07.06.22.52 (version=SSLv3 cipher=RC4-MD5); Fri, 07 Aug 2009 06:22:53 -0700 (PDT) X-Mailer: Evolution 2.26.3 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:66932 Archived-At: Hi all, I implemented an indent function for a mode that I created. The function is as follows: (defun eventb-indent-line () "Indent current line as EventB code" (interactive) (beginning-of-line) (cond ((or (bobp) (looking-at "^[ \t]*End")) ;; Rule 1 (indent-line-to 0)) ((looking-at "^[ \t]*\\(Axioms\\|Constants\\|Contexts\\|Event\\| Extends\\|Initialisation\\|Invariants\\|Machine\\|Sees\\|Sets\\|\ \Theorems\\|Variables\\|Variants\\)") ;; Rule 2 (indent-line-to default-tab-width)) ((looking-at "^[ \t]*end") ; Rule 3 (let (cur-indent) (save-excursion (forward-line -1) (setq cur-indent (- (current-indentation) default-tab-width))) (indent-line-to cur-indent))) ((looking-at "^[ \t]*\\(any\\|when\\|where\\|then\\|status\ \)") ; Rule 4 (let ((not-indented t) cur-indent) (save-excursion (while not-indented (forward-line -1) (if (looking-at "^[ \t]*\\(Axioms\\|Constants\\|Contexts\ \|Event\\|Extends\\|Initialisation\\|Invariants\\|Machine\\|Sees\\|Sets\ \|\\Theorems\\|Variables\\|Variants\\)") (progn (setq cur-indent (+ (current-indentation) default-tab-width)) (setq not-indented nil)) (if (bobp) ;; Rule 5 (setq not-indented nil))))) (if cur-indent (indent-line-to cur-indent) (indent-line-to 0)))) (t (let (cur-indent) (save-excursion (forward-line -1) (if (or (looking-at "^[ \t]*\\(any\\|when\\|where\\|then\\| status\\)") (looking-at "^[ \t]*\\(Axioms\\|Constants\\| Contexts\\|Event\\|Extends\\|Initialisation\\|Invariants\\|Machine\\| Sees\\|Sets\\|\\Theorems\\|Variables\\|Variants\\)")) (setq cur-indent (+ (current-indentation) default-tab-width)) (setq cur-indent (current-indentation)))) (indent-line-to cur-indent))))) Interestingly enough, when I press to indent a line, the cursor instead of staying in the same place moves to the first character of the line, why is this? I thought save-excursion would avoid this from happening. Cheers, Paulo Matos