Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| acde895fb7 | |||
| 78d522ba98 | |||
| feb6667a24 | |||
|
|
66c79e0762 | ||
| a51b98c31f | |||
| 707362574c |
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
|
|||||||
project(ke C) # Specify C language explicitly
|
project(ke C) # Specify C language explicitly
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 99)
|
set(CMAKE_C_STANDARD 99)
|
||||||
set(KE_VERSION "1.3.5")
|
set(KE_VERSION "1.3.6")
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g")
|
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g")
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DEFAULT_SOURCE -D_XOPEN_SOURCE")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DEFAULT_SOURCE -D_XOPEN_SOURCE")
|
||||||
|
|||||||
21
default.nix
21
default.nix
@@ -1,16 +1,25 @@
|
|||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
installShellFiles,
|
|
||||||
stdenv,
|
stdenv,
|
||||||
|
cmake,
|
||||||
|
installShellFiles,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
pname = "ke";
|
pname = "ke";
|
||||||
version = "1.3.5";
|
version = "1.3.6";
|
||||||
|
|
||||||
src = lib.cleanSource ./.;
|
src = lib.cleanSource ./.;
|
||||||
|
|
||||||
nativeBuildInputs = [ installShellFiles ];
|
nativeBuildInputs = [
|
||||||
|
cmake
|
||||||
|
installShellFiles
|
||||||
|
];
|
||||||
|
|
||||||
|
cmakeFlags = [
|
||||||
|
"-DENABLE_ASAN=on"
|
||||||
|
"-DCMAKE_BUILD_TYPE=Debug"
|
||||||
|
];
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
@@ -18,10 +27,8 @@ stdenv.mkDerivation {
|
|||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
cp ke $out/bin/
|
cp ke $out/bin/
|
||||||
|
|
||||||
|
installManPage ../ke.1
|
||||||
|
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|
||||||
postInstall = ''
|
|
||||||
installManPage ke.1
|
|
||||||
'';
|
|
||||||
}
|
}
|
||||||
|
|||||||
5
ke.1
5
ke.1
@@ -22,6 +22,7 @@ grandeur. Many commands work with and without control; for example,
|
|||||||
saving a file can be done with either C-k s or C-k C-s. Other commands work
|
saving a file can be done with either C-k s or C-k C-s. Other commands work
|
||||||
with ESC or CTRL.
|
with ESC or CTRL.
|
||||||
.Sh K-COMMANDS
|
.Sh K-COMMANDS
|
||||||
|
k-command mode can be exited with ESC or C-g.
|
||||||
.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.
|
||||||
@@ -36,7 +37,7 @@ Edit a new file. Also C-k C-e.
|
|||||||
.It C-k f
|
.It C-k f
|
||||||
Incremental find.
|
Incremental find.
|
||||||
.It C-k g
|
.It C-k g
|
||||||
Go to a specific line. Also C-k C-g.
|
Go to a specific line.
|
||||||
.It C-k l
|
.It C-k l
|
||||||
List the number of lines of code in a saved file.
|
List the number of lines of code in a saved file.
|
||||||
.It C-k m
|
.It C-k m
|
||||||
@@ -54,6 +55,8 @@ Dump core.
|
|||||||
.El
|
.El
|
||||||
.Sh OTHER KEYBINDINGS
|
.Sh OTHER KEYBINDINGS
|
||||||
.Bl -tag -width xxxxxxxxxxxx -offset indent
|
.Bl -tag -width xxxxxxxxxxxx -offset indent
|
||||||
|
.It C-g
|
||||||
|
In general, C-g cancels an operation.
|
||||||
.It C-l
|
.It C-l
|
||||||
Refresh the display.
|
Refresh the display.
|
||||||
.It C-s
|
.It C-s
|
||||||
|
|||||||
65
main.c
65
main.c
@@ -152,11 +152,16 @@ void killring_append_char(unsigned char ch);
|
|||||||
void killring_prepend_char(unsigned char ch);
|
void killring_prepend_char(unsigned char ch);
|
||||||
void toggle_markset(void);
|
void toggle_markset(void);
|
||||||
int cursor_after_mark(void);
|
int cursor_after_mark(void);
|
||||||
|
int count_chars_from_cursor_to_mark(void);
|
||||||
|
void kill_region(void);
|
||||||
void indent_region(void);
|
void indent_region(void);
|
||||||
|
void delete_region(void);
|
||||||
|
|
||||||
/* miscellaneous */
|
/* miscellaneous */
|
||||||
|
void kwrite(int fd, const char *buf, int len);
|
||||||
void die(const char *s);
|
void die(const char *s);
|
||||||
int get_winsz(int *rows, int *cols);
|
int get_winsz(int *rows, int *cols);
|
||||||
|
void jump_to_position(int col, int row);
|
||||||
void goto_line(void);
|
void goto_line(void);
|
||||||
int cursor_at_eol(void);
|
int cursor_at_eol(void);
|
||||||
void delete_row(int at);
|
void delete_row(int at);
|
||||||
@@ -853,8 +858,7 @@ delete_region(void)
|
|||||||
swap_int(&cury, &marky);
|
swap_int(&cury, &marky);
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.curx = markx;
|
jump_to_position(markx, marky);
|
||||||
editor.cury = marky;
|
|
||||||
|
|
||||||
while (killed < count) {
|
while (killed < count) {
|
||||||
move_cursor(ARROW_RIGHT);
|
move_cursor(ARROW_RIGHT);
|
||||||
@@ -862,16 +866,34 @@ delete_region(void)
|
|||||||
killed++;
|
killed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (editor.curx != markx && editor.cury != marky) {
|
||||||
|
deletech(KILLRING_NO_OP);
|
||||||
|
}
|
||||||
|
|
||||||
editor.kill = 1;
|
editor.kill = 1;
|
||||||
editor_set_status("Region killed.");
|
editor_set_status("Region killed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
kwrite(const int fd, const char *buf, const int len)
|
||||||
|
{
|
||||||
|
int wlen = 0;
|
||||||
|
|
||||||
|
wlen = write(fd, buf, len);
|
||||||
|
assert(wlen != -1);
|
||||||
|
assert(wlen == len);
|
||||||
|
if (wlen == -1) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
die(const char *s)
|
die(const char *s)
|
||||||
{
|
{
|
||||||
(void)write(STDOUT_FILENO, "\x1b[2J", 4);
|
kwrite(STDOUT_FILENO, "\x1b[2J", 4);
|
||||||
(void)write(STDOUT_FILENO, "\x1b[H", 3);
|
kwrite(STDOUT_FILENO, "\x1b[H", 3);
|
||||||
|
|
||||||
perror(s);
|
perror(s);
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -902,6 +924,15 @@ get_winsz(int *rows, int *cols)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
jump_to_position(const int x, const int y)
|
||||||
|
{
|
||||||
|
editor.curx = x;
|
||||||
|
editor.cury = y;
|
||||||
|
|
||||||
|
editor.rowoffs = editor.cury - (editor.rows / 2);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
goto_line(void)
|
goto_line(void)
|
||||||
{
|
{
|
||||||
@@ -920,8 +951,7 @@ goto_line(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.cury = lineno - 1;
|
jump_to_position(0, lineno - 1);
|
||||||
editor.rowoffs = editor.cury - (editor.rows / 2);
|
|
||||||
free(query);
|
free(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1542,7 +1572,7 @@ editor_find_callback(char *query, int16_t c)
|
|||||||
char *match;
|
char *match;
|
||||||
struct erow *row;
|
struct erow *row;
|
||||||
|
|
||||||
if (c == '\r' || c == ESC_KEY) {
|
if (c == '\r' || c == ESC_KEY || c == CTRL_KEY('g')) {
|
||||||
/* reset search */
|
/* reset search */
|
||||||
lmatch = -1;
|
lmatch = -1;
|
||||||
dir = 1;
|
dir = 1;
|
||||||
@@ -1911,7 +1941,6 @@ process_kcommand(int16_t c)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
case CTRL_KEY('g'):
|
|
||||||
goto_line();
|
goto_line();
|
||||||
break;
|
break;
|
||||||
case BACKSPACE:
|
case BACKSPACE:
|
||||||
@@ -1957,13 +1986,20 @@ process_kcommand(int16_t c)
|
|||||||
case 'y':
|
case 'y':
|
||||||
killring_yank();
|
killring_yank();
|
||||||
break;
|
break;
|
||||||
|
case ESC_KEY:
|
||||||
|
case CTRL_KEY('g'):
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
if (isprint(c)) {
|
||||||
|
editor_set_status("unknown kcommand '%c'", c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
editor_set_status("unknown kcommand: %04x", c);
|
editor_set_status("unknown kcommand: %04x", c);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.dirtyex = 1;
|
editor.dirtyex = 1;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1995,6 +2031,8 @@ process_normal(int16_t c)
|
|||||||
deletech(KILLRING_PREPEND);
|
deletech(KILLRING_PREPEND);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CTRL_KEY('g'):
|
||||||
|
break;
|
||||||
case CTRL_KEY('l'):
|
case CTRL_KEY('l'):
|
||||||
display_refresh();
|
display_refresh();
|
||||||
break;
|
break;
|
||||||
@@ -2066,6 +2104,9 @@ process_escape(int16_t c)
|
|||||||
case BACKSPACE:
|
case BACKSPACE:
|
||||||
delete_prev_word();
|
delete_prev_word();
|
||||||
break;
|
break;
|
||||||
|
case ESC_KEY:
|
||||||
|
case CTRL_KEY('g'):
|
||||||
|
break; /* escape out of escape-mode */
|
||||||
default:
|
default:
|
||||||
editor_set_status("unknown ESC key: %04x", c);
|
editor_set_status("unknown ESC key: %04x", c);
|
||||||
}
|
}
|
||||||
@@ -2150,8 +2191,8 @@ void
|
|||||||
display_clear(struct abuf *ab)
|
display_clear(struct abuf *ab)
|
||||||
{
|
{
|
||||||
if (ab == NULL) {
|
if (ab == NULL) {
|
||||||
(void)write(STDOUT_FILENO, ESCSEQ "2J", 4);
|
kwrite(STDOUT_FILENO, ESCSEQ "2J", 4);
|
||||||
(void)write(STDOUT_FILENO, ESCSEQ "H", 3);
|
kwrite(STDOUT_FILENO, ESCSEQ "H", 3);
|
||||||
} else {
|
} else {
|
||||||
ab_append(ab, ESCSEQ "2J", 4);
|
ab_append(ab, ESCSEQ "2J", 4);
|
||||||
ab_append(ab, ESCSEQ "H", 3);
|
ab_append(ab, ESCSEQ "H", 3);
|
||||||
@@ -2365,7 +2406,7 @@ display_refresh(void)
|
|||||||
/* ab_append(&ab, ESCSEQ "1;2H", 7); */
|
/* ab_append(&ab, ESCSEQ "1;2H", 7); */
|
||||||
ab_append(&ab, ESCSEQ "?25h", 6);
|
ab_append(&ab, ESCSEQ "?25h", 6);
|
||||||
|
|
||||||
(void)write(STDOUT_FILENO, ab.b, ab.len);
|
kwrite(STDOUT_FILENO, ab.b, ab.len);
|
||||||
ab_free(&ab);
|
ab_free(&ab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user