[Geany] Can I use own folding marks?

Randy Kramer rhkramer at xxxxx
Tue Sep 1 11:20:39 UTC 2009


Good morning, Joerg,

(At least it's morning for me ;-)

I probably shouldn't have jumped in to try to answer your questions--I 
guess I got out of my depth--knowing that Geany uses Scintilla, I 
assumed (I know) that the same possibilities existed for configuration 
by .properties files.  Oh, wait, it looks like there are something like 
Scintilla's properties in the filetypes files in /user/share/geany.  
Also, there are some .conf files, including your personal .conf file,  
~/geany.conf.  You might check those out, or someone else might be know 
whether Scintilla properties can be utilized directly in one or the 
other of those files.

I'll add some comments below, but somebody else will have to chip in to 
answer your questions...

On Tuesday 01 September 2009 05:21:03 am Joerg Desch wrote:
> On Mon, 31 Aug 2009 08:52:56 -0400
> Randy Kramer <rhkramer at gmail.com> wrote:
> > You can revise or write a new lexer for Scintilla that handles
> > those marks, or you can use the alternatives already defined in the
> > C/C++ lexer for Scintilla, which are:
> >
> > For opening:
> >
> > //{
> >
> > and, for closing:
> >
> > //}
>
> OK. I assume there is no option to configure this?

It's not mentioned in the documentation, so I suspect not.  OTOH, 
(without having spent much time looking at the C/C++ lexer in Scintilla 
(geany/scintilla/LexCPP.cxx)), it might not be too hard to make a 
change and then recompile:

</code>
		if (foldComment && IsStreamCommentStyle(style)) {
			if (!IsStreamCommentStyle(stylePrev) && (stylePrev != 
SCE_C_COMMENTLINEDOC)) {
				levelNext++;
			} else if (!IsStreamCommentStyle(styleNext) && (styleNext != 
SCE_C_COMMENTLINEDOC) && !atEOL) {
				// Comments don't end at end of line and the next character may be 
unstyled.
				levelNext--;
			}
		}
		if (foldComment && (style == SCE_C_COMMENTLINE)) {
			if ((ch == '/') && (chNext == '/')) {
				char chNext2 = styler.SafeGetCharAt(i + 2);
				if (chNext2 == '{') {
					levelNext++;
				} else if (chNext2 == '}') {
					levelNext--;
				}
			}
		}
<code>

Clearly (??), if your comment delimiter is longer than 3 characters, 
you'll need to check more than the 3 characters checked above, 
presumably using styler.SafeGetCharAt(i + 3) and higher.

BTW, in Scintilla, foldComment is set based on the value of the 
Scintilla property: fold.comment.

<also from LexCPP.cxx>
	bool foldComment = styler.GetPropertyInt("fold.comment") != 0;

BTW, LexCPP.cxx is used for C++, C, Java, and JavaScript.

> > These don't work out of the box in Scintilla, you must set a
> > specific property to make them work--let me see if I can find
> > that...ahh, yes--you need to set the property "fold.comment=1" in a
> > property file.
>
> Is this a property which is available in the geany configuration
> files? Or do you mean a function call?

I'm not sure, and don't have time to look atm (busy day)--I'd look in 
the geany *.conf and filetype.* (in ~ and /usr/share/geany)--you might 
be able to put Scintilla property "declarations" in those files 
directly (but maybe Geany does some sort of transformation and can't 
use the Scintilla properties directly?).

> > I'm almost sure these work only for C/C++ languages, specifically
> > those lexed by the LexCPP.cxx lexer.
>
> Hard to believe that this feature is implemented in the lexer. Most
> languages have single line comments, so it should be easy implements
> foldings marks for all languages. But this is only a thought.
>
> Nevertheless, thanks for your answer.

Hope I haven't mislead you too much!

Randy Kramer



More information about the Users mailing list