Panel update: type accuracy.
[pantumic.git] / src / editor / edit-impl.h
blob6f3459043b872d4a3c762d67edd3d612683b31e1
1 /* edit.h - editor private API
3 Copyright (C) 1996, 1997, 2009 Free Software Foundation, Inc.
5 Authors: 1996, 1997 Paul Sheer
6 2009 Andrew Borodin
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA.
24 /** \file edit-impl.h
25 * \brief Header: editor low level data handling and cursor fundamentals
26 * \author Paul Sheer
27 * \date 1996, 1997
30 #ifndef MC__EDIT_IMPL_H
31 #define MC__EDIT_IMPL_H
33 #include <stdio.h>
35 #include "lib/search.h" /* mc_search_type_t */
36 #include "lib/widget.h" /* cb_ret_t */
38 #include "edit.h"
40 /*** typedefs(not structures) and defined constants **********************************************/
42 #define SEARCH_DIALOG_OPTION_NO_SCANF (1 << 0)
43 #define SEARCH_DIALOG_OPTION_NO_REGEX (1 << 1)
44 #define SEARCH_DIALOG_OPTION_NO_CASE (1 << 2)
45 #define SEARCH_DIALOG_OPTION_BACKWARDS (1 << 3)
46 #define SEARCH_DIALOG_OPTION_BOOKMARK (1 << 4)
48 #define EDIT_KEY_EMULATION_NORMAL 0
49 #define EDIT_KEY_EMULATION_EMACS 1
50 #define EDIT_KEY_EMULATION_USER 2
52 #define REDRAW_LINE (1 << 0)
53 #define REDRAW_LINE_ABOVE (1 << 1)
54 #define REDRAW_LINE_BELOW (1 << 2)
55 #define REDRAW_AFTER_CURSOR (1 << 3)
56 #define REDRAW_BEFORE_CURSOR (1 << 4)
57 #define REDRAW_PAGE (1 << 5)
58 #define REDRAW_IN_BOUNDS (1 << 6)
59 #define REDRAW_CHAR_ONLY (1 << 7)
60 #define REDRAW_COMPLETELY (1 << 8)
62 #define EDIT_TEXT_HORIZONTAL_OFFSET 0
63 #define EDIT_TEXT_VERTICAL_OFFSET 1
65 #define EDIT_RIGHT_EXTREME option_edit_right_extreme
66 #define EDIT_LEFT_EXTREME option_edit_left_extreme
67 #define EDIT_TOP_EXTREME option_edit_top_extreme
68 #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
71 * The editor keeps data in two arrays of buffers.
72 * All buffers have the same size, which must be a power of 2.
75 /* Configurable: log2 of the buffer size in bytes */
76 #ifndef S_EDIT_BUF_SIZE
77 #define S_EDIT_BUF_SIZE 16
78 #endif
80 /* Size of the buffer */
81 #define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE)
83 /* Buffer mask (used to find cursor position relative to the buffer) */
84 #define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1)
87 * Configurable: Maximal allowed number of buffers in each buffer array.
88 * This number can be increased for systems with enough physical memory.
90 #ifndef MAXBUFF
91 #define MAXBUFF 1024
92 #endif
94 /* Maximal length of file that can be opened */
95 #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
97 /* Initial size of the undo stack, in bytes */
98 #define START_STACK_SIZE 32
100 /* Some codes that may be pushed onto or returned from the undo stack */
101 #define CURS_LEFT 601
102 #define CURS_RIGHT 602
103 #define DELCHAR 603
104 #define BACKSPACE 604
105 #define STACK_BOTTOM 605
106 #define CURS_LEFT_LOTS 606
107 #define CURS_RIGHT_LOTS 607
108 #define COLUMN_ON 608
109 #define COLUMN_OFF 609
110 #define MARK_1 1000
111 #define MARK_2 700000000
112 #define KEY_PRESS 1400000000
114 /* Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
115 #define TAB_SIZE option_tab_spacing
116 #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
118 /* max count stack files */
119 #define MAX_HISTORY_MOVETO 50
120 #define LINE_STATE_WIDTH 8
122 #define LB_NAMES (LB_MAC + 1)
124 #define get_sys_error(s) (s)
126 #define edit_error_dialog(h,s) query_dialog (h, s, D_ERROR, 1, _("&Dismiss"))
128 #define edit_query_dialog2(h,t,a,b) query_dialog (h, t, D_NORMAL, 2, a, b)
129 #define edit_query_dialog3(h,t,a,b,c) query_dialog (h, t, D_NORMAL, 3, a, b, c)
131 #ifndef MAX_PATH_LEN
132 #ifdef PATH_MAX
133 #define MAX_PATH_LEN PATH_MAX
134 #else
135 #define MAX_PATH_LEN 1024
136 #endif
137 #endif
139 /*** enums ***************************************************************************************/
141 /* type for file which is currently being edited */
142 typedef enum
144 EDIT_FILE_COMMON = 0,
145 EDIT_FILE_SYNTAX = 1,
146 EDIT_FILE_MENU = 2
147 } edit_current_file_t;
149 /* line breaks */
150 typedef enum
152 LB_ASIS = 0,
153 LB_UNIX,
154 LB_WIN,
155 LB_MAC
156 } LineBreaks;
158 typedef enum
160 EDIT_QUICK_SAVE = 0,
161 EDIT_SAFE_SAVE,
162 EDIT_DO_BACKUP
163 } edit_save_mode_t;
165 /*** structures declarations (and typedefs of structures)*****************************************/
167 /* search/replace options */
168 typedef struct edit_search_options_t
170 mc_search_type_t type;
171 gboolean case_sens;
172 gboolean backwards;
173 gboolean only_in_selection;
174 gboolean whole_words;
175 gboolean all_codepages;
176 } edit_search_options_t;
178 typedef struct edit_stack_type
180 long line;
181 char *filename;
182 } edit_stack_type;
184 struct macro
186 unsigned long command;
187 int ch;
190 struct Widget;
191 struct WMenuBar;
193 /*** global variables defined in .c file *********************************************************/
195 extern const char VERTICAL_MAGIC[5];
196 /* if enable_show_tabs_tws ==1 then use visible_tab visible_tws */
197 extern int enable_show_tabs_tws;
199 extern edit_search_options_t edit_search_options;
201 extern int edit_stack_iterator;
202 extern edit_stack_type edit_history_moveto[MAX_HISTORY_MOVETO];
204 extern int option_line_state_width;
206 extern int option_max_undo;
207 extern int option_auto_syntax;
209 extern int option_edit_right_extreme;
210 extern int option_edit_left_extreme;
211 extern int option_edit_top_extreme;
212 extern int option_edit_bottom_extreme;
214 extern const char *option_whole_chars_search;
215 extern gboolean search_create_bookmark;
217 /*** declarations of public functions ************************************************************/
219 int edit_drop_hotkey_menu (WEdit * e, int key);
220 void edit_menu_cmd (WEdit * e);
221 void edit_init_menu (struct WMenuBar *menubar);
222 void menu_save_mode_cmd (void);
223 int edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch);
224 int edit_get_byte (WEdit * edit, long byte_index);
225 char *edit_get_byte_ptr (WEdit * edit, long byte_index);
226 char *edit_get_buf_ptr (WEdit * edit, long byte_index);
227 int edit_get_utf (WEdit * edit, long byte_index, int *char_width);
228 int edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width);
229 long edit_count_lines (WEdit * edit, long current, long upto);
230 long edit_move_forward (WEdit * edit, long current, long lines, long upto);
231 long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
232 long edit_move_backward (WEdit * edit, long current, long lines);
233 void edit_scroll_screen_over_cursor (WEdit * edit);
234 void edit_render_keypress (WEdit * edit);
235 void edit_scroll_upward (WEdit * edit, unsigned long i);
236 void edit_scroll_downward (WEdit * edit, int i);
237 void edit_scroll_right (WEdit * edit, int i);
238 void edit_scroll_left (WEdit * edit, int i);
239 void edit_move_up (WEdit * edit, unsigned long i, int scroll);
240 void edit_move_down (WEdit * edit, unsigned long i, int scroll);
241 void edit_move_to_prev_col (WEdit * edit, long p);
242 int edit_get_col (WEdit * edit);
243 long edit_bol (WEdit * edit, long current);
244 long edit_eol (WEdit * edit, long current);
245 void edit_update_curs_row (WEdit * edit);
246 void edit_update_curs_col (WEdit * edit);
247 void edit_find_bracket (WEdit * edit);
248 int edit_reload_line (WEdit * edit, const char *filename, long line);
249 void edit_set_codeset (WEdit * edit);
251 void edit_block_copy_cmd (WEdit * edit);
252 void edit_block_move_cmd (WEdit * edit);
253 int edit_block_delete_cmd (WEdit * edit);
254 void edit_delete_line (WEdit * edit);
255 void insert_spaces_tab (WEdit * edit, int half);
257 int edit_delete (WEdit * edit, const int byte_delete);
258 void edit_insert (WEdit * edit, int c);
259 void edit_cursor_move (WEdit * edit, long increment);
260 void edit_move_block_to_right (WEdit * edit);
261 void edit_move_block_to_left (WEdit * edit);
262 void edit_push_action (WEdit * edit, long c, ...);
263 void edit_push_key_press (WEdit * edit);
264 void edit_insert_ahead (WEdit * edit, int c);
265 long edit_write_stream (WEdit * edit, FILE * f);
266 char *edit_get_write_filter (const char *writename, const char *filename);
267 int edit_save_confirm_cmd (WEdit * edit);
268 int edit_save_as_cmd (WEdit * edit);
269 WEdit *edit_init (WEdit * edit, int lines, int columns, const char *filename, long line);
270 int edit_clean (WEdit * edit);
271 gboolean edit_ok_to_exit (WEdit * edit);
272 int edit_renew (WEdit * edit);
273 int edit_new_cmd (WEdit * edit);
274 int edit_reload (WEdit * edit, const char *filename);
275 int edit_load_cmd (WEdit * edit, edit_current_file_t what);
276 void edit_mark_cmd (WEdit * edit, int unmark);
277 void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
278 void edit_push_markers (WEdit * edit);
279 void edit_replace_cmd (WEdit * edit, int again);
280 void edit_search_cmd (WEdit * edit, gboolean again);
281 int edit_search_cmd_callback (const void *user_data, gsize char_offset);
282 void edit_complete_word_cmd (WEdit * edit);
283 void edit_get_match_keyword_cmd (WEdit * edit);
284 int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
285 int edit_save_block_cmd (WEdit * edit);
286 int edit_insert_file_cmd (WEdit * edit);
287 void edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width);
288 int edit_insert_column_of_text_from_file (WEdit * edit, int file);
289 int edit_insert_file (WEdit * edit, const char *filename);
290 int edit_load_back_cmd (WEdit * edit);
291 int edit_load_forward_cmd (WEdit * edit);
292 void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block);
293 void edit_refresh_cmd (WEdit * edit);
294 void edit_date_cmd (WEdit * edit);
295 void edit_goto_cmd (WEdit * edit);
296 int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
297 void edit_status (WEdit * edit);
298 void edit_execute_key_command (WEdit * edit, unsigned long command, int char_for_insertion);
299 void edit_update_screen (WEdit * edit);
300 int edit_print_string (WEdit * e, const char *s);
301 void edit_move_to_line (WEdit * e, long line);
302 void edit_move_display (WEdit * e, long line);
303 void edit_word_wrap (WEdit * edit);
304 int edit_sort_cmd (WEdit * edit);
305 int edit_ext_cmd (WEdit * edit);
306 void edit_help_cmd (WEdit * edit);
308 int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n);
309 int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k);
310 void edit_delete_macro_cmd (WEdit * edit);
312 int edit_copy_to_X_buf_cmd (WEdit * edit);
313 int edit_cut_to_X_buf_cmd (WEdit * edit);
314 void edit_paste_from_X_buf_cmd (WEdit * edit);
316 void edit_select_codepage_cmd (WEdit * edit);
317 void edit_insert_literal_cmd (WEdit * edit);
318 void edit_execute_macro_cmd (WEdit * edit);
319 void edit_begin_end_macro_cmd (WEdit * edit);
321 void edit_paste_from_history (WEdit * edit);
323 void edit_set_filename (WEdit * edit, const char *name);
325 void edit_load_syntax (WEdit * edit, char ***pnames, const char *type);
326 void edit_free_syntax_rules (WEdit * edit);
327 void edit_get_syntax_color (WEdit * edit, long byte_index, int *color);
329 void book_mark_insert (WEdit * edit, size_t line, int c);
330 int book_mark_query_color (WEdit * edit, int line, int c);
331 int book_mark_query_all (WEdit * edit, int line, int *c);
332 struct _book_mark *book_mark_find (WEdit * edit, int line);
333 int book_mark_clear (WEdit * edit, int line, int c);
334 void book_mark_flush (WEdit * edit, int c);
335 void book_mark_inc (WEdit * edit, int line);
336 void book_mark_dec (WEdit * edit, int line);
337 void book_mark_serialize (WEdit * edit, int color);
338 void book_mark_restore (WEdit * edit, int color);
340 int line_is_blank (WEdit * edit, long line);
341 int edit_indent_width (WEdit * edit, long p);
342 void edit_insert_indent (WEdit * edit, int indent);
343 void edit_options_dialog (WEdit * edit);
344 void edit_syntax_dialog (WEdit * edit);
345 void edit_mail_dialog (WEdit * edit);
346 void format_paragraph (WEdit * edit, int force);
348 unsigned int edit_unlock_file (WEdit * edit);
349 unsigned int edit_lock_file (WEdit * edit);
351 /* either command or char_for_insertion must be passed as -1 */
352 void edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion);
354 /*** inline functions ****************************************************************************/
356 #endif /* MC__EDIT_IMPL_H */