Skip to content

Instantly share code, notes, and snippets.

@b4n
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b4n/eceff3c39f4c825c1106 to your computer and use it in GitHub Desktop.
Save b4n/eceff3c39f4c825c1106 to your computer and use it in GitHub Desktop.
Geany disabled C preprocessor highlighter
/*
* Copyright 2015 Colomban Wendling <colomban@geany.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <glib.h>
#include <geanyplugin.h>
#include <SciLexer.h>
GeanyPlugin *geany_plugin;
GeanyData *geany_data;
GeanyFunctions *geany_functions;
PLUGIN_VERSION_CHECK (211) /* FIXME */
PLUGIN_SET_INFO ("C Proprocessor highlight", "Highlights disabled C code",
"0.1", "Colomban Wendling <colomban@geany.org>")
#define BG_COLOR_ADD -0x111111
#define FG_COLOR_ADD +0x333333
#define ACTIVITY_FLAG 0x40 /* see LexCPP */
static void on_filetype_set (GObject *obj,
GeanyDocument *doc,
GeanyFiletype *filetype_old,
gpointer user_data)
{
sptr_t lexer = scintilla_send_message (doc->editor->sci, SCI_GETLEXER, 0, 0);
if (lexer == SCLEX_CPP) {
uptr_t i;
for (i = 0; i < ACTIVITY_FLAG; i++) {
sptr_t v;
v = scintilla_send_message (doc->editor->sci, SCI_STYLEGETBACK, i, 0);
scintilla_send_message (doc->editor->sci, SCI_STYLESETBACK,
i | ACTIVITY_FLAG, v + BG_COLOR_ADD);
v = scintilla_send_message (doc->editor->sci, SCI_STYLEGETFORE, i, 0);
scintilla_send_message (doc->editor->sci, SCI_STYLESETFORE,
i | ACTIVITY_FLAG, v + FG_COLOR_ADD);
#define COPY_SCI_STYLE(which) \
v = scintilla_send_message (doc->editor->sci, SCI_STYLEGET##which, i, 0); \
scintilla_send_message (doc->editor->sci, SCI_STYLESET##which, \
i | ACTIVITY_FLAG, v);
COPY_SCI_STYLE (BOLD)
COPY_SCI_STYLE (ITALIC)
COPY_SCI_STYLE (SIZE)
COPY_SCI_STYLE (EOLFILLED)
COPY_SCI_STYLE (UNDERLINE)
COPY_SCI_STYLE (CASE)
COPY_SCI_STYLE (VISIBLE)
#undef COPY_SCI_STYLE
}
}
}
void plugin_init (GeanyData *data)
{
plugin_signal_connect (geany_plugin, NULL, "document-filetype-set", TRUE,
G_CALLBACK (on_filetype_set), NULL);
}
void plugin_cleanup (void)
{
}
#!/usr/bin/make -f
PLUGIN = c-preproc-hl
VPATH ?= .
# fetch from https://github.com/b4n/geany-plugin.mk
include $(VPATH)/geany-plugin.mk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment