[Geany] New Templates?

John Gabriele jmg3000 at xxxxx
Wed Jul 18 18:32:20 UTC 2007


On 7/18/07, Enrico Tröger <enrico.troeger at uvena.de> wrote:
> On Wed, 18 Jul 2007 08:59:59 -0400, Lee Underwood <leeu at cfl.rr.com>
> wrote:
>
> > On Wed, 18 Jul 2007 12:24:09 +0100 Nick Treleaven
> > <nick.treleaven at btinternet.com> wrote:
> >
> > | On 07/17/2007 09:37:47 PM, Lee Underwood wrote:
> > | > Is it possible to create personal templates and have them show up
> > | > on the dropdown list under the "New" selection on the menu?
> > | >
> > | [snip]
> >
> > Actually, I don't mean filetype templates. I mean a template for a
> > page layout, e.g., a certain type of template for an article, one for
> > news..
>
> As Nick mentioned it isn't really possible at the moment. But it would
> be a good reason for another plugin ;-).
>

Here's a trick you might use: save the following script as
"article_template.py":

=== snip =================================
#!/usr/bin/env python

# Usage: Select one line in Geany that looks like this:
#
#     title text;subtitle text;author;date
#
# and pipe it through this script.

import sys
text = sys.stdin.read()

title, subtitle, author, date = text.split(';')

title_lines = (len(title) + 2) * '='
subtitle_underline = len(subtitle) * '-'

template = '''%(thick)s
 %(title)s
%(thick)s

%(subt)s
%(thin)s

:Author: %(a)s
:Date:   %(d)s

Article text goes here.
''' % {'thick': title_lines,
       'title': title,
       'subt':  subtitle,
       'thin':  subtitle_underline,
       'a':     author,
       'd':     date}

print template
=== /snip =================================

Make that script executable (``chmod +x article_template.py``) and
drop it into some bin directory on your $PATH.

Now go into Geany and do: "Edit --> Format --> Send selection to -->
Set custom commands". Set this script to be activated by, say, Ctrl-1
(just put the name of the script into the field provided).

Now open a file and write out the following line:

Foo Today;Do we really need more Foo?;J.R. Hacker;July 18, 2007

While on that line, hit Shift-Alt-L to select the line, then Ctrl-1 to
send it to article_template.py.

---John

P.S. -- to transform the resulting output to html, save the file (say,
as article.txt), and convert it to html like so:

rst2html article.txt > article.html

(You'll need to install python-docutils for this to work.)


More information about the Users mailing list