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

Question: highlight-API: is loading/querying of individual styles possible? #2331

Open
lpaulsen93 opened this issue Oct 1, 2019 · 7 comments

Comments

@lpaulsen93
Copy link
Contributor

I like to find the best way to let the user specify colors, e.g. by config, theme or whatever (I am talking about colors for text highlighting here not the UI parts outside the editor widget). The colorschemes seem to do the job.

Looking at highlight.c it seems that every style specified in a colorscheme is loaded to the hash named_style_hash. How can a plugin access a style by its key name?

I only found this API call for querying a style but it does not look like it is allowing individual styles:

const GeanyLexerStyle *highlighting_get_style(gint ft_id, gint style_id);

Thanks for all answers in advance.

@elextr
Copy link
Member

elextr commented Oct 1, 2019

The colorschemes seem to do the job.

Yep, thats the approved method for users to specify colours.

The sequence is:

  1. highlighting maps the Scintilla style numbers to syntactic entity names for each lexer, and

  2. filetypes.common defines named styles and default styles for them (this is Geany's default colour scheme), and

  3. the individual filetype files map syntactic entity names used by that filetypes lexer to named styles, and

  4. the colour scheme can override the default styles from filetypes.common for the named styles

If a user wants different colours for the same syntactic entity in different filetypes they can create new named styles and only use them in some filetypes files, or replace the mapping in the filetype files between entities and style names with a literal style if they only want to change one filetype.

There is no API because setting it programatically would break this configuration scheme.

@codebrainz
Copy link
Member

@LarsGit223 can you elaborate on what you're trying to do in your plugin?

@lpaulsen93
Copy link
Contributor Author

@codebrainz: I saw an issue for the pairtaghighlighter plugin asking to make the highlihgt color/style configurable. Then I thought let's quickly add a new key/value pair to a color scheme and use that values. But then I stumbled across the API.

@lpaulsen93
Copy link
Contributor Author

lpaulsen93 commented Oct 2, 2019

There is no API because setting it programatically would break this configuration scheme.

I only want to read a value, preferably by key name. There is a function for it, but it's static.

@elextr
Copy link
Member

elextr commented Oct 2, 2019

I saw an issue for the pairtaghighlighter plugin asking to make the highlihgt color/style

Ahh, probably the best would be to use indicators for that, they are independent of the highlighting styles so easy for plugins to apply, see scintilla docs https://www.scintilla.org/ScintillaDoc.html#Indicators.

@lpaulsen93
Copy link
Contributor Author

@elextr:

Ahh, probably the best would be to use indicators for that,

My question is not about how highlighting itself can be implemented. The highlighting is already implemented in the plugin, see the code below and yes it's using indicators:

static void highlight_tag(ScintillaObject *sci, gint openingBracket,
                          gint closingBracket, gint color)
{
    scintilla_send_message(sci, SCI_SETINDICATORCURRENT, INDICATOR_TAGMATCH, 0);
    scintilla_send_message(sci, SCI_INDICSETSTYLE,
                            INDICATOR_TAGMATCH, INDIC_ROUNDBOX);
    scintilla_send_message(sci, SCI_INDICSETFORE, INDICATOR_TAGMATCH, rgb2bgr(color));
    scintilla_send_message(sci, SCI_INDICSETALPHA, INDICATOR_TAGMATCH, 60);
    scintilla_send_message(sci, SCI_INDICATORFILLRANGE,
                            openingBracket, closingBracket-openingBracket+1);
}

The issue is that the colors are fixed coded into the plugin. And as always this can just be fine for some themes and for others it's causing bad readability because the color/style cannot be adjusted to the theme.

So I wondered if there is an already implemented, re-usable way to read in color/style values. Colorschemes does not seem to add a new key and access it somehow. I would prefer to define a key explicitly for the pairtaghighlighter plugin. But colorschemes seem to be bound to predefined meanings/styles.

@elextr
Copy link
Member

elextr commented Oct 3, 2019

The highlighting is already implemented in the plugin, see the code below and yes it's using indicators

Ahh, they followed my advice before I gave it, excellent 😁

The issue is that the colors are fixed coded into the plugin.

Ok, then I strongly suggest just making it manually configurable.

Trying to automatically adjust to the theme is tricky because the plugin is highlighting the whole tag and that has different styles for element name, attribute names, and attribute values, so its quite likely that part of a tag will clash unless you somehow consider all the tag styles.

I guess you would need to consider the actual colours for SCE_H_TAG, SCE_H_TAGUNKNOWN, SCE_H_ATTRIBUTE, SCE_H_ATTRIBUTEUNKNOWN, SCE_H_NUMBER, SCE_H_DOUBLESTRING, SCE_H_SINGLESTRING, SCE_H_OTHER, SCE_H_COMMENT, SCE_H_ENTITY, SCE_H_TAGEND all of which can occur in a tag IIUC.

So I wondered if there is an already implemented, re-usable way to read in color/style values.

Not that I'm aware of any way, but highlighting[mappings].[hc] is @b4n's baby and maybe its hidden away there somewhere.

But plugins can read the styles from Scintilla eg foreground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants