Add the look, search, and write commands. - sam - An updated version of the sam text editor.
(HTM) git clone git://vernunftzentrum.de/sam.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit e3c7cd4d198971a71e0cff17613c17248d58a76b
(DIR) parent 3f2c8e96b3233b85916aaca81d4f414a8e90887f
(HTM) Author: Rob King <jking@deadpixi.com>
Date: Fri, 23 Sep 2016 21:57:21 -0500
Add the look, search, and write commands.
Diffstat:
doc/samrc | 6 +++++-
doc/samrc.5 | 3 +++
samterm/main.c | 36 ++++++++++++++++++++++++++++++-
samterm/menu.c | 6 ++++++
samterm/samrc.c | 3 +++
samterm/samterm.h | 5 ++++-
6 files changed, 56 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/doc/samrc b/doc/samrc
@@ -49,9 +49,13 @@ bind C z command send u
bind C Enter command send +-a/\n/
# Control-S writes the file, Control-Shift-S writes all files.
-bind C s command send w
+bind C s command write
bind CS s command send X w
+# Control-N does a search, Control-Shift-N does a look
+bind C n command search
+bind CS n command look
+
# I like 13pt Inconsolata (I need new glasses)
font Inconsolata:size=13
(DIR) diff --git a/doc/samrc.5 b/doc/samrc.5
@@ -260,6 +260,9 @@ eol Move to end of line None
bol Move to beginning of line None
tab Insert a (possibly expanded) tab Tab
send Append argument to command window None
+write Write the current file to disk None
+look Find the next occurance of the string in dot None
+search Find the next occurance of the last regex None
.TE
.Pp
Additionally,
(DIR) diff --git a/samterm/main.c b/samterm/main.c
@@ -670,6 +670,37 @@ cmdjump(Flayer *l, long a, Text *u, const char *arg)
}
static long
+cmdlook(Flayer *l, long a, Text *t, const char *arg)
+{
+ outTsll(Tlook, t->tag, which->p0, which->p1);
+ setlock();
+ return a;
+}
+
+static long
+cmdsearch(Flayer *l, long a, Text *t, const char *arg)
+{
+ if (t != &cmd && haspat()){
+ outcmd();
+ outT0(Tsearch);
+ setlock();
+ }
+ return a;
+}
+
+static long
+cmdwrite(Flayer *l, long a, Text *t, const char *arg)
+{
+ cursorswitch(BullseyeCursor);
+ if (t != &cmd){
+ outTs(Twrite, t->tag);
+ setlock();
+ }
+ cursorswitch(cursor);
+ return a;
+}
+
+static long
cmdescape(Flayer *l, long a, Text *t, const char *arg)
{
if (typeesc >= 0){
@@ -914,7 +945,10 @@ CommandEntry commands[Cmax] ={
[Ceol] = {cmdeol, false, false},
[Cbol] = {cmdbol, false, false},
[Ctab] = {cmdtab, false, false},
- [Csend] = {cmdsend, false, false}
+ [Csend] = {cmdsend, false, false},
+ [Clook] = {cmdlook, false, false},
+ [Csearch] = {cmdsearch, false, false},
+ [Cwrite] = {cmdwrite, false, false}
};
(DIR) diff --git a/samterm/menu.c b/samterm/menu.c
@@ -265,6 +265,12 @@ setpat(char *s)
menu2str[Search] = pat;
}
+bool
+haspat(void)
+{
+ return (bool)(menu2str[Search]);
+}
+
#define NBUF 64
static uchar buf[NBUF*UTFmax]={' ', ' ', ' ', ' '};
(DIR) diff --git a/samterm/samrc.c b/samterm/samrc.c
@@ -45,6 +45,9 @@ static Namemapping commandmapping[] ={
{"bol", Cbol},
{"tab", Ctab},
{"send", Csend},
+ {"look", Clook},
+ {"search", Csearch},
+ {"write", Cwrite},
{NULL, 0}
};
(DIR) diff --git a/samterm/samterm.h b/samterm/samterm.h
@@ -6,7 +6,6 @@
#define NL 5
enum{
-
Cescape = Csysmax + 1, /* highlight recently typed text */
Cscrolldown, /* scroll file down by screen */
Cscrollup, /* scroll file up by screen */
@@ -29,6 +28,9 @@ enum{
Cbol, /* move to end of line */
Ctab, /* insert a possibly expanded tab */
Csend, /* send a command to the editor */
+ Cwrite, /* write the current file */
+ Clook, /* literal search */
+ Csearch, /* search for regex again */
Cmax /* invalid command */
};
@@ -148,6 +150,7 @@ void menuins(int, uchar*, Text*, int, int);
void menudel(int);
Text *sweeptext(int, int);
void setpat(char*);
+bool haspat(void);
void scrdraw(Flayer*, long tot);
int rcontig(Rasp*, ulong, ulong, int);
int rmissing(Rasp*, ulong, ulong);