all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Indent goes to beginning of line
@ 2009-08-07 13:22 Paulo J. Matos
  2009-08-07 16:34 ` Ian Eure
  0 siblings, 1 reply; 3+ messages in thread
From: Paulo J. Matos @ 2009-08-07 13:22 UTC (permalink / raw)
  To: help-gnu-emacs

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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Indent goes to beginning of line
  2009-08-07 13:22 Indent goes to beginning of line Paulo J. Matos
@ 2009-08-07 16:34 ` Ian Eure
  2009-08-07 22:05   ` Paulo J. Matos
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Eure @ 2009-08-07 16:34 UTC (permalink / raw)
  To: Paulo J. Matos; +Cc: help-gnu-emacs

On Aug 7, 2009, at 6:22 AM, Paulo J. Matos wrote:

>
> 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.

> The function is as follows:
> (defun eventb-indent-line ()
>  "Indent current line as EventB code"
>  (interactive)
>  (beginning-of-line)
     ^^^^^^^^^^^^^^^

This isn't wrapped in save-excursion.

  - Ian




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Indent goes to beginning of line
  2009-08-07 16:34 ` Ian Eure
@ 2009-08-07 22:05   ` Paulo J. Matos
  0 siblings, 0 replies; 3+ messages in thread
From: Paulo J. Matos @ 2009-08-07 22:05 UTC (permalink / raw)
  To: Ian Eure; +Cc: help-gnu-emacs

On Fri, 2009-08-07 at 09:34 -0700, Ian Eure wrote:
> On Aug 7, 2009, at 6:22 AM, Paulo J. Matos wrote:
> 
> >
> > 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.
> 
> > The function is as follows:
> > (defun eventb-indent-line ()
> >  "Indent current line as EventB code"
> >  (interactive)
> >  (beginning-of-line)
>      ^^^^^^^^^^^^^^^
> 
> This isn't wrapped in save-excursion.
> 

You're right. Thanks! :)

>   - Ian





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-07 22:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-07 13:22 Indent goes to beginning of line Paulo J. Matos
2009-08-07 16:34 ` Ian Eure
2009-08-07 22:05   ` Paulo J. Matos

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.