static PyObject * Scintilla_get_current_line(Scintilla *self) { gint line; SCI_RET_IF_FAIL(self); line = sci_get_current_line(self->sci); return Py_BuildValue("i", line); }
void vte_send_selection_to_vte(void) { GeanyDocument *doc; gchar *text; gsize len; doc = document_get_current(); g_return_if_fail(doc != NULL); if (sci_has_selection(doc->editor->sci)) { text = g_malloc0(sci_get_selected_text_length(doc->editor->sci) + 1); sci_get_selected_text(doc->editor->sci, text); } else { /* Get the current line */ gint line_num = sci_get_current_line(doc->editor->sci); text = sci_get_line(doc->editor->sci, line_num); } len = strlen(text); if (vc->send_selection_unsafe) { /* Explicitly append a trailing newline character to get the command executed, this is disabled by default as it could cause all sorts of damage. */ if (text[len-1] != '\n' && text[len-1] != '\r') { SETPTR(text, g_strconcat(text, "\n", NULL)); len++; } } else { /* Make sure there is no newline character at the end to prevent unwanted execution */ while (text[len-1] == '\n' || text[len-1] == '\r') { text[len-1] = '\0'; len--; } } vf->vte_terminal_feed_child(VTE_TERMINAL(vc->vte), text, len); /* show the VTE */ gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_VTE); gtk_widget_grab_focus(vc->vte); msgwin_show_hide(TRUE); g_free(text); }
/* tries to insert a comment in the current document * @line: The line for which insert comment, or -1 for the current line */ static void insert_comment (gint line) { GeanyDocument *doc; doc = document_get_current (); if (DOC_VALID (doc)) { /* try to ensure tags corresponds to the actual state of the file */ refresh_tag_list (doc->tm_file, doc->editor->sci, doc); if (line < 0) { line = sci_get_current_line (doc->editor->sci); } ggd_insert_comment (doc, line, ggd_plugin_get_doctype (doc->file_type->id)); } }
static void define_format_newline(ScintillaObject *sci) { gint end_pos; gint line; line = sci_get_current_line(sci); if(!inside_define(sci, line, TRUE)) return; line--; end_pos = sci_get_line_end_position(sci, line); sci_insert_text(sci, end_pos, "\\"); line += 2; dprintf("Added line: %d\n", line); g_array_append_val(lines_stack, line); }
static PyObject * ZenEditor_get_current_line(ZenEditor *self, PyObject *args) { PyObject *result; gchar *line; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); line = sci_get_line(sci, sci_get_current_line(sci)); result = Py_BuildValue("s", line); g_free(line); return result; }
static PyObject * ZenEditor_get_current_line_range(ZenEditor *self, PyObject *args) { PyObject *result; gint line, line_start, line_end; ScintillaObject *sci; print_called(); py_return_none_if_null(sci = ZenEditor_get_scintilla(self)); line = sci_get_current_line(sci); line_start = sci_get_position_from_line(sci, line); line_end = sci_get_line_end_position(sci, line); result = Py_BuildValue("ii", line_start, line_end); return result; }
static PyObject * Scintilla_ensure_line_is_visible(Scintilla *self, PyObject *args, PyObject *kwargs) { gint line = -1; static gchar *kwlist[] = { "line", NULL }; SCI_RET_IF_FAIL(self); if (PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &line)) { if (line == -1) line = sci_get_current_line(self->sci); sci_ensure_line_is_visible(self->sci, line); } Py_RETURN_NONE; }
static PyObject * Scintilla_get_position_from_line(Scintilla *self, PyObject *args, PyObject *kwargs) { gint line = -1, pos; static gchar *kwlist[] = { "line", NULL }; SCI_RET_IF_FAIL(self); if (PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &line)) { if (line == -1) line = sci_get_current_line(self->sci); pos = sci_get_position_from_line(self->sci, line); return Py_BuildValue("i", pos); } Py_RETURN_NONE; }
static LocationInfo * location_query_cb() { GeanyDocument *doc = document_get_current(); if (!(doc && doc->is_valid)) { return NULL; } if (doc->file_name) { LocationInfo *abi; gint line; abi = g_new0(LocationInfo, 1); line = sci_get_current_line(doc->editor->sci); abi->filename = g_strdup(doc->file_name); if (line >= 0) { abi->line_num = g_strdup_printf("%d", line + 1); } abi->symbol = get_current_word(); return abi; } return NULL; }
static PyObject * Scintilla_get_line(Scintilla *self, PyObject *args, PyObject *kwargs) { gint line_num = -1; gchar *text; PyObject *py_text; static gchar *kwlist[] = { "line_num", NULL }; SCI_RET_IF_FAIL(self); if (PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &line_num)) { if (line_num == -1) line_num = sci_get_current_line(self->sci); text = sci_get_line(self->sci, line_num); if (text == NULL) Py_RETURN_NONE; py_text = PyString_FromString(text); g_free(text); return py_text; } Py_RETURN_NONE; }
static void run_tag_highlighter(ScintillaObject *sci) { gint position = sci_get_current_position(sci); gint lineNumber = sci_get_current_line(sci); gint lineStart = sci_get_position_from_line(sci, lineNumber); gint lineEnd = sci_get_line_end_position(sci, lineNumber); gint openingBracket = findBracket(sci, position, lineStart, '<', '>', FALSE); gint closingBracket = findBracket(sci, position, lineEnd, '>', '<', TRUE); int i; if(-1 == openingBracket || -1 == closingBracket) { clear_previous_highlighting(sci, highlightedBrackets[0], highlightedBrackets[1]); clear_previous_highlighting(sci, highlightedBrackets[2], highlightedBrackets[3]); for(i=0; i<3; i++) highlightedBrackets[i] = 0; return; } /* If the cursor jumps from one tag into another, clear * previous highlighted tags*/ if(openingBracket != highlightedBrackets[0] || closingBracket != highlightedBrackets[1]) { clear_previous_highlighting(sci, highlightedBrackets[0], highlightedBrackets[1]); clear_previous_highlighting(sci, highlightedBrackets[2], highlightedBrackets[3]); } /* Don't run search on empty brackets <> */ if (closingBracket - openingBracket > 1) { highlightedBrackets[0] = openingBracket; highlightedBrackets[1] = closingBracket; findMatchingTag(sci, openingBracket, closingBracket); } }
/* if type == -1 then we will try to autodetect the type */ void glatex_insert_environment(const gchar *environment, gint type) { GeanyDocument *doc = NULL; doc = document_get_current(); /* Only do anything if it is realy needed to */ if (doc != NULL && environment != NULL) { if (sci_has_selection(doc->editor->sci)) { gchar *selection = NULL; gchar *replacement = NULL; selection = sci_get_selection_contents(doc->editor->sci); sci_start_undo_action(doc->editor->sci); if (utils_str_equal(environment, "block") == TRUE) { replacement = g_strconcat("\\begin{", environment, "}{}\n", selection, "\n\\end{", environment, "}\n", NULL); } else { replacement = g_strconcat("\\begin{", environment, "}\n", selection, "\n\\end{", environment, "}\n", NULL); } sci_replace_sel(doc->editor->sci, replacement); sci_end_undo_action(doc->editor->sci); g_free(selection); g_free(replacement); } else { gint indent, pos; GString *tmpstring = NULL; gchar *tmp = NULL; static const GeanyIndentPrefs *indention_prefs = NULL; if (type == -1) { gint i; /* First, we check whether we have a known list over here * an reset type to fit new value*/ for (i = 0; i < GLATEX_LIST_END; i++) { if (utils_str_equal(glatex_list_environments[i], environment) == TRUE) { type = GLATEX_ENVIRONMENT_TYPE_LIST; break; } } } pos = sci_get_current_position(doc->editor->sci); sci_start_undo_action(doc->editor->sci); tmpstring = g_string_new("\\begin{"); g_string_append(tmpstring, environment); if (utils_str_equal(environment, "block") == TRUE) { g_string_append(tmpstring, "}{}"); } else { g_string_append(tmpstring, "}"); } g_string_append(tmpstring, "\n"); if (type == GLATEX_ENVIRONMENT_TYPE_LIST) { g_string_append(tmpstring, "\t\\item "); } tmp = g_string_free(tmpstring, FALSE); glatex_insert_string(tmp, TRUE); g_free(tmp); indent = sci_get_line_indentation(doc->editor->sci, sci_get_line_from_position(doc->editor->sci, pos)); tmp = g_strdup_printf("\n\\end{%s}", environment); glatex_insert_string(tmp, FALSE); g_free(tmp); indention_prefs = editor_get_indent_prefs(doc->editor); if (type == GLATEX_ENVIRONMENT_TYPE_LIST) { sci_set_line_indentation(doc->editor->sci, sci_get_current_line(doc->editor->sci), indent + indention_prefs->width); } sci_set_line_indentation(doc->editor->sci, sci_get_current_line(doc->editor->sci) + 1, indent); sci_end_undo_action(doc->editor->sci); } } }
/* * Occures when key is pressed. * Handles debug Run/Stop/... and add/remove breakpoint activities */ gboolean keys_callback(guint key_id) { switch (key_id) { case KEY_RUN: debug_run(); break; case KEY_STOP: debug_stop(); break; case KEY_RESTART: debug_restart(); break; case KEY_STEP_OVER: debug_step_over(); break; case KEY_STEP_INTO: debug_step_into(); break; case KEY_STEP_OUT: debug_step_out(); break; case KEY_EXECUTE_UNTIL: { GeanyDocument *doc = document_get_current(); if (doc) { int line = sci_get_current_line(doc->editor->sci) + 1; debug_execute_until(DOC_FILENAME(doc), line); } break; } case KEY_BREAKPOINT: { GeanyDocument *doc = document_get_current(); if (doc) { int line = sci_get_current_line(doc->editor->sci) + 1; break_state bs = breaks_get_state(DOC_FILENAME(doc), line); if (BS_NOT_SET == bs) breaks_add(DOC_FILENAME(doc), line, NULL, TRUE, 0); else if (BS_ENABLED == bs) breaks_remove(DOC_FILENAME(doc), line); else if (BS_DISABLED == bs) breaks_switch(DOC_FILENAME(doc), line); scintilla_send_message(doc->editor->sci, SCI_SETFOCUS, TRUE, 0); } break; } case KEY_CURRENT_INSTRUCTION: { if (DBS_STOPPED == debug_get_state() && debug_current_instruction_have_sources()) { debug_jump_to_current_instruction(); gtk_widget_set_sensitive(tab_call_stack, FALSE); stree_select_first_frame(FALSE); gtk_widget_set_sensitive(tab_call_stack, TRUE); } } } return TRUE; }
static gboolean editor_notify_cb(GObject *object, GeanyEditor *editor, SCNotification *nt, gpointer data) { gint i = 0, val; gint old_position = 0; gint old_lposition = 0; gint old_line = 0; gint pos; if(NULL == editor || NULL == editor->sci) return FALSE; if(nt->nmhdr.code == SCN_CHARADDED) { if('\n' == nt->ch) define_format_newline(editor->sci); } if(nt->nmhdr.code == SCN_UPDATEUI) { if(g_array_index(lines_stack, gint, 0)) { /* save current position */ old_line = sci_get_current_line(editor->sci); old_lposition = sci_get_line_end_position(editor->sci, old_line) - sci_get_line_length(editor->sci, old_line); old_position = sci_get_current_position(editor->sci); sci_start_undo_action(editor->sci); } while((val = g_array_index(lines_stack, gint, i))) { i++; define_format_line(editor->sci, val - 1); dprintf("Removed from stack: %d\n", val); } if(i > 0) { sci_end_undo_action(editor->sci); g_array_remove_range(lines_stack, 0, i); /* restore current position */ pos = sci_get_line_end_position(editor->sci, old_line) - sci_get_line_length(editor->sci, old_line); sci_set_current_position(editor->sci, old_position + pos - old_lposition, FALSE); } } if(nt->nmhdr.code == SCN_MODIFIED) { if(nt->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT)) { if(nt->modificationType & (SC_PERFORMED_UNDO | SC_PERFORMED_REDO)) return FALSE; gint line = sci_get_line_from_position(editor->sci, nt->position) + 1; if(sci_get_char_at(editor->sci, get_line_end(editor->sci, line - 1) - 1) == '\\') { gboolean found = FALSE; while((val = g_array_index(lines_stack, gint, i))) { if(val == line) { found = TRUE; break; } i++; } if(!found) { dprintf("Added line: %d\n", line); g_array_append_val(lines_stack, line); } } } } return FALSE; }
static void do_format(GeanyDocument *doc, bool entire_doc, bool autof) { GString *formatted; ScintillaObject *sci; size_t offset = 0, length = 0, sci_len; size_t cursor_pos, old_first_line, new_first_line, line_delta; const char *sci_buf; bool changed = true; bool was_changed; if (doc == NULL) doc = document_get_current(); if (!DOC_VALID(doc)) { g_warning("Cannot format with no documents open"); return; } sci = doc->editor->sci; was_changed = doc->changed; // FIXME: instead of failing, ask user to save the document once if (!doc->real_path) { g_warning("Cannot format document that's never been saved"); return; } if (!entire_doc) { if (sci_has_selection(sci)) { // format selection offset = sci_get_selection_start(sci); length = sci_get_selection_end(sci) - offset; } else { // format current line size_t cur_line = sci_get_current_line(sci); offset = sci_get_position_from_line(sci, cur_line); length = sci_get_line_end_position(sci, cur_line) - offset; } } else { // format entire document offset = 0; length = sci_get_length(sci); } cursor_pos = sci_get_current_position(sci); sci_len = sci_get_length(sci); sci_buf = (const char *)scintilla_send_message(sci, SCI_GETCHARACTERPOINTER, 0, 0); formatted = fmt_clang_format(doc->file_name, sci_buf, sci_len, &cursor_pos, offset, length, false); // FIXME: handle better if (formatted == NULL) return; if (!autof) { changed = (formatted->len != sci_len) || (g_strcmp0(formatted->str, sci_buf) != 0); } old_first_line = scintilla_send_message(sci, SCI_GETFIRSTVISIBLELINE, 0, 0); // Replace document text and move cursor to new position scintilla_send_message(sci, SCI_BEGINUNDOACTION, 0, 0); scintilla_send_message(sci, SCI_CLEARALL, 0, 0); scintilla_send_message(sci, SCI_ADDTEXT, formatted->len, (sptr_t)formatted->str); scintilla_send_message(sci, SCI_GOTOPOS, cursor_pos, 0); new_first_line = scintilla_send_message(sci, SCI_GETFIRSTVISIBLELINE, 0, 0); line_delta = new_first_line - old_first_line; scintilla_send_message(sci, SCI_LINESCROLL, 0, -line_delta); scintilla_send_message(sci, SCI_ENDUNDOACTION, 0, 0); document_set_text_changed(doc, (was_changed || changed)); g_string_free(formatted, true); }