2019-09-10 15:55:44 +02:00
|
|
|
/* $NetBSD: vi.c,v 1.63 2019/07/23 10:18:52 christos Exp $ */
|
2011-03-31 02:46:27 +02:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Christos Zoulas of Cornell University.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2011-03-31 03:13:05 +02:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2011-03-31 02:46:27 +02:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
#include "config.h"
|
2011-03-31 02:46:27 +02:00
|
|
|
#if !defined(lint) && !defined(SCCSID)
|
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
|
|
|
|
#else
|
2019-09-10 15:55:44 +02:00
|
|
|
__RCSID("$NetBSD: vi.c,v 1.63 2019/07/23 10:18:52 christos Exp $");
|
2011-03-31 02:46:27 +02:00
|
|
|
#endif
|
|
|
|
#endif /* not lint && not SCCSID */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vi.c: Vi mode commands.
|
|
|
|
*/
|
2016-02-28 16:57:37 +01:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2011-03-31 02:46:27 +02:00
|
|
|
#include "el.h"
|
2016-02-28 16:57:37 +01:00
|
|
|
#include "common.h"
|
|
|
|
#include "emacs.h"
|
2017-09-13 17:57:58 +02:00
|
|
|
#include "fcns.h"
|
2016-02-28 16:57:37 +01:00
|
|
|
#include "vi.h"
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2017-09-13 17:57:58 +02:00
|
|
|
static el_action_t cv_action(EditLine *, wint_t);
|
|
|
|
static el_action_t cv_paste(EditLine *, wint_t);
|
2011-03-31 02:46:27 +02:00
|
|
|
|
|
|
|
/* cv_action():
|
|
|
|
* Handle vi actions.
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
static el_action_t
|
2016-02-28 16:57:37 +01:00
|
|
|
cv_action(EditLine *el, wint_t c)
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_chared.c_vcmd.action != NOP) {
|
|
|
|
/* 'cc', 'dd' and (possibly) friends */
|
2016-02-28 16:57:37 +01:00
|
|
|
if (c != (wint_t)el->el_chared.c_vcmd.action)
|
2011-03-31 03:13:05 +02:00
|
|
|
return CC_ERROR;
|
|
|
|
|
|
|
|
if (!(c & YANK))
|
|
|
|
cv_undo(el);
|
|
|
|
cv_yank(el, el->el_line.buffer,
|
2011-03-31 20:34:50 +02:00
|
|
|
(int)(el->el_line.lastchar - el->el_line.buffer));
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_chared.c_vcmd.action = NOP;
|
|
|
|
el->el_chared.c_vcmd.pos = 0;
|
2011-03-31 20:23:38 +02:00
|
|
|
if (!(c & YANK)) {
|
|
|
|
el->el_line.lastchar = el->el_line.buffer;
|
|
|
|
el->el_line.cursor = el->el_line.buffer;
|
|
|
|
}
|
2011-03-31 03:00:31 +02:00
|
|
|
if (c & INSERT)
|
|
|
|
el->el_map.current = el->el_map.key;
|
|
|
|
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
el->el_chared.c_vcmd.pos = el->el_line.cursor;
|
|
|
|
el->el_chared.c_vcmd.action = c;
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ARGHACK;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cv_paste():
|
|
|
|
* Paste previous deletion before or after the cursor
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
static el_action_t
|
2016-02-28 16:57:37 +01:00
|
|
|
cv_paste(EditLine *el, wint_t c)
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:13:05 +02:00
|
|
|
c_kill_t *k = &el->el_chared.c_kill;
|
2011-03-31 20:34:50 +02:00
|
|
|
size_t len = (size_t)(k->last - k->buf);
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (k->buf == NULL || len == 0)
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ERROR;
|
2011-03-31 02:46:27 +02:00
|
|
|
#ifdef DEBUG_PASTE
|
2017-09-13 17:57:58 +02:00
|
|
|
(void) fprintf(el->el_errfile, "Paste: \"%.*ls\"\n", (int)len,
|
2017-01-30 23:35:42 +01:00
|
|
|
k->buf);
|
2011-03-31 02:46:27 +02:00
|
|
|
#endif
|
2011-03-31 03:13:05 +02:00
|
|
|
|
|
|
|
cv_undo(el);
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
if (!c && el->el_line.cursor < el->el_line.lastchar)
|
|
|
|
el->el_line.cursor++;
|
|
|
|
|
2011-03-31 20:34:50 +02:00
|
|
|
c_insert(el, (int)len);
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_line.cursor + len > el->el_line.lastchar)
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ERROR;
|
2011-03-31 20:34:50 +02:00
|
|
|
(void) memcpy(el->el_line.cursor, k->buf, len *
|
|
|
|
sizeof(*el->el_line.cursor));
|
2011-03-31 20:23:38 +02:00
|
|
|
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
/* vi_paste_next():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi paste previous deletion to the right of the cursor
|
|
|
|
* [p]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_paste_next(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2012-09-25 12:41:30 +02:00
|
|
|
return cv_paste(el, 0);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
/* vi_paste_prev():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi paste previous deletion to the left of the cursor
|
|
|
|
* [P]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_paste_prev(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2012-09-25 12:41:30 +02:00
|
|
|
return cv_paste(el, 1);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
/* vi_prev_big_word():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi move to the previous space delimited word
|
|
|
|
* [B]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_prev_big_word(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
if (el->el_line.cursor == el->el_line.buffer)
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ERROR;
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
el->el_line.cursor = cv_prev_word(el->el_line.cursor,
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_line.buffer,
|
|
|
|
el->el_state.argument,
|
2011-03-31 03:13:05 +02:00
|
|
|
cv__isWord);
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_chared.c_vcmd.action != NOP) {
|
2011-03-31 03:00:31 +02:00
|
|
|
cv_delfini(el);
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 03:00:31 +02:00
|
|
|
}
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_CURSOR;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
/* vi_prev_word():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi move to the previous word
|
2011-03-31 03:13:05 +02:00
|
|
|
* [b]
|
2011-03-31 02:46:27 +02:00
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_prev_word(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
if (el->el_line.cursor == el->el_line.buffer)
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ERROR;
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
el->el_line.cursor = cv_prev_word(el->el_line.cursor,
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_line.buffer,
|
|
|
|
el->el_state.argument,
|
2011-03-31 03:13:05 +02:00
|
|
|
cv__isword);
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_chared.c_vcmd.action != NOP) {
|
2011-03-31 03:00:31 +02:00
|
|
|
cv_delfini(el);
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 03:00:31 +02:00
|
|
|
}
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_CURSOR;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
/* vi_next_big_word():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi move to the next space delimited word
|
|
|
|
* [W]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_next_big_word(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_line.cursor >= el->el_line.lastchar - 1)
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ERROR;
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
|
2011-03-31 03:13:05 +02:00
|
|
|
el->el_line.lastchar, el->el_state.argument, cv__isWord);
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
if (el->el_map.type == MAP_VI)
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_chared.c_vcmd.action != NOP) {
|
2011-03-31 03:00:31 +02:00
|
|
|
cv_delfini(el);
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 03:00:31 +02:00
|
|
|
}
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_CURSOR;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
|
|
|
|
/* vi_next_word():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi move to the next word
|
|
|
|
* [w]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_next_word(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_line.cursor >= el->el_line.lastchar - 1)
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ERROR;
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
|
2011-03-31 03:13:05 +02:00
|
|
|
el->el_line.lastchar, el->el_state.argument, cv__isword);
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
if (el->el_map.type == MAP_VI)
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_chared.c_vcmd.action != NOP) {
|
2011-03-31 03:00:31 +02:00
|
|
|
cv_delfini(el);
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 03:00:31 +02:00
|
|
|
}
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_CURSOR;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
/* vi_change_case():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi change case of character under the cursor and advance one character
|
|
|
|
* [~]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_change_case(EditLine *el, wint_t c)
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:13:05 +02:00
|
|
|
int i;
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_line.cursor >= el->el_line.lastchar)
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ERROR;
|
2011-03-31 03:13:05 +02:00
|
|
|
cv_undo(el);
|
|
|
|
for (i = 0; i < el->el_state.argument; i++) {
|
|
|
|
|
2011-03-31 20:34:50 +02:00
|
|
|
c = *el->el_line.cursor;
|
2017-09-13 17:57:58 +02:00
|
|
|
if (iswupper(c))
|
|
|
|
*el->el_line.cursor = towlower(c);
|
|
|
|
else if (iswlower(c))
|
|
|
|
*el->el_line.cursor = towupper(c);
|
2011-03-31 03:13:05 +02:00
|
|
|
|
|
|
|
if (++el->el_line.cursor >= el->el_line.lastchar) {
|
|
|
|
el->el_line.cursor--;
|
|
|
|
re_fastaddc(el);
|
|
|
|
break;
|
|
|
|
}
|
2011-03-31 03:00:31 +02:00
|
|
|
re_fastaddc(el);
|
|
|
|
}
|
2011-03-31 03:13:05 +02:00
|
|
|
return CC_NORM;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
/* vi_change_meta():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi change prefix command
|
|
|
|
* [c]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_change_meta(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete with insert == change: first we delete and then we leave in
|
|
|
|
* insert mode.
|
|
|
|
*/
|
2012-09-25 12:41:30 +02:00
|
|
|
return cv_action(el, DELETE | INSERT);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
/* vi_insert_at_bol():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi enter insert mode at the beginning of line
|
|
|
|
* [I]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_insert_at_bol(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_line.cursor = el->el_line.buffer;
|
2011-03-31 03:13:05 +02:00
|
|
|
cv_undo(el);
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_map.current = el->el_map.key;
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_CURSOR;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
/* vi_replace_char():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi replace character under the cursor with the next character typed
|
|
|
|
* [r]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_replace_char(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_line.cursor >= el->el_line.lastchar)
|
|
|
|
return CC_ERROR;
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_map.current = el->el_map.key;
|
|
|
|
el->el_state.inputmode = MODE_REPLACE_1;
|
2011-03-31 03:13:05 +02:00
|
|
|
cv_undo(el);
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ARGHACK;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
/* vi_replace_mode():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi enter replace mode
|
|
|
|
* [R]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_replace_mode(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
|
|
|
el->el_map.current = el->el_map.key;
|
|
|
|
el->el_state.inputmode = MODE_REPLACE;
|
2011-03-31 03:13:05 +02:00
|
|
|
cv_undo(el);
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_NORM;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
/* vi_substitute_char():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi replace character under the cursor and enter insert mode
|
2011-03-31 03:13:05 +02:00
|
|
|
* [s]
|
2011-03-31 02:46:27 +02:00
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_substitute_char(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
|
|
|
c_delafter(el, el->el_state.argument);
|
|
|
|
el->el_map.current = el->el_map.key;
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
/* vi_substitute_line():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi substitute entire line
|
|
|
|
* [S]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_substitute_line(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
cv_undo(el);
|
|
|
|
cv_yank(el, el->el_line.buffer,
|
2011-03-31 20:34:50 +02:00
|
|
|
(int)(el->el_line.lastchar - el->el_line.buffer));
|
2011-03-31 03:00:31 +02:00
|
|
|
(void) em_kill_line(el, 0);
|
|
|
|
el->el_map.current = el->el_map.key;
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
/* vi_change_to_eol():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi change to end of line
|
|
|
|
* [C]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_change_to_eol(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
cv_undo(el);
|
|
|
|
cv_yank(el, el->el_line.cursor,
|
2011-03-31 20:34:50 +02:00
|
|
|
(int)(el->el_line.lastchar - el->el_line.cursor));
|
2011-03-31 03:00:31 +02:00
|
|
|
(void) ed_kill_line(el, 0);
|
|
|
|
el->el_map.current = el->el_map.key;
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_insert():
|
|
|
|
* Vi enter insert mode
|
|
|
|
* [i]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_insert(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_map.current = el->el_map.key;
|
2011-03-31 03:13:05 +02:00
|
|
|
cv_undo(el);
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_NORM;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_add():
|
2011-03-31 03:00:31 +02:00
|
|
|
* Vi enter insert mode after the cursor
|
2011-03-31 02:46:27 +02:00
|
|
|
* [a]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_add(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
int ret;
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_map.current = el->el_map.key;
|
|
|
|
if (el->el_line.cursor < el->el_line.lastchar) {
|
|
|
|
el->el_line.cursor++;
|
|
|
|
if (el->el_line.cursor > el->el_line.lastchar)
|
|
|
|
el->el_line.cursor = el->el_line.lastchar;
|
|
|
|
ret = CC_CURSOR;
|
|
|
|
} else
|
|
|
|
ret = CC_NORM;
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
cv_undo(el);
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2012-09-25 12:41:30 +02:00
|
|
|
return (el_action_t)ret;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_add_at_eol():
|
|
|
|
* Vi enter insert mode at end of line
|
|
|
|
* [A]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_add_at_eol(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_map.current = el->el_map.key;
|
|
|
|
el->el_line.cursor = el->el_line.lastchar;
|
2011-03-31 03:13:05 +02:00
|
|
|
cv_undo(el);
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_CURSOR;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_delete_meta():
|
2011-03-31 03:00:31 +02:00
|
|
|
* Vi delete prefix command
|
2011-03-31 02:46:27 +02:00
|
|
|
* [d]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_delete_meta(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2012-09-25 12:41:30 +02:00
|
|
|
return cv_action(el, DELETE);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
/* vi_end_big_word():
|
2011-03-31 03:00:31 +02:00
|
|
|
* Vi move to the end of the current space delimited word
|
|
|
|
* [E]
|
2011-03-31 02:46:27 +02:00
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_end_big_word(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
if (el->el_line.cursor == el->el_line.lastchar)
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ERROR;
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_line.cursor = cv__endword(el->el_line.cursor,
|
2011-03-31 03:13:05 +02:00
|
|
|
el->el_line.lastchar, el->el_state.argument, cv__isWord);
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_chared.c_vcmd.action != NOP) {
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_line.cursor++;
|
|
|
|
cv_delfini(el);
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 03:00:31 +02:00
|
|
|
}
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_CURSOR;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
/* vi_end_word():
|
2011-03-31 02:46:27 +02:00
|
|
|
* Vi move to the end of the current word
|
|
|
|
* [e]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_end_word(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
if (el->el_line.cursor == el->el_line.lastchar)
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ERROR;
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_line.cursor = cv__endword(el->el_line.cursor,
|
2011-03-31 03:13:05 +02:00
|
|
|
el->el_line.lastchar, el->el_state.argument, cv__isword);
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_chared.c_vcmd.action != NOP) {
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_line.cursor++;
|
|
|
|
cv_delfini(el);
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 03:00:31 +02:00
|
|
|
}
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_CURSOR;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_undo():
|
|
|
|
* Vi undo last change
|
|
|
|
* [u]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_undo(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:13:05 +02:00
|
|
|
c_undo_t un = el->el_chared.c_undo;
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (un.len == -1)
|
|
|
|
return CC_ERROR;
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
/* switch line buffer and undo buffer */
|
|
|
|
el->el_chared.c_undo.buf = el->el_line.buffer;
|
|
|
|
el->el_chared.c_undo.len = el->el_line.lastchar - el->el_line.buffer;
|
2011-03-31 20:34:50 +02:00
|
|
|
el->el_chared.c_undo.cursor =
|
|
|
|
(int)(el->el_line.cursor - el->el_line.buffer);
|
2011-03-31 03:13:05 +02:00
|
|
|
el->el_line.limit = un.buf + (el->el_line.limit - el->el_line.buffer);
|
|
|
|
el->el_line.buffer = un.buf;
|
|
|
|
el->el_line.cursor = un.buf + un.cursor;
|
|
|
|
el->el_line.lastchar = un.buf + un.len;
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_command_mode():
|
|
|
|
* Vi enter command mode (use alternative key bindings)
|
|
|
|
* [<ESC>]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_command_mode(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
/* [Esc] cancels pending action */
|
|
|
|
el->el_chared.c_vcmd.action = NOP;
|
|
|
|
el->el_chared.c_vcmd.pos = 0;
|
|
|
|
|
|
|
|
el->el_state.doingarg = 0;
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_state.inputmode = MODE_INSERT;
|
|
|
|
el->el_map.current = el->el_map.alt;
|
2011-03-31 02:46:27 +02:00
|
|
|
#ifdef VI_MOVE
|
2011-03-31 03:00:31 +02:00
|
|
|
if (el->el_line.cursor > el->el_line.buffer)
|
|
|
|
el->el_line.cursor--;
|
2011-03-31 02:46:27 +02:00
|
|
|
#endif
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_CURSOR;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2011-03-31 02:46:27 +02:00
|
|
|
/* vi_zero():
|
2011-03-31 03:00:31 +02:00
|
|
|
* Vi move to the beginning of line
|
2011-03-31 02:46:27 +02:00
|
|
|
* [0]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_zero(EditLine *el, wint_t c)
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_state.doingarg)
|
|
|
|
return ed_argument_digit(el, c);
|
|
|
|
|
|
|
|
el->el_line.cursor = el->el_line.buffer;
|
|
|
|
if (el->el_chared.c_vcmd.action != NOP) {
|
|
|
|
cv_delfini(el);
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 03:00:31 +02:00
|
|
|
}
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_CURSOR;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_delete_prev_char():
|
2016-02-28 16:57:37 +01:00
|
|
|
* Vi move to previous character (backspace)
|
2011-03-31 03:13:05 +02:00
|
|
|
* [^H] in insert mode only
|
2011-03-31 03:00:31 +02:00
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_line.cursor <= el->el_line.buffer)
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ERROR;
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
c_delbefore1(el);
|
|
|
|
el->el_line.cursor--;
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 03:00:31 +02:00
|
|
|
}
|
2011-03-31 02:46:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* vi_list_or_eof():
|
|
|
|
* Vi list choices for completion or indicate end of file if empty line
|
|
|
|
* [^D]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_list_or_eof(EditLine *el, wint_t c)
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_line.cursor == el->el_line.lastchar) {
|
|
|
|
if (el->el_line.cursor == el->el_line.buffer) {
|
2012-09-25 12:41:30 +02:00
|
|
|
terminal_writec(el, c); /* then do a EOF */
|
|
|
|
return CC_EOF;
|
2011-03-31 03:13:05 +02:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Here we could list completions, but it is an
|
|
|
|
* error right now
|
|
|
|
*/
|
2012-09-25 12:41:30 +02:00
|
|
|
terminal_beep(el);
|
|
|
|
return CC_ERROR;
|
2011-03-31 03:13:05 +02:00
|
|
|
}
|
2011-03-31 03:00:31 +02:00
|
|
|
} else {
|
2011-03-31 03:13:05 +02:00
|
|
|
#ifdef notyet
|
2011-03-31 03:00:31 +02:00
|
|
|
re_goto_bottom(el);
|
|
|
|
*el->el_line.lastchar = '\0'; /* just in case */
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_LIST_CHOICES;
|
2011-03-31 03:13:05 +02:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Just complain for now.
|
|
|
|
*/
|
2012-09-25 12:41:30 +02:00
|
|
|
terminal_beep(el);
|
|
|
|
return CC_ERROR;
|
2011-03-31 02:46:27 +02:00
|
|
|
#endif
|
2011-03-31 03:13:05 +02:00
|
|
|
}
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_kill_line_prev():
|
2011-03-31 03:00:31 +02:00
|
|
|
* Vi cut from beginning of line to cursor
|
2011-03-31 02:46:27 +02:00
|
|
|
* [^U]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_kill_line_prev(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2017-09-13 17:57:58 +02:00
|
|
|
wchar_t *kp, *cp;
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:00:31 +02:00
|
|
|
cp = el->el_line.buffer;
|
|
|
|
kp = el->el_chared.c_kill.buf;
|
|
|
|
while (cp < el->el_line.cursor)
|
|
|
|
*kp++ = *cp++; /* copy it */
|
|
|
|
el->el_chared.c_kill.last = kp;
|
2011-03-31 20:34:50 +02:00
|
|
|
c_delbefore(el, (int)(el->el_line.cursor - el->el_line.buffer));
|
2011-03-31 03:00:31 +02:00
|
|
|
el->el_line.cursor = el->el_line.buffer; /* zap! */
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_search_prev():
|
|
|
|
* Vi search history previous
|
|
|
|
* [?]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_search_prev(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2012-09-25 12:41:30 +02:00
|
|
|
return cv_search(el, ED_SEARCH_PREV_HISTORY);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_search_next():
|
|
|
|
* Vi search history next
|
|
|
|
* [/]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_search_next(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2012-09-25 12:41:30 +02:00
|
|
|
return cv_search(el, ED_SEARCH_NEXT_HISTORY);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_repeat_search_next():
|
|
|
|
* Vi repeat current search in the same search direction
|
|
|
|
* [n]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_repeat_search_next(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
|
|
|
if (el->el_search.patlen == 0)
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ERROR;
|
2011-03-31 03:00:31 +02:00
|
|
|
else
|
2012-09-25 12:41:30 +02:00
|
|
|
return cv_repeat_srch(el, el->el_search.patdir);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_repeat_search_prev():
|
|
|
|
* Vi repeat current search in the opposite search direction
|
|
|
|
* [N]
|
|
|
|
*/
|
|
|
|
/*ARGSUSED*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_repeat_search_prev(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:00:31 +02:00
|
|
|
|
|
|
|
if (el->el_search.patlen == 0)
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_ERROR;
|
2011-03-31 03:00:31 +02:00
|
|
|
else
|
|
|
|
return (cv_repeat_srch(el,
|
|
|
|
el->el_search.patdir == ED_SEARCH_PREV_HISTORY ?
|
|
|
|
ED_SEARCH_NEXT_HISTORY : ED_SEARCH_PREV_HISTORY));
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_next_char():
|
|
|
|
* Vi move to the character specified next
|
|
|
|
* [f]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_next_char(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:13:05 +02:00
|
|
|
return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 0);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_prev_char():
|
|
|
|
* Vi move to the character specified previous
|
|
|
|
* [F]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:13:05 +02:00
|
|
|
return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 0);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_to_next_char():
|
|
|
|
* Vi move up to the character specified next
|
|
|
|
* [t]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_to_next_char(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:13:05 +02:00
|
|
|
return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 1);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_to_prev_char():
|
|
|
|
* Vi move up to the character specified previous
|
|
|
|
* [T]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_to_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:13:05 +02:00
|
|
|
return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 1);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_repeat_next_char():
|
|
|
|
* Vi repeat current character search in the same search direction
|
|
|
|
* [;]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_repeat_next_char(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
return cv_csearch(el, el->el_search.chadir, el->el_search.chacha,
|
|
|
|
el->el_state.argument, el->el_search.chatflg);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_repeat_prev_char():
|
|
|
|
* Vi repeat current character search in the opposite search direction
|
|
|
|
* [,]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 02:46:27 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_repeat_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 02:46:27 +02:00
|
|
|
{
|
2011-03-31 03:13:05 +02:00
|
|
|
el_action_t r;
|
|
|
|
int dir = el->el_search.chadir;
|
2011-03-31 02:46:27 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
r = cv_csearch(el, -dir, el->el_search.chacha,
|
|
|
|
el->el_state.argument, el->el_search.chatflg);
|
|
|
|
el->el_search.chadir = dir;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* vi_match():
|
|
|
|
* Vi go to matching () {} or []
|
|
|
|
* [%]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 03:13:05 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_match(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 03:13:05 +02:00
|
|
|
{
|
2017-09-13 17:57:58 +02:00
|
|
|
const wchar_t match_chars[] = L"()[]{}";
|
|
|
|
wchar_t *cp;
|
2011-03-31 20:34:50 +02:00
|
|
|
size_t delta, i, count;
|
2017-09-13 17:57:58 +02:00
|
|
|
wchar_t o_ch, c_ch;
|
2011-03-31 03:13:05 +02:00
|
|
|
|
|
|
|
*el->el_line.lastchar = '\0'; /* just in case */
|
|
|
|
|
2017-09-13 17:57:58 +02:00
|
|
|
i = wcscspn(el->el_line.cursor, match_chars);
|
2011-03-31 03:13:05 +02:00
|
|
|
o_ch = el->el_line.cursor[i];
|
|
|
|
if (o_ch == 0)
|
|
|
|
return CC_ERROR;
|
2017-09-13 17:57:58 +02:00
|
|
|
delta = (size_t)(wcschr(match_chars, o_ch) - match_chars);
|
2011-03-31 03:13:05 +02:00
|
|
|
c_ch = match_chars[delta ^ 1];
|
|
|
|
count = 1;
|
|
|
|
delta = 1 - (delta & 1) * 2;
|
|
|
|
|
|
|
|
for (cp = &el->el_line.cursor[i]; count; ) {
|
|
|
|
cp += delta;
|
|
|
|
if (cp < el->el_line.buffer || cp >= el->el_line.lastchar)
|
|
|
|
return CC_ERROR;
|
|
|
|
if (*cp == o_ch)
|
|
|
|
count++;
|
|
|
|
else if (*cp == c_ch)
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
el->el_line.cursor = cp;
|
|
|
|
|
|
|
|
if (el->el_chared.c_vcmd.action != NOP) {
|
|
|
|
/* NB posix says char under cursor should NOT be deleted
|
|
|
|
for -ve delta - this is different to netbsd vi. */
|
|
|
|
if (delta > 0)
|
|
|
|
el->el_line.cursor++;
|
|
|
|
cv_delfini(el);
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_REFRESH;
|
2011-03-31 03:13:05 +02:00
|
|
|
}
|
2012-09-25 12:41:30 +02:00
|
|
|
return CC_CURSOR;
|
2011-03-31 03:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vi_undo_line():
|
|
|
|
* Vi undo all changes to line
|
|
|
|
* [U]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 03:13:05 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_undo_line(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 03:13:05 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
cv_undo(el);
|
|
|
|
return hist_get(el);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vi_to_column():
|
|
|
|
* Vi go to specified column
|
|
|
|
* [|]
|
|
|
|
* NB netbsd vi goes to screen column 'n', posix says nth character
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 03:13:05 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_to_column(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 03:13:05 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
el->el_line.cursor = el->el_line.buffer;
|
|
|
|
el->el_state.argument--;
|
|
|
|
return ed_next_char(el, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vi_yank_end():
|
|
|
|
* Vi yank to end of line
|
|
|
|
* [Y]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 03:13:05 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_yank_end(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 03:13:05 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
cv_yank(el, el->el_line.cursor,
|
2011-03-31 20:34:50 +02:00
|
|
|
(int)(el->el_line.lastchar - el->el_line.cursor));
|
2011-03-31 03:13:05 +02:00
|
|
|
return CC_REFRESH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vi_yank():
|
|
|
|
* Vi yank
|
|
|
|
* [y]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 03:13:05 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_yank(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 03:13:05 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
return cv_action(el, YANK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vi_comment_out():
|
|
|
|
* Vi comment out current command
|
2011-03-31 20:23:38 +02:00
|
|
|
* [#]
|
2011-03-31 03:13:05 +02:00
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 03:13:05 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_comment_out(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 03:13:05 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
el->el_line.cursor = el->el_line.buffer;
|
|
|
|
c_insert(el, 1);
|
|
|
|
*el->el_line.cursor = '#';
|
|
|
|
re_refresh(el);
|
|
|
|
return ed_newline(el, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vi_alias():
|
|
|
|
* Vi include shell alias
|
|
|
|
* [@]
|
2011-03-31 20:23:38 +02:00
|
|
|
* NB: posix implies that we should enter insert mode, however
|
2011-03-31 03:13:05 +02:00
|
|
|
* this is against historical precedent...
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 03:13:05 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_alias(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 03:13:05 +02:00
|
|
|
{
|
|
|
|
char alias_name[3];
|
2015-01-12 22:33:35 +01:00
|
|
|
const char *alias_text;
|
2011-03-31 03:13:05 +02:00
|
|
|
|
2015-01-12 22:33:35 +01:00
|
|
|
if (el->el_chared.c_aliasfun == NULL)
|
2011-03-31 03:13:05 +02:00
|
|
|
return CC_ERROR;
|
|
|
|
|
|
|
|
alias_name[0] = '_';
|
|
|
|
alias_name[2] = 0;
|
|
|
|
if (el_getc(el, &alias_name[1]) != 1)
|
|
|
|
return CC_ERROR;
|
|
|
|
|
2015-01-12 22:33:35 +01:00
|
|
|
alias_text = (*el->el_chared.c_aliasfun)(el->el_chared.c_aliasarg,
|
|
|
|
alias_name);
|
2011-03-31 03:13:05 +02:00
|
|
|
if (alias_text != NULL)
|
2017-09-13 17:57:58 +02:00
|
|
|
el_wpush(el, ct_decode_string(alias_text, &el->el_scratch));
|
2011-03-31 03:13:05 +02:00
|
|
|
return CC_NORM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vi_to_history_line():
|
|
|
|
* Vi go to specified history file line.
|
|
|
|
* [G]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 03:13:05 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_to_history_line(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 03:13:05 +02:00
|
|
|
{
|
|
|
|
int sv_event_no = el->el_history.eventno;
|
|
|
|
el_action_t rval;
|
|
|
|
|
|
|
|
|
|
|
|
if (el->el_history.eventno == 0) {
|
2017-09-13 17:57:58 +02:00
|
|
|
(void) wcsncpy(el->el_history.buf, el->el_line.buffer,
|
2011-03-31 03:13:05 +02:00
|
|
|
EL_BUFSIZ);
|
|
|
|
el->el_history.last = el->el_history.buf +
|
|
|
|
(el->el_line.lastchar - el->el_line.buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lack of a 'count' means oldest, not 1 */
|
|
|
|
if (!el->el_state.doingarg) {
|
|
|
|
el->el_history.eventno = 0x7fffffff;
|
|
|
|
hist_get(el);
|
|
|
|
} else {
|
|
|
|
/* This is brain dead, all the rest of this code counts
|
|
|
|
* upwards going into the past. Here we need count in the
|
|
|
|
* other direction (to match the output of fc -l).
|
|
|
|
* I could change the world, but this seems to suffice.
|
|
|
|
*/
|
|
|
|
el->el_history.eventno = 1;
|
|
|
|
if (hist_get(el) == CC_ERROR)
|
|
|
|
return CC_ERROR;
|
2016-02-28 16:57:37 +01:00
|
|
|
el->el_history.eventno = 1 + el->el_history.ev.num
|
2011-03-31 03:13:05 +02:00
|
|
|
- el->el_state.argument;
|
|
|
|
if (el->el_history.eventno < 0) {
|
|
|
|
el->el_history.eventno = sv_event_no;
|
|
|
|
return CC_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rval = hist_get(el);
|
|
|
|
if (rval == CC_ERROR)
|
|
|
|
el->el_history.eventno = sv_event_no;
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vi_histedit():
|
|
|
|
* Vi edit history line with vi
|
|
|
|
* [v]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 03:13:05 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_histedit(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 03:13:05 +02:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
pid_t pid;
|
2011-03-31 20:34:50 +02:00
|
|
|
ssize_t st;
|
|
|
|
int status;
|
2011-03-31 03:13:05 +02:00
|
|
|
char tempfile[] = "/tmp/histedit.XXXXXXXXXX";
|
2012-09-25 12:41:30 +02:00
|
|
|
char *cp = NULL;
|
2011-03-31 20:34:50 +02:00
|
|
|
size_t len;
|
2017-09-13 17:57:58 +02:00
|
|
|
wchar_t *line = NULL;
|
2011-03-31 03:13:05 +02:00
|
|
|
|
|
|
|
if (el->el_state.doingarg) {
|
|
|
|
if (vi_to_history_line(el, 0) == CC_ERROR)
|
|
|
|
return CC_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = mkstemp(tempfile);
|
|
|
|
if (fd < 0)
|
|
|
|
return CC_ERROR;
|
2011-03-31 20:34:50 +02:00
|
|
|
len = (size_t)(el->el_line.lastchar - el->el_line.buffer);
|
|
|
|
#define TMP_BUFSIZ (EL_BUFSIZ * MB_LEN_MAX)
|
2019-09-10 15:55:44 +02:00
|
|
|
cp = el_calloc(TMP_BUFSIZ, sizeof(*cp));
|
2011-03-31 20:34:50 +02:00
|
|
|
if (cp == NULL)
|
2012-09-25 12:41:30 +02:00
|
|
|
goto error;
|
2019-09-10 15:55:44 +02:00
|
|
|
line = el_calloc(len + 1, sizeof(*line));
|
2012-09-25 12:41:30 +02:00
|
|
|
if (line == NULL)
|
|
|
|
goto error;
|
2017-09-13 17:57:58 +02:00
|
|
|
wcsncpy(line, el->el_line.buffer, len);
|
2011-03-31 20:34:50 +02:00
|
|
|
line[len] = '\0';
|
2017-09-13 17:57:58 +02:00
|
|
|
wcstombs(cp, line, TMP_BUFSIZ - 1);
|
2011-03-31 20:34:50 +02:00
|
|
|
cp[TMP_BUFSIZ - 1] = '\0';
|
|
|
|
len = strlen(cp);
|
|
|
|
write(fd, cp, len);
|
2012-09-25 12:41:30 +02:00
|
|
|
write(fd, "\n", (size_t)1);
|
2011-03-31 03:13:05 +02:00
|
|
|
pid = fork();
|
|
|
|
switch (pid) {
|
|
|
|
case -1:
|
2012-09-25 12:41:30 +02:00
|
|
|
goto error;
|
2011-03-31 03:13:05 +02:00
|
|
|
case 0:
|
|
|
|
close(fd);
|
2011-03-31 20:34:50 +02:00
|
|
|
execlp("vi", "vi", tempfile, (char *)NULL);
|
2011-03-31 03:13:05 +02:00
|
|
|
exit(0);
|
|
|
|
/*NOTREACHED*/
|
|
|
|
default:
|
2011-03-31 20:34:50 +02:00
|
|
|
while (waitpid(pid, &status, 0) != pid)
|
2011-03-31 03:13:05 +02:00
|
|
|
continue;
|
2011-03-31 20:34:50 +02:00
|
|
|
lseek(fd, (off_t)0, SEEK_SET);
|
2016-02-07 02:38:50 +01:00
|
|
|
st = read(fd, cp, TMP_BUFSIZ - 1);
|
2011-03-31 20:34:50 +02:00
|
|
|
if (st > 0) {
|
2016-02-07 02:38:50 +01:00
|
|
|
cp[st] = '\0';
|
|
|
|
len = (size_t)(el->el_line.limit - el->el_line.buffer);
|
2017-09-13 17:57:58 +02:00
|
|
|
len = mbstowcs(el->el_line.buffer, cp, len);
|
2016-02-07 02:38:50 +01:00
|
|
|
if (len > 0 && el->el_line.buffer[len - 1] == '\n')
|
2011-03-31 20:34:50 +02:00
|
|
|
--len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
len = 0;
|
|
|
|
el->el_line.cursor = el->el_line.buffer;
|
|
|
|
el->el_line.lastchar = el->el_line.buffer + len;
|
|
|
|
el_free(cp);
|
|
|
|
el_free(line);
|
2011-03-31 03:13:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
unlink(tempfile);
|
|
|
|
/* return CC_REFRESH; */
|
|
|
|
return ed_newline(el, 0);
|
2012-09-25 12:41:30 +02:00
|
|
|
error:
|
|
|
|
el_free(line);
|
|
|
|
el_free(cp);
|
|
|
|
close(fd);
|
|
|
|
unlink(tempfile);
|
|
|
|
return CC_ERROR;
|
2011-03-31 03:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vi_history_word():
|
|
|
|
* Vi append word from previous input line
|
|
|
|
* [_]
|
|
|
|
* Who knows where this one came from!
|
|
|
|
* '_' in vi means 'entire current line', so 'cc' is a synonym for 'c_'
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 03:13:05 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_history_word(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 03:13:05 +02:00
|
|
|
{
|
2017-09-13 17:57:58 +02:00
|
|
|
const wchar_t *wp = HIST_FIRST(el);
|
|
|
|
const wchar_t *wep, *wsp;
|
2011-03-31 03:13:05 +02:00
|
|
|
int len;
|
2017-09-13 17:57:58 +02:00
|
|
|
wchar_t *cp;
|
|
|
|
const wchar_t *lim;
|
2011-03-31 03:13:05 +02:00
|
|
|
|
|
|
|
if (wp == NULL)
|
|
|
|
return CC_ERROR;
|
|
|
|
|
2017-09-13 17:57:58 +02:00
|
|
|
wep = wsp = NULL;
|
2011-03-31 03:13:05 +02:00
|
|
|
do {
|
2017-09-13 17:57:58 +02:00
|
|
|
while (iswspace(*wp))
|
2011-03-31 03:13:05 +02:00
|
|
|
wp++;
|
|
|
|
if (*wp == 0)
|
|
|
|
break;
|
|
|
|
wsp = wp;
|
2017-09-13 17:57:58 +02:00
|
|
|
while (*wp && !iswspace(*wp))
|
2011-03-31 03:13:05 +02:00
|
|
|
wp++;
|
|
|
|
wep = wp;
|
2011-03-31 20:34:50 +02:00
|
|
|
} while ((!el->el_state.doingarg || --el->el_state.argument > 0)
|
|
|
|
&& *wp != 0);
|
2011-03-31 03:13:05 +02:00
|
|
|
|
2017-09-13 17:57:58 +02:00
|
|
|
if (wsp == NULL || (el->el_state.doingarg && el->el_state.argument != 0))
|
2011-03-31 03:13:05 +02:00
|
|
|
return CC_ERROR;
|
|
|
|
|
|
|
|
cv_undo(el);
|
2011-03-31 20:34:50 +02:00
|
|
|
len = (int)(wep - wsp);
|
2011-03-31 03:13:05 +02:00
|
|
|
if (el->el_line.cursor < el->el_line.lastchar)
|
|
|
|
el->el_line.cursor++;
|
|
|
|
c_insert(el, len + 1);
|
|
|
|
cp = el->el_line.cursor;
|
|
|
|
lim = el->el_line.limit;
|
|
|
|
if (cp < lim)
|
|
|
|
*cp++ = ' ';
|
|
|
|
while (wsp < wep && cp < lim)
|
|
|
|
*cp++ = *wsp++;
|
|
|
|
el->el_line.cursor = cp;
|
|
|
|
|
|
|
|
el->el_map.current = el->el_map.key;
|
|
|
|
return CC_REFRESH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vi_redo():
|
|
|
|
* Vi redo last non-motion command
|
|
|
|
* [.]
|
|
|
|
*/
|
2017-09-13 17:57:58 +02:00
|
|
|
libedit_private el_action_t
|
2011-03-31 03:13:05 +02:00
|
|
|
/*ARGSUSED*/
|
2016-02-28 16:57:37 +01:00
|
|
|
vi_redo(EditLine *el, wint_t c __attribute__((__unused__)))
|
2011-03-31 03:13:05 +02:00
|
|
|
{
|
|
|
|
c_redo_t *r = &el->el_chared.c_redo;
|
|
|
|
|
|
|
|
if (!el->el_state.doingarg && r->count) {
|
|
|
|
el->el_state.doingarg = 1;
|
|
|
|
el->el_state.argument = r->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
el->el_chared.c_vcmd.pos = el->el_line.cursor;
|
|
|
|
el->el_chared.c_vcmd.action = r->action;
|
|
|
|
if (r->pos != r->buf) {
|
|
|
|
if (r->pos + 1 > r->lim)
|
|
|
|
/* sanity */
|
|
|
|
r->pos = r->lim - 1;
|
|
|
|
r->pos[0] = 0;
|
2017-09-13 17:57:58 +02:00
|
|
|
el_wpush(el, r->buf);
|
2011-03-31 03:13:05 +02:00
|
|
|
}
|
2011-03-31 03:00:31 +02:00
|
|
|
|
2011-03-31 03:13:05 +02:00
|
|
|
el->el_state.thiscmd = r->cmd;
|
|
|
|
el->el_state.thisch = r->ch;
|
2012-09-25 12:41:30 +02:00
|
|
|
return (*el->el_map.func[r->cmd])(el, r->ch);
|
2011-03-31 02:46:27 +02:00
|
|
|
}
|