From: "Paulo J. Matos" <pocmatos@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Indent goes to beginning of line
Date: Fri, 07 Aug 2009 14:22:51 +0100 [thread overview]
Message-ID: <1249651371.16381.2.camel@drserver> (raw)
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 <tab> 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
next reply other threads:[~2009-08-07 13:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-07 13:22 Paulo J. Matos [this message]
2009-08-07 16:34 ` Indent goes to beginning of line Ian Eure
2009-08-07 22:05 ` Paulo J. Matos
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1249651371.16381.2.camel@drserver \
--to=pocmatos@gmail.com \
--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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.