all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
To: help-gnu-emacs@gnu.org
Subject: Re: Modify indention for C/C++
Date: Wed, 11 Jun 2014 17:07:49 +0200	[thread overview]
Message-ID: <87a99jscvu.fsf@debian.uxu> (raw)
In-Reply-To: mailman.3406.1402493094.1147.help-gnu-emacs@gnu.org

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	other threads:[~2014-06-11 15:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.3406.1402493094.1147.help-gnu-emacs@gnu.org>
2014-06-11 15:07 ` Emanuel Berg [this message]
2014-06-11 13:24 Modify indention for C/C++ Florian Lindner
2014-06-11 13:31 ` Florian Lindner
2014-06-12  6:59   ` Kevin Rodgers
2014-06-11 13:42 ` Teemu Likonen
2014-06-11 14:23   ` Florian Lindner

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=87a99jscvu.fsf@debian.uxu \
    --to=embe8573@student.uu.se \
    --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.