Merge branch '402_select_codepage'
[midnight-commander.git] / edit / edit.h
blobac984455513b70dd7c31356af2f1ebc0a8244dd4
1 /* edit.h - main include file
3 Copyright (C) 1996, 1997 Free Software Foundation, Inc.
5 Authors: 1996, 1997 Paul Sheer
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA.
23 /** \file
24 * \brief Source: editor low level data handling and cursor fundamentals
25 * edit.h - main include file
26 * \author Paul Sheer
27 * \date 1996, 1997
30 #ifndef MC_EDIT_H
31 #define MC_EDIT_H
33 #include <stdio.h>
35 #define SEARCH_DIALOG_OPTION_NO_SCANF (1 << 0)
36 #define SEARCH_DIALOG_OPTION_NO_REGEX (1 << 1)
37 #define SEARCH_DIALOG_OPTION_NO_CASE (1 << 2)
38 #define SEARCH_DIALOG_OPTION_BACKWARDS (1 << 3)
39 #define SEARCH_DIALOG_OPTION_BOOKMARK (1 << 4)
41 #define EDIT_KEY_EMULATION_NORMAL 0
42 #define EDIT_KEY_EMULATION_EMACS 1
43 #define EDIT_KEY_EMULATION_USER 2
45 #define REDRAW_LINE (1 << 0)
46 #define REDRAW_LINE_ABOVE (1 << 1)
47 #define REDRAW_LINE_BELOW (1 << 2)
48 #define REDRAW_AFTER_CURSOR (1 << 3)
49 #define REDRAW_BEFORE_CURSOR (1 << 4)
50 #define REDRAW_PAGE (1 << 5)
51 #define REDRAW_IN_BOUNDS (1 << 6)
52 #define REDRAW_CHAR_ONLY (1 << 7)
53 #define REDRAW_COMPLETELY (1 << 8)
55 #define EDIT_TEXT_HORIZONTAL_OFFSET 0
56 #define EDIT_TEXT_VERTICAL_OFFSET 1
58 #define EDIT_RIGHT_EXTREME option_edit_right_extreme
59 #define EDIT_LEFT_EXTREME option_edit_left_extreme
60 #define EDIT_TOP_EXTREME option_edit_top_extreme
61 #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
64 * The editor keeps data in two arrays of buffers.
65 * All buffers have the same size, which must be a power of 2.
68 /* Configurable: log2 of the buffer size in bytes */
69 #ifndef S_EDIT_BUF_SIZE
70 #define S_EDIT_BUF_SIZE 16
71 #endif
73 /* Size of the buffer */
74 #define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE)
76 /* Buffer mask (used to find cursor position relative to the buffer) */
77 #define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1)
80 * Configurable: Maximal allowed number of buffers in each buffer array.
81 * This number can be increased for systems with enough physical memory.
83 #ifndef MAXBUFF
84 #define MAXBUFF 1024
85 #endif
87 /* Maximal length of file that can be opened */
88 #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
90 /* Initial size of the undo stack, in bytes */
91 #define START_STACK_SIZE 32
93 /* Some codes that may be pushed onto or returned from the undo stack */
94 #define CURS_LEFT 601
95 #define CURS_RIGHT 602
96 #define DELCHAR 603
97 #define BACKSPACE 604
98 #define STACK_BOTTOM 605
99 #define CURS_LEFT_LOTS 606
100 #define CURS_RIGHT_LOTS 607
101 #define COLUMN_ON 608
102 #define COLUMN_OFF 609
103 #define MARK_1 1000
104 #define MARK_2 700000000
105 #define KEY_PRESS 1400000000
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 typedef struct edit_stack_type {
116 long line;
117 char *filename;
118 }edit_stack_type;
120 struct macro {
121 short command;
122 short ch;
125 struct WEdit;
126 typedef struct WEdit WEdit;
127 struct Menu;
129 /* type for file which is currently being edited */
130 typedef enum {
131 EDIT_FILE_COMMON = 0,
132 EDIT_FILE_SYNTAX = 1,
133 EDIT_FILE_MENU = 2
134 } edit_current_file_t;
136 int edit_drop_hotkey_menu (WEdit *e, int key);
137 void edit_menu_cmd (WEdit *e);
138 struct WMenu *edit_create_menu (void);
139 void edit_done_menu (struct WMenu *wmenu);
140 void edit_reload_menu (void);
141 void menu_save_mode_cmd (void);
142 int edit_file (const char *_file, int line);
143 int edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch);
144 int edit_get_byte (WEdit * edit, long byte_index);
145 char *edit_get_byte_ptr (WEdit * edit, long byte_index);
146 char *edit_get_buf_ptr (WEdit * edit, long byte_index);
147 int edit_get_utf (WEdit * edit, long byte_index, int *char_width);
148 int edit_get_prev_utf (WEdit * edit, long byte_index, int *char_width);
149 int edit_count_lines (WEdit * edit, long current, int upto);
150 long edit_move_forward (WEdit * edit, long current, int lines, long upto);
151 long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
152 long edit_move_backward (WEdit * edit, long current, int lines);
153 void edit_scroll_screen_over_cursor (WEdit * edit);
154 void edit_render_keypress (WEdit * edit);
155 void edit_scroll_upward (WEdit * edit, unsigned long i);
156 void edit_scroll_downward (WEdit * edit, int i);
157 void edit_scroll_right (WEdit * edit, int i);
158 void edit_scroll_left (WEdit * edit, int i);
159 void edit_move_up (WEdit * edit, unsigned long i, int scroll);
160 void edit_move_down (WEdit * edit, int i, int scroll);
161 void edit_move_to_prev_col (WEdit *edit, long p);
162 int edit_get_col (WEdit * edit);
163 long edit_bol (WEdit * edit, long current);
164 long edit_eol (WEdit * edit, long current);
165 void edit_update_curs_row (WEdit * edit);
166 void edit_update_curs_col (WEdit * edit);
167 void edit_find_bracket (WEdit * edit);
168 int edit_reload_line (WEdit *edit, const char *filename, long line);
170 void edit_block_copy_cmd (WEdit * edit);
171 void edit_block_move_cmd (WEdit * edit);
172 int edit_block_delete_cmd (WEdit * edit);
173 void edit_delete_line (WEdit * edit);
174 void insert_spaces_tab (WEdit * edit, int half);
176 int edit_delete (WEdit * edit, const int byte_delete);
177 void edit_insert (WEdit * edit, int c);
178 void edit_cursor_move (WEdit * edit, long increment);
179 void edit_move_block_to_right (WEdit * edit);
180 void edit_move_block_to_left (WEdit * edit);
181 void edit_push_action (WEdit * edit, long c, ...);
182 void edit_push_key_press (WEdit * edit);
183 void edit_insert_ahead (WEdit * edit, int c);
184 long edit_write_stream (WEdit * edit, FILE * f);
185 char *edit_get_write_filter (const char *writename, const char *filename);
186 int edit_save_confirm_cmd (WEdit * edit);
187 int edit_save_as_cmd (WEdit * edit);
188 WEdit *edit_init (WEdit *edit, int lines, int columns,
189 const char *filename, long line);
190 int edit_clean (WEdit * edit);
191 int edit_ok_to_exit (WEdit *edit);
192 int edit_renew (WEdit * edit);
193 int edit_new_cmd (WEdit * edit);
194 int edit_reload (WEdit *edit, const char *filename);
195 int edit_load_cmd (WEdit * edit, edit_current_file_t what);
196 void edit_mark_cmd (WEdit * edit, int unmark);
197 void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
198 void edit_push_markers (WEdit * edit);
199 void edit_replace_cmd (WEdit * edit, int again);
200 void edit_search_cmd (WEdit * edit, int again);
201 void edit_complete_word_cmd (WEdit * edit);
202 void edit_get_match_keyword_cmd (WEdit *edit);
203 int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
204 int edit_save_block_cmd (WEdit * edit);
205 int edit_insert_file_cmd (WEdit * edit);
206 int edit_insert_file (WEdit * edit, const char *filename);
207 int edit_load_back_cmd (WEdit * edit);
208 int edit_load_forward_cmd (WEdit * edit);
209 void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block);
210 void edit_refresh_cmd (WEdit * edit);
211 void edit_date_cmd (WEdit * edit);
212 void edit_goto_cmd (WEdit * edit);
213 int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
214 void edit_status (WEdit * edit);
215 void edit_execute_key_command (WEdit *edit, int command,
216 int char_for_insertion);
217 void edit_update_screen (WEdit * edit);
218 int edit_print_string (WEdit * e, const char *s);
219 void edit_move_to_line (WEdit * e, long line);
220 void edit_move_display (WEdit * e, long line);
221 void edit_word_wrap (WEdit * edit);
222 int edit_sort_cmd (WEdit * edit);
223 int edit_ext_cmd (WEdit * edit);
224 void edit_help_cmd (WEdit * edit);
226 int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n);
227 int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k);
228 void edit_delete_macro_cmd (WEdit * edit);
230 int edit_copy_to_X_buf_cmd (WEdit * edit);
231 int edit_cut_to_X_buf_cmd (WEdit * edit);
232 void edit_paste_from_X_buf_cmd (WEdit * edit);
234 void edit_select_codepage_cmd (WEdit *edit);
235 void edit_insert_literal_cmd (WEdit *edit);
236 void edit_execute_macro_cmd (WEdit *edit);
237 void edit_begin_end_macro_cmd(WEdit *edit);
239 void edit_paste_from_history (WEdit *edit);
241 void edit_set_filename (WEdit *edit, const char *name);
243 void edit_load_syntax (WEdit * edit, char ***pnames, const char *type);
244 void edit_free_syntax_rules (WEdit * edit);
245 void edit_get_syntax_color (WEdit * edit, long byte_index, int *color);
248 void book_mark_insert (WEdit * edit, int line, int c);
249 int book_mark_query_color (WEdit * edit, int line, int c);
250 int book_mark_query_all (WEdit * edit, int line, int *c);
251 struct _book_mark *book_mark_find (WEdit * edit, int line);
252 int book_mark_clear (WEdit * edit, int line, int c);
253 void book_mark_flush (WEdit * edit, int c);
254 void book_mark_inc (WEdit * edit, int line);
255 void book_mark_dec (WEdit * edit, int line);
257 int line_is_blank (WEdit *edit, long line);
258 int edit_indent_width (WEdit *edit, long p);
259 void edit_insert_indent (WEdit *edit, int indent);
260 void edit_options_dialog (void);
261 void edit_syntax_dialog (void);
262 void edit_mail_dialog (WEdit *edit);
263 void format_paragraph (WEdit *edit, int force);
265 /* either command or char_for_insertion must be passed as -1 */
266 void edit_execute_cmd (WEdit *edit, int command, int char_for_insertion);
268 #define get_sys_error(s) (s)
270 #define edit_error_dialog(h,s) query_dialog (h, s, D_ERROR, 1, _("&Dismiss"))
272 #define edit_query_dialog2(h,t,a,b) query_dialog (h, t, D_NORMAL, 2, a, b)
273 #define edit_query_dialog3(h,t,a,b,c) query_dialog (h, t, D_NORMAL, 3, a, b, c)
275 #define color_palette(x) win->color[x].pixel
277 #define NUM_SELECTION_HISTORY 64
279 #ifndef MAX_PATH_LEN
280 #ifdef PATH_MAX
281 #define MAX_PATH_LEN PATH_MAX
282 #else
283 #define MAX_PATH_LEN 1024
284 #endif
285 #endif
288 what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
289 or EDIT_KEY_EMULATION_EMACS
291 extern int edit_key_emulation;
293 extern WEdit *wedit;
294 struct WMenu;
295 extern struct WMenu *edit_menubar;
297 extern int option_word_wrap_line_length;
298 extern int option_typewriter_wrap;
299 extern int option_auto_para_formatting;
300 extern int option_tab_spacing;
301 extern int option_fill_tabs_with_spaces;
302 extern int option_return_does_auto_indent;
303 extern int option_backspace_through_tabs;
304 extern int option_fake_half_tabs;
305 extern int option_persistent_selections;
306 extern int option_line_state;
307 extern int option_line_state_width;
309 typedef enum {
310 EDIT_QUICK_SAVE = 0,
311 EDIT_SAFE_SAVE,
312 EDIT_DO_BACKUP
313 } edit_save_mode_t;
315 extern int option_save_mode;
316 extern int option_save_position;
317 extern int option_max_undo;
318 extern int option_syntax_highlighting;
319 extern int option_auto_syntax;
320 extern char *option_syntax_type;
321 extern int editor_option_check_nl_at_eof;
323 extern int option_edit_right_extreme;
324 extern int option_edit_left_extreme;
325 extern int option_edit_top_extreme;
326 extern int option_edit_bottom_extreme;
328 extern const char *option_whole_chars_search;
329 extern char *option_backup_ext;
331 extern int edit_confirm_save;
332 extern int column_highlighting;
334 extern int visible_tabs;
335 extern int visible_tws;
337 extern int simple_statusbar;
339 /* File names */
340 #define EDIT_DIR ".mc" PATH_SEP_STR "cedit"
341 #define SYNTAX_FILE EDIT_DIR PATH_SEP_STR "Syntax"
342 #define CLIP_FILE EDIT_DIR PATH_SEP_STR "cooledit.clip"
343 #define MACRO_FILE EDIT_DIR PATH_SEP_STR "cooledit.macros"
344 #define BLOCK_FILE EDIT_DIR PATH_SEP_STR "cooledit.block"
345 #define TEMP_FILE EDIT_DIR PATH_SEP_STR "cooledit.temp"
347 #define CEDIT_GLOBAL_MENU "cedit.menu"
348 #define CEDIT_LOCAL_MENU ".cedit.menu"
349 #define CEDIT_HOME_MENU ".mc" PATH_SEP_STR "cedit" PATH_SEP_STR "menu"
352 #endif