On 10/26/2010 06:57 PM, Ross McKay wrote:
Good stuff, I'll stand back and watch :) and will applaud wildly when it
comes through!

cheers,
Ross

A patch against Scintilla's trunk (in Mercurial) has been posted to the scintilla-interest list[1]. I tested the code in Geany using a similar patch. Scintilla trunk patches won't apply cleanly to the Scintilla included with Geany, since it's an older version and has a slightly different directory structure.

So attached is the patch I used to test the feature! It applies against the Geany trunk currently in SVN. Major difference between this patch and the one for trunk is that this includes the "if (!sorted)" block in WordList::InListWildcard(), as WordList::InList() and WordList::InListAbbreviated() already have. The method is also not declared const, again just like the other two.

All-in-all, I say don't use *this* patch, just update to Scintilla 2.23 some day and get the wildcard matches for free. ;) Although, you can already start using data-* and aria-* in filetypes.xml right now. It will have no visible effect until Scintilla supports wildcards, because an asterisk (*) is not a valid attribute character.


[1] http://groups.google.com/group/scintilla-interest/browse_thread/thread/407808dd3f0db79b
Index: scintilla/LexHTML.cxx
===================================================================
--- scintilla/LexHTML.cxx	(revision 5336)
+++ scintilla/LexHTML.cxx	(working copy)
@@ -254,7 +254,7 @@ static void classifyAttribHTML(unsigned int start,
 	} else {
 		char s[100];
 		GetTextSegment(styler, start, end, s, sizeof(s));
-		if (keywords.InList(s))
+		if (keywords.InListWildcard(s, "abcdefghijklmnopqrstuvwxyz0123456789-_.!#/"))
 			chAttr = SCE_H_ATTRIBUTE;
 	}
 	if ((chAttr == SCE_H_ATTRIBUTEUNKNOWN) && !keywords)
Index: scintilla/include/KeyWords.h
===================================================================
--- scintilla/include/KeyWords.h	(revision 5336)
+++ scintilla/include/KeyWords.h	(working copy)
@@ -30,6 +30,7 @@ class WordList {
 	void Set(const char *s);
 	bool InList(const char *s);
 	bool InListAbbreviated(const char *s, const char marker);
+	bool InListWildcard(const char *s, const char *charList);
 };
 
 typedef void (*LexerFunction)(unsigned int startPos, int lengthDoc, int initStyle,
Index: scintilla/KeyWords.cxx
===================================================================
--- scintilla/KeyWords.cxx	(revision 5336)
+++ scintilla/KeyWords.cxx	(working copy)
@@ -209,6 +209,68 @@ bool WordList::InListAbbreviated(const char *s, co
 	return false;
 }
 
+/** similar to InList, but word s can contain a simple wildcard *, that will
+ * match all of the characters specified in charList.
+ * eg. the keyword define is defined as "def*ine". And charlist is "-_abc".
+ * This means the word must start with "def" and end with "ine" to be a keyword.
+ * define, def-ine, and def_cba_ine are valid.
+ * def+ine, def_321_ine are invalid.
+ * Note that a keyword ending with a wildcard will not match a null-byte:
+ * Keyword "def*" will not match "def" but will match "def-".
+ */
+bool WordList::InListWildcard(const char *s, const char *charList) {
+	if (0 == words)
+		return false;
+	if (!sorted) {
+		sorted = true;
+		SortWordList(words, len);
+		for (unsigned int k = 0; k < (sizeof(starts) / sizeof(starts[0])); k++)
+			starts[k] = -1;
+		for (int l = len - 1; l >= 0; l--) {
+			unsigned char indexChar = words[l][0];
+			starts[indexChar] = l;
+		}
+	}
+	unsigned char firstChar = s[0];
+	int j = starts[firstChar];
+	if (j >= 0) {
+		while ((unsigned char)words[j][0] == firstChar) {
+			if (s[1] == words[j][1]) {
+				const char *a = words[j] + 1;
+				const char *b = s + 1;
+				while (*a && *b && (*a == *b || *a == '*')) {
+					if (*a == '*') {
+						while (*b && strchr(charList, *b))
+							b++;
+					}
+					else {
+						b++;
+					}
+					a++;
+				}
+				if (!*a && !*b)
+					return true;
+			}
+			j++;
+		}
+	}
+	j = starts['^'];
+	if (j >= 0) {
+		while (words[j][0] == '^') {
+			const char *a = words[j] + 1;
+			const char *b = s;
+			while (*a && *a == *b) {
+				a++;
+				b++;
+			}
+			if (!*a)
+				return true;
+			j++;
+		}
+	}
+	return false;
+}
+
 const LexerModule *LexerModule::base = 0;
 int LexerModule::nextLanguage = SCLEX_AUTOMATIC+1;
 
Index: data/filetypes.xml
===================================================================
--- data/filetypes.xml	(revision 5336)
+++ data/filetypes.xml	(working copy)
@@ -73,7 +73,7 @@ jscript_regex=0x105090;0xffffff;false;false
 
 
 [keywords]
-html=a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em embed fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol optgroup option p param pre q quality s samp script select small span strike strong style sub sup table tbody td textarea tfoot th thead title tr tt u ul var xmlns leftmargin topmargin abbr accept-charset accept accesskey action align alink alt archive axis background bgcolor border cellpadding cellspacing char charoff charset checked cite class classid clear codebase codetype color cols colspan compact content coords data datafld dataformatas datapagesize datasrc datetime declare defer dir disabled enctype face for frame frameborder selected headers height href hreflang hspace http-equiv id ismap label lang language link longdesc marginwidth marginheight maxlength media framespacing method multiple name nohref noresize noshade nowrap object onblur onchange onclick ondblclick onfocus onkeydown onkeypress onkeyup onload onmousedown onmousemove onmouseover onmouseout onmouseup onreset onselect onsubmit onunload profile prompt pluginspage readonly rel rev rows rowspan rules scheme scope scrolling shape size span src standby start style summary tabindex target text title type usemap valign value valuetype version vlink vspace width text password checkbox radio submit reset file hidden image public doctype xml xml:lang article aside audio canvas command details datalist figure figcaption footer header hgroup keygen mark meter nav output progress section time video wbr async autocomplete autofocus contenteditable contextmenu draggable formaction formenctype formnovalidate formtarget list manifest max min novalidate pattern ping placeholder required reversed role sandbox scoped seamless sizes spellcheck srcdoc step
+html=a abbr acronym address applet area b base basefont bdo big blockquote body br button caption center cite code col colgroup dd del dfn dir div dl dt em embed fieldset font form frame frameset h1 h2 h3 h4 h5 h6 head hr html i iframe img input ins isindex kbd label legend li link map menu meta noframes noscript object ol optgroup option p param pre q quality s samp script select small span strike strong style sub sup table tbody td textarea tfoot th thead title tr tt u ul var xmlns leftmargin topmargin abbr accept-charset accept accesskey action align alink alt archive axis background bgcolor border cellpadding cellspacing char charoff charset checked cite class classid clear codebase codetype color cols colspan compact content coords data datafld dataformatas datapagesize datasrc datetime declare defer dir disabled enctype face for frame frameborder selected headers height href hreflang hspace http-equiv id ismap label lang language link longdesc marginwidth marginheight maxlength media framespacing method multiple name nohref noresize noshade nowrap object onblur onchange onclick ondblclick onfocus onkeydown onkeypress onkeyup onload onmousedown onmousemove onmouseover onmouseout onmouseup onreset onselect onsubmit onunload profile prompt pluginspage readonly rel rev rows rowspan rules scheme scope scrolling shape size span src standby start style summary tabindex target text title type usemap valign value valuetype version vlink vspace width text password checkbox radio submit reset file hidden image public doctype xml xml:lang article aside audio canvas command details datalist figure figcaption footer header hgroup keygen mark meter nav output progress section time video wbr async autocomplete autofocus contenteditable contextmenu draggable formaction formenctype formnovalidate formtarget list manifest max min novalidate pattern ping placeholder required reversed role sandbox scoped seamless sizes spellcheck srcdoc step data-* aria-*
 javascript=abs abstract acos anchor asin atan atan2 big bold boolean break byte case catch ceil char charAt charCodeAt class concat const continue cos Date debugger default delete do double else enum escape eval exp export extends false final finally fixed float floor fontcolor fontsize for fromCharCode function goto if implements import in indexOf Infinity instanceof int interface isFinite isNaN italics join lastIndexOf length link log long Math max MAX_VALUE min MIN_VALUE NaN native NEGATIVE_INFINITY new null Number package parseFloat parseInt pop POSITIVE_INFINITY pow private protected public push random return reverse round shift short sin slice small sort splice split sqrt static strike string String sub substr substring sup super switch synchronized tan this throw throws toLowerCase toString toUpperCase transient true try typeof undefined unescape unshift valueOf var void volatile while with
 vbscript=and as boolean byref byte byval call case class const continue currency date dim do double each else elseif empty end error exit false for function get global goto if in integer long loop me new next not nothing object on optional or private property public put redim rem resume select set single string sub then to true type until variant wend while with
 python=and assert break class continue complex def del elif else except exec finally for from global if import in inherit is int lambda not or pass print raise return tuple try unicode while yield long float str list

<<attachment: jason_oster.vcf>>

_______________________________________________
Geany mailing list
[email protected]
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany

Reply via email to