static void autoindent_brace_code (GtkScintilla *sci, PreferencesManager *pref) { gint current_pos; gint current_line; gint previous_line; gint previous_line_indentation; gint previous_line_end; current_pos = gtk_scintilla_get_current_pos(sci); current_line = gtk_scintilla_line_from_position(sci, current_pos); gphpedit_debug (DEBUG_DOCUMENT); if (current_line>0) { gtk_scintilla_begin_undo_action(sci); previous_line = current_line-1; previous_line_indentation = gtk_scintilla_get_line_indentation(sci, previous_line); previous_line_end = gtk_scintilla_get_line_end_position(sci, previous_line); indent_line(sci, current_line, previous_line_indentation); gphpedit_debug_message (DEBUG_DOCUMENT, "previous_line=%d, previous_indent=%d\n", previous_line, previous_line_indentation); gint pos; gboolean tabs_instead_spaces; g_object_get(pref,"tabs_instead_spaces", &tabs_instead_spaces, NULL); if(tabs_instead_spaces){ pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation/gtk_scintilla_get_tab_width(sci)); } else { pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation); } gtk_scintilla_goto_pos(sci, pos); gtk_scintilla_end_undo_action(sci); } }
static void pop_element(FILE *fp, long_vector_t elemstack){ int type = long_vector_pop(elemstack); indent_line(fp, long_vector_size(elemstack)); switch(type){ case XML_TOPOLOGY_TAG_CLUSTER: fprintf(fp, "</%s>\n", XML_CLUSTER_ELEMENT); break; case XML_TOPOLOGY_TAG_SWITCH: fprintf(fp, "</%s>\n", XML_SWITCH_ELEMENT); break; } }
static void push_element(FILE *fp, int type, long_vector_t elemstack, float band, const char *hostname){ indent_line(fp, long_vector_size(elemstack)); switch(type){ case XML_TOPOLOGY_TAG_CLUSTER: fprintf(fp, "<%s>\n", XML_CLUSTER_ELEMENT); long_vector_add(elemstack, type); break; case XML_TOPOLOGY_TAG_SWITCH: fprintf(fp, "<%s bandwidth=\"%.1f\">\n", XML_SWITCH_ELEMENT, band); long_vector_add(elemstack, type); break; case XML_TOPOLOGY_TAG_NODE: fprintf(fp, "<%s bandwidth=\"%.1f\" hostname=\"%s\" />\n", XML_NODE_ELEMENT, band, hostname); break; } }
/*{{{ newline_and_indent */ int newline_and_indent () { static int in_function; if (in_function) return -1; #if JED_HAS_LINE_ATTRIBUTES if (check_line_attr_no_modify (CLine) || ((CLine->next != NULL) && eolp () && check_line_attr_no_modify (CLine->next))) return 0; #endif if ((CBuf->buffer_hooks != NULL) && (CBuf->buffer_hooks->newline_indent_hook != NULL)) { in_function = 1; SLexecute_function(CBuf->buffer_hooks->newline_indent_hook); in_function = 0; return 1; } if (0 == jed_insert_newline ()) indent_line(); return(1); }
static void autoindent_brace_code (GtkScintilla *sci, PreferencesManager *pref) { gint current_pos; gint current_line; gint previous_line; gint previous_line_indentation; gint previous_line_start; gint previous_line_end; gchar *previous_char_buffer; gint previous_char_buffer_length; gchar *previous_line_buffer; gint previous_line_buffer_length; current_pos = gtk_scintilla_get_current_pos(sci); current_line = gtk_scintilla_line_from_position(sci, current_pos); gphpedit_debug (DEBUG_DOCUMENT); if (current_line>0) { gtk_scintilla_begin_undo_action(sci); previous_line = current_line-1; previous_line_indentation = gtk_scintilla_get_line_indentation(sci, previous_line); previous_line_end = gtk_scintilla_get_line_end_position(sci, previous_line); previous_char_buffer = gtk_scintilla_get_text_range (sci, previous_line_end-1, previous_line_end, &previous_char_buffer_length); if (is_css_char_autoindent(*previous_char_buffer)) { gint indentation_size; g_object_get(pref, "indentation_size", &indentation_size, NULL); previous_line_indentation+=indentation_size; } else if (is_css_char_autounindent(*previous_char_buffer)) { gint indentation_size; g_object_get(pref, "indentation_size", &indentation_size, NULL); previous_line_indentation-=indentation_size; if (previous_line_indentation < 0) previous_line_indentation = 0; previous_line_start = gtk_scintilla_position_from_line(sci, previous_line); previous_line_buffer = gtk_scintilla_get_text_range (sci, previous_line_start, previous_line_end, &previous_line_buffer_length); gboolean unindent = TRUE; gint char_act = 0; while (char_act <= previous_line_buffer_length) { char c = previous_line_buffer[char_act]; if (!(g_ascii_iscntrl(c) || g_ascii_isspace(c) || is_css_char_autounindent(c))) { unindent = FALSE; break; } char_act++; } if (unindent) gtk_scintilla_set_line_indentation(sci, previous_line, previous_line_indentation); g_free(previous_line_buffer); } g_free(previous_char_buffer); indent_line(sci, current_line, previous_line_indentation); gphpedit_debug_message (DEBUG_DOCUMENT, "previous_line=%d, previous_indent=%d\n", previous_line, previous_line_indentation); gint pos; gboolean tabs_instead_spaces; g_object_get(pref,"tabs_instead_spaces", &tabs_instead_spaces, NULL); if(tabs_instead_spaces) { pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation/gtk_scintilla_get_tab_width(sci)); } else { pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation); } gtk_scintilla_goto_pos(sci, pos); gtk_scintilla_end_undo_action(sci); } }
/*{{{ ins_char_cmd */ int ins_char_cmd (void) { unsigned char ch; int wrap = Buffer_Local.wrap_column; int do_blink; int did_abbrev = 0; SLang_Name_Type *wrapok_hook; CHECK_READ_ONLY #if 0 ; #endif #if JED_HAS_LINE_ATTRIBUTES if (check_line_attr_no_modify (CLine)) return 0; #endif ch = SLang_Last_Key_Char; if (ch == '\n') { newline(); return(1); } #if JED_HAS_ABBREVS if (CBuf->flags & ABBREV_MODE) { if (-1 == (did_abbrev = jed_expand_abbrev (ch))) return -1; } #endif if ((CBuf->flags & OVERWRITE_MODE) && !eolp()) { /* FIXME: jed_del_wchar should be called for the last byte of a * UTF-8 sequence */ if ((did_abbrev == 0) && (-1 == jed_del_wchar ())) return -1; } /* It is ok to use Point as an estimator of the current column. This * avoids the more expensive call to calculate_column. */ if (CBuf->buffer_hooks != NULL) wrapok_hook = CBuf->buffer_hooks->wrapok_hook; else wrapok_hook = NULL; if (((ch == ' ') || (Point >= wrap)) && ((CBuf->modes & WRAP_MODE) || (wrapok_hook != NULL)) && (calculate_column() > wrap) && ((wrapok_hook == NULL) || (1 == execute_is_ok_hook (wrapok_hook)))) { unsigned int this_line_num = LineNum; if ((did_abbrev == 0) && (-1 == jed_insert_byte (ch))) return -1; if (1 != wrap_line(0)) /* do not format--- just wrap */ return -1; /* line isn't wrapable */ /* There is a bug involving wrapping a very long line containing * no whitespace and then we try to insert a character. This work * arounds the bug. */ if ((this_line_num == LineNum) && (ch == ' ')) /* && (calculate_column () > wrap)) */ { if (0 == jed_right (1)) newline (); } if ((CBuf->buffer_hooks != NULL) && (CBuf->buffer_hooks->wrap_hook != NULL)) SLexecute_function(CBuf->buffer_hooks->wrap_hook); else if (Indented_Text_Mode) indent_line (); return(1); } do_blink = ((((CBuf->syntax_table != NULL) && ((CBuf->syntax_table->char_syntax[(unsigned char) ch] & CLOSE_DELIM_SYNTAX))) || ((ch == ')') || (ch == '}') || (ch == ']'))) && !input_pending(&Number_Zero)); if (did_abbrev == 0) (void) jed_insert_byte (ch); if (do_blink) blink_match (); return 1; }