[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs lisp.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs lisp.c |
Date: |
Fri, 18 Apr 2014 21:00:46 +0000 |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 14/04/18 21:00:46
Modified files:
. : lisp.c
Log message:
improve lisp mode
* colorize standard lisp functions and builtins as 'keywords' and
'types'
* parse and colorize character constants, numbers, symbols, quoted
symbols
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/lisp.c?cvsroot=qemacs&r1=1.10&r2=1.11
Patches:
Index: lisp.c
===================================================================
RCS file: /sources/qemacs/qemacs/lisp.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- lisp.c 5 Apr 2014 15:49:16 -0000 1.10
+++ lisp.c 18 Apr 2014 21:00:45 -0000 1.11
@@ -24,6 +24,18 @@
/*---------------- Lisp colors ----------------*/
+static const char lisp_keywords[] = {
+ "defun|defvar|let|let*|if|concat|list|set|setq|when|and|or|max|min|"
+ "unless|car|cdr|cons|cond|prog1|progn|case|setcar|setcdr|while|"
+ "defsubst|eq|remove|not|otherwise|dolist|incf|decf|boundp|"
+ "1+|1-|<|>|<=|>=|-|+|*|/|=|<>|/=|"
+ //"interactive|"
+};
+
+static const char lisp_types[] = {
+ "nil|t|"
+};
+
enum {
IN_LISP_COMMENT = 0x01,
IN_LISP_STRING = 0x02,
@@ -32,14 +44,62 @@
enum {
LISP_STYLE_TEXT = QE_STYLE_DEFAULT,
LISP_STYLE_COMMENT = QE_STYLE_COMMENT,
+ LISP_STYLE_NUMBER = QE_STYLE_NUMBER,
LISP_STYLE_STRING = QE_STYLE_STRING,
+ LISP_STYLE_CHARCONST = QE_STYLE_STRING_Q,
+ LISP_STYLE_KEYWORD = QE_STYLE_KEYWORD,
+ LISP_STYLE_TYPE = QE_STYLE_TYPE,
+ LISP_STYLE_QSYMBOL = QE_STYLE_PREPROCESS,
+ LISP_STYLE_MACRO = QE_STYLE_TAG,
};
+static int lisp_get_symbol(char *buf, int buf_size, unsigned int *p)
+{
+ buf_t outbuf, *out;
+ unsigned int c;
+ int i;
+
+ out = buf_init(&outbuf, buf, buf_size);
+
+ for (i = 0; (c = p[i]) != '\0'; i++) {
+ if (qe_isspace(c) || qe_findchar(";(){}[]#'`,\"", c))
+ break;
+ buf_putc_utf8(out, c);
+ }
+ return i;
+}
+
+static int lisp_is_number(const char *str)
+{
+ int i;
+
+ /* XXX: parse other syntaxes, ie hex constants */
+ if (qe_isdigit(*str)) {
+ for (; qe_isdigit(*str); str++)
+ continue;
+ if (*str == '.') {
+ for (str++; qe_isdigit(*str); str++)
+ continue;
+ }
+ if (qe_tolower(*str) == 'e') {
+ i = 1;
+ if (str[i] == '+' || str[i] == '-')
+ i++;
+ if (qe_isdigit(str[i])) {
+ for (str += i + 1; qe_isdigit(*str); str++)
+ break;
+ }
+ }
+ }
+ return (*str) ? 0 : 1;
+}
+
static void lisp_colorize_line(QEColorizeContext *cp,
unsigned int *str, int n, int mode_flags)
{
int colstate = cp->colorize_state;
- int i = 0, start = i;
+ int i = 0, start = i, len;
+ char kbuf[32];
if (colstate & IN_LISP_STRING) {
while (i < n) {
@@ -66,6 +126,10 @@
while (i < n) {
start = i;
switch (str[i++]) {
+ case '`':
+ case ',':
+ SET_COLOR(str, start, i, LISP_STYLE_MACRO);
+ continue;
case ';':
i = n;
SET_COLOR(str, start, i, LISP_STYLE_COMMENT);
@@ -99,7 +163,44 @@
}
SET_COLOR(str, start, i, LISP_STYLE_STRING);
continue;
+ case '?':
+ /* parse char const */
+ /* XXX: Should parse keys syntax */
+ if (str[i] == '\\' && i + 1 < n) {
+ i += 2;
+ } else
+ if (i < n) {
+ i += 1;
+ }
+ SET_COLOR(str, start, i, LISP_STYLE_CHARCONST);
+ continue;
+ case '\'':
+ len = lisp_get_symbol(kbuf, sizeof(kbuf), str + i);
+ if (len > 0) {
+ i += len;
+ SET_COLOR(str, start, i, LISP_STYLE_QSYMBOL);
+ continue;
+ }
+ break;
default:
+ len = lisp_get_symbol(kbuf, sizeof(kbuf), str + i - 1);
+ if (len > 0) {
+ i += len - 1;
+ if (lisp_is_number(kbuf)) {
+ SET_COLOR(str, start, i, LISP_STYLE_NUMBER);
+ continue;
+ }
+ if (strfind(lisp_keywords, kbuf)) {
+ SET_COLOR(str, start, i, LISP_STYLE_KEYWORD);
+ continue;
+ }
+ if (strfind(lisp_types, kbuf)) {
+ SET_COLOR(str, start, i, LISP_STYLE_TYPE);
+ continue;
+ }
+ /* skip other symbol */
+ continue;
+ }
break;
}
}
- [Qemacs-commit] qemacs lisp.c,
Charlie Gordon <=