/** * name: cb_eval * * This callback function is invoked when the 'LispEdit: eval' menu option is selected. * If the cursor is placed after a closing parenthesis the function will look for the matching * opening parenthesis. If there is no matching parenthesis it will display a warning dialog box. * * If the closing parenthesis has a matching opening parenthesis, all the characters between the parentheses * including the parentheses are sent to the child process running in the VTE. * * @param menuitem GtkMenuItem. * @param gdata gpointer. * @return void **/ static void cb_eval(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata) { if (have_vte) { doc = document_get_current(); end_pos = sci_get_current_position(doc->editor->sci); if (end_pos > 0) end_pos--; gchar letter = sci_get_char_at(doc->editor->sci, end_pos); switch (letter) { case ')': start_pos = sci_find_matching_brace(doc->editor->sci, end_pos); if (start_pos < 0) { dialogs_show_msgbox(GTK_MESSAGE_WARNING, "Found an isolated closing brace!!!"); } else if (start_pos >= 0) { sci_get_text_range(doc->editor->sci, start_pos, ++end_pos, cmd_string); vte_terminal_feed_child(vte, "\n", strlen("\n")); vte_terminal_feed_child(vte, cmd_string, strlen(cmd_string)); vte_terminal_feed_child(vte, "\n", strlen("\n")); } break; } } else { show_error_message(); } }
static PyObject * Scintilla_find_matching_brace(Scintilla *self, PyObject *args, PyObject *kwargs) { gint pos, match_pos; static gchar *kwlist[] = { "pos", NULL }; SCI_RET_IF_FAIL(self); if (PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &pos)) { match_pos = sci_find_matching_brace(self->sci, pos); return Py_BuildValue("i", match_pos); } Py_RETURN_NONE; }
static gboolean handle_backspace( AutocloseUserData *data, ScintillaObject *sci, gchar ch, gchar *ch_left, gchar *ch_right, GdkEventKey *event, gint indent_width) { gint pos = sci_get_current_position(sci); gint end_pos; gint line_start, line_end, line; gint i; if (!ac_info->delete_pairing_brace) return AC_CONTINUE_ACTION; ch = char_at(sci, pos - 1); if (!check_chars(sci, ch, ch_left, ch_right)) return AC_CONTINUE_ACTION; if (event->state & GDK_SHIFT_MASK) { if ((ch_left[0] == ch || ch_right[0] == ch) && ac_info->bcksp_remove_pair) { end_pos = sci_find_matching_brace(sci, pos - 1); if (-1 == end_pos) return AC_CONTINUE_ACTION; sci_start_undo_action(sci); line_start = sci_get_line_from_position(sci, pos); line_end = sci_get_line_from_position(sci, end_pos); SSM(sci, SCI_DELETERANGE, end_pos, 1); if (end_pos < pos) pos--; SSM(sci, SCI_DELETERANGE, pos - 1, 1); /* remove indentation magick */ if (char_is_curly_bracket(ch)) { if (line_start == line_end) goto final; if (line_start > line_end) { line = line_end; line_end = line_start; line_start = line; } if (blank_line(sci, line_start)) { delete_line(sci, line_start); line_end--; } else line_start++; if (blank_line(sci, line_end)) delete_line(sci, line_end); line_end--; /* unindent */ for (i = line_start; i <= line_end; i++) { unindent_line(sci, i, indent_width); } } final: sci_end_undo_action(sci); return AC_STOP_ACTION; }