~ubuntu-branches/debian/sid/geany-plugins/sid

« back to all changes in this revision

Viewing changes to addons/src/ao_blanklines.c

  • Committer: Bazaar Package Importer
  • Author(s): Evgeni Golov, Chow Loong Jin, Evgeni Golov
  • Date: 2010-09-04 23:05:00 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100904230500-4n99m507u6drouv5
Tags: 0.19-1
[ Chow Loong Jin ]
* New upstream release
  + Builds against geany 0.19 (Closes: #590346, #587141)
* debian/control, debian/rules:
  + Shift geany dependency to geany-plugins-common instead, since it's a
    common dependency for all plugins
* debian/control:
  + Add new packages for codenav, extrasel, gendoc, insertnum,
    prettyprinter and treebrowser plugins
  + Update build-deps:
    - Bump geany dependency to 0.19. (Closes: #573318)
    - Add libctpl-dev and python-docutils for geanygendoc
    - Add libxml2-dev for prettyprinter
  + No-change bump of Standards-Version from 3.8.3 to 3.9.0
  + Tighten dependency on geany-plugins-common (= instead of >=)
  + Add a Breaks on all geany-plugin-* packages prior to this version to
    ensure geany-plugins-common and geany-plugin-* versions match
* debian/geany-plugin-codenav.{docs,install},
  debian/geany-plugin-extrasel.{docs,install},
  geany-plugin-gendoc.{docs,install},
  geany-plugin-insertnum.{docs,install},
  geany-plugin-prettyprinter.install
  geany-plugin-treebrowser.{docs,install}:
  + Install plugin files into individual packages

[ Evgeni Golov ]
* debian/control:
  + Disable the new plugins for now.
    If you want to build them localy, just uncomment them.
  + Don't D-B on libctpl-dev (it's not in Debian yet).
  + Add myself to Uploaders.
  + Standards-Version: 3.9.1
* debian/copyright:
  + Update to include latest plugins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *                      ao_blanklines.c - this file is part of Addons, a Geany plugin
 
3
 *
 
4
 *                      Copyright 2009 Eugene Arshinov <earshinov@gmail.com>
 
5
 *
 
6
 *                      This program is free software; you can redistribute it and/or modify
 
7
 *                      it under the terms of the GNU General Public License as published by
 
8
 *                      the Free Software Foundation; either version 2 of the License, or
 
9
 *                      (at your option) any later version.
 
10
 *
 
11
 *                      This program is distributed in the hope that it will be useful,
 
12
 *                      but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *                      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
 
14
 *                      GNU General Public License for more details.
 
15
 *
 
16
 *                      You should have received a copy of the GNU General Public License
 
17
 *                      along with this program; if not, write to the Free Software
 
18
 *                      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
19
 *                      MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#include "geanyplugin.h"
 
23
 
 
24
#include "addons.h"
 
25
#include "ao_blanklines.h"
 
26
 
 
27
static gboolean enabled = FALSE;
 
28
 
 
29
static void editor_strip_trailing_newlines(GeanyEditor *editor)
 
30
{
 
31
        const gint maxline = sci_get_line_count(editor->sci) - 1;
 
32
        const gint maxpos = sci_get_line_end_position(editor->sci, maxline);
 
33
 
 
34
        gint line, start, end, pos;
 
35
        gchar ch;
 
36
 
 
37
        /*
 
38
         * Store index of the last non-empty line in `line' and position of the first
 
39
         * of its trailing spaces in `pos'. If all lines are empty, `line' will
 
40
         * contain -1, and `pos' will be undefined. If `line' does not contain
 
41
         * trailing spaces, `pos' will be its end position.
 
42
         */
 
43
        for (line = maxline; line >= 0; line--)
 
44
        {
 
45
                start = sci_get_position_from_line(editor->sci, line);
 
46
                end = sci_get_line_end_position(editor->sci, line);
 
47
 
 
48
                /*
 
49
                 * We can't be sure that `geany_data->file_prefs->strip_trailing_spaces'
 
50
                 * setting is set, so we should check for trailing spaces manually.
 
51
                 * Performance overhead of the for loop below is very small anyway,
 
52
                 * so it does not worth checking the setting manually and writing
 
53
                 * additional code.
 
54
                 */
 
55
 
 
56
                for (pos = end-1; pos >= start; pos--)
 
57
                {
 
58
                        ch = sci_get_char_at(editor->sci, pos);
 
59
                        if (ch != ' ' && ch != '\t')
 
60
                                break;
 
61
                }
 
62
                ++pos;
 
63
                if (pos > start)
 
64
                        break;
 
65
        }
 
66
 
 
67
        if (line == -1 || geany_data->file_prefs->final_new_line)
 
68
        {
 
69
                /* leave one newline */
 
70
                line++;
 
71
                pos = sci_get_position_from_line(editor->sci, line);
 
72
        }
 
73
 
 
74
        if (pos < maxpos)
 
75
        {
 
76
                /* there are some lines to be removed */
 
77
                sci_set_target_start(editor->sci, pos);
 
78
                sci_set_target_end(editor->sci, maxpos);
 
79
                sci_replace_target(editor->sci, "", FALSE);
 
80
        }
 
81
}
 
82
 
 
83
void ao_blanklines_set_enable(gboolean enabled_)
 
84
{
 
85
        enabled = enabled_;
 
86
}
 
87
 
 
88
void ao_blanklines_on_document_before_save(GObject *object, GeanyDocument *doc, gpointer data)
 
89
{
 
90
        if (enabled)
 
91
                editor_strip_trailing_newlines(doc->editor);
 
92
}