help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modify indention for C/C++


From: Emanuel Berg
Subject: Re: Modify indention for C/C++
Date: Wed, 11 Jun 2014 17:07:49 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Florian Lindner <mailinglists@xgm.de> writes:

> what is the canonical way to modify indention for
> certain keywords? I've found numerous ways in the
> internets. I want to change the linux style so, that
> is does not do indention for namespaces.

I wrote a major mode [1] some times back (with a little
help from my friends, as always) and I remember I
wanted to have indentation just like in C because the
syntax was sort of, but not quite, as C.

So I wrote the following defun - perhaps it can be of
value to you:

(defun fpscalc-indent-line ()
  "Indentation function."
  (interactive)
  (beginning-of-line)
  (if (bobp) (indent-line-to 0)
    (let ((not-indented t)
          (cur-indent   0)
          (indent-unit  2))
      (if (looking-at "^[ \t]*}")
          (progn
            (save-excursion
              (forward-line -1)
              (setq cur-indent (- (current-indentation) indent-unit) ))
            (if (< cur-indent 0) (setq cur-indent 0)) )
        (save-excursion
          (while not-indented
            (forward-line -1)
            (if (looking-at "^[ \t]*}")
                (progn
                  (setq cur-indent (current-indentation))
                  (setq not-indented nil) )
              (if (looking-at "^[ 
\t]*\\(system\\|declarations\\|semaphores\\|initialise\\|formulas\\)")
                  (progn
                    (setq cur-indent (+ (current-indentation) indent-unit))
                    (setq not-indented nil) )
                (if (bobp) (setq not-indented nil) ))))))
      (indent-line-to cur-indent) )))

Then somewhere:

(setq indent-line-function 'fpscalc-indent-line)

[1] project:  http://user.it.uu.se/~embe8573/fps/
    code:     http://user.it.uu.se/~embe8573/fps/fpscalc.el

-- 
underground experts united:
http://user.it.uu.se/~embe8573


reply via email to

[Prev in Thread] Current Thread [Next in Thread]