[Libreoffice] [SCRIPT, EASYHACK] "add-modelines", a script to add modelines to source files

jesse at boldandbusted.com jesse at boldandbusted.com
Sun Oct 10 01:27:09 PDT 2010

On Sun, 10 Oct 2010 01:15 -0700, someone at boldandbusted.com wrote:
> On Sat, 09 Oct 2010 20:24 +0100, "Caolán McNamara" <caolanm at redhat.com>
> wrote:
> > On Sat, 2010-10-09 at 11:41 -0700, someone at boldandbusted.com wrote:
> > > Howdy, all. It took some effort for this SysAdmin to craft a shell
> > > script to meet this "EasyHack",
> > 
> > The principal looks good. Here's a edge-case test file though, e.g.
> > 
> > writer/sw/source/filter/ww8/ww8atr.cxx
> > 
> > it already has a "/* vi:"... modeline at the bottom, so maybe best thing
> > is to detect and remove conflicting modelines. Though there's so few of
> > them, they could be handled manually, so its no biggy.
> > 
> > C.
> > 
> > 
> Hi Caolán,
> One thing that is stinky about this edge case is that the Emacs(?)
> modeline is actually in the *middle* of the file (after the first
> #include). Not sure what to do about that, since it is pretty expensive
> to actually search every part of every file, versus only search the top
> line and bottom line as add-modelines does now. But, based on your
> comment, I don't think I'll spend too much effort on dealing with that
> since it appears to be a quick manual fix.
> I'm almost ready to submit the next version of the script. It'll have
> arguments that can be specified to:
> * Set the top-level directory to search (-p <sourcecode path>)
> * Wipe out existing modelines (or not) (-z)
> * Specify filetype via any number of *.<suffix> (-s <file glob>)
> Also, if none are specified, it'll use defaults that are the same as the
> previous version (don't zap existing modelines, decscend down from the
> cwd, change *.cxx and *.cpp).
> So, for example you could do this:
> ./add-modelines -z -p LibreOffice-source/ -s *.cxx *.hxx *.h
> and existing modelines would be replaced, the path would be
> ./LibreOffice-source/, and the file types would be *.cxx, *.hxx and *.h
> .
> All functions work, generally, though I'm working through a bug that,
> interestingly enough, added a second modeline to the bottom of this
> particular edge-case file, rather than replacing it as I asked. Once
> that bug is quashed, I'll post the updated script to this list.
> Cheers,
> Jesse Adelman
> San Francisco, CA
> Bold and Busted LLC
> http://www.boldandbusted.com/
> _______________________________________________
> LibreOffice mailing list
> LibreOffice at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/libreoffice

Ah, and now I see why add-modelines messed up the last line.
add-modelines checks the first 6 characters of the line to determine if
there's a modeline present. It uses the beginning of the to-be-set
modeline to determine the answer to "what is a modeline?". However, that
line in your edge-case has "vi:set", rather than "vim:set", so
add-modeline didn't see it. I hope that this edge case doesn't have
lurking partners in crime elsewhere in the codebase. I suppose I should
start some urgent grepping to see?

I'll have to consider whether that's worth lowering the check to 5 and
risk picking up comments as modeline "false-positives", or just ask you
to change those by hand before running the script. ;)


Jesse Adelman
San Francisco, CA
Bold and Busted LLC

More information about the LibreOffice mailing list