Indent region, version bump.
Some checks failed
Release / Bump Homebrew formula (push) Has been cancelled
Some checks failed
Release / Bump Homebrew formula (push) Has been cancelled
This commit is contained in:
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
|
||||
project(ke C) # Specify C language explicitly
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(KE_VERSION "1.3.4")
|
||||
set(KE_VERSION "1.3.5")
|
||||
|
||||
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")
|
||||
|
||||
@@ -16,3 +16,6 @@ To get verbose ASAN messages:
|
||||
export LSAN_OPTIONS=verbosity=1:log_threads=1
|
||||
|
||||
Released under an ISC license.
|
||||
|
||||
Started by following along with kilo:
|
||||
https://viewsourcecode.org/snaptoken/kilo/
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
}:
|
||||
stdenv.mkDerivation {
|
||||
pname = "ke";
|
||||
version = "1.3.4";
|
||||
version = "1.3.5";
|
||||
|
||||
src = lib.cleanSource ./.;
|
||||
|
||||
|
||||
65
main.c
65
main.c
@@ -2,11 +2,7 @@
|
||||
* kyle's editor
|
||||
*
|
||||
* first version is a run-through of the kilo editor walkthrough as a
|
||||
* set of guiderails. I've made a lot of changes and did some things
|
||||
* differently. keep an eye for for kte, kyle's text editor - the
|
||||
* rewrite that will be coming out... when it comes out.
|
||||
*
|
||||
* https://viewsourcecode.org/snaptoken/kilo/
|
||||
* set of guiderails. I've made a lot of changes.
|
||||
*/
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
@@ -156,6 +152,7 @@ void killring_append_char(unsigned char ch);
|
||||
void killring_prepend_char(unsigned char ch);
|
||||
void toggle_markset(void);
|
||||
int cursor_after_mark(void);
|
||||
void indent_region(void);
|
||||
|
||||
/* miscellaneous */
|
||||
void die(const char *s);
|
||||
@@ -791,6 +788,50 @@ kill_region(void)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
indent_region(void)
|
||||
{
|
||||
int start_row, end_row;
|
||||
int i;
|
||||
|
||||
if (!editor.mark_set) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (editor.mark_cury < editor.cury) {
|
||||
start_row = editor.mark_cury;
|
||||
end_row = editor.cury;
|
||||
} else if (editor.mark_cury > editor.cury) {
|
||||
start_row = editor.cury;
|
||||
end_row = editor.mark_cury;
|
||||
} else {
|
||||
start_row = end_row = editor.cury;
|
||||
}
|
||||
|
||||
/* Ensure bounds are valid */
|
||||
if (start_row < 0) {
|
||||
start_row = 0;
|
||||
}
|
||||
|
||||
if (end_row >= editor.nrows) {
|
||||
end_row = editor.nrows - 1;
|
||||
}
|
||||
|
||||
if (start_row >= editor.nrows || end_row < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Prepend a tab character to every row in the region */
|
||||
for (i = start_row; i <= end_row; i++) {
|
||||
row_insert_ch(&editor.row[i], 0, '\t');
|
||||
}
|
||||
|
||||
/* Move cursor to beginning of the line it was on */
|
||||
editor.curx = 0;
|
||||
editor.dirty++;
|
||||
}
|
||||
|
||||
|
||||
/* call after kill_region */
|
||||
void
|
||||
delete_region(void)
|
||||
@@ -1741,7 +1782,10 @@ newline(void)
|
||||
{
|
||||
struct erow *row = NULL;
|
||||
|
||||
if (editor.curx == 0) {
|
||||
if (editor.cury >= editor.nrows) {
|
||||
/* At or past end of file, insert empty line */
|
||||
erow_insert(editor.cury, "", 0);
|
||||
} else if (editor.curx == 0) {
|
||||
erow_insert(editor.cury, "", 0);
|
||||
} else {
|
||||
row = &editor.row[editor.cury];
|
||||
@@ -1969,8 +2013,13 @@ process_normal(int16_t c)
|
||||
editor.mode = MODE_ESCAPE;
|
||||
break;
|
||||
default:
|
||||
/* Insert any printable byte: ASCII 0x20–0x7E and all bytes >=0x80. */
|
||||
if ((c == TAB_KEY) || (c >= 0x20 && c != 0x7f)) {
|
||||
if (c == TAB_KEY) {
|
||||
if (editor.mark_set) {
|
||||
indent_region();
|
||||
} else {
|
||||
insertch(c);
|
||||
}
|
||||
} else if (c >= 0x20 && c != 0x7f) {
|
||||
insertch(c);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user