diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-28 21:08:12 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-28 21:08:12 -0800 |
commit | e80af9206ca91a66455064e01454121ae7dc1ae7 (patch) | |
tree | 77606c44c3cacdb9cbc667d8bbc3fd311c3b055e /src | |
parent | eec4845c31e55f68b945ba549e98057dd5b4c054 (diff) | |
download | teliva-e80af9206ca91a66455064e01454121ae7dc1ae7.tar.gz |
ctrl-/ to comment/uncomment line
Diffstat (limited to 'src')
-rw-r--r-- | src/kilo.c | 27 | ||||
-rw-r--r-- | src/teliva.h | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/kilo.c b/src/kilo.c index 64d09db..2452751 100644 --- a/src/kilo.c +++ b/src/kilo.c @@ -572,6 +572,26 @@ static void editorDelChar() { E.dirty++; } +static void editorUncommentCursorRow() { + erow *row = &E.row[E.rowoff+E.cy]; + editorRowDelChar(row, 0); + editorRowDelChar(row, 0); + editorRowDelChar(row, 0); + editorRowDelChar(row, 0); + E.coloff = 0; + E.cx = 0; +} + +static void editorCommentCursorRow() { + erow *row = &E.row[E.rowoff+E.cy]; + editorRowInsertChar(row, 0, ' '); + editorRowInsertChar(row, 0, '?'); + editorRowInsertChar(row, 0, '-'); + editorRowInsertChar(row, 0, '-'); + E.coloff = 0; + E.cx = 0; +} + /* Load the specified program in the editor memory and returns 0 on success * or 1 on error. */ int editorOpen(char *filename) { @@ -656,6 +676,7 @@ static void editorMenu(void) { draw_menu_item("^l", "end of line"); draw_menu_item("^u", "delete to start of line"); draw_menu_item("^k", "delete to end of line"); + draw_menu_item("^/", "(un)comment line"); attrset(A_NORMAL); } @@ -1113,6 +1134,12 @@ static void editorProcessKeypress(lua_State* L) { editorDelChar(); } break; + case CTRL_SLASH: + if (starts_with(E.row[E.rowoff+E.cy].chars, "--? ")) + editorUncommentCursorRow(); + else + editorCommentCursorRow(); + break; case KEY_UP: case KEY_DOWN: case KEY_LEFT: diff --git a/src/teliva.h b/src/teliva.h index d3183b9..1f57a13 100644 --- a/src/teliva.h +++ b/src/teliva.h @@ -26,6 +26,7 @@ enum KEY_ACTION { CTRL_U = 21, CTRL_X = 24, ESC = 27, + CTRL_SLASH = 31, }; #endif |