* zle_hist.c - history editing
* This file is part of zsh, the Z shell.
* This software is Copyright 1992 by Paul Falstad
* Permission is hereby granted to copy, reproduce, redistribute or otherwise
* use this software as long as: there is no monetary profit gained
* specifically from the use or reproduction of this software, it is not
* sold, rented, traded or otherwise marketed, and this copyright notice is
* included prominently in any copy made.
* The author make no claims as to the fitness or correctness of this software
* for any use whatsoever, and it is provided as is. Any use of this software
* is at the user's own risk.
void toggleliteralhistory() /**/
curhistline
= ztrdup(line
);
if (!(s
= qgetevent(histline
)))
if (mult
< 0) { mult
= -mult
; downhistory(); return; }
curhistline
= ztrdup(line
);
if (!(s
= qgetevent(histline
)))
if (unset(NOHISTBEEP
)) feep();
void uplineorhistory() /**/
if (mult
< 0) { mult
= -mult
; downlineorhistory(); return; }
if ((lastcmd
& ZLE_LINEMOVE
) != ZLE_LINEMOVE
)
void downlineorhistory() /**/
if (mult
< 0) { mult
= -mult
; uplineorhistory(); return; }
if ((lastcmd
& ZLE_LINEMOVE
) != ZLE_LINEMOVE
)
void acceptlineanddownhistory() /**/
if (!(s
= qgetevent(histline
+1)))
pushnode(bufstack
,t
= ztrdup(s
));
if (mult
< 0) { mult
= -mult
; uphistory(); return; }
if (!(s
= qgetevent(histline
)))
if (unset(NOHISTBEEP
)) feep();
void historysearchbackward() /**/
int t0
,ohistline
= histline
;
curhistline
= ztrdup(line
);
if (lastcmd
& ZLE_HISTSEARCH
) t0
= histpos
;
else for (t0
= 0; line
[t0
] && iword(line
[t0
]); t0
++);
if (!(s
= qgetevent(histline
)))
if (!hstrncmp(s
,line
,t0
) && hstrcmp(s
,line
))
void historysearchforward() /**/
int t0
,ohistline
= histline
;
curhistline
= ztrdup(line
);
if (lastcmd
& ZLE_HISTSEARCH
) t0
= histpos
;
else for (t0
= 0; line
[t0
] && iword(line
[t0
]); t0
++);
if (!(s
= qgetevent(histline
)))
if (!hstrncmp(s
,line
,t0
) && hstrcmp(s
,line
))
void beginningofbufferorhistory() /**/
void beginningofhistory() /**/
curhistline
= ztrdup(line
);
if (!(s
= qgetevent(firsthist())))
if (unset(NOHISTBEEP
)) feep();
void endofbufferorhistory() /**/
if (histline
== curhist
) {
if (unset(NOHISTBEEP
)) feep();
sethistline(curhistline
);
void insertlastword() /**/
/* multiple calls will now search back through the history, pem */
static int lasthist
, lastpos
;
int evhist
= curhist
- 1;
int len
= strlen(lastinsert
);
strncmp(lastinsert
, (char *) &line
[lastpos
], len
) == 0) {
if (!(s
= qgetevent(evhist
), lithist
= z
, s
))
for (t
= s
+strlen(s
); t
> s
; t
--)
spaceinline(len
= strlen(t
));
strncpy((char *) line
+cs
,t
,len
);
return ((ev
== curhist
) ? curhistline
: quietgetevent(ev
));
pushnode(bufstack
,ztrdup(line
));
pushnode(bufstack
,ztrdup(""));
char *s
= getnode(bufstack
);
strncpy((char *) line
+cs
,s
,cc
);
void historyincrementalsearchbackward() /**/
void historyincrementalsearchforward() /**/
char ibuf
[256],*sbuf
= ibuf
+10;
int sbptr
= 0,ch
,ohl
= histline
,ocs
= cs
;
int nomatch
= 0,chequiv
= 0;
strcpy(ibuf
,"i-search: ");
curhistline
= ztrdup(line
);
if (sbptr
> 1 || (sbptr
== 1 && sbuf
[0] != '^'))
int ohistline
= histline
;
if (!(s
= qgetevent(histline
)))
(t
= (hstrncmp(s
,sbuf
+1,sbptr
-1)) ? NULL
: s
) :
(t
= hstrnstr(s
,sbuf
,sbptr
)))
if (!(chequiv
&& !hstrcmp(line
,s
)))
cs
= t
-s
+sbptr
-(sbuf
[0] == '^');
if ((ch
= getkey(1)) == -1)
if (ch
== 22 || ch
== 17) {
if ((ch
= getkey(1)) == -1)
} else if (ch
== 24) { /* ^XS and ^XR */
if ((ch
= getkey(1)) == -1)
if (ch
!= 's' && ch
!= 'r') {
} else if (ch
== 8 || ch
== 127) {
} else if (ch
== 7 || ch
== 3) {
else if (ch
== 10 || ch
== 13) {
ohl
= (histline
+= (dir
= -1));
ohl
= (histline
+= (dir
= 1));
} else if (!(ch
& 0x60)) {
if (!nomatch
&& sbptr
!= 39 && !icntrl(ch
)) {
void acceptandinfernexthistory() /**/
for (t0
= histline
-2;;t0
--)
if (!(s
= qgetevent(t0
)))
if (!hstrncmp(s
,line
,ll
))
if (!(s
= qgetevent(t0
+1)))
pushnode(bufstack
,t
= ztrdup(s
));
void infernexthistory() /**/
if (!(t
= qgetevent(histline
-1)))
for (t0
= histline
-2;;t0
--)
if (!(s
= qgetevent(t0
)))
if (!(s
= qgetevent(t0
+1)))
void vifetchhistory() /**/
if (histline
== curhist
) {
if (!(lastcmd
& ZLE_ARG
)) {
curhistline
= ztrdup(line
);
if (!(lastcmd
& ZLE_ARG
)) mult
= curhist
;
if (!(s
= qgetevent(mult
)))
if (c
== '\r' || c
== '\n' || c
== '\033')
visrchstr
= ztrdup(sbuf
+1);
if (c
== '\b' || c
== 127)
void vihistorysearchforward() /**/
void vihistorysearchbackward() /**/
void virepeatsearch() /**/
int ohistline
= histline
,t0
;
curhistline
= ztrdup(line
);
if (!(s
= qgetevent(histline
)))
if (!hstrncmp(s
,visrchstr
+1,t0
-1))
if (hstrnstr(s
,visrchstr
,t0
))
void virevrepeatsearch() /**/
visrchsense
= -visrchsense
;
visrchsense
= -visrchsense
;