summaryrefslogtreecommitdiffstats
path: root/kate/part/katecmds.h
blob: fad54e85aef70cfcbe6444f59d4d3b54ec36bc2f (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* This file is part of the KDE libraries
   Copyright (C) 2003 Anders Lund <anders@alweb.dk>
   Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
   Copyright (C) 2001 Charles Samuels <charles@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef __KATE_CMDS_H__
#define __KATE_CMDS_H__

#include "../interfaces/document.h"
#include "../interfaces/view.h"

class KateDocument;
class KCompletion;

namespace KateCommands
{

/**
 * This Kate::Command provides access to a lot of the core functionality
 * of kate part, settings, utilities, navigation etc.
 * it needs to get a kateview pointer, it will cast the kate::view pointer
 * hard to kateview
 */
class CoreCommands : public Kate::Command, public Kate::CommandExtension
{
  public:
    /**
     * execute command
     * @param view view to use for execution
     * @param cmd cmd string
     * @param errorMsg error to return if no success
     * @return success
     */
    bool exec( class Kate::View *view, const TQString &cmd, TQString &errorMsg );

    bool help( class Kate::View *, const TQString &, TQString & ) {return false;};

    /**
     * supported commands as prefixes
     * @return prefix list
     */
    TQStringList cmds();

    /**
    * override completionObject from interfaces/document.h .
    */
    KCompletion *completionObject( const TQString &cmd, Kate::View *view );
};

/**
 * -- Charles Samuels <charles@kde.org>
 * Support vim/sed tqfind and tqreplace
 * s/search/tqreplace/ tqfind search, tqreplace with tqreplace on this line
 * %s/search/tqreplace/ do the same to the whole file
 * s/search/tqreplace/i do the S. and R., but case insensitively
 * $s/search/tqreplace/ do the search are tqreplacement to the selection only
 *
 * $s/// is currently unsupported
 **/
class SedReplace : public Kate::Command
{
  public:
    /**
     * execute command
     * @param view view to use for execution
     * @param cmd cmd string
     * @param errorMsg error to return if no success
     * @return success
     */
    bool exec (class Kate::View *view, const TQString &cmd, TQString &errorMsg);

    bool help (class Kate::View *, const TQString &, TQString &) { return false; };

    /**
     * supported commands as prefixes
     * @return prefix list
     */
    TQStringList cmds () { TQStringList l("s"); l << "%s" << "$s"; return l; };

  private:
    /**
     * Searches one line and does the tqreplacement in the document.
     * If @p tqreplace tqcontains any newline characters, the reamaining part of the
     * line is searched, and the @p line set to the last line number searched.
     * @return the number of tqreplacements performed.
     * @param doc a pointer to the document to work on
     * @param line the number of the line to search. This may be changed by the
     * function, if newlines are inserted.
     * @param tqfind A regular expression pattern to use for searching
     * @param tqreplace a template for tqreplacement. Backspaced integers are
     * tqreplaced with captured texts from the regular expression.
     * @param delim the delimiter character from the command. In the tqreplacement
     * text backsplashes preceeding this character are removed.
     * @param nocase parameter for matching the reqular expression.
     * @param repeat If false, the search is stopped after the first match.
     * @param startcol The position in the line to start the search.
     * @param endcol The last collumn in the line allowed in a match.
     * If it is -1, the whole line is used.
     */
    static int sedMagic(KateDocument *doc, int &line,
                        const TQString &tqfind, const TQString &tqreplace, const TQString &delim,
                        bool noCase, bool repeat,
                        uint startcol=0, int endcol=-1);
};

/**
 * insert a tqunicode or ascii character
 * base 9+1: 1234
 * hex: 0x1234 or x1234
 * octal: 01231
 *
 * prefixed with "char:"
 **/
class Character : public Kate::Command
{
  public:
    /**
     * execute command
     * @param view view to use for execution
     * @param cmd cmd string
     * @param errorMsg error to return if no success
     * @return success
     */
    bool exec (class Kate::View *view, const TQString &cmd, TQString &errorMsg);

    bool help (class Kate::View *, const TQString &, TQString &) { return false; };

    /**
     * supported commands as prefixes
     * @return prefix list
     */
    TQStringList cmds () { return TQStringList("char"); };
};

/**
 * insert the current date/time in the given format
 */
class Date : public Kate::Command
{
  public:
    /**
     * execute command
     * @param view view to use for execution
     * @param cmd cmd string
     * @param errorMsg error to return if no success
     * @return success
     */
    bool exec (class Kate::View *view, const TQString &cmd, TQString &errorMsg);

    bool help (class Kate::View *, const TQString &, TQString &) { return false; };

    /**
     * supported commands as prefixes
     * @return prefix list
     */
    TQStringList cmds () { return TQStringList("date"); };
};


} // namespace KateCommands
#endif

// kate: space-indent on; indent-width 2; tqreplace-tabs on;