aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2013-01-23 18:44:26 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2013-01-23 18:44:26 +0100
commit4c37f988b68b35d2510de25a185e091e692d00d5 (patch)
tree9f8ee521d244f7d56f8646db964fc337ca1dce93 /src
parentaea39acc84741eb2fa868865e9fdc0395fa94478 (diff)
downloadsciteco-4c37f988b68b35d2510de25a185e091e692d00d5.tar.gz
implemented special save last commandline command ("*" at beginning of commandline macro)
* only works as part of commandline macro, * at the beginning of other macros, it is treated like an arithmetic asterisk * variables defined in cmdline.cpp are now declared by new cmdline.h
Diffstat (limited to 'src')
-rw-r--r--src/cmdline.cpp25
-rw-r--r--src/cmdline.h44
-rw-r--r--src/interface-gtk.cpp1
-rw-r--r--src/interface-ncurses.cpp1
-rw-r--r--src/main.cpp1
-rw-r--r--src/parser.cpp5
-rw-r--r--src/sciteco.h5
-rw-r--r--src/undo.cpp1
8 files changed, 77 insertions, 6 deletions
diff --git a/src/cmdline.cpp b/src/cmdline.cpp
index f36aab5..483b011 100644
--- a/src/cmdline.cpp
+++ b/src/cmdline.cpp
@@ -35,6 +35,7 @@
#include "goto.h"
#include "undo.h"
#include "symbols.h"
+#include "cmdline.h"
static inline const gchar *process_edit_cmd(gchar key);
static gchar *macro_echo(const gchar *macro);
@@ -48,9 +49,14 @@ static const gchar *last_occurrence(const gchar *str,
static inline gboolean filename_is_dir(const gchar *filename);
gchar *cmdline = NULL;
+static gchar *last_cmdline = NULL;
bool quit_requested = false;
+namespace States {
+ StateSaveCmdline save_cmdline;
+}
+
void
cmdline_keypress(gchar key)
{
@@ -195,7 +201,9 @@ process_edit_cmd(gchar key)
Goto::table->clear();
expressions.clear();
- *cmdline = '\0';
+ g_free(last_cmdline);
+ last_cmdline = cmdline;
+ cmdline = NULL;
macro_pc = 0;
break;
}
@@ -375,6 +383,21 @@ symbol_complete(SymbolList &list, const gchar *symbol, gchar completed)
}
/*
+ * Command states
+ */
+
+State *
+StateSaveCmdline::got_register(QRegister *reg) throw (Error)
+{
+ BEGIN_EXEC(&States::start);
+
+ reg->undo_set_string();
+ reg->set_string(last_cmdline);
+
+ return &States::start;
+}
+
+/*
* Auxiliary functions
*/
diff --git a/src/cmdline.h b/src/cmdline.h
new file mode 100644
index 0000000..fab7850
--- /dev/null
+++ b/src/cmdline.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2012-2013 Robin Haberkorn
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __CMDLINE_H
+#define __CMDLINE_H
+
+#include <glib.h>
+
+#include "sciteco.h"
+#include "parser.h"
+
+extern gchar *cmdline;
+extern bool quit_requested;
+
+void cmdline_keypress(gchar key);
+
+/*
+ * Command states
+ */
+
+class StateSaveCmdline : public StateExpectQReg {
+private:
+ State *got_register(QRegister *reg) throw (Error);
+};
+
+namespace States {
+ extern StateSaveCmdline save_cmdline;
+}
+
+#endif
diff --git a/src/interface-gtk.cpp b/src/interface-gtk.cpp
index 6d86f4b..c1a557a 100644
--- a/src/interface-gtk.cpp
+++ b/src/interface-gtk.cpp
@@ -35,6 +35,7 @@
#include <ScintillaWidget.h>
#include "sciteco.h"
+#include "cmdline.h"
#include "qregisters.h"
#include "ring.h"
#include "interface.h"
diff --git a/src/interface-ncurses.cpp b/src/interface-ncurses.cpp
index f376a1f..899043c 100644
--- a/src/interface-ncurses.cpp
+++ b/src/interface-ncurses.cpp
@@ -34,6 +34,7 @@
#include <ScintillaTerm.h>
#include "sciteco.h"
+#include "cmdline.h"
#include "qregisters.h"
#include "ring.h"
#include "interface.h"
diff --git a/src/main.cpp b/src/main.cpp
index eda7328..1a3205d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -33,6 +33,7 @@
#include <SciLexer.h>
#include "sciteco.h"
+#include "cmdline.h"
#include "interface.h"
#include "parser.h"
#include "goto.h"
diff --git a/src/parser.cpp b/src/parser.cpp
index 48e7d5f..4d0c6b5 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -36,6 +36,7 @@
#include "parser.h"
#include "symbols.h"
#include "search.h"
+#include "cmdline.h"
//#define DEBUG
@@ -650,6 +651,10 @@ StateStart::custom(gchar chr) throw (Error)
break;
case '*':
+ if (!g_strcmp0(cmdline, "*"))
+ /* special save last commandline command */
+ return &States::save_cmdline;
+
BEGIN_EXEC(this);
expressions.push_calc(Expressions::OP_MUL);
break;
diff --git a/src/sciteco.h b/src/sciteco.h
index 1968ad1..441b262 100644
--- a/src/sciteco.h
+++ b/src/sciteco.h
@@ -34,11 +34,6 @@ namespace Flags {
extern sig_atomic_t sigint_occurred;
-extern gchar *cmdline;
-extern bool quit_requested;
-
-void cmdline_keypress(gchar key);
-
#define IS_CTL(C) ((C) < ' ')
#define CTL_ECHO(C) ((C) | 0x40)
#define CTL_KEY(C) ((C) & ~0x40)
diff --git a/src/undo.cpp b/src/undo.cpp
index f873540..82f1eda 100644
--- a/src/undo.cpp
+++ b/src/undo.cpp
@@ -29,6 +29,7 @@
#include <Scintilla.h>
#include "sciteco.h"
+#include "cmdline.h"
#include "interface.h"
#include "undo.h"