Hi all,

First of all a big "thank you" to all you guys for developing Geany!

I use it for most of my source code editing nowadays, and was really
glad to find it after trying out (and rejecting) fat monsters like
kdevelop, kate or even Eclipse *horrors*.

Geany provides just the right amount of project integration for my
needs; that is to run "make" (cmake, automake). :-)

There are of course a few things which could be improved, but as a whole
it's a very fine little IDE. Thank you!

That said, I'm not a GUI-type of guy but more down to the command line,
so I would certainly not qualify as a Geany (that is: GTK+) developer.

On the other hand, I would still like to contribute somehow to the
project; at least a little bit.

And as I write a lot of scripts for various tasks (who doesn't), I
thought it might be a good idea to post some of them (which are
Geany-related) to this list.

Perhaps someone here also finds them useful!

On the other hand I do not want to flood this list with unwanted
contribitions. But I could not find a better place where to send them,
so I'll give it a try.

This is my first one - it does a very simple thing: It scans Geany's
configuration file and removes all MRU entries which refer to files
which don't exist any more.

I presume Geany should not run while this script is executed, or it
might write back the old MRU entries when it exits.

The reason for writing this script was that I frequently edit projects
which are then moved around in the directory tree. This creates "dead"
entries with the same basename as the new entries in the MRU lists,
because the old locations are still listed there. This can quickly get
confusing if there are like 3 entries for a single project, but only one
of them functional. This little script gets rid of the dead ones.

I have to apologize that the script is written in Lua rather than just a
shell script, but I'm just learning how to master this language and
therefore write as much as I can in it. ;-)

Anyway, Lua is one of the script language implementations with the
lowest disk space footprint; my total installation size here is only 1.6
megs! Compare this to Perl oder Python...

Greetings,

Guenther
#! /usr/bin/env lua
-- Remove stale MRU entries form "Geany"-editor's config file.
--
-- (c) 2010 by Guenther Brunthaler.
-- Distribution is permitted under the terms of the GPLv3.


local cfgfile= (
        os.getenv("XDG_CONFIG_HOME") or os.getenv("HOME") .. "/.config"
) .. '/geany/geany.conf'
local tmp= assert(io.tmpfile())
local in_section, k, v, valid, fh, nline
local removed= 0
local settings= 0
for line in io.lines(cfgfile) do
   if string.match(line, "^%s*%[%s*files%s*%]") then
      in_section= true
   end
   if in_section then
      k, v= string.match(line, "^%s*(recent_[_%w]+s)%s*=%s*(.-)%s*$")
      if k then
         valid= {}
         if not string.match(v, ";$") then
            v= v .. ";" -- Add terminator but avoid creating empty entries.
         end
         for s in string.gmatch(v, "([^;]*);") do
            if s == "" then
               fh= nil
            else
               fh= io.open(s, "rb")
               if fh then
                  table.insert(valid, s)
                  assert(fh:close())
               end
            end
            if not fh then
               removed= removed + 1
            end
         end
         table.insert(valid, "")
         nline= k .. "=" .. table.concat(valid, ";")
         if nline ~= line then
            settings= settings + 1
            line= nline
         end
      end
   end
   assert(tmp:write(line, "\n"))
end
assert(tmp:seek("set"))
--[[
   cfgfile= cfgfile .. ".new"
--]]
fh= assert(io.open(cfgfile, "w"))
for line in tmp:lines() do
   assert(fh:write(line, "\n"))
end
assert(fh:close())
assert(tmp:close())
print(
   string.format(
      'Removed %d entries from %d lines of "%s".', removed, settings, cfgfile
   )
)
_______________________________________________
Geany-devel mailing list
[email protected]
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel

Reply via email to