Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* When enabled, plugin wraps selected text in single/double quotes or parentheses.
- * Press ctrl+ ' , " , or ( to surround selected text.
- *
- * Build with:
- * gcc -c surroundText.c -fPIC `pkg-config --cflags geany`
- * gcc surroundText.o -o surroundText.so -shared `pkg-config --libs geany`
- *
- */
- #include <geanyplugin.h>
- GeanyPlugin *geany_plugin;
- GeanyData *geany_data;
- GeanyFunctions *geany_functions;
- PLUGIN_VERSION_CHECK (147);
- PLUGIN_SET_INFO ("Text Encloser",
- "Encloses selected text with single quotes, double quotes, or parentheses.",
- "0.1", "Alex M.");
- gboolean on_editor_notify(GObject *, GeanyEditor *, SCNotification *, gpointer);
- void plugin_init(GeanyData *data)
- {
- plugin_signal_connect (geany_plugin, NULL, "editor_notify", FALSE, (GCallback)
- &on_editor_notify, NULL);
- }
- gboolean on_editor_notify(GObject *object, GeanyEditor *editor, SCNotification *nt, gpointer data)
- {
- if (nt->nmhdr.code == SCN_KEY)
- {
- if ((nt->ch == 0x22 || nt->ch == 0x27 || nt->ch == 0x28) &&
- sci_get_selected_text_length (editor->sci) > 0)
- {
- int end = 0;
- gchar prior_char [2]; /* prior_char is the char inserted before selection,
- with a zero terminator. end_char is the char inserted
- after the selection, also with a zero terminator. */
- gchar end_char [2];
- prior_char [1] = 0;
- end_char [1] = 0;
- prior_char [0] = nt->ch; /* prior_char is always the character that was typed,
- end_char might be something different (eg closing brace) */
- if (nt->ch == 0x22)
- end_char [0] = 0x22;
- else if (nt->ch == 0x27)
- end_char [0] = 0x27;
- else
- end_char [0] = 0x29;
- end = sci_get_selection_end (editor->sci);
- sci_insert_text (editor->sci, sci_get_selection_start (editor->sci),
- prior_char);
- sci_insert_text (editor->sci, end+1, end_char); /* end+1 to account for the
- newly added character*/
- sci_set_current_position (editor->sci, end+2, TRUE);
- return FALSE;
- }
- }
- return FALSE;
- }
- void plugin_cleanup(void)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement