1 /* edit.h - editor private API
3 Copyright (C) 1996, 1997, 2009 Free Software Foundation, Inc.
5 Authors: 1996, 1997 Paul Sheer
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
25 * \brief Header: editor low level data handling and cursor fundamentals
30 #ifndef MC__EDIT_IMPL_H
31 #define MC__EDIT_IMPL_H
35 #include "lib/search.h" /* mc_search_type_t */
36 #include "lib/widget.h" /* cb_ret_t */
40 /*** typedefs(not structures) and defined constants **********************************************/
42 #define REDRAW_LINE (1 << 0)
43 #define REDRAW_LINE_ABOVE (1 << 1)
44 #define REDRAW_LINE_BELOW (1 << 2)
45 #define REDRAW_AFTER_CURSOR (1 << 3)
46 #define REDRAW_BEFORE_CURSOR (1 << 4)
47 #define REDRAW_PAGE (1 << 5)
48 #define REDRAW_IN_BOUNDS (1 << 6)
49 #define REDRAW_CHAR_ONLY (1 << 7)
50 #define REDRAW_COMPLETELY (1 << 8)
52 #define EDIT_TEXT_HORIZONTAL_OFFSET 0
53 #define EDIT_TEXT_VERTICAL_OFFSET 0
55 #define EDIT_RIGHT_EXTREME option_edit_right_extreme
56 #define EDIT_LEFT_EXTREME option_edit_left_extreme
57 #define EDIT_TOP_EXTREME option_edit_top_extreme
58 #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
61 * The editor keeps data in two arrays of buffers.
62 * All buffers have the same size, which must be a power of 2.
65 /* Configurable: log2 of the buffer size in bytes */
66 #ifndef S_EDIT_BUF_SIZE
67 #define S_EDIT_BUF_SIZE 16
70 /* Size of the buffer */
71 #define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE)
73 /* Buffer mask (used to find cursor position relative to the buffer) */
74 #define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1)
77 * Configurable: Maximal allowed number of buffers in each buffer array.
78 * This number can be increased for systems with enough physical memory.
84 /* Maximal length of file that can be opened */
85 #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
87 /* Initial size of the undo stack, in bytes */
88 #define START_STACK_SIZE 32
90 /* Some codes that may be pushed onto or returned from the undo stack */
92 #define CURS_RIGHT 602
95 #define STACK_BOTTOM 605
96 #define CURS_LEFT_LOTS 606
97 #define CURS_RIGHT_LOTS 607
99 #define COLUMN_OFF 609
100 #define DELCHAR_BR 610
101 #define BACKSPACE_BR 611
103 #define MARK_2 500000000
104 #define MARK_CURS 1000000000
105 #define KEY_PRESS 1500000000
107 /* Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
108 #define TAB_SIZE option_tab_spacing
109 #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
111 /* max count stack files */
112 #define MAX_HISTORY_MOVETO 50
113 #define LINE_STATE_WIDTH 8
115 #define LB_NAMES (LB_MAC + 1)
117 #define get_sys_error(s) (s)
119 #define edit_error_dialog(h,s) query_dialog (h, s, D_ERROR, 1, _("&Dismiss"))
121 #define edit_query_dialog2(h,t,a,b) query_dialog (h, t, D_NORMAL, 2, a, b)
122 #define edit_query_dialog3(h,t,a,b,c) query_dialog (h, t, D_NORMAL, 3, a, b, c)
124 /*** enums ***************************************************************************************/
126 /* type for file which is currently being edited */
129 EDIT_FILE_COMMON
= 0,
130 EDIT_FILE_SYNTAX
= 1,
132 } edit_current_file_t
;
150 /*** structures declarations (and typedefs of structures)*****************************************/
152 /* search/replace options */
153 typedef struct edit_search_options_t
155 mc_search_type_t type
;
158 gboolean only_in_selection
;
159 gboolean whole_words
;
160 gboolean all_codepages
;
161 } edit_search_options_t
;
163 typedef struct edit_stack_type
172 /*** global variables defined in .c file *********************************************************/
174 extern const char VERTICAL_MAGIC
[5];
175 /* if enable_show_tabs_tws ==1 then use visible_tab visible_tws */
176 extern int enable_show_tabs_tws
;
178 extern edit_search_options_t edit_search_options
;
180 extern int edit_stack_iterator
;
181 extern edit_stack_type edit_history_moveto
[MAX_HISTORY_MOVETO
];
183 extern int option_line_state_width
;
185 extern int option_max_undo
;
186 extern int option_auto_syntax
;
188 extern int option_edit_right_extreme
;
189 extern int option_edit_left_extreme
;
190 extern int option_edit_top_extreme
;
191 extern int option_edit_bottom_extreme
;
193 extern const char *option_whole_chars_search
;
194 extern gboolean search_create_bookmark
;
196 /*** declarations of public functions ************************************************************/
198 int edit_drop_hotkey_menu (WEdit
* e
, int key
);
199 void edit_menu_cmd (WEdit
* e
);
200 void user_menu (WEdit
* edit
, const char *menu_file
, int selected_entry
);
201 void edit_init_menu (struct WMenuBar
*menubar
);
202 void menu_save_mode_cmd (void);
203 int edit_translate_key (WEdit
* edit
, long x_key
, int *cmd
, int *ch
);
204 int edit_get_byte (WEdit
* edit
, long byte_index
);
205 char *edit_get_byte_ptr (WEdit
* edit
, long byte_index
);
206 char *edit_get_buf_ptr (WEdit
* edit
, long byte_index
);
207 int edit_get_utf (WEdit
* edit
, long byte_index
, int *char_width
);
208 int edit_get_prev_utf (WEdit
* edit
, long byte_index
, int *char_width
);
209 long edit_count_lines (WEdit
* edit
, long current
, long upto
);
210 long edit_move_forward (WEdit
* edit
, long current
, long lines
, long upto
);
211 long edit_move_forward3 (WEdit
* edit
, long current
, int cols
, long upto
);
212 long edit_move_backward (WEdit
* edit
, long current
, long lines
);
213 void edit_scroll_screen_over_cursor (WEdit
* edit
);
214 void edit_render_keypress (WEdit
* edit
);
215 void edit_scroll_upward (WEdit
* edit
, unsigned long i
);
216 void edit_scroll_downward (WEdit
* edit
, int i
);
217 void edit_scroll_right (WEdit
* edit
, int i
);
218 void edit_scroll_left (WEdit
* edit
, int i
);
219 void edit_move_up (WEdit
* edit
, unsigned long i
, int scroll
);
220 void edit_move_down (WEdit
* edit
, unsigned long i
, int scroll
);
221 void edit_move_to_prev_col (WEdit
* edit
, long p
);
222 int edit_get_col (WEdit
* edit
);
223 long edit_bol (WEdit
* edit
, long current
);
224 long edit_eol (WEdit
* edit
, long current
);
225 void edit_update_curs_row (WEdit
* edit
);
226 void edit_update_curs_col (WEdit
* edit
);
227 void edit_find_bracket (WEdit
* edit
);
228 int edit_reload_line (WEdit
* edit
, const char *filename
, long line
);
229 void edit_set_codeset (WEdit
* edit
);
231 void edit_block_copy_cmd (WEdit
* edit
);
232 void edit_block_move_cmd (WEdit
* edit
);
233 int edit_block_delete_cmd (WEdit
* edit
);
234 void edit_delete_line (WEdit
* edit
);
235 void insert_spaces_tab (WEdit
* edit
, int half
);
237 int edit_delete (WEdit
* edit
, const int byte_delete
);
238 void edit_insert (WEdit
* edit
, int c
);
239 void edit_cursor_move (WEdit
* edit
, long increment
);
240 void edit_move_block_to_right (WEdit
* edit
);
241 void edit_move_block_to_left (WEdit
* edit
);
242 void edit_push_undo_action (WEdit
* edit
, long c
, ...);
243 void edit_push_redo_action (WEdit
* edit
, long c
, ...);
244 void edit_push_key_press (WEdit
* edit
);
245 void edit_insert_ahead (WEdit
* edit
, int c
);
246 long edit_write_stream (WEdit
* edit
, FILE * f
);
247 char *edit_get_write_filter (const char *writename
, const char *filename
);
248 int edit_save_confirm_cmd (WEdit
* edit
);
249 int edit_save_as_cmd (WEdit
* edit
);
250 WEdit
*edit_init (WEdit
* edit
, int y
, int x
, int lines
, int cols
, const char *filename
, long line
);
251 int edit_clean (WEdit
* edit
);
252 gboolean
edit_ok_to_exit (WEdit
* edit
);
253 int edit_renew (WEdit
* edit
);
254 int edit_new_cmd (WEdit
* edit
);
255 int edit_reload (WEdit
* edit
, const char *filename
);
256 int edit_load_cmd (WEdit
* edit
, edit_current_file_t what
);
257 void edit_mark_cmd (WEdit
* edit
, int unmark
);
258 void edit_mark_current_word_cmd (WEdit
* edit
);
259 void edit_mark_current_line_cmd (WEdit
* edit
);
260 void edit_set_markers (WEdit
* edit
, long m1
, long m2
, int c1
, int c2
);
261 void edit_push_markers (WEdit
* edit
);
262 void edit_replace_cmd (WEdit
* edit
, int again
);
263 void edit_search_cmd (WEdit
* edit
, gboolean again
);
264 int edit_search_cmd_callback (const void *user_data
, gsize char_offset
);
265 void edit_complete_word_cmd (WEdit
* edit
);
266 void edit_get_match_keyword_cmd (WEdit
* edit
);
267 int edit_save_block (WEdit
* edit
, const char *filename
, long start
, long finish
);
268 int edit_save_block_cmd (WEdit
* edit
);
269 int edit_insert_file_cmd (WEdit
* edit
);
270 void edit_insert_over (WEdit
* edit
);
271 void edit_insert_column_of_text (WEdit
* edit
, unsigned char *data
, int size
, int width
,
272 long *start_pos
, long *end_pos
, int *col1
, int *col2
);
273 int edit_insert_column_of_text_from_file (WEdit
* edit
, int file
,
274 long *start_pos
, long *end_pos
, int *col1
, int *col2
);
275 long edit_insert_file (WEdit
* edit
, const char *filename
);
276 int edit_load_back_cmd (WEdit
* edit
);
277 int edit_load_forward_cmd (WEdit
* edit
);
278 void edit_block_process_cmd (WEdit
* edit
, int macro_number
);
279 void edit_refresh_cmd (WEdit
* edit
);
280 void edit_date_cmd (WEdit
* edit
);
281 void edit_goto_cmd (WEdit
* edit
);
282 int eval_marks (WEdit
* edit
, long *start_mark
, long *end_mark
);
283 void edit_status (WEdit
* edit
);
284 void edit_execute_key_command (WEdit
* edit
, unsigned long command
, int char_for_insertion
);
285 void edit_update_screen (WEdit
* edit
);
286 int edit_print_string (WEdit
* e
, const char *s
);
287 void edit_move_to_line (WEdit
* e
, long line
);
288 void edit_move_display (WEdit
* e
, long line
);
289 void edit_word_wrap (WEdit
* edit
);
290 int edit_sort_cmd (WEdit
* edit
);
291 int edit_ext_cmd (WEdit
* edit
);
292 void edit_help_cmd (WEdit
* edit
);
294 int edit_store_macro_cmd (WEdit
* edit
);
295 gboolean
edit_load_macro_cmd (WEdit
* edit
);
296 void edit_delete_macro_cmd (WEdit
* edit
);
297 gboolean
edit_repeat_macro_cmd (WEdit
* edit
);
299 int edit_copy_to_X_buf_cmd (WEdit
* edit
);
300 int edit_cut_to_X_buf_cmd (WEdit
* edit
);
301 void edit_paste_from_X_buf_cmd (WEdit
* edit
);
303 void edit_select_codepage_cmd (WEdit
* edit
);
304 void edit_insert_literal_cmd (WEdit
* edit
);
305 gboolean
edit_execute_macro (WEdit
* edit
, int hotkey
);
306 void edit_begin_end_macro_cmd (WEdit
* edit
);
307 void edit_begin_end_repeat_cmd (WEdit
* edit
);
309 void edit_paste_from_history (WEdit
* edit
);
311 void edit_set_filename (WEdit
* edit
, const char *name
);
313 void edit_load_syntax (WEdit
* edit
, char ***pnames
, const char *type
);
314 void edit_free_syntax_rules (WEdit
* edit
);
315 void edit_get_syntax_color (WEdit
* edit
, long byte_index
, int *color
);
317 void book_mark_insert (WEdit
* edit
, size_t line
, int c
);
318 int book_mark_query_color (WEdit
* edit
, int line
, int c
);
319 int book_mark_query_all (WEdit
* edit
, int line
, int *c
);
320 struct _book_mark
*book_mark_find (WEdit
* edit
, int line
);
321 int book_mark_clear (WEdit
* edit
, int line
, int c
);
322 void book_mark_flush (WEdit
* edit
, int c
);
323 void book_mark_inc (WEdit
* edit
, int line
);
324 void book_mark_dec (WEdit
* edit
, int line
);
325 void book_mark_serialize (WEdit
* edit
, int color
);
326 void book_mark_restore (WEdit
* edit
, int color
);
328 int line_is_blank (WEdit
* edit
, long line
);
329 int edit_indent_width (WEdit
* edit
, long p
);
330 void edit_insert_indent (WEdit
* edit
, int indent
);
331 void edit_options_dialog (WEdit
* edit
);
332 void edit_syntax_dialog (WEdit
* edit
);
333 void edit_mail_dialog (WEdit
* edit
);
334 void format_paragraph (WEdit
* edit
, int force
);
336 unsigned int edit_unlock_file (WEdit
* edit
);
337 unsigned int edit_lock_file (WEdit
* edit
);
339 /* either command or char_for_insertion must be passed as -1 */
340 void edit_execute_cmd (WEdit
* edit
, unsigned long command
, int char_for_insertion
);
342 /*** inline functions ****************************************************************************/
344 #endif /* MC__EDIT_IMPL_H */