[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemacs-commit] qemacs TODO.org clang.c htmlsrc.c qe.h xml.c
From: |
Charlie Gordon |
Subject: |
[Qemacs-commit] qemacs TODO.org clang.c htmlsrc.c qe.h xml.c |
Date: |
Tue, 15 Apr 2014 08:08:02 +0000 |
CVSROOT: /sources/qemacs
Module name: qemacs
Changes by: Charlie Gordon <chqrlie> 14/04/15 08:08:02
Modified files:
. : TODO.org clang.c htmlsrc.c qe.h xml.c
Log message:
improve C, js, java modes, add php mode
* add php support as variant of c-mode
* add js_colorize_line, css_colorize_line and php_colorize_line
as special cases of c_colorize_line
* use mode_flag specific keyword and type lists for C/CPP, Java, JS, PHP
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qemacs/TODO.org?cvsroot=qemacs&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/qemacs/clang.c?cvsroot=qemacs&r1=1.56&r2=1.57
http://cvs.savannah.gnu.org/viewcvs/qemacs/htmlsrc.c?cvsroot=qemacs&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/qemacs/qe.h?cvsroot=qemacs&r1=1.163&r2=1.164
http://cvs.savannah.gnu.org/viewcvs/qemacs/xml.c?cvsroot=qemacs&r1=1.19&r2=1.20
Patches:
Index: TODO.org
===================================================================
RCS file: /sources/qemacs/qemacs/TODO.org,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- TODO.org 4 Apr 2014 15:33:01 -0000 1.3
+++ TODO.org 15 Apr 2014 08:08:01 -0000 1.4
@@ -8,6 +8,10 @@
** basic: indent-rigidly
** basic: minibuffer completion -> bad return on C-x C-f . SPC qe SPC RET
** basic: scripting
+** basic: handle chinese encodings
+** basic: handle euc-kr
+** basic: autodetect sjis, euc-jp...
+** basic: fix colors, default schemes...
** c-mode: fix c indentation inside comments
** c-mode: fix c indentation inside struct, array and enum initializers
** dired: fix layout mess when dired/bufed side window loses focus
@@ -20,6 +24,7 @@
** files: insert-file: load via separate buffer with charset conversion
** files: reload-file on C-x C-r
** html: fix scoring for xml / html / htmlsrc
+** html-src/xml: fix colorizer for multi-line tags and attributes
** modes: header-line format
** modes: mode-line format
** modes: split modes into colorizers, interaction, io, charset, eoltype
@@ -208,7 +213,6 @@
*** global QTAGS file indexed with global includes
** see if java/javascript/c++ is OK.
** autocomplete keyword, function, variable, member names
-** show-ifdefs
** automatic indentation detection
** c-mode descendants:
*** as-mode: ActionStript files
@@ -226,6 +230,7 @@
*** idl-mode
** DONE auto-indent
** DONE forward-ifdef, backward-ifdef
+** DONE show-ifdefs
* HTML mode
@@ -263,7 +268,6 @@
* Bufed
** make bufed a popup window -> buffer-menu
-** adjust bufed gutter width for max name length
** DONE show modified status and mode in bufed
* Dired
@@ -274,12 +278,12 @@
** snap dired left window horiz scroll
** make dired left window temporary popleft window
** dired left window delete sometimes doesn't fix layout.
-** refresh side view when current file changes on line 1
** improve dired (file commands, nicer display)
*** t -> dired-touch
*** | -> dired-shell-command
*** D -> dired-mkdir
** make archive mode use dired commands
+** DONE refresh side view when current file changes on line 1
** DONE full listing
* Modes
@@ -323,6 +327,8 @@
*** ruby-mode ->
*** sh-mode -> shell script files
*** vbasic-mode -> Visual Basic.
+*** ocaml-mode ->
+*** php-mode -> PHP.
** missing languages:
*** ada-mode -> Ada
*** asp-mode ->
@@ -381,13 +387,11 @@
*** nroff-mode
*** nsis-mode ->
*** objj-mode ->
-*** ocaml-mode ->
*** ocl-mode ->
*** octave-mode ->
*** ooc-mode ->
*** opal-mode ->
*** opencl-mode ->
-*** php-mode -> PHP.
*** pkgconfig-mode ->
*** po-mode -> translation files
*** prolog-mode ->
Index: clang.c
===================================================================
RCS file: /sources/qemacs/qemacs/clang.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -b -r1.56 -r1.57
--- clang.c 13 Apr 2014 22:45:51 -0000 1.56
+++ clang.c 15 Apr 2014 08:08:01 -0000 1.57
@@ -21,15 +21,39 @@
#include "qe.h"
-static const char cc_keywords[] = {
+static const char c_keywords[] = {
+ "auto|break|case|const|continue|default|do|else|enum|extern|for|goto|"
+ "if|inline|register|restrict|return|sizeof|static|struct|switch|"
+ "typedef|union|volatile|while|"
+};
+
+static const char c_types[] = {
+ "char|double|float|int|long|unsigned|short|signed|void|"
+ "_Bool|_Complex|_Imaginary|"
+};
+
+static const char cpp_keywords[] = {
"asm|catch|class|delete|friend|inline|new|operator|"
"private|protected|public|template|try|this|virtual|throw|"
};
+static const char java_keywords[] = {
+ "abstract|assert|break|byte|case|catch|class|const|continue|"
+ "default|do|extends|false|final|finally|for|function|"
+ "if|implements|import|in|instanceof|interface|native|new|null|"
+ "package|private|protected|public|return|"
+ "static|super|switch|synchronized|"
+ "this|throw|throws|transient|true|try|var|while|with|"
+};
+
+static const char java_types[] = {
+ "boolean|byte|char|double|float|int|long|short|void|String|"
+};
+
static const char js_keywords[] = {
"break|case|catch|continue|debugger|default|delete|do|"
"else|finally|for|function|if|in|instanceof|new|"
- "return|switch|this|throw|try|typeof|var|void|while|with|"
+ "return|switch|this|throw|try|typeof|while|with|"
/* FutureReservedWord */
"class|const|enum|import|export|extends|super|"
/* The following tokens are also considered to be
@@ -42,25 +66,22 @@
"eval|arguments|"
};
-static const char java_keywords[] = {
- "abstract|boolean|break|byte|case|catch|class|const|continue|"
- "default|do|alse|extends|false|final|finally|for|function|"
- "if|implements|import|in|instanceof|interface|native|new|null|"
- "package|private|protected|public|return|"
- "static|super|switch|synchronized|"
- "this|throw|throws|transient|true|try|var|while|with|"
+static const char js_types[] = {
+ "void|var|"
};
-static const char c_keywords[] = {
- "auto|break|case|const|continue|default|do|else|enum|extern|for|goto|"
- "if|inline|register|restrict|return|sizeof|static|struct|switch|"
- "typedef|union|volatile|while|"
+static const char php_keywords[] = {
+ "abstract|assert|break|case|catch|class|clone|const|continue|"
+ "declare|default|elseif|else|enddeclare|endif|endswitch|end|exit|"
+ "extends|false|final|foreach|for|function|goto|if|implements|"
+ "include_once|include|instanceof|interface|list|namespace|new|"
+ "overload|parent|private|public|require_once|require|return|"
+ "self|sizeof|static|switch|throw|trait|true|try|use|var|while|"
+ "NULL|"
};
-/* NOTE: 'var' is added for javascript */
-static const char c_mode_types[] = {
- "char|double|float|int|long|unsigned|short|signed|void|var|"
- "_Bool|_Complex|_Imaginary|"
+static const char php_types[] = {
+ "array|boolean|bool|double|float|integer|int|object|real|string|"
};
static const char c_mode_extensions[] = {
@@ -86,7 +107,7 @@
i = j = 0;
c = p[i];
- if (qe_isalpha_(c & CHAR_MASK)) {
+ if (qe_isalpha_(c & CHAR_MASK) || c == '$') {
do {
if (j < buf_size - 1)
buf[j++] = c;
@@ -231,9 +252,12 @@
state = IN_C_PREPROCESS;
style = C_STYLE_PREPROCESS;
}
+ if (mode_flags & CLANG_PHP) {
+ goto parse_comment1;
+ }
break;
case 'L': /* wide character and string literals */
- /* XXX: C only */
+ if (mode_flags & (CLANG_C | CLANG_CPP | CLANG_OBJC)) {
if (str[i] == '\'') {
i++;
goto parse_string_q;
@@ -242,6 +266,7 @@
i++;
goto parse_string;
}
+ }
goto normal;
case '\'': /* character constant */
parse_string_q:
@@ -277,30 +302,34 @@
type_decl = 0;
break;
case '<': /* JavaScript extension */
- /* XXX: js only */
+ if (mode_flags & CLANG_JS) {
if (str[i] == '!' && str[i + 1] == '-' && str[i + 2] == '-')
goto parse_comment1;
+ }
break;
default:
normal:
if (state & IN_C_PREPROCESS)
break;
if (qe_isdigit(c)) {
+ /* XXX: should parse actual number syntax */
while (qe_isalnum(str[i]) || str[i] == '.') {
i++;
}
SET_COLOR(str, start, i, C_STYLE_NUMBER);
continue;
}
- if (qe_isalpha_(c)) {
- /* XXX: should support :: and $ */
+ if (qe_isalpha_(c) || c == '$') {
+ /* XXX: should support :: */
klen = get_c_identifier(kbuf, countof(kbuf), str + start);
i = start + klen;
- if (((mode_flags & (CLANG_C|CLANG_CPP|CLANG_OBJC)) &&
strfind(c_keywords, kbuf))
- || ((mode_flags & CLANG_CPP) && strfind(cc_keywords, kbuf))
- || ((mode_flags & CLANG_JS) && strfind(js_keywords, kbuf))
+ if (((mode_flags & (CLANG_C|CLANG_CPP|CLANG_OBJC)) &&
+ strfind(c_keywords, kbuf))
+ || ((mode_flags & CLANG_CPP) && strfind(cpp_keywords, kbuf))
|| ((mode_flags & CLANG_JAVA) && strfind(java_keywords, kbuf))
+ || ((mode_flags & CLANG_JS) && strfind(js_keywords, kbuf))
+ || ((mode_flags & CLANG_PHP) && strfind(php_keywords, kbuf))
) {
SET_COLOR(str, start, i, C_STYLE_KEYWORD);
continue;
@@ -313,9 +342,12 @@
while (str[i2] == '*' || qe_isblank(str[i2]))
i2++;
- /* XXX: should check type depending on flavor */
- if (strfind(c_mode_types, kbuf) || strend(kbuf, "_t", NULL)) {
- /* c type */
+ if (((mode_flags & (CLANG_C | CLANG_CPP | CLANG_OBJC)) &&
+ (strfind(c_types, kbuf) ||
+ strend(kbuf, "_t", NULL)))
+ || ((mode_flags & CLANG_JAVA) && strfind(java_types, kbuf))
+ || ((mode_flags & CLANG_JS) && strfind(js_types, kbuf))
+ || ((mode_flags & CLANG_PHP) && strfind(php_types, kbuf))) {
/* if not cast, assume type declaration */
if (str[i2] != ')') {
type_decl = 1;
@@ -331,7 +363,7 @@
continue;
}
/* assume typedef if starting at first column */
- if (start == 0)
+ if (start == 0 && qe_isalpha_(str[i]))
type_decl = 1;
if (type_decl) {
@@ -884,18 +916,14 @@
s->mode_name = "ObjC";
s->mode_flags = CLANG_OBJC;
} else
- if (match_extension(s->b->filename, "js|json")) {
- s->mode_name = "Javascript";
- s->mode_flags = CLANG_JS | CLANG_REGEX;
- } else
- if (match_extension(s->b->filename, "st")) {
- s->mode_name = "Syntax";
- s->mode_flags = CLANG_C | CLANG_REGEX;
- } else
if (match_extension(s->b->filename, "jav|java")) {
s->mode_name = "Java";
s->mode_flags = CLANG_JAVA;
} else
+ if (match_extension(s->b->filename, "js|json")) {
+ s->mode_name = "Javascript";
+ s->mode_flags = CLANG_JS | CLANG_REGEX;
+ } else
if (match_extension(s->b->filename, "l|lex")) {
s->mode_name = "Lex";
s->mode_flags = CLANG_C | CLANG_LEX;
@@ -903,6 +931,10 @@
if (match_extension(s->b->filename, "y")) {
s->mode_name = "Yacc";
s->mode_flags = CLANG_C | CLANG_YACC;
+ } else
+ if (match_extension(s->b->filename, "st")) {
+ s->mode_name = "Syntax";
+ s->mode_flags = CLANG_C | CLANG_REGEX;
}
return 0;
}
Index: htmlsrc.c
===================================================================
RCS file: /sources/qemacs/qemacs/htmlsrc.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- htmlsrc.c 10 Apr 2014 08:03:04 -0000 1.14
+++ htmlsrc.c 15 Apr 2014 08:08:01 -0000 1.15
@@ -66,6 +66,8 @@
IN_HTML_SCRIPT = 0x080, /* <script> [...] </script> */
IN_HTML_STYLE_TAG = 0x100, /* <style ... > */
IN_HTML_STYLE = 0x200, /* <style> [...] </style> */
+ IN_HTML_PHP_TAG = 0x400, /* <?php ... ?> */
+ IN_HTML_PHP_STRING = 0x800, /* "<?php ... ?>" */
};
enum {
@@ -76,7 +78,6 @@
HTML_STYLE_STRING = QE_STYLE_HTML_STRING,
HTML_STYLE_TAG = QE_STYLE_HTML_TAG,
HTML_STYLE_CSS = QE_STYLE_CSS,
- //HTML_STYLE_TEXT = QE_STYLE_HTML_TEXT,
};
static int htmlsrc_tag_match(const unsigned int *buf, int i, const char *str,
@@ -110,6 +111,31 @@
start = i;
c = str[i];
+ if (state & (IN_HTML_PHP_TAG | IN_HTML_PHP_STRING)) {
+ for (; i < n; i++) {
+ if (str[i] == '?' && str[i + 1] == '>')
+ break;
+ }
+ c = str[i]; /* save char to set '\0' delimiter */
+ str[i] = '\0';
+ cp->colorize_state = state & ~(IN_HTML_PHP_TAG|IN_HTML_PHP_STRING);
+ php_colorize_line(cp, str + start, i - start, 0);
+ state = cp->colorize_state |
+ (state & (IN_HTML_PHP_TAG|IN_HTML_PHP_STRING));
+ str[i] = c;
+ if (c) {
+ start = i;
+ i += 2;
+ SET_COLOR(str, start, i, HTML_STYLE_PREPROCESS);
+ if (state & IN_HTML_PHP_TAG) {
+ state = 0;
+ } else {
+ /* XXX: should set these bits higher */
+ state = IN_HTML_STRING | IN_HTML_TAG;
+ }
+ }
+ continue;
+ }
if (state & IN_HTML_SCRIPT) {
for (; i < n; i++) {
if (str[i] == '<'
@@ -121,9 +147,7 @@
str[i] = '\0';
state &= ~IN_HTML_SCRIPT;
cp->colorize_state = state;
- /* XXX: should have js_colorize_func */
- c_colorize_line(cp, str + start, i - start,
- CLANG_JS | CLANG_REGEX);
+ js_colorize_line(cp, str + start, i - start, 0);
state = cp->colorize_state;
state |= IN_HTML_SCRIPT;
str[i] = c;
@@ -143,8 +167,7 @@
str[i] = '\0';
state &= ~IN_HTML_STYLE;
cp->colorize_state = state;
- /* XXX: should have css_colorize_func */
- c_colorize_line(cp, str + start, i - start, 0);
+ css_colorize_line(cp, str + start, i - start, 0);
state = cp->colorize_state;
state |= IN_HTML_STYLE;
str[i] = c;
@@ -197,8 +220,21 @@
state &= ~(IN_HTML_STRING | IN_HTML_STRING1);
break;
}
- /* Premature end of string */
+ if (str[i] == '<'
+ && htmlsrc_tag_match(str, i, "<?php", NULL)) {
+ SET_COLOR(str, start, i, HTML_STYLE_STRING);
+ SET_COLOR(str, i, i + 5, HTML_STYLE_PREPROCESS);
+ i += 5;
+ start = i;
+ state = IN_HTML_PHP_STRING;
+ break;
+ } else
+ if (str[i] == '?' && str[i + 1] == '>') {
+ /* special case embedded script tags */
+ i += 1;
+ } else
if (str[i] == '>') {
+ /* Premature end of string */
state &= ~(IN_HTML_STRING | IN_HTML_STRING1);
break;
}
@@ -248,15 +284,21 @@
/* Plain text stream */
for (; i < n; i++) {
if (str[i] == '<'
+ && htmlsrc_tag_match(str, i, "<?php", &i)) {
+ SET_COLOR(str, start, i, HTML_STYLE_PREPROCESS);
+ state = IN_HTML_PHP_TAG;
+ break;
+ }
+ if (str[i] == '<'
&& (qe_isalpha(str[i + 1]) || str[i + 1] == '!'
|| str[i + 1] == '/' || str[i + 1] == '?')) {
//SET_COLOR(str, start, i, HTML_STYLE_TEXT);
start = i;
- if (ustristart(str + i, "<script", NULL)) {
+ if (htmlsrc_tag_match(str, i, "<script", NULL)) {
state |= IN_HTML_SCRIPT_TAG;
break;
}
- if (ustristart(str + i, "<style", NULL)) {
+ if (htmlsrc_tag_match(str, i, "<style", NULL)) {
state |= IN_HTML_STYLE_TAG;
break;
}
@@ -297,6 +339,8 @@
s2++;
s1++;
}
+ if (qe_isalnum_(*s1))
+ return -1;
return 0;
}
@@ -306,7 +350,7 @@
/* first check file extension */
if (match_extension(p->filename, mode->extensions))
- return 90;
+ return 85;
/* then try buffer contents */
if (p->buf_size >= 5 &&
@@ -314,7 +358,7 @@
!html_tagcmp(buf, "<SCRIPT") ||
!html_tagcmp(buf, "<?XML") ||
!html_tagcmp(buf, "<!DOCTYPE"))) {
- return 90;
+ return 85;
}
return 1;
@@ -333,7 +377,7 @@
/* html-src mode is almost like the text mode, so we copy and patch it */
memcpy(&htmlsrc_mode, &text_mode, sizeof(ModeDef));
htmlsrc_mode.name = "html-src";
- htmlsrc_mode.extensions = "html|htm|asp|shtml|hta|htp|phtml";
+ htmlsrc_mode.extensions = "html|htm|asp|shtml|hta|htp|phtml|php";
htmlsrc_mode.mode_probe = htmlsrc_mode_probe;
htmlsrc_mode.colorize_func = htmlsrc_colorize_line;
Index: qe.h
===================================================================
RCS file: /sources/qemacs/qemacs/qe.h,v
retrieving revision 1.163
retrieving revision 1.164
diff -u -b -r1.163 -r1.164
--- qe.h 13 Apr 2014 22:45:22 -0000 1.163
+++ qe.h 15 Apr 2014 08:08:01 -0000 1.164
@@ -1951,18 +1951,38 @@
/* clang.c */
-#define CLANG_C 0x01
-#define CLANG_CPP 0x02
-#define CLANG_OBJC 0x04
-#define CLANG_JS 0x08
-#define CLANG_JAVA 0x10
-#define CLANG_LEX 0x20
-#define CLANG_YACC 0x40
-#define CLANG_REGEX 0x80
+#define CLANG_C 0x0001
+#define CLANG_CPP 0x0002
+#define CLANG_OBJC 0x0004
+#define CLANG_JS 0x0008
+#define CLANG_JAVA 0x0010
+#define CLANG_LEX 0x0020
+#define CLANG_YACC 0x0040
+#define CLANG_REGEX 0x0080
+#define CLANG_PHP 0x0100
void c_colorize_line(QEColorizeContext *cp,
unsigned int *str, int n, int mode_flags);
+static inline void js_colorize_line(QEColorizeContext *cp,
+ unsigned int *str, int n, int mode_flags)
+{
+ c_colorize_line(cp, str, n, mode_flags | CLANG_JS | CLANG_REGEX);
+}
+
+static inline void php_colorize_line(QEColorizeContext *cp,
+ unsigned int *str, int n, int mode_flags)
+{
+ c_colorize_line(cp, str, n, mode_flags | CLANG_PHP | CLANG_REGEX);
+}
+
+static inline void css_colorize_line(QEColorizeContext *cp,
+ unsigned int *str, int n, int mode_flags)
+{
+ /* XXX: should have real colorizer for CSS syntax */
+ c_colorize_line(cp, str, n, mode_flags);
+}
+
/* xml.c */
extern ModeDef xml_mode;
Index: xml.c
===================================================================
RCS file: /sources/qemacs/qemacs/xml.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- xml.c 10 Apr 2014 08:03:09 -0000 1.19
+++ xml.c 15 Apr 2014 08:08:01 -0000 1.20
@@ -140,9 +140,7 @@
str[i] = '\0';
state &= ~IN_XML_SCRIPT;
cp->colorize_state = state;
- /* XXX: should have js_colorize_func */
- c_colorize_line(cp, str + start, i - start,
- CLANG_JS | CLANG_REGEX);
+ js_colorize_line(cp, str + start, i - start, 0);
state = cp->colorize_state;
state |= IN_XML_SCRIPT;
str[i] = c;
@@ -164,8 +162,7 @@
str[i] = '\0';
state &= ~IN_XML_STYLE;
cp->colorize_state = state;
- /* XXX: should have css_colorize_func */
- c_colorize_line(cp, str + start, i - start, 0);
+ css_colorize_line(cp, str + start, i - start, 0);
state = cp->colorize_state;
state |= IN_XML_STYLE;
str[i] = c;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qemacs-commit] qemacs TODO.org clang.c htmlsrc.c qe.h xml.c,
Charlie Gordon <=