• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Kate

  • kde-4.14
  • applications
  • kate
  • part
  • utils
katecmds.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries and the Kate part.
2  *
3  * Copyright (C) 2003-2005 Anders Lund <anders@alweb.dk>
4  * Copyright (C) 2001-2010 Christoph Cullmann <cullmann@kde.org>
5  * Copyright (C) 2001 Charles Samuels <charles@kde.org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #include "katecmds.h"
24 
25 #include "katedocument.h"
26 #include "kateview.h"
27 #include "kateconfig.h"
28 #include "kateautoindent.h"
29 #include "katetextline.h"
30 #include "katesyntaxmanager.h"
31 #include "kateglobal.h"
32 #include "kateviglobal.h"
33 #include "katevinormalmode.h"
34 #include "katerenderer.h"
35 #include "kateviemulatedcommandbar.h"
36 #include "katecmd.h"
37 
38 #include <kdebug.h>
39 #include <klocale.h>
40 #include <kurl.h>
41 #include <kshellcompletion.h>
42 
43 #include <QDir>
44 #include <QtCore/QRegExp>
45 
46 //BEGIN CoreCommands
47 KateCommands::CoreCommands* KateCommands::CoreCommands::m_instance = 0;
48 
49 // this returns wheather the string s could be converted to
50 // a bool value, one of on|off|1|0|true|false. the argument val is
51 // set to the extracted value in case of success
52 static bool getBoolArg( const QString &t, bool *val )
53 {
54  bool res( false );
55  QString s = t.toLower();
56  res = (s == "on" || s == "1" || s == "true");
57  if ( res )
58  {
59  *val = true;
60  return true;
61  }
62  res = (s == "off" || s == "0" || s == "false");
63  if ( res )
64  {
65  *val = false;
66  return true;
67  }
68  return false;
69 }
70 
71 const QStringList &KateCommands::CoreCommands::cmds()
72 {
73  static QStringList l;
74 
75  if (l.isEmpty())
76  l << "indent" << "unindent" << "cleanindent" << "fold" << "tfold" << "unfold"
77  << "comment" << "uncomment" << "goto" << "kill-line"
78  << "set-tab-width" << "set-replace-tabs" << "set-show-tabs"
79  << "set-indent-width"
80  << "set-indent-mode" << "set-auto-indent"
81  << "set-line-numbers" << "set-folding-markers" << "set-icon-border"
82  << "set-indent-pasted-text" << "set-word-wrap" << "set-word-wrap-column"
83  << "set-replace-tabs-save" << "set-remove-trailing-spaces"
84  << "set-highlight" << "set-mode" << "set-show-indent"
85  << "print";
86 
87  return l;
88 }
89 
90 bool KateCommands::CoreCommands::help(KTextEditor::View *, const QString &cmd, QString &msg)
91 {
92  QString realcmd=cmd.trimmed();
93  if (realcmd=="indent") {
94  msg=i18n("<p>indent</p>"
95  "<p>Indents the selected lines or the current line</p>");
96  return true;
97  } else if (realcmd=="unindent") {
98  msg=i18n("<p>unindent</p>"
99  "<p>Unindents the selected lines or current line.</p>");
100  return true;
101  } else if (realcmd=="cleanindent") {
102  msg=i18n("<p>cleanindent</p>"
103  "<p>Cleans up the indentation of the selected lines or current line according to the indentation settings in the document. </p>");
104  return true;
105  } else if (realcmd=="comment") {
106  msg=i18n("<p>comment</p>"
107  "<p>Inserts comment markers to make the selection or selected lines or current line a comment according to the text format as defined by the syntax highlight definition for the document.</p>");
108  return true;
109  } else if (realcmd=="uncomment") {
110  msg=i18n("<p>uncomment</p>"
111  "<p>Removes comment markers from the selection or selected lines or current line according to the text format as defined by the syntax highlight definition for the document.</p>");
112  return true;
113  } else if (realcmd=="goto") {
114  msg=i18n("<p>goto <b>line number</b></p>"
115  "<p>This command navigates to the specified line number.</p>");
116  return true;
117  } else if (realcmd=="set-indent-pasted-text") {
118  msg=i18n("<p>set-indent-pasted-text <b>enable</b></p>"
119  "<p>If enabled, indentation of text pasted from the clipboard is adjusted using the current indenter.</p>"
120  "<p>Possible true values: 1 on true<br/>"
121  "possible false values: 0 off false</p>");
122  return true;
123  } else if (realcmd=="kill-line") {
124  msg=i18n("Deletes the current line.");
125  return true;
126  } else if (realcmd=="set-tab-width") {
127  msg=i18n("<p>set-tab-width <b>width</b></p>"
128  "<p>Sets the tab width to the number <b>width</b></p>");
129  return true;
130  } else if (realcmd=="set-replace-tab") {
131  msg=i18n("<p>set-replace-tab <b>enable</b></p>"
132  "<p>If enabled, tabs are replaced with spaces as you type.</p>"
133  "<p>Possible true values: 1 on true<br/>"
134  "possible false values: 0 off false</p>");
135  return true;
136  } else if (realcmd=="set-show-tabs") {
137  msg=i18n("<p>set-show-tabs <b>enable</b></p>"
138  "<p>If enabled, TAB characters and trailing whitespace will be visualized by a small dot.</p>"
139  "<p>Possible true values: 1 on true<br/>"
140  "possible false values: 0 off false</p>");
141  return true;
142  } else if (realcmd=="set-remove-trailing-spaces") {
143  msg=i18n("<p>set-remove-trailing-spaces <b>mode</b></p>"
144  "<p>Removes the trailing spaces in the document depending on the <b>mode</b>.</p>"
145  "<p>Possible values:"
146  "<ul>"
147  "<li><b>none</b>: never remove trailing spaces.</li>"
148  "<li><b>modified</b>: remove trailing spaces only of modified lines.</li>"
149  "<li><b>all</b>: remove trailing spaces in the entire document.</li>"
150  "</ul></p>");
151  return true;
152  } else if (realcmd=="set-indent-width") {
153  msg=i18n("<p>set-indent-width <b>width</b></p>"
154  "<p>Sets the indentation width to the number <b>width</b>. Used only if you are indenting with spaces.</p>");
155  return true;
156  } else if (realcmd=="set-indent-mode") {
157  msg=i18n("<p>set-indent-mode <b>mode</b></p>"
158  "<p>The mode parameter is a value as seen in the Tools - Indentation menu</p>");
159  return true;
160  } else if (realcmd=="set-auto-indent") {
161  msg=i18n("<p>set-auto-indent <b>enable</b></p>"
162  "<p>Enable or disable autoindentation.</p>"
163  "<p>possible true values: 1 on true<br/>"
164  "possible false values: 0 off false</p>");
165  return true;
166  } else if (realcmd=="set-line-numbers") {
167  msg=i18n("<p>set-line-numbers <b>enable</b></p>"
168  "<p>Sets the visibility of the line numbers pane.</p>"
169  "<p> possible true values: 1 on true<br/>"
170  "possible false values: 0 off false</p>");
171  return true;
172  } else if (realcmd=="set-folding-markers") {
173  msg=i18n("<p>set-folding-markers <b>enable</b></p>"
174  "<p>Sets the visibility of the folding markers pane.</p>"
175  "<p> possible true values: 1 on true<br/>"
176  "possible false values: 0 off false</p>");
177  return true;
178  } else if (realcmd=="set-icon-border") {
179  msg=i18n("<p>set-icon-border <b>enable</b></p>"
180  "<p>Sets the visibility of the icon border.</p>"
181  "<p> possible true values: 1 on true<br/>"
182  "possible false values: 0 off false</p>");
183  return true;
184  } else if (realcmd=="set-word-wrap") {
185  msg=i18n("<p>set-word-wrap <b>enable</b></p>"
186  "<p>Enables dynamic word wrap according to <b>enable</b></p>"
187  "<p> possible true values: 1 on true<br/>"
188  "possible false values: 0 off false</p>");
189  return true;
190  } else if (realcmd=="set-word-wrap-column") {
191  msg=i18n("<p>set-word-wrap-column <b>width</b></p>"
192  "<p>Sets the line width for hard wrapping to <b>width</b>. This is used if you are having your text wrapped automatically.</p>");
193  return true;
194  } else if (realcmd=="set-replace-tabs-save") {
195  msg=i18n("<p>set-replace-tabs-save <b>enable</b></p>"
196  "<p>When enabled, tabs will be replaced with whitespace whenever the document is saved.</p>"
197  "<p> possible true values: 1 on true<br/>"
198  "possible false values: 0 off false</p>");
199  return true;
200  } else if (realcmd=="set-highlight") {
201  msg=i18n("<p>set-highlight <b>highlight</b></p>"
202  "<p>Sets the syntax highlighting system for the document. The argument must be a valid highlight name, as seen in the Tools → Highlighting menu. This command provides an autocompletion list for its argument.</p>");
203  return true;
204  } else if (realcmd=="set-mode") {
205  msg=i18n("<p>set-mode <b>mode</b></p>"
206  "<p>Sets the mode as seen in Tools - Mode</p>");
207  return true;
208  } else if (realcmd=="set-show-indent") {
209  msg=i18n("<p>set-show-indent <b>enable</b></p>"
210  "<p>If enabled, indentation will be visualized by a vertical dotted line.</p>"
211  "<p> possible true values: 1 on true<br/>"
212  "possible false values: 0 off false</p>");
213  return true;
214  } else if (realcmd=="print") {
215  msg=i18n("<p>Open the Print dialog to print the current document.</p>");
216  return true;
217  } else
218  return false;
219 }
220 
221 bool KateCommands::CoreCommands::exec(KTextEditor::View *view,
222  const QString &_cmd,
223  QString &errorMsg)
224 {
225  return exec( view, _cmd, errorMsg, KTextEditor::Range::invalid() );
226 }
227 
228 bool KateCommands::CoreCommands::exec(KTextEditor::View *view,
229  const QString &_cmd,
230  QString &errorMsg,
231  const KTextEditor::Range& range)
232 {
233 #define KCC_ERR(s) { errorMsg=s; return false; }
234  // cast it hardcore, we know that it is really a kateview :)
235  KateView *v = static_cast<KateView*>(view);
236 
237  if ( ! v )
238  KCC_ERR( i18n("Could not access view") );
239 
240  //create a list of args
241  QStringList args(_cmd.split( QRegExp("\\s+"), QString::SkipEmptyParts)) ;
242  QString cmd ( args.takeFirst() );
243 
244  // ALL commands that takes no arguments.
245  if ( cmd == "indent" )
246  {
247  if ( range.isValid() ) {
248  v->doc()->editStart();
249  for ( int line = range.start().line(); line <= range.end().line(); line++ ) {
250  v->doc()->indent( KTextEditor::Range(line, 0, line, 0), 1 );
251  }
252  v->doc()->editEnd();
253  } else {
254  v->indent();
255  }
256  return true;
257  }
258  else if ( cmd == "unindent" )
259  {
260  if ( range.isValid() ) {
261  v->doc()->editStart();
262  for ( int line = range.start().line(); line <= range.end().line(); line++ ) {
263  v->doc()->indent( KTextEditor::Range(line, 0, line, 0), -1 );
264  }
265  v->doc()->editEnd();
266  } else {
267  v->unIndent();
268  }
269  return true;
270  }
271  else if ( cmd == "cleanindent" )
272  {
273  if ( range.isValid() ) {
274  v->doc()->editStart();
275  for ( int line = range.start().line(); line <= range.end().line(); line++ ) {
276  v->doc()->indent( KTextEditor::Range(line, 0, line, 0), 0 );
277  }
278  v->doc()->editEnd();
279  } else {
280  v->cleanIndent();
281  }
282  return true;
283  }
284  else if ( cmd == "fold" )
285  {
286  return (v->textFolding().newFoldingRange (range.isValid() ? range : v->selectionRange(), Kate::TextFolding::Persistent | Kate::TextFolding::Folded) != -1);
287  }
288  else if ( cmd == "tfold" )
289  {
290  return (v->textFolding().newFoldingRange (range.isValid() ? range : v->selectionRange(), Kate::TextFolding::Folded) != -1);
291  }
292  else if ( cmd == "unfold" )
293  {
294  QVector<QPair<qint64, Kate::TextFolding::FoldingRangeFlags> > startingRanges = v->textFolding().foldingRangesStartingOnLine (v->cursorPosition().line());
295  bool unfolded = false;
296  for (int i = 0; i < startingRanges.size(); ++i) {
297  if (startingRanges[i].second & Kate::TextFolding::Folded) {
298  unfolded = v->textFolding().unfoldRange (startingRanges[i].first) || unfolded;
299  }
300  }
301  return unfolded;
302  }
303  else if ( cmd == "comment" )
304  {
305  if ( range.isValid() ) {
306  v->doc()->editStart();
307  for ( int line = range.start().line(); line <= range.end().line(); line++ ) {
308  v->doc()->comment( v, line, 0, 1 );
309  }
310  v->doc()->editEnd();
311  } else {
312  v->comment();
313  }
314  return true;
315  }
316  else if ( cmd == "uncomment" )
317  {
318  if ( range.isValid() ) {
319  v->doc()->editStart();
320  for ( int line = range.start().line(); line <= range.end().line(); line++ ) {
321  v->doc()->comment( v, line, 0, -1 );
322  }
323  v->doc()->editEnd();
324  } else {
325  v->uncomment();
326  }
327  return true;
328  }
329  else if ( cmd == "kill-line" )
330  {
331  if ( range.isValid() ) {
332  v->doc()->editStart();
333  for ( int line = range.start().line(); line <= range.end().line(); line++ ) {
334  v->doc()->removeLine( range.start().line() );
335  }
336  v->doc()->editEnd();
337  } else {
338  v->killLine();
339  }
340  return true;
341  }
342  else if ( cmd == "print" )
343  {
344  v->doc()->printDialog();
345  return true;
346  }
347 
348  // ALL commands that take a string argument
349  else if ( cmd == "set-indent-mode" ||
350  cmd == "set-highlight" ||
351  cmd == "set-mode" )
352  {
353  // need at least one item, otherwise args.first() crashes
354  if ( ! args.count() )
355  KCC_ERR( i18n("Missing argument. Usage: %1 <value>", cmd ) );
356 
357  if ( cmd == "set-indent-mode" )
358  {
359  v->doc()->config()->setIndentationMode( args.join(" ") );
360  v->doc()->rememberUserDidSetIndentationMode ();
361  return true;
362  }
363  else if ( cmd == "set-highlight" )
364  {
365  if ( v->doc()->setHighlightingMode( args.first()) )
366  {
367  static_cast<KateDocument*>(v->doc())->setDontChangeHlOnSave ();
368  return true;
369  }
370 
371  KCC_ERR( i18n("No such highlighting '%1'", args.first() ) );
372  }
373  else if ( cmd == "set-mode" )
374  {
375  if ( v->doc()->setMode( args.first()) )
376  return true;
377 
378  KCC_ERR( i18n("No such mode '%1'", args.first() ) );
379  }
380  }
381  // ALL commands that takes exactly one integer argument.
382  else if ( cmd == "set-tab-width" ||
383  cmd == "set-indent-width" ||
384  cmd == "set-word-wrap-column" ||
385  cmd == "goto" )
386  {
387  // find a integer value > 0
388  if ( ! args.count() )
389  KCC_ERR( i18n("Missing argument. Usage: %1 <value>", cmd ) );
390  bool ok;
391  int val ( args.first().toInt( &ok, 10 ) ); // use base 10 even if the string starts with '0'
392  if ( !ok )
393  KCC_ERR( i18n("Failed to convert argument '%1' to integer.",
394  args.first() ) );
395 
396  if ( cmd == "set-tab-width" )
397  {
398  if ( val < 1 )
399  KCC_ERR( i18n("Width must be at least 1.") );
400  v->doc()->config()->setTabWidth( val );
401  }
402  else if ( cmd == "set-indent-width" )
403  {
404  if ( val < 1 )
405  KCC_ERR( i18n("Width must be at least 1.") );
406  v->doc()->config()->setIndentationWidth( val );
407  }
408  else if ( cmd == "set-word-wrap-column" )
409  {
410  if ( val < 2 )
411  KCC_ERR( i18n("Column must be at least 1.") );
412  v->doc()->setWordWrapAt( val );
413  }
414  else if ( cmd == "goto" )
415  {
416  if ( args.first().at(0) == '-' || args.first().at(0) == '+' ) {
417  // if the number starts with a minus or plus sign, add/subract the number
418  val = v->cursorPosition().line() + val;
419  } else {
420  val--; // convert given line number to the internal representation of line numbers
421  }
422 
423  // constrain cursor to the range [0, number of lines]
424  if ( val < 0 ) {
425  val = 0;
426  } else if ( val > v->doc()->lines()-1 ) {
427  val = v->doc()->lines()-1;
428  }
429 
430  v->setCursorPosition( KTextEditor::Cursor( val, 0 ) );
431  return true;
432  }
433  return true;
434  }
435 
436  // ALL commands that takes 1 boolean argument.
437  else if ( cmd == "set-icon-border" ||
438  cmd == "set-folding-markers" ||
439  cmd == "set-indent-pasted-text" ||
440  cmd == "set-line-numbers" ||
441  cmd == "set-replace-tabs" ||
442  cmd == "set-show-tabs" ||
443  cmd == "set-word-wrap" ||
444  cmd == "set-wrap-cursor" ||
445  cmd == "set-replace-tabs-save" ||
446  cmd == "set-show-indent" )
447  {
448  if ( ! args.count() )
449  KCC_ERR( i18n("Usage: %1 on|off|1|0|true|false", cmd ) );
450  bool enable = false;
451  KateDocumentConfig * const config = v->doc()->config();
452  if ( getBoolArg( args.first(), &enable ) )
453  {
454  if ( cmd == "set-icon-border" )
455  v->setIconBorder( enable );
456  else if (cmd == "set-folding-markers")
457  v->setFoldingMarkersOn( enable );
458  else if ( cmd == "set-line-numbers" )
459  v->setLineNumbersOn( enable );
460  else if ( cmd == "set-show-indent" )
461  v->renderer()->setShowIndentLines( enable );
462  else if (cmd == "set-indent-pasted-text")
463  config->setIndentPastedText( enable );
464  else if ( cmd == "set-replace-tabs" )
465  config->setReplaceTabsDyn( enable );
466  else if ( cmd == "set-show-tabs" )
467  config->setShowTabs( enable );
468  else if ( cmd == "set-show-trailing-spaces" )
469  config->setShowSpaces( enable );
470  else if ( cmd == "set-word-wrap" )
471  v->doc()->setWordWrap( enable );
472 
473  return true;
474  }
475  else
476  KCC_ERR( i18n("Bad argument '%1'. Usage: %2 on|off|1|0|true|false",
477  args.first() , cmd ) );
478  }
479  else if ( cmd == "set-remove-trailing-spaces" ) {
480  // need at least one item, otherwise args.first() crashes
481  if ( args.count() != 1 )
482  KCC_ERR( i18n("Usage: set-remove-trailing-spaces 0|-|none or 1|+|mod|modified or 2|*|all") );
483 
484  QString tmp = args.first().toLower().trimmed();
485  if (tmp == "1" || tmp == "modified" || tmp == "mod" || tmp == "+") {
486  v->doc()->config()->setRemoveSpaces(1);
487  } else if (tmp == "2" || tmp == "all" || tmp == "*") {
488  v->doc()->config()->setRemoveSpaces(2);
489  } else {
490  v->doc()->config()->setRemoveSpaces(0);
491  }
492  }
493 
494  // unlikely..
495  KCC_ERR( i18n("Unknown command '%1'", cmd) );
496 }
497 
498 bool KateCommands::CoreCommands::supportsRange(const QString &range)
499 {
500  static QStringList l;
501 
502  if (l.isEmpty())
503  l << "indent" << "unindent" << "cleanindent"
504  << "comment" << "uncomment" << "kill-line" << "fold" << "tfold";
505 
506  return l.contains(range);
507 }
508 
509 KCompletion *KateCommands::CoreCommands::completionObject( KTextEditor::View *view, const QString &cmd )
510 {
511  Q_UNUSED(view)
512 
513  if ( cmd == "set-highlight" )
514  {
515  QStringList l;
516  for ( int i = 0; i < KateHlManager::self()->highlights(); i++ )
517  l << KateHlManager::self()->hlName (i);
518 
519  KateCmdShellCompletion *co = new KateCmdShellCompletion();
520  co->setItems( l );
521  co->setIgnoreCase( true );
522  return co;
523  }
524  else if ( cmd == "set-remove-trailing-spaces" )
525  {
526  QStringList l;
527  l << "none" << "modified" << "all";
528 
529  KateCmdShellCompletion *co = new KateCmdShellCompletion();
530  co->setItems( l );
531  co->setIgnoreCase( true );
532  return co;
533  }
534  else if ( cmd == "set-indent-mode" )
535  {
536  QStringList l = KateAutoIndent::listIdentifiers();
537  KateCmdShellCompletion *co = new KateCmdShellCompletion();
538  co->setItems( l );
539  co->setIgnoreCase( true );
540  return co;
541  }
542 
543  return 0L;
544 }
545 //END CoreCommands
546 
547 // BEGIN ViCommands
548 KateCommands::ViCommands* KateCommands::ViCommands::m_instance = 0;
549 
550 const QStringList &KateCommands::ViCommands::cmds()
551 {
552  static QStringList l;
553 
554  if (l.isEmpty())
555  l << mappingCommands() << "d" << "delete" << "j" << "c" << "change" << "<" << ">" << "y" << "yank" <<
556  "ma" << "mark" << "k";
557 
558  return l;
559 }
560 
561 bool KateCommands::ViCommands::exec(KTextEditor::View *view,
562  const QString &_cmd,
563  QString &msg)
564 {
565  return exec( view, _cmd, msg, KTextEditor::Range::invalid() );
566 }
567 
568 bool KateCommands::ViCommands::exec(KTextEditor::View *view,
569  const QString &_cmd,
570  QString &msg,
571  const KTextEditor::Range& range)
572 {
573  Q_UNUSED(range)
574  // cast it hardcore, we know that it is really a kateview :)
575  KateView *v = static_cast<KateView*>(view);
576 
577  if ( !v ) {
578  msg = i18n("Could not access view");
579  return false;
580  }
581 
582  //create a list of args
583  QStringList args(_cmd.split( QRegExp("\\s+"), QString::SkipEmptyParts)) ;
584  QString cmd ( args.takeFirst() );
585 
586 
587  // ALL commands that takes no arguments.
588  if (mappingCommands().contains(cmd))
589  {
590  if (cmd.endsWith("unmap"))
591  {
592  if (args.count() == 1)
593  {
594  KateGlobal::self()->viInputModeGlobal()->removeMapping(modeForMapCommand(cmd), args.at(0));
595  return true;
596  }
597  else
598  {
599  msg = i18n("Missing argument. Usage: %1 <from>", cmd );
600  return false;
601  }
602  }
603  if ( args.count() == 1 ) {
604  msg = KateGlobal::self()->viInputModeGlobal()->getMapping( modeForMapCommand(cmd), args.at( 0 ), true );
605  if ( msg.isEmpty() ) {
606  msg = i18n( "No mapping found for \"%1\"", args.at(0) );
607  return false;
608  } else {
609  msg = i18n( "\"%1\" is mapped to \"%2\"", args.at( 0 ), msg );
610  }
611  } else if ( args.count() == 2 ) {
612  KateViGlobal::MappingRecursion mappingRecursion = (isMapCommandRecursive(cmd)) ? KateViGlobal::Recursive : KateViGlobal::NonRecursive;
613  KateGlobal::self()->viInputModeGlobal()->addMapping( modeForMapCommand(cmd), args.at( 0 ), args.at( 1 ), mappingRecursion);
614  } else {
615  msg = i18n("Missing argument(s). Usage: %1 <from> [<to>]", cmd );
616  return false;
617  }
618 
619  return true;
620  }
621 
622  KateViNormalMode* nm = v->getViInputModeManager()->getViNormalMode();
623 
624  if (cmd == "d" || cmd == "delete" || cmd == "j" ||
625  cmd == "c" || cmd == "change" || cmd == "<" || cmd == ">" ||
626  cmd == "y" || cmd == "yank") {
627 
628  KTextEditor::Cursor start_cursor_position = v->cursorPosition();
629 
630  int count = 1;
631  if (range.isValid()){
632  count = qAbs(range.end().line() - range.start().line())+1;
633  v->setCursorPosition(KTextEditor::Cursor(qMin(range.start().line(),
634  range.end().line()),0));
635  }
636 
637  QRegExp number("^(\\d+)$");
638  for (int i = 0; i < args.count(); i++) {
639  if (number.indexIn(args.at(i)) != -1)
640  count += number.cap().toInt() - 1;
641 
642  QChar r = args.at(i).at(0);
643  if (args.at(i).size() == 1 && ( (r >= 'a' && r <= 'z') || r == '_' || r == '+' || r == '*' ))
644  nm->setRegister(r);
645  }
646 
647  nm->setCount(count);
648 
649  if (cmd == "d" || cmd == "delete" )
650  nm->commandDeleteLine();
651  if (cmd == "j")
652  nm->commandJoinLines();
653  if (cmd == "c" || cmd == "change" )
654  nm->commandChangeLine();
655  if (cmd == "<")
656  nm->commandUnindentLine();
657  if (cmd == ">")
658  nm->commandIndentLine();
659  if (cmd == "y" || cmd == "yank" ){
660  nm->commandYankLine();
661  v->setCursorPosition(start_cursor_position);
662  }
663 
664  // TODO - should we resetParser, here? We'd have to make it public, if so.
665  // Or maybe synthesise a KateViCommand to execute instead ... ?
666  nm->setCount(0);
667 
668  return true;
669  }
670 
671  if (cmd == "mark" || cmd == "ma" || cmd == "k" ) {
672  if (args.count() == 0){
673  if (cmd == "mark"){
674  // TODO: show up mark list;
675  } else {
676  msg = i18n("Wrong arguments");
677  return false;
678  }
679  } else if (args.count() == 1) {
680 
681  QChar r = args.at(0).at(0);
682  int line;
683  if ( (r >= 'a' && r <= 'z') || r == '_' || r == '+' || r == '*' ) {
684  if (range.isValid())
685  line = qMax(range.end().line(),range.start().line());
686  else
687  line = v->cursorPosition().line();
688 
689  v->getViInputModeManager()->addMark(v->doc(),r,KTextEditor::Cursor(line, 0));
690  }
691  } else {
692  msg = i18n("Wrong arguments");
693  return false;
694  }
695  return true;
696  }
697 
698  // should not happen :)
699  msg = i18n("Unknown command '%1'", cmd);
700  return false;
701 }
702 
703 bool KateCommands::ViCommands::supportsRange(const QString &range)
704 {
705  static QStringList l;
706 
707  if (l.isEmpty())
708  l << "d" << "delete" << "j" << "c" << "change" << "<" <<
709  ">" << "y" << "yank" << "ma" << "mark" << "k";
710 
711  return l.contains(range.split(" ").at(0));
712 }
713 
714 KCompletion *KateCommands::ViCommands::completionObject( KTextEditor::View *view, const QString &cmd )
715 {
716  Q_UNUSED(view)
717 
718  KateView *v = static_cast<KateView*>(view);
719 
720  if ( v && ( cmd == "nn" || cmd == "nnoremap" ) )
721  {
722  QStringList l = KateGlobal::self()->viInputModeGlobal()->getMappings( KateViGlobal::NormalModeMapping );
723 
724  KateCmdShellCompletion *co = new KateCmdShellCompletion();
725  co->setItems( l );
726  co->setIgnoreCase( false );
727  return co;
728  }
729  return 0L;
730 }
731 
732 const QStringList& KateCommands::ViCommands::mappingCommands()
733 {
734  static QStringList mappingsCommands;
735  if (mappingsCommands.isEmpty())
736  {
737  mappingsCommands << "nmap" << "nm" << "noremap" << "nnoremap" << "nn" << "no"
738  << "vmap" << "vm" << "vnoremap" << "vn"
739  << "imap" << "im" << "inoremap" << "ino"
740  << "cmap" << "cm" << "cnoremap" << "cno";
741 
742  mappingsCommands << "nunmap" << "vunmap" << "iunmap" << "cunmap";
743  }
744  return mappingsCommands;
745 }
746 
747 KateViGlobal::MappingMode KateCommands::ViCommands::modeForMapCommand(const QString& mapCommand)
748 {
749  static QMap<QString, KateViGlobal::MappingMode> modeForMapCommand;
750  if (modeForMapCommand.isEmpty())
751  {
752  // Normal is the default.
753  modeForMapCommand.insert("vmap", KateViGlobal::VisualModeMapping);
754  modeForMapCommand.insert("vm", KateViGlobal::VisualModeMapping);
755  modeForMapCommand.insert("vnoremap", KateViGlobal::VisualModeMapping);
756  modeForMapCommand.insert("vn", KateViGlobal::VisualModeMapping);
757  modeForMapCommand.insert("imap", KateViGlobal::InsertModeMapping);
758  modeForMapCommand.insert("im", KateViGlobal::InsertModeMapping);
759  modeForMapCommand.insert("inoremap", KateViGlobal::InsertModeMapping);
760  modeForMapCommand.insert("ino", KateViGlobal::InsertModeMapping);
761  modeForMapCommand.insert("cmap", KateViGlobal::CommandModeMapping);
762  modeForMapCommand.insert("cm", KateViGlobal::CommandModeMapping);
763  modeForMapCommand.insert("cnoremap", KateViGlobal::CommandModeMapping);
764  modeForMapCommand.insert("cno", KateViGlobal::CommandModeMapping);
765 
766  modeForMapCommand.insert("nunmap", KateViGlobal::NormalModeMapping);
767  modeForMapCommand.insert("vunmap", KateViGlobal::VisualModeMapping);
768  modeForMapCommand.insert("iunmap", KateViGlobal::InsertModeMapping);
769  modeForMapCommand.insert("cunmap", KateViGlobal::CommandModeMapping);
770  }
771  return modeForMapCommand[mapCommand];
772 }
773 
774 bool KateCommands::ViCommands::isMapCommandRecursive(const QString& mapCommand)
775 {
776  static QMap<QString, bool> isMapCommandRecursive;
777  {
778  isMapCommandRecursive.insert("nmap", true);
779  isMapCommandRecursive.insert("nm", true);
780  isMapCommandRecursive.insert("vmap", true);
781  isMapCommandRecursive.insert("vm", true);
782  isMapCommandRecursive.insert("imap", true);
783  isMapCommandRecursive.insert("im", true);
784  isMapCommandRecursive.insert("cmap", true);
785  isMapCommandRecursive.insert("cm", true);
786  }
787  return isMapCommandRecursive[mapCommand];
788 }
789 
790 
791 //END ViCommands
792 
793 // BEGIN AppCommands
794 KateCommands::AppCommands* KateCommands::AppCommands::m_instance = 0;
795 
796 KateCommands::AppCommands::AppCommands()
797  : KTextEditor::Command()
798 {
799  re_write.setPattern("w"); // temporarily add :w
800  //re_write.setPattern("w(a)?");
801  //re_quit.setPattern("(w)?q?(a)?");
802  //re_exit.setPattern("x(a)?");
803  //re_changeBuffer.setPattern("b(n|p)");
804  //re_edit.setPattern("e(dit)?");
805  //re_new.setPattern("(v)?new");
806 }
807 
808 const QStringList& KateCommands::AppCommands::cmds()
809 {
810  static QStringList l;
811 
812  if (l.empty()) {
813  //l << "q" << "qa" << "w" << "wq" << "wa" << "wqa" << "x" << "xa"
814  //<< "bn" << "bp" << "new" << "vnew" << "e" << "edit" << "enew";
815  l << "w";
816  }
817 
818  return l;
819 }
820 
821 // commands that don't need to live in the hosting application should be
822 // implemented here. things such as quitting and splitting the view can not be
823 // done from the editor part and needs to be implemented in the hosting
824 // application.
825 bool KateCommands::AppCommands::exec(KTextEditor::View *view,
826  const QString &cmd, QString &msg )
827 {
828  QStringList args(cmd.split( QRegExp("\\s+"), QString::SkipEmptyParts)) ;
829  QString command( args.takeFirst() );
830  QString file = args.join(QString(' '));
831 
832  if (re_write.exactMatch(command)) { // w, wa
833  /* if (!re_write.cap(1).isEmpty()) { // [a]ll
834  view->document()->saveAll();
835  msg = i18n("All documents written to disk");
836  } else { // w*/
837  // Save file
838  if (file.isEmpty()) {
839  view->document()->documentSave();
840  } else {
841  KUrl base = view->document()->url();
842  KUrl url( base.isValid() ? base : KUrl( QDir::homePath() ), file );
843  view->document()->saveAs( url );
844  }
845  msg = i18n("Document written to disk");
846  }
847 
848  return true;
849 }
850 
851 bool KateCommands::AppCommands::help(KTextEditor::View *view, const QString &cmd, QString &msg)
852 {
853  Q_UNUSED(view);
854 
855  if (re_write.exactMatch(cmd)) {
856  msg = i18n("<p><b>w/wa &mdash; write document(s) to disk</b></p>"
857  "<p>Usage: <tt><b>w[a]</b></tt></p>"
858  "<p>Writes the current document(s) to disk. "
859  "It can be called in two ways:<br />"
860  " <tt>w</tt> &mdash; writes the current document to disk<br />"
861  " <tt>wa</tt> &mdash; writes all document to disk.</p>"
862  "<p>If no file name is associated with the document, "
863  "a file dialog will be shown.</p>");
864  return true;
865  }
866  return false;
867 }
868 //END AppCommands
869 
870 //BEGIN SedReplace
871 KateCommands::SedReplace* KateCommands::SedReplace::m_instance = 0;
872 
873 static int backslashString(const QString &haystack, const QString &needle, int index)
874 {
875  int len = haystack.length();
876  int searchlen = needle.length();
877  bool evenCount = true;
878  while (index < len)
879  {
880  if (haystack[index] == '\\')
881  {
882  evenCount = !evenCount;
883  }
884  else
885  { // isn't a slash
886  if (!evenCount)
887  {
888  if (haystack.mid(index, searchlen) == needle)
889  return index - 1;
890  }
891  evenCount = true;
892  }
893  ++index;
894 
895  }
896 
897  return -1;
898 }
899 
900 // exchange "\t" for the actual tab character, for example
901 static void exchangeAbbrevs(QString &str)
902 {
903  // the format is (findreplace)*[nullzero]
904  const char *magic = "a\x07t\tn\n";
905 
906  while (*magic)
907  {
908  int index = 0;
909  char replace = magic[1];
910  while ((index = backslashString(str, QString (QChar::fromAscii(*magic)), index)) != -1)
911  {
912  str.replace(index, 2, QChar(replace));
913  ++index;
914  }
915  ++magic;
916  ++magic;
917  }
918 }
919 
920 bool KateCommands::SedReplace::exec (KTextEditor::View *view, const QString &cmd, QString &msg)
921 {
922  return exec(view, cmd, msg, KTextEditor::Range::invalid());
923 }
924 
925 bool KateCommands::SedReplace::exec (class KTextEditor::View *view, const QString &cmd,
926  QString &msg, const KTextEditor::Range &r)
927 {
928  kDebug(13025) << "SedReplace::execCmd( " << cmd << " )";
929  if (r.isValid()) {
930  kDebug(13025) << "Range: " << r;
931  }
932 
933  int findBeginPos = -1;
934  int findEndPos = -1;
935  int replaceBeginPos = -1;
936  int replaceEndPos = -1;
937  QString delimiter;
938  if (!parse(cmd, delimiter, findBeginPos, findEndPos, replaceBeginPos, replaceEndPos))
939  {
940  return false;
941  }
942 
943  const QString searchParamsString = cmd.mid(cmd.lastIndexOf(delimiter));
944  const bool noCase = searchParamsString.contains('i');
945  const bool repeat = searchParamsString.contains('g');
946  const bool interactive = searchParamsString.contains('c');
947 
948  QString find = cmd.mid(findBeginPos, findEndPos - findBeginPos + 1);
949  kDebug(13025) << "SedReplace: find =" << find;
950 
951  QString replace = cmd.mid(replaceBeginPos, replaceEndPos - replaceBeginPos + 1);
952  exchangeAbbrevs(replace);
953  kDebug(13025) << "SedReplace: replace =" << replace;
954 
955  if (find.isEmpty())
956  {
957  // Nothing to do.
958  return true;
959  }
960 
961  KateView *kateView = static_cast<KateView*>(view);
962  KateDocument *doc = kateView->doc();
963  if ( !doc ) return false;
964  // Only current line ...
965  int startLine = kateView->cursorPosition().line();
966  int endLine = kateView->cursorPosition().line();
967  // ... unless a range was provided.
968  if (r.isValid())
969  {
970  startLine = r.start().line();
971  endLine = r.end().line();
972  }
973 
974  QSharedPointer<InteractiveSedReplacer> interactiveSedReplacer(new InteractiveSedReplacer(doc, find, replace, !noCase, !repeat, startLine, endLine));
975 
976  if (interactive)
977  {
978  if (kateView->viInputMode() && KateViewConfig::global()->viInputModeEmulateCommandBar())
979  {
980  KateViEmulatedCommandBar *emulatedCommandBar = kateView->viModeEmulatedCommandBar();
981  emulatedCommandBar->startInteractiveSearchAndReplace(interactiveSedReplacer);
982  return true;
983  }
984  else
985  {
986  kDebug(13025) << "Interactive sedreplace is only currently supported with Vi mode plus Vi emulated command bar.";
987  return false;
988  }
989  }
990 
991  kateView->setSearchPattern(find);
992 
993  interactiveSedReplacer->replaceAllRemaining();
994  msg = interactiveSedReplacer->finalStatusReportMessage();
995 
996  return true;
997 }
998 
999 bool KateCommands::SedReplace::parse(const QString& sedReplaceString, QString& destDelim, int& destFindBeginPos, int& destFindEndPos, int& destReplaceBeginPos, int& destReplaceEndPos)
1000 {
1001  // valid delimiters are all non-word, non-space characters plus '_'
1002  QRegExp delim("^s\\s*([^\\w\\s]|_)");
1003  if ( delim.indexIn( sedReplaceString ) < 0 ) return false;
1004 
1005  QString d = delim.cap(1);
1006  kDebug(13025) << "SedReplace: delimiter is '" << d << "'";
1007 
1008  QRegExp splitter( QString("^s\\s*") + d + "((?:[^\\\\\\" + d + "]|\\\\.)*)\\"
1009  + d + "((?:[^\\\\\\" + d + "]|\\\\.)*)(\\" + d + "[igc]{0,3})?$" );
1010  if (splitter.indexIn(sedReplaceString) < 0) return false;
1011 
1012  const QString find = splitter.cap(1);
1013  const QString replace = splitter.cap(2);
1014 
1015  destDelim = d;
1016  destFindBeginPos = splitter.pos(1);
1017  destFindEndPos = splitter.pos(1) + find.length() - 1;
1018  destReplaceBeginPos = splitter.pos(2);
1019  destReplaceEndPos = splitter.pos(2) + replace.length() - 1;
1020 
1021  return true;
1022 }
1023 
1024 KateCommands::SedReplace::InteractiveSedReplacer::InteractiveSedReplacer(KateDocument* doc, const QString& findPattern, const QString& replacePattern, bool caseSensitive, bool onlyOnePerLine, int startLine, int endLine)
1025  : m_findPattern(findPattern),
1026  m_replacePattern(replacePattern),
1027  m_onlyOnePerLine(onlyOnePerLine),
1028  m_startLine(startLine),
1029  m_endLine(endLine),
1030  m_doc(doc),
1031  m_regExpSearch(doc, caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive),
1032  m_numReplacementsDone(0),
1033  m_numLinesTouched(0),
1034  m_lastChangedLineNum(-1)
1035 {
1036  m_currentSearchPos = Cursor(startLine, 0);
1037 }
1038 
1039 Range KateCommands::SedReplace::InteractiveSedReplacer::currentMatch()
1040 {
1041  QVector<Range> matches = fullCurrentMatch();
1042 
1043  if (matches.isEmpty()) {
1044  return Range::invalid();
1045  }
1046 
1047  if (matches.first().start().line() > m_endLine) {
1048  return Range::invalid();
1049  }
1050 
1051  return matches.first();
1052 }
1053 
1054 void KateCommands::SedReplace::InteractiveSedReplacer::skipCurrentMatch()
1055 {
1056  const Range currentMatch = this->currentMatch();
1057  m_currentSearchPos = currentMatch.end();
1058  if (m_onlyOnePerLine && currentMatch.start().line() == m_currentSearchPos.line())
1059  {
1060  m_currentSearchPos = Cursor(m_currentSearchPos.line() + 1, 0);
1061  }
1062 }
1063 
1064 void KateCommands::SedReplace::InteractiveSedReplacer::replaceCurrentMatch()
1065 {
1066  const Range currentMatch = this->currentMatch();
1067  const QString currentMatchText = m_doc->text(currentMatch);
1068  const QString replacementText = replacementTextForCurrentMatch();
1069 
1070  m_doc->editBegin();
1071  m_doc->removeText(currentMatch);
1072  m_doc->insertText(currentMatch.start(), replacementText);
1073  m_doc->editEnd();
1074 
1075  // Begin next search from directly after replacement.
1076  if (!replacementText.contains('\n')) {
1077  const int moveChar = currentMatch.isEmpty() ? 1 : 0; // if the search was for \s*, make sure we advance a char
1078  const int col = currentMatch.start().column() + replacementText.length() + moveChar;
1079 
1080  m_currentSearchPos = Cursor(currentMatch.start().line(), col);
1081  } else {
1082  m_currentSearchPos = Cursor(currentMatch.start().line() + replacementText.count('\n'),
1083  replacementText.length() - replacementText.lastIndexOf('\n') - 1);
1084  }
1085  if (m_onlyOnePerLine)
1086  {
1087  // Drop down to next line.
1088  m_currentSearchPos = Cursor(m_currentSearchPos.line() + 1, 0);
1089  }
1090 
1091  // Adjust end line down by the number of new newlines just added, minus the number taken away.
1092  m_endLine += replacementText.count('\n');
1093  m_endLine -= currentMatchText.count('\n');
1094 
1095  m_numReplacementsDone++;
1096  if (m_lastChangedLineNum != currentMatch.start().line())
1097  {
1098  // Counting "swallowed" lines as being "touched".
1099  m_numLinesTouched += currentMatchText.count('\n') + 1;
1100  }
1101  m_lastChangedLineNum = m_currentSearchPos.line();
1102 }
1103 
1104 void KateCommands::SedReplace::InteractiveSedReplacer::replaceAllRemaining()
1105 {
1106  m_doc->editBegin();
1107  while (currentMatch().isValid())
1108  {
1109  replaceCurrentMatch();
1110  }
1111  m_doc->editEnd();
1112 }
1113 
1114 QString KateCommands::SedReplace::InteractiveSedReplacer::currentMatchReplacementConfirmationMessage()
1115 {
1116  return i18n("replace with %1?", replacementTextForCurrentMatch().replace('\n', "\\n"));
1117 }
1118 
1119 QString KateCommands::SedReplace::InteractiveSedReplacer::finalStatusReportMessage()
1120 {
1121  return i18ncp("%2 is the translation of the next message",
1122  "1 replacement done on %2", "%1 replacements done on %2", m_numReplacementsDone,
1123  i18ncp("substituted into the previous message",
1124  "1 line", "%1 lines", m_numLinesTouched));
1125 
1126 }
1127 
1128 
1129 const QVector< Range > KateCommands::SedReplace::InteractiveSedReplacer::fullCurrentMatch()
1130 {
1131  if (m_currentSearchPos > m_doc->documentEnd()) {
1132  return QVector<Range>();
1133  }
1134 
1135  return m_regExpSearch.search(m_findPattern, Range(m_currentSearchPos, m_doc->documentEnd()));
1136 }
1137 
1138 QString KateCommands::SedReplace::InteractiveSedReplacer::replacementTextForCurrentMatch()
1139 {
1140  const Range currentMatch = this->currentMatch();
1141  const QVector<KTextEditor::Range> captureRanges = fullCurrentMatch();
1142  QStringList captureTexts;
1143  foreach(const Range& captureRange, captureRanges)
1144  {
1145  captureTexts << m_doc->text(captureRange);
1146  }
1147  const QString replacementText = m_regExpSearch.buildReplacement(m_replacePattern, captureTexts, 0);
1148  return replacementText;
1149 
1150 }
1151 
1152 
1153 
1154 //END SedReplace
1155 
1156 //BEGIN Character
1157 KateCommands::Character* KateCommands::Character::m_instance = 0;
1158 
1159 bool KateCommands::Character::help (class KTextEditor::View *, const QString &cmd, QString &msg)
1160 {
1161  if (cmd.trimmed()=="char") {
1162  msg = i18n("<p> char <b>identifier</b> </p>"
1163  "<p>This command allows you to insert literal characters by their numerical identifier, in decimal, octal or hexadecimal form.</p>"
1164  "<p>Examples:<ul>"
1165  "<li>char <b>234</b></li>"
1166  "<li>char <b>0x1234</b></li>"
1167  "</ul></p>");
1168  return true;
1169  }
1170  return false;
1171 }
1172 
1173 bool KateCommands::Character::exec (KTextEditor::View *view, const QString &_cmd, QString &)
1174 {
1175  QString cmd = _cmd;
1176 
1177  // hex, octal, base 9+1
1178  QRegExp num("^char *(0?x[0-9A-Fa-f]{1,4}|0[0-7]{1,6}|[0-9]{1,5})$");
1179  if (num.indexIn(cmd)==-1) return false;
1180 
1181  cmd=num.cap(1);
1182 
1183  // identify the base
1184 
1185  unsigned short int number=0;
1186  int base=10;
1187  if (cmd[0]=='x' || cmd.startsWith(QLatin1String("0x")))
1188  {
1189  cmd.remove(QRegExp("^0?x"));
1190  base=16;
1191  }
1192  else if (cmd[0]=='0')
1193  base=8;
1194  bool ok;
1195  number=cmd.toUShort(&ok, base);
1196  if (!ok || number==0) return false;
1197  if (number<=255)
1198  {
1199  char buf[2];
1200  buf[0]=(char)number;
1201  buf[1]=0;
1202 
1203  view->document()->insertText(view->cursorPosition(), QString(buf));
1204  }
1205  else
1206  { // do the unicode thing
1207  QChar c(number);
1208 
1209  view->document()->insertText(view->cursorPosition(), QString(&c, 1));
1210  }
1211 
1212  return true;
1213 }
1214 
1215 //END Character
1216 
1217 //BEGIN Date
1218 KateCommands::Date* KateCommands::Date::m_instance = 0;
1219 
1220 bool KateCommands::Date::help (class KTextEditor::View *, const QString &cmd, QString &msg)
1221 {
1222  if (cmd.trimmed()=="date") {
1223  msg = i18n("<p>date or date <b>format</b></p>"
1224  "<p>Inserts a date/time string as defined by the specified format, or the format yyyy-MM-dd hh:mm:ss if none is specified.</p>"
1225  "<p>Possible format specifiers are:"
1226  "<table>"
1227  "<tr><td>d</td><td>The day as number without a leading zero (1-31).</td></tr>"
1228  "<tr><td>dd</td><td>The day as number with a leading zero (01-31).</td></tr>"
1229  "<tr><td>ddd</td><td>The abbreviated localized day name (e.g. 'Mon'..'Sun').</td></tr>"
1230  "<tr><td>dddd</td><td>The long localized day name (e.g. 'Monday'..'Sunday').</td></tr>"
1231  "<tr><td>M</td><td>The month as number without a leading zero (1-12).</td></tr>"
1232  "<tr><td>MM</td><td>The month as number with a leading zero (01-12).</td></tr>"
1233  "<tr><td>MMM</td><td>The abbreviated localized month name (e.g. 'Jan'..'Dec').</td></tr>"
1234  "<tr><td>yy</td><td>The year as two digit number (00-99).</td></tr>"
1235  "<tr><td>yyyy</td><td>The year as four digit number (1752-8000).</td></tr>"
1236  "<tr><td>h</td><td>The hour without a leading zero (0..23 or 1..12 if AM/PM display).</td></tr>"
1237  "<tr><td>hh</td><td>The hour with a leading zero (00..23 or 01..12 if AM/PM display).</td></tr>"
1238  "<tr><td>m</td><td>The minute without a leading zero (0..59).</td></tr>"
1239  "<tr><td>mm</td><td>The minute with a leading zero (00..59).</td></tr>"
1240  "<tr><td>s</td><td>The second without a leading zero (0..59).</td></tr>"
1241  "<tr><td>ss</td><td>The second with a leading zero (00..59).</td></tr>"
1242  "<tr><td>z</td><td>The milliseconds without leading zeroes (0..999).</td></tr>"
1243  "<tr><td>zzz</td><td>The milliseconds with leading zeroes (000..999).</td></tr>"
1244  "<tr><td>AP</td><td>Use AM/PM display. AP will be replaced by either \"AM\" or \"PM\".</td></tr>"
1245  "<tr><td>ap</td><td>Use am/pm display. ap will be replaced by either \"am\" or \"pm\".</td></tr>"
1246  "</table></p>");
1247  return true;
1248  }
1249  return false;
1250 }
1251 
1252 bool KateCommands::Date::exec (KTextEditor::View *view, const QString &cmd, QString &)
1253 {
1254  if (!cmd.startsWith(QLatin1String("date")))
1255  return false;
1256 
1257  if (QDateTime::currentDateTime().toString(cmd.mid(5, cmd.length()-5)).length() > 0)
1258  view->document()->insertText(view->cursorPosition(), QDateTime::currentDateTime().toString(cmd.mid(5, cmd.length()-5)));
1259  else
1260  view->document()->insertText(view->cursorPosition(), QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"));
1261 
1262  return true;
1263 }
1264 
1265 //END Date
1266 
1267 // kate: space-indent on; indent-width 2; replace-tabs on;
katevinormalmode.h
KateHlManager::hlName
QString hlName(int n)
Definition: katesyntaxmanager.cpp:360
QRegExp::pos
int pos(int nth) const
KateDocument::config
KateDocumentConfig * config()
Configuration.
Definition: katedocument.h:1009
KateViEmulatedCommandBar::startInteractiveSearchAndReplace
void startInteractiveSearchAndReplace(QSharedPointer< KateCommands::SedReplace::InteractiveSedReplacer > interactiveSedReplace)
Definition: kateviemulatedcommandbar.cpp:1222
KateDocument::setWordWrap
void setWordWrap(bool on)
Definition: katedocument.cpp:3923
QDateTime::toString
QString toString(Qt::DateFormat format) const
KateCommands::CoreCommands
This KTextEditor::Command provides access to a lot of the core functionality of kate part...
Definition: katecmds.h:49
katetextline.h
QRegExp::cap
QString cap(int nth) const
kateview.h
kateviemulatedcommandbar.h
Kate::Script::i18n
QScriptValue i18n(QScriptContext *context, QScriptEngine *engine)
i18n("text", arguments [optional])
Definition: katescripthelpers.cpp:186
KateDocumentConfig::setIndentationMode
void setIndentationMode(const QString &identationMode)
Definition: kateconfig.cpp:500
KateCommands::SedReplace::exec
bool exec(class KTextEditor::View *view, const QString &cmd, QString &errorMsg)
Execute command.
Definition: katecmds.cpp:920
KateViewConfig::viInputModeEmulateCommandBar
bool viInputModeEmulateCommandBar() const
Definition: kateconfig.cpp:1862
KateViGlobal::getMapping
const QString getMapping(MappingMode mode, const QString &from, bool decode=false) const
Definition: kateviglobal.cpp:186
KateDocument::printDialog
bool printDialog()
Definition: katedocument.cpp:1848
KateCommands::CoreCommands::cmds
const QStringList & cmds()
supported commands as prefixes
Definition: katecmds.cpp:71
KateCommands::Date
insert the current date/time in the given format
Definition: katecmds.h:354
KateCommands::CoreCommands::supportsRange
bool supportsRange(const QString &range)
Definition: katecmds.cpp:498
KateView::renderer
KateRenderer * renderer()
Definition: kateview.cpp:1664
KateView::comment
void comment()
Definition: kateview.cpp:2519
katerenderer.h
KateCommands::CoreCommands::completionObject
KCompletion * completionObject(KTextEditor::View *, const QString &)
override completionObject from interfaces/document.h .
Definition: katecmds.cpp:509
KateDocument::removeLine
virtual bool removeLine(int line)
Definition: katedocument.cpp:727
KateView::cleanIndent
void cleanIndent()
Definition: kateview.cpp:2500
KateCommands::SedReplace::InteractiveSedReplacer::InteractiveSedReplacer
InteractiveSedReplacer(KateDocument *doc, const QString &findPattern, const QString &replacePattern, bool caseSensitive, bool onlyOnePerLine, int startLine, int endLine)
Definition: katecmds.cpp:1024
KateCommands::ViCommands::supportsRange
bool supportsRange(const QString &range)
Definition: katecmds.cpp:703
KateViInputModeManager::addMark
void addMark(KateDocument *doc, const QChar &mark, const KTextEditor::Cursor &pos, const bool moveoninsert=true, const bool showmark=true)
Add a mark to the document.
Definition: kateviinputmodemanager.cpp:737
KateViNormalMode::commandIndentLine
bool commandIndentLine()
Definition: katevinormalmode.cpp:1567
QChar
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
KateDocument::rememberUserDidSetIndentationMode
void rememberUserDidSetIndentationMode()
set indentation mode by user this will remember that a user did set it and will avoid reset on save ...
Definition: katedocument.h:952
kateautoindent.h
KateDocument::setMode
virtual bool setMode(const QString &name)
Set the current mode of the document by giving its name.
Definition: katedocument.cpp:1462
KateViNormalMode::commandJoinLines
bool commandJoinLines()
Definition: katevinormalmode.cpp:1079
KateViGlobal::MappingRecursion
MappingRecursion
Definition: kateviglobal.h:60
KateViGlobal::InsertModeMapping
Definition: kateviglobal.h:61
KateViGlobal::getMappings
const QStringList getMappings(MappingMode mode, bool decode=false) const
Definition: kateviglobal.cpp:196
QList::at
const T & at(int i) const
QMap
KateCommands::ViCommands::completionObject
KCompletion * completionObject(KTextEditor::View *, const QString &)
override completionObject from interfaces/document.h .
Definition: katecmds.cpp:714
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
KateDocument::setWordWrapAt
void setWordWrapAt(uint col)
Definition: katedocument.cpp:3933
katedocument.h
KateCommands::AppCommands
This KTextEditor::Command provides vi commands for the application.
Definition: katecmds.h:175
KateCommands::Character::help
bool help(class KTextEditor::View *, const QString &, QString &)
This command does not have help.
Definition: katecmds.cpp:1159
KateCommands::SedReplace
Support vim/sed style search and replace.
Definition: katecmds.h:220
KateGlobal::self
static KateGlobal * self()
Kate Part Internal stuff ;)
Definition: kateglobal.cpp:465
QVector::first
T & first()
KateCommands::ViCommands::cmds
const QStringList & cmds()
supported commands as prefixes
Definition: katecmds.cpp:550
QString::remove
QString & remove(int position, int n)
KateCommands::Date::help
bool help(class KTextEditor::View *, const QString &, QString &)
This command does not have help.
Definition: katecmds.cpp:1220
KateCommands::SedReplace::InteractiveSedReplacer::finalStatusReportMessage
QString finalStatusReportMessage()
Definition: katecmds.cpp:1119
KateAutoIndent::listIdentifiers
static QStringList listIdentifiers()
List all possible names, i.e.
Definition: kateautoindent.cpp:55
KateView::textFolding
Kate::TextFolding & textFolding()
Folding handler for this view.
Definition: kateview.h:574
KateView::setCursorPosition
bool setCursorPosition(KTextEditor::Cursor position)
Definition: kateview.cpp:2418
KateCommands::AppCommands::exec
bool exec(class KTextEditor::View *view, const QString &cmd, QString &msg)
execute command
Definition: katecmds.cpp:825
QDir::homePath
QString homePath()
KateViGlobal::VisualModeMapping
Definition: kateviglobal.h:61
KateDocument::indent
void indent(KTextEditor::Range range, int change)
Definition: katedocument.cpp:2899
KateCommands::SedReplace::InteractiveSedReplacer::currentMatchReplacementConfirmationMessage
QString currentMatchReplacementConfirmationMessage()
Definition: katecmds.cpp:1114
KateViGlobal::removeMapping
void removeMapping(MappingMode mode, const QString &from)
Definition: kateviglobal.cpp:181
Kate::Script::i18ncp
QScriptValue i18ncp(QScriptContext *context, QScriptEngine *engine)
i18ncp("context", "singular", "plural", number, arguments [optional])
Definition: katescripthelpers.cpp:273
KateViGlobal::addMapping
void addMapping(MappingMode mode, const QString &from, const QString &to, MappingRecursion recursion)
Definition: kateviglobal.cpp:171
KateView::getViInputModeManager
KateViInputModeManager * getViInputModeManager()
Definition: kateview.cpp:1587
KateDocument::comment
void comment(KateView *view, uint line, uint column, int change)
Definition: katedocument.cpp:3302
QString::lastIndexOf
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
KateCommands::Character
insert a unicode or ascii character base 9+1: 1234 hex: 0x1234 or x1234 octal: 01231 ...
Definition: katecmds.h:317
Kate::TextFolding::unfoldRange
bool unfoldRange(qint64 id, bool remove=false)
Unfold the given range.
Definition: katetextfolding.cpp:191
KateViNormalMode::commandYankLine
bool commandYankLine()
Definition: katevinormalmode.cpp:1253
KateView::setLineNumbersOn
void setLineNumbersOn(bool enable)
Definition: kateview.cpp:1426
KateView::selectionRange
virtual const KTextEditor::Range & selectionRange() const
Definition: kateview.cpp:2815
KateDocument::setHighlightingMode
virtual bool setHighlightingMode(const QString &name)
Set the current mode of the document by giving its name.
Definition: katedocument.cpp:1484
QRegExp::indexIn
int indexIn(const QString &str, int offset, CaretMode caretMode) const
QRegExp
katesyntaxmanager.h
Kate::TextFolding::foldingRangesStartingOnLine
QVector< QPair< qint64, FoldingRangeFlags > > foldingRangesStartingOnLine(int line) const
Queries which folding ranges start at the given line and returns the id + flags for all of them...
Definition: katetextfolding.cpp:476
QList::empty
bool empty() const
exchangeAbbrevs
static void exchangeAbbrevs(QString &str)
Definition: katecmds.cpp:901
QSharedPointer
KateCommands::SedReplace::InteractiveSedReplacer::replaceAllRemaining
void replaceAllRemaining()
Definition: katecmds.cpp:1104
KateViModeBase::setCount
void setCount(unsigned int count)
Definition: katevimodebase.h:85
KateCommands::CoreCommands::exec
bool exec(class KTextEditor::View *view, const QString &cmd, QString &errorMsg)
execute command
Definition: katecmds.cpp:221
KateCommands::ViCommands
This KTextEditor::Command provides vi 'ex' commands.
Definition: katecmds.h:110
KCC_ERR
#define KCC_ERR(s)
kateglobal.h
QString::toInt
int toInt(bool *ok, int base) const
QList::isEmpty
bool isEmpty() const
QString::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
KateViInputModeManager::getViNormalMode
KateViNormalMode * getViNormalMode()
Definition: kateviinputmodemanager.cpp:546
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
KateDocument::lines
virtual int lines() const
Definition: katedocument.cpp:753
KateCommands::AppCommands::help
bool help(class KTextEditor::View *, const QString &, QString &)
Help for AppCommands.
Definition: katecmds.cpp:851
KateCommands::SedReplace::InteractiveSedReplacer
Definition: katecmds.h:275
Kate::TextFolding::Folded
Range is folded away.
Definition: katetextfolding.h:69
katecmd.h
KateViModeBase::setRegister
void setRegister(QChar reg)
Definition: katevimodebase.h:86
QString
KateDocumentConfig::setRemoveSpaces
void setRemoveSpaces(int triState)
Remove trailing spaces on save.
Definition: kateconfig.cpp:745
KateView::killLine
void killLine()
Definition: kateview.cpp:2543
KateCommands::AppCommands::cmds
const QStringList & cmds()
supported commands as prefixes
Definition: katecmds.cpp:808
KateCommands::ViCommands::exec
bool exec(class KTextEditor::View *view, const QString &cmd, QString &msg)
execute command
Definition: katecmds.cpp:561
KateDocumentConfig::setShowTabs
void setShowTabs(bool on)
Definition: kateconfig.cpp:682
QStringList
KateView
Definition: kateview.h:77
KateCommands::SedReplace::InteractiveSedReplacer::replaceCurrentMatch
void replaceCurrentMatch()
Definition: katecmds.cpp:1064
Kate::TextFolding::Persistent
Range is persistent, e.g.
Definition: katetextfolding.h:64
KateViGlobal::NonRecursive
Definition: kateviglobal.h:60
QString::toLower
QString toLower() const
KateViNormalMode::commandChangeLine
bool commandChangeLine()
Definition: katevinormalmode.cpp:1184
KateView::setSearchPattern
void setSearchPattern(const QString &searchPattern)
Set the current search pattern.
Definition: kateview.cpp:2476
KateDocument
Definition: katedocument.h:74
KateViGlobal::NormalModeMapping
Definition: kateviglobal.h:61
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
KateViNormalMode
Commands for the vi normal mode.
Definition: katevinormalmode.h:49
KateView::cursorPosition
KTextEditor::Cursor cursorPosition() const
Definition: kateview.cpp:2423
QString::replace
QString & replace(int position, int n, QChar after)
KateGlobal::viInputModeGlobal
KateViGlobal * viInputModeGlobal()
vi input mode global
Definition: kateglobal.h:339
KateViGlobal::Recursive
Definition: kateviglobal.h:60
QDateTime::currentDateTime
QDateTime currentDateTime()
KateViGlobal::CommandModeMapping
Definition: kateviglobal.h:61
QString::mid
QString mid(int position, int n) const
QVector
KateView::viInputMode
bool viInputMode() const
Definition: kateview.cpp:1530
KateView::uncomment
void uncomment()
Definition: kateview.cpp:2526
QLatin1String
KateDocumentConfig::setShowSpaces
void setShowSpaces(bool on)
Definition: kateconfig.cpp:703
KateView::viModeEmulatedCommandBar
KateViEmulatedCommandBar * viModeEmulatedCommandBar()
Definition: kateview.cpp:3051
QVector::isEmpty
bool isEmpty() const
QString::count
int count() const
KateDocument::editEnd
void editEnd()
End a editor operation.
Definition: katedocument.cpp:796
QChar::fromAscii
QChar fromAscii(char c)
getBoolArg
static bool getBoolArg(const QString &t, bool *val)
Definition: katecmds.cpp:52
KateDocumentConfig::setReplaceTabsDyn
void setReplaceTabsDyn(bool on)
Definition: kateconfig.cpp:724
KateCommands::Date::exec
bool exec(class KTextEditor::View *view, const QString &cmd, QString &errorMsg)
execute command
Definition: katecmds.cpp:1252
QString::length
int length() const
KateCommands::CoreCommands::help
bool help(class KTextEditor::View *, const QString &, QString &)
This command does not have help.
Definition: katecmds.cpp:90
KateDocumentConfig
Definition: kateconfig.h:145
Kate::TextFolding::newFoldingRange
qint64 newFoldingRange(const KTextEditor::Range &range, FoldingRangeFlags flags=FoldingRangeFlags())
Create a new folding range.
Definition: katetextfolding.cpp:99
KateViNormalMode::commandUnindentLine
bool commandUnindentLine()
Definition: katevinormalmode.cpp:1576
KateCommands::SedReplace::InteractiveSedReplacer::currentMatch
KTextEditor::Range currentMatch()
Will return invalid Range if there are no further matches.
Definition: katecmds.cpp:1039
KateView::doc
KateDocument * doc()
accessor to katedocument pointer
Definition: kateview.h:553
QMap::insert
iterator insert(const Key &key, const T &value)
QMap::isEmpty
bool isEmpty() const
KateCommands::Character::exec
bool exec(class KTextEditor::View *view, const QString &cmd, QString &errorMsg)
execute command
Definition: katecmds.cpp:1173
KateViGlobal::MappingMode
MappingMode
Definition: kateviglobal.h:61
KateDocumentConfig::setIndentPastedText
void setIndentPastedText(bool on)
Definition: kateconfig.cpp:619
KateCmdShellCompletion
A KCompletion object that completes last ?unquoted? word in the string passed.
Definition: katecmd.h:67
KateDocument::editStart
void editStart()
Enclose editor actions with editStart() and editEnd() to group them.
Definition: katedocument.cpp:776
KateViNormalMode::commandDeleteLine
bool commandDeleteLine()
Definition: katevinormalmode.cpp:721
KateRenderer::setShowIndentLines
void setShowIndentLines(bool showLines)
Set whether a guide should be painted to help identifying indent lines.
Definition: katerenderer.cpp:125
KateDocumentConfig::setTabWidth
void setTabWidth(int tabWidth)
Definition: kateconfig.cpp:452
QVector::size
int size() const
backslashString
static int backslashString(const QString &haystack, const QString &needle, int index)
Definition: katecmds.cpp:873
KateView::setIconBorder
void setIconBorder(bool enable)
Definition: kateview.cpp:1416
KateView::setFoldingMarkersOn
void setFoldingMarkersOn(bool enable)
Definition: kateview.cpp:1481
kateviglobal.h
kateconfig.h
katecmds.h
KateHlManager::self
static KateHlManager * self()
Definition: katesyntaxmanager.cpp:103
KateDocumentConfig::setIndentationWidth
void setIndentationWidth(int indentationWidth)
Definition: kateconfig.cpp:476
KateViEmulatedCommandBar
A KateViewBarWidget that attempts to emulate some of the features of Vim's own command bar...
Definition: kateviemulatedcommandbar.h:40
KateCommands::SedReplace::InteractiveSedReplacer::skipCurrentMatch
void skipCurrentMatch()
Definition: katecmds.cpp:1054
KateCommands::SedReplace::parse
static bool parse(const QString &sedReplaceString, QString &destDelim, int &destFindBeginPos, int &destFindEndPos, int &destReplaceBeginPos, int &destReplaceEndPos)
Parses sedReplaceString to see if it is a valid sed replace expression (e.g.
Definition: katecmds.cpp:999
KateViewConfig::global
static KateViewConfig * global()
Definition: kateconfig.h:402
KateHlManager::highlights
int highlights()
Definition: katesyntaxmanager.cpp:355
KateView::unIndent
void unIndent()
Definition: kateview.cpp:2493
KateView::indent
void indent()
Definition: kateview.cpp:2486
QString::toUShort
ushort toUShort(bool *ok, int base) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal