Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removal of editorRowHasOpenComment() #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions kilo.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
#include <fcntl.h>
#include <signal.h>

/* logical xor */
#define xor(a,b) (!!(a) != !!(b))

/* Syntax highlight types */
#define HL_NORMAL 0
#define HL_NONPRINT 1
Expand Down Expand Up @@ -367,16 +370,6 @@ int is_separator(int c) {
return c == '\0' || isspace(c) || strchr(",.()+-/*=~%[];",c) != NULL;
}

/* Return true if the specified row last char is part of a multi line comment
* that starts at this row or at one before, and does not end at the end
* of the row but spawns to the next row. */
int editorRowHasOpenComment(erow *row) {
if (row->hl && row->rsize && row->hl[row->rsize-1] == HL_MLCOMMENT &&
(row->rsize < 2 || (row->render[row->rsize-2] != '*' ||
row->render[row->rsize-1] != '/'))) return 1;
return 0;
}

/* Set every byte of row->hl (that corresponds to every character in the line)
* to the right syntax highlight type (HL_* defines). */
void editorUpdateSyntax(erow *row) {
Expand Down Expand Up @@ -405,8 +398,7 @@ void editorUpdateSyntax(erow *row) {

/* If the previous line has an open comment, this line starts
* with an open comment state. */
if (row->idx > 0 && editorRowHasOpenComment(&E.row[row->idx-1]))
in_comment = 1;
if (row->idx > 0) in_comment = E.row[row->idx-1].hl_oc;

while(*p) {
/* Handle // comments. */
Expand Down Expand Up @@ -510,10 +502,12 @@ void editorUpdateSyntax(erow *row) {
/* Propagate syntax change to the next row if the open commen
* state changed. This may recursively affect all the following rows
* in the file. */
int oc = editorRowHasOpenComment(row);
if (row->hl_oc != oc && row->idx+1 < E.numrows)
editorUpdateSyntax(&E.row[row->idx+1]);
row->hl_oc = oc;
if (xor(row->hl_oc, in_comment)) {
row->hl_oc = in_comment;
if (row->idx+1 < E.numrows)
editorUpdateSyntax(&E.row[row->idx+1]);
}

}

/* Maps syntax highlight token types to terminal colors. */
Expand Down