summaryrefslogtreecommitdiffstats
path: root/computer/gedit-changelog-line-snippet.rst
blob: 1891cfeece02df71edb73d468ffa21e4dfc1193c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
gedit snippet generating RPM spec %changelog line
#################################################

:date: 2015-08-01T00:26:00
:category: computer
:tags: gedit, Fedora

I have done a little bit of work to make gedit fully working in
RHEL-7 (appropriate packages with almost all my fixes will be
most likely available in the next minor release of RHEL-7).
Generally my feeling is that gedit is a way less powerful (and
writing Python plugins more complicated) than the similar stuff
in vim. However, there are some things which are shockingly
powerful. One of the things which quite surprised me are
snippets_. They are **a way more** powerful than just simple text
replacements. With this functionality I can create even something
so crazy as this snippet generating ``%changelog`` line in the
RPM spec files.::

    $<
    import rpm
    import datetime

    spec = rpm.spec($GEDIT_CURRENT_DOCUMENT_PATH)
    date = datetime.date.today().strftime("%a %b %d %Y")
    headers = spec.packages[0].header
    version = headers['Version']
    release = ".".join(headers['Release'].split(".")[:-1])
    packager = headers['Packager']
    newheader = "* %s %s - %s-%s\n- " % (date, packager, version, release)
    return newheader
    >

To install this snippet, open ``Manage Snippets..`` in the gedit
application menu and in the ``RPM Spec`` section create a new snippet and copy the code above to the text box on the right side. Give to this snippet some TAB trigger (I have ``chi`` there) or a key shortcut and be done. Then activate this snippet in the top of the ``%changelog`` section.

.. _snippets:
    https://wiki.gnome.org/Apps/Gedit/Plugins/Snippets