Adds optional paren matching to keyboard input
This commit is contained in:
parent
7893ea5cd4
commit
ad78331348
3
config.h
3
config.h
|
@ -9,6 +9,9 @@
|
|||
// Set global tab width for the editor here
|
||||
static const int tabwidth = 4;
|
||||
|
||||
// Turn on or off paren matching for: (, {, [
|
||||
static const int MATCH_PARENS = 1;
|
||||
|
||||
/*
|
||||
* Values from 1 to 256 representing 256 color/8-bit pallate
|
||||
* see: https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
||||
|
|
23
hermes.c
23
hermes.c
|
@ -353,6 +353,19 @@ void editorUpdateSyntax(erow *row) {
|
|||
editorUpdateSyntax(&E.row[row->idx + 1]);
|
||||
}
|
||||
|
||||
char editorGetMatchingParen(char c) {
|
||||
switch (c) {
|
||||
case '{':
|
||||
return '}';
|
||||
case '(':
|
||||
return ')';
|
||||
case '[':
|
||||
return ']';
|
||||
default:
|
||||
return ' ';
|
||||
}
|
||||
}
|
||||
|
||||
int editorSyntaxToColor(int hl) {
|
||||
switch (hl) {
|
||||
case HL_NUMBER: return HL_NUMBER_COLOR;
|
||||
|
@ -1152,6 +1165,16 @@ void editorInputKp(int c) {
|
|||
if (c == DEL_KEY) editorMoveCursor(ARROW_RIGHT);
|
||||
editorDeleteChar();
|
||||
break;
|
||||
case '(':
|
||||
case '{':
|
||||
case '[':
|
||||
editorInsertChar(c);
|
||||
if (MATCH_PARENS) {
|
||||
char match = editorGetMatchingParen(c);
|
||||
editorInsertChar(match);
|
||||
editorMoveCursor(ARROW_LEFT);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
editorInsertChar(c);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue