6 * \brief Header: editor low level data handling and cursor fundamentals
11 #ifndef MC__EDIT_IMPL_H
12 #define MC__EDIT_IMPL_H
16 #include "lib/search.h" /* mc_search_type_t */
17 #include "lib/widget.h" /* cb_ret_t */
18 #include "lib/vfs/vfs.h" /* vfs_path_t */
22 /*** typedefs(not structures) and defined constants **********************************************/
24 #define REDRAW_LINE (1 << 0)
25 #define REDRAW_LINE_ABOVE (1 << 1)
26 #define REDRAW_LINE_BELOW (1 << 2)
27 #define REDRAW_AFTER_CURSOR (1 << 3)
28 #define REDRAW_BEFORE_CURSOR (1 << 4)
29 #define REDRAW_PAGE (1 << 5)
30 #define REDRAW_IN_BOUNDS (1 << 6)
31 #define REDRAW_CHAR_ONLY (1 << 7)
32 #define REDRAW_COMPLETELY (1 << 8)
34 #define EDIT_TEXT_HORIZONTAL_OFFSET 0
35 #define EDIT_TEXT_VERTICAL_OFFSET 0
37 #define EDIT_RIGHT_EXTREME option_edit_right_extreme
38 #define EDIT_LEFT_EXTREME option_edit_left_extreme
39 #define EDIT_TOP_EXTREME option_edit_top_extreme
40 #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
43 * The editor keeps data in two arrays of buffers.
44 * All buffers have the same size, which must be a power of 2.
47 /* Configurable: log2 of the buffer size in bytes */
48 #ifndef S_EDIT_BUF_SIZE
49 #define S_EDIT_BUF_SIZE 16
52 /* Size of the buffer */
53 #define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE)
55 /* Buffer mask (used to find cursor position relative to the buffer) */
56 #define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1)
59 * Configurable: Maximal allowed number of buffers in each buffer array.
60 * This number can be increased for systems with enough physical memory.
66 /* Maximal length of file that can be opened */
67 #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
69 /* Initial size of the undo stack, in bytes */
70 #define START_STACK_SIZE 32
72 /* Some codes that may be pushed onto or returned from the undo stack */
74 #define CURS_RIGHT 602
77 #define STACK_BOTTOM 605
78 #define CURS_LEFT_LOTS 606
79 #define CURS_RIGHT_LOTS 607
81 #define COLUMN_OFF 609
82 #define DELCHAR_BR 610
83 #define BACKSPACE_BR 611
85 #define MARK_2 500000000
86 #define MARK_CURS 1000000000
87 #define KEY_PRESS 1500000000
89 /* Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
90 #define TAB_SIZE option_tab_spacing
91 #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
93 /* max count stack files */
94 #define MAX_HISTORY_MOVETO 50
95 #define LINE_STATE_WIDTH 8
97 #define LB_NAMES (LB_MAC + 1)
99 #define get_sys_error(s) (s)
101 #define edit_error_dialog(h,s) query_dialog (h, s, D_ERROR, 1, _("&Dismiss"))
103 #define edit_query_dialog2(h,t,a,b) query_dialog (h, t, D_NORMAL, 2, a, b)
104 #define edit_query_dialog3(h,t,a,b,c) query_dialog (h, t, D_NORMAL, 3, a, b, c)
106 /*** enums ***************************************************************************************/
124 /*** structures declarations (and typedefs of structures)*****************************************/
126 /* search/replace options */
127 typedef struct edit_search_options_t
129 mc_search_type_t type
;
132 gboolean only_in_selection
;
133 gboolean whole_words
;
134 gboolean all_codepages
;
135 } edit_search_options_t
;
137 typedef struct edit_stack_type
140 vfs_path_t
*filename_vpath
;
146 /*** global variables defined in .c file *********************************************************/
148 extern const char VERTICAL_MAGIC
[5];
149 /* if enable_show_tabs_tws ==1 then use visible_tab visible_tws */
150 extern int enable_show_tabs_tws
;
152 extern edit_search_options_t edit_search_options
;
154 extern unsigned int edit_stack_iterator
;
155 extern edit_stack_type edit_history_moveto
[MAX_HISTORY_MOVETO
];
157 extern int option_line_state_width
;
159 extern int option_max_undo
;
160 extern int option_auto_syntax
;
162 extern int option_edit_right_extreme
;
163 extern int option_edit_left_extreme
;
164 extern int option_edit_top_extreme
;
165 extern int option_edit_bottom_extreme
;
167 extern const char *option_whole_chars_search
;
168 extern gboolean search_create_bookmark
;
170 extern char *edit_window_state_char
;
171 extern char *edit_window_close_char
;
173 /*** declarations of public functions ************************************************************/
175 gboolean
edit_add_window (Dlg_head
* h
, int y
, int x
, int lines
, int cols
,
176 const vfs_path_t
* f
, long fline
);
177 WEdit
*find_editor (const Dlg_head
* h
);
178 gboolean
edit_widget_is_editor (const Widget
* w
);
179 gboolean
edit_drop_hotkey_menu (Dlg_head
* h
, int key
);
180 void edit_menu_cmd (Dlg_head
* h
);
181 void user_menu (WEdit
* edit
, const char *menu_file
, int selected_entry
);
182 void edit_init_menu (struct WMenuBar
*menubar
);
183 void edit_save_mode_cmd (void);
184 gboolean
edit_translate_key (WEdit
* edit
, long x_key
, int *cmd
, int *ch
);
185 int edit_get_byte (const WEdit
* edit
, off_t byte_index
);
186 int edit_get_utf (const WEdit
* edit
, off_t byte_index
, int *char_width
);
187 long edit_count_lines (const WEdit
* edit
, off_t current
, off_t upto
);
188 off_t
edit_move_forward (const WEdit
* edit
, off_t current
, long lines
, off_t upto
);
189 off_t
edit_move_forward3 (const WEdit
* edit
, off_t current
, long cols
, off_t upto
);
190 off_t
edit_move_backward (const WEdit
* edit
, off_t current
, long lines
);
191 void edit_scroll_screen_over_cursor (WEdit
* edit
);
192 void edit_render_keypress (WEdit
* edit
);
193 void edit_scroll_upward (WEdit
* edit
, long i
);
194 void edit_scroll_downward (WEdit
* edit
, long i
);
195 void edit_scroll_right (WEdit
* edit
, long i
);
196 void edit_scroll_left (WEdit
* edit
, long i
);
197 void edit_move_up (WEdit
* edit
, long i
, gboolean do_scroll
);
198 void edit_move_down (WEdit
* edit
, long i
, gboolean do_scroll
);
199 void edit_move_to_prev_col (WEdit
* edit
, off_t p
);
200 long edit_get_col (const WEdit
* edit
);
201 off_t
edit_bol (const WEdit
* edit
, off_t current
);
202 off_t
edit_eol (const WEdit
* edit
, off_t current
);
203 void edit_update_curs_row (WEdit
* edit
);
204 void edit_update_curs_col (WEdit
* edit
);
205 void edit_find_bracket (WEdit
* edit
);
206 gboolean
edit_reload_line (WEdit
* edit
, const vfs_path_t
* filename_vpath
, long line
);
207 void edit_set_codeset (WEdit
* edit
);
209 void edit_block_copy_cmd (WEdit
* edit
);
210 void edit_block_move_cmd (WEdit
* edit
);
211 int edit_block_delete_cmd (WEdit
* edit
);
212 void edit_delete_line (WEdit
* edit
);
214 int edit_delete (WEdit
* edit
, gboolean byte_delete
);
215 int edit_backspace (WEdit
* edit
, gboolean byte_delete
);
216 void edit_insert (WEdit
* edit
, int c
);
217 void edit_cursor_move (WEdit
* edit
, off_t increment
);
218 void edit_push_undo_action (WEdit
* edit
, long c
);
219 void edit_push_redo_action (WEdit
* edit
, long c
);
220 void edit_push_key_press (WEdit
* edit
);
221 void edit_insert_ahead (WEdit
* edit
, int c
);
222 off_t
edit_write_stream (WEdit
* edit
, FILE * f
);
223 char *edit_get_write_filter (const vfs_path_t
* write_name_vpath
,
224 const vfs_path_t
* filename_vpath
);
225 gboolean
edit_save_confirm_cmd (WEdit
* edit
);
226 gboolean
edit_save_as_cmd (WEdit
* edit
);
227 WEdit
*edit_init (WEdit
* edit
, int y
, int x
, int lines
, int cols
,
228 const vfs_path_t
* filename_vpath
, long line
);
229 gboolean
edit_clean (WEdit
* edit
);
230 gboolean
edit_ok_to_exit (WEdit
* edit
);
231 gboolean
edit_load_cmd (Dlg_head
* h
);
232 gboolean
edit_load_syntax_file (Dlg_head
* h
);
233 gboolean
edit_load_menu_file (Dlg_head
* h
);
234 gboolean
edit_close_cmd (WEdit
* edit
);
235 void edit_mark_cmd (WEdit
* edit
, gboolean unmark
);
236 void edit_mark_current_word_cmd (WEdit
* edit
);
237 void edit_mark_current_line_cmd (WEdit
* edit
);
238 void edit_set_markers (WEdit
* edit
, off_t m1
, off_t m2
, long c1
, long c2
);
239 void edit_push_markers (WEdit
* edit
);
240 void edit_replace_cmd (WEdit
* edit
, int again
);
241 void edit_search_cmd (WEdit
* edit
, gboolean again
);
242 mc_search_cbret_t
edit_search_cmd_callback (const void *user_data
, gsize char_offset
,
244 void edit_complete_word_cmd (WEdit
* edit
);
245 void edit_get_match_keyword_cmd (WEdit
* edit
);
248 int edit_suggest_current_word (WEdit
* edit
);
249 void edit_spellcheck_file (WEdit
* edit
);
250 void edit_set_spell_lang (void);
253 gboolean
edit_save_block (WEdit
* edit
, const char *filename
, off_t start
, off_t finish
);
254 gboolean
edit_save_block_cmd (WEdit
* edit
);
255 gboolean
edit_insert_file_cmd (WEdit
* edit
);
256 void edit_insert_over (WEdit
* edit
);
257 off_t
edit_insert_column_of_text_from_file (WEdit
* edit
, int file
,
258 off_t
* start_pos
, off_t
* end_pos
, long *col1
,
261 char *edit_get_word_from_pos (const WEdit
* edit
, off_t start_pos
, off_t
* start
, gsize
* len
,
263 long edit_insert_file (WEdit
* edit
, const vfs_path_t
* filename_vpath
);
264 gboolean
edit_load_back_cmd (WEdit
* edit
);
265 gboolean
edit_load_forward_cmd (WEdit
* edit
);
266 void edit_block_process_cmd (WEdit
* edit
, int macro_number
);
267 void edit_refresh_cmd (void);
268 void edit_syntax_onoff_cmd (Dlg_head
* h
);
269 void edit_show_tabs_tws_cmd (Dlg_head
* h
);
270 void edit_show_margin_cmd (Dlg_head
* h
);
271 void edit_show_numbers_cmd (Dlg_head
* h
);
272 void edit_date_cmd (WEdit
* edit
);
273 void edit_goto_cmd (WEdit
* edit
);
274 int eval_marks (WEdit
* edit
, off_t
* start_mark
, off_t
* end_mark
);
275 void edit_status (WEdit
* edit
, gboolean active
);
276 void edit_execute_key_command (WEdit
* edit
, unsigned long command
, int char_for_insertion
);
277 void edit_update_screen (WEdit
* edit
);
278 void edit_save_size (WEdit
* edit
);
279 gboolean
edit_handle_move_resize (WEdit
* edit
, unsigned long command
);
280 void edit_toggle_fullscreen (WEdit
* edit
);
281 void edit_move_to_line (WEdit
* e
, long line
);
282 void edit_move_display (WEdit
* e
, long line
);
283 void edit_word_wrap (WEdit
* edit
);
284 int edit_sort_cmd (WEdit
* edit
);
285 int edit_ext_cmd (WEdit
* edit
);
287 int edit_store_macro_cmd (WEdit
* edit
);
288 gboolean
edit_load_macro_cmd (WEdit
* edit
);
289 void edit_delete_macro_cmd (WEdit
* edit
);
290 gboolean
edit_repeat_macro_cmd (WEdit
* edit
);
292 gboolean
edit_copy_to_X_buf_cmd (WEdit
* edit
);
293 gboolean
edit_cut_to_X_buf_cmd (WEdit
* edit
);
294 gboolean
edit_paste_from_X_buf_cmd (WEdit
* edit
);
296 void edit_select_codepage_cmd (WEdit
* edit
);
297 void edit_insert_literal_cmd (WEdit
* edit
);
298 gboolean
edit_execute_macro (WEdit
* edit
, int hotkey
);
299 void edit_begin_end_macro_cmd (WEdit
* edit
);
300 void edit_begin_end_repeat_cmd (WEdit
* edit
);
302 void edit_paste_from_history (WEdit
* edit
);
304 void edit_set_filename (WEdit
* edit
, const vfs_path_t
* name_vpath
);
306 void edit_load_syntax (WEdit
* edit
, char ***pnames
, const char *type
);
307 void edit_free_syntax_rules (WEdit
* edit
);
308 int edit_get_syntax_color (WEdit
* edit
, off_t byte_index
);
310 void book_mark_insert (WEdit
* edit
, long line
, int c
);
311 gboolean
book_mark_query_color (WEdit
* edit
, long line
, int c
);
312 struct edit_book_mark_t
*book_mark_find (WEdit
* edit
, long line
);
313 gboolean
book_mark_clear (WEdit
* edit
, long line
, int c
);
314 void book_mark_flush (WEdit
* edit
, int c
);
315 void book_mark_inc (WEdit
* edit
, long line
);
316 void book_mark_dec (WEdit
* edit
, long line
);
317 void book_mark_serialize (WEdit
* edit
, int color
);
318 void book_mark_restore (WEdit
* edit
, int color
);
320 gboolean
edit_line_is_blank (WEdit
* edit
, long line
);
321 gboolean
is_break_char (char c
);
322 long edit_indent_width (const WEdit
* edit
, off_t p
);
323 void edit_insert_indent (WEdit
* edit
, int indent
);
324 void edit_options_dialog (Dlg_head
* h
);
325 void edit_syntax_dialog (WEdit
* edit
);
326 void edit_mail_dialog (WEdit
* edit
);
327 void format_paragraph (WEdit
* edit
, int force
);
329 /* either command or char_for_insertion must be passed as -1 */
330 void edit_execute_cmd (WEdit
* edit
, unsigned long command
, int char_for_insertion
);
332 /*** inline functions ****************************************************************************/
335 * Load a new file into the editor. If it fails, preserve the old file.
336 * To do it, allocate a new widget, initialize it and, if the new file
337 * was loaded, copy the data to the old widget.
339 * @return TRUE on success, FALSE on failure.
341 static inline gboolean
342 edit_reload (WEdit
* edit
, const vfs_path_t
* filename_vpath
)
344 return edit_reload_line (edit
, filename_vpath
, 0);
347 #endif /* MC__EDIT_IMPL_H */