ke: add delete-line

This commit is contained in:
Kyle Isom 2024-05-29 08:54:42 -07:00
parent c35a489092
commit a337852d27
2 changed files with 22 additions and 17 deletions

View File

@ -24,6 +24,8 @@ saving a file can be done with either C-k s or C-k C-s.
.Bl -tag -width xxxxxxxxxxxx -offset indent .Bl -tag -width xxxxxxxxxxxx -offset indent
.It C-k BACKSPACE .It C-k BACKSPACE
Delete from the cursor to the beginning of the line. Delete from the cursor to the beginning of the line.
.It C-k C-d
Delete the current row.
.It C-k d .It C-k d
Delete from the cursor to the end of the line. Delete from the cursor to the end of the line.
.It C-k e .It C-k e

View File

@ -44,7 +44,7 @@
/* /*
* Function declarations. * Function and struct declarations.
*/ */
/* append buffer */ /* append buffer */
@ -364,7 +364,7 @@ get_winsz(int *rows, int *cols)
void void
goto_line() goto_line(void)
{ {
int lineno = 0; int lineno = 0;
char *query = editor_prompt("Line: %s", NULL); char *query = editor_prompt("Line: %s", NULL);
@ -465,7 +465,7 @@ insertch(int16_t c)
void void
deletech() deletech(void)
{ {
struct erow *row = NULL; struct erow *row = NULL;
@ -565,7 +565,7 @@ rows_to_buffer(int *buflen)
int int
save_file() save_file(void)
{ {
int fd = -1; int fd = -1;
int len; int len;
@ -652,7 +652,7 @@ is_arrow_key(int16_t c)
int16_t int16_t
get_keypress() get_keypress(void)
{ {
char seq[3]; char seq[3];
char c = -1; char c = -1;
@ -818,7 +818,7 @@ editor_find_callback(char *query, int16_t c)
void void
editor_find() editor_find(void)
{ {
char *query; char *query;
int scx = editor.curx; int scx = editor.curx;
@ -842,7 +842,7 @@ editor_find()
void void
editor_openfile() editor_openfile(void)
{ {
char *filename; char *filename;
@ -943,7 +943,7 @@ move_cursor(int16_t c)
void void
newline() newline(void)
{ {
struct erow *row = NULL; struct erow *row = NULL;
@ -983,6 +983,9 @@ process_kcommand(int16_t c)
case CTRL_KEY('x'): case CTRL_KEY('x'):
case 'x': case 'x':
exit(save_file()); exit(save_file());
case CTRL_KEY('d'):
delete_row(editor.cury);
break;
case 'd': case 'd':
while ((editor.row[editor.cury].size - editor.curx) > 0) { while ((editor.row[editor.cury].size - editor.curx) > 0) {
process_normal(DEL_KEY); process_normal(DEL_KEY);
@ -1101,7 +1104,7 @@ process_escape(int16_t c)
int int
process_keypress() process_keypress(void)
{ {
int16_t c = get_keypress(); int16_t c = get_keypress();
@ -1137,7 +1140,7 @@ process_keypress()
* is to be in canonical (cooked) mode, which is a buffered input mode. * is to be in canonical (cooked) mode, which is a buffered input mode.
*/ */
void void
enable_termraw() enable_termraw(void)
{ {
struct termios raw; struct termios raw;
@ -1187,7 +1190,7 @@ display_clear(struct abuf *ab)
void void
disable_termraw() disable_termraw(void)
{ {
display_clear(NULL); display_clear(NULL);
@ -1198,7 +1201,7 @@ disable_termraw()
void void
setup_terminal() setup_terminal(void)
{ {
if (tcgetattr(STDIN_FILENO, &editor.entry_term) == -1) { if (tcgetattr(STDIN_FILENO, &editor.entry_term) == -1) {
die("can't snapshot terminal settings"); die("can't snapshot terminal settings");
@ -1255,7 +1258,7 @@ draw_rows(struct abuf *ab)
char char
status_mode_char() status_mode_char(void)
{ {
switch (editor.mode) { switch (editor.mode) {
case MODE_NORMAL: case MODE_NORMAL:
@ -1317,7 +1320,7 @@ draw_message_line(struct abuf *ab)
void void
scroll() scroll(void)
{ {
editor.rx = 0; editor.rx = 0;
if (editor.cury < editor.nrows) { if (editor.cury < editor.nrows) {
@ -1345,7 +1348,7 @@ scroll()
void void
display_refresh() display_refresh(void)
{ {
char buf[32]; char buf[32];
struct abuf ab = ABUF_INIT; struct abuf ab = ABUF_INIT;
@ -1385,7 +1388,7 @@ editor_set_status(const char *fmt, ...)
void void
loop() loop(void)
{ {
int up = 1; /* update on the first runthrough */ int up = 1; /* update on the first runthrough */
@ -1409,7 +1412,7 @@ loop()
* init_editor should set up the global editor struct. * init_editor should set up the global editor struct.
*/ */
void void
init_editor() init_editor(void)
{ {
editor.cols = 0; editor.cols = 0;
editor.rows = 0; editor.rows = 0;