Article View: gnu.epoch.misc
Article #1750Re: indentation of fn declarations.
From: Lars Henrik Mathiesen
Date: Fri, 18 Oct 1991 02:31
Date: Fri, 18 Oct 1991 02:31
56 lines
2553 bytes
2553 bytes
haider@rice.edu (Haider Abbas Rizvi) writes:
> I want the first function after the macro and include declarations to be on
> the first column too as the rest of them are. Does anyone have any ideas as
> to what is causing this and a solution.
>I get the following,
>#include <stdio.h>
> void main()
>{
>}
>int panga()
>{
>}
The problem manifests itself when the first line of the file is a
preprocessor directive, and no directives with () or {} pairs exist
before the first top-level declaration.
Work-around: Put a blank line or comment first.
Even worse problem: If a first-line directive has blank space before
the #, an infinite loop occurs. The problem is with the function
c-backward-to-noncomment: it assumes that its limit argument points to
some sort of open-char, but it's called with (point-min). I append a
version that handles that case better (eliminating your problem).
Another way to get bad indentation: Put in a #define with ()'s that
does not _end_ with ), }, or ; (e.g., #define foo(s) 0) --- or one
with non-matching {/}. The culprit here is parse-partial-sexp, because
it doesn't ignore preprocessor lines (and that's much harder to fix).
--
Lars Mathiesen, DIKU, U of Copenhagen, Denmark [uunet!]mcsun!diku!thorinn
Warning: This article may contain unmarked humour. thorinn@diku.dk
;;; Fixed version of auxiliary c-mode function.
(defun c-backward-to-noncomment (lim)
(let (opoint stop)
(while (not stop)
(skip-chars-backward " \t\n\f" lim)
(setq opoint (point))
(if (and (>= (point) (+ 2 lim))
(save-excursion
(forward-char -2)
(looking-at "\\*/")))
(search-backward "/*" lim 'move)
(beginning-of-line)
(if (<= (point) lim)
(setq stop lim))
(save-excursion
(skip-chars-forward " \t")
(if (not (looking-at "#"))
(setq stop opoint)))))
(goto-char stop)))
Technical Details
Message-ID:
<1991Oct18.023134.16735@odin.diku.dk>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!news.funet.fi!sunic!dkuug!diku!thorinnReferences:
<9110160427.AA19118@phecda> <9110161946.AA16411@pi.rice.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc7ee,379b81911a975a44 X-Google-Attributes: gidfc7ee,public X-Google-ArrivalTime: 1991-10-18 06:52:26 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!news.funet.fi!sunic!dkuug!diku!thorinn From: thorinn@diku.dk (Lars Henrik Mathiesen) Newsgroups: gnu.epoch.misc Subject: Re: indentation of fn declarations. Message-ID: <1991Oct18.023134.16735@odin.diku.dk> Date: 18 Oct 91 02:31:34 GMT References: <9110160427.AA19118@phecda> <9110161946.AA16411@pi.rice.edu> Sender: thorinn@skinfaxe.diku.dk Distribution: gnu Organization: Department of Computer Science, U of Copenhagen Lines: 56