1 /* edit.h - main include file
3 Copyright (C) 1996, 1997 the Free Software Foundation
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., 59 Temple Place, Suite 330, Boston, MA
27 # define HAVE_SYNTAXH 1
32 #include <sys/types.h>
45 #if !defined(STDC_HEADERS) && defined(HAVE_MALLOC_H)
49 #if defined(HAVE_RX_H) && defined(HAVE_REGCOMP)
55 #include "src/global.h"
57 #include "src/main.h" /* for char *shell */
60 #include "src/widget.h"
61 #include "src/color.h"
62 #include "src/dialog.h"
63 #include "src/mouse.h"
66 #include "src/wtools.h" /* for QuickWidgets */
67 #include "src/cmd.h" /* for menu_edit_cmd */
71 #include "edit-widget.h"
72 #include "src/user.h" /* for user_menu_cmd, must be after edit-widget.h */
76 # define WIDGET_COMMAND (WIDGET_USER + 10)
79 #define SEARCH_DIALOG_OPTION_NO_SCANF 1
80 #define SEARCH_DIALOG_OPTION_NO_REGEX 2
81 #define SEARCH_DIALOG_OPTION_NO_CASE 4
82 #define SEARCH_DIALOG_OPTION_BACKWARDS 8
83 #define SEARCH_DIALOG_OPTION_BOOKMARK 16
85 #define EDIT_KEY_EMULATION_NORMAL 0
86 #define EDIT_KEY_EMULATION_EMACS 1
88 #define REDRAW_LINE (1 << 0)
89 #define REDRAW_LINE_ABOVE (1 << 1)
90 #define REDRAW_LINE_BELOW (1 << 2)
91 #define REDRAW_AFTER_CURSOR (1 << 3)
92 #define REDRAW_BEFORE_CURSOR (1 << 4)
93 #define REDRAW_PAGE (1 << 5)
94 #define REDRAW_IN_BOUNDS (1 << 6)
95 #define REDRAW_CHAR_ONLY (1 << 7)
96 #define REDRAW_COMPLETELY (1 << 8)
98 #define MOD_ABNORMAL (1 << 0)
99 #define MOD_UNDERLINED (1 << 1)
100 #define MOD_BOLD (1 << 2)
101 #define MOD_HIGHLIGHTED (1 << 3)
102 #define MOD_MARKED (1 << 4)
103 #define MOD_ITALIC (1 << 5)
104 #define MOD_CURSOR (1 << 6)
105 #define MOD_INVERSE (1 << 7)
107 #define EDIT_TEXT_HORIZONTAL_OFFSET 0
108 #define EDIT_TEXT_VERTICAL_OFFSET 1
109 #define FONT_OFFSET_X 0
110 #define FONT_OFFSET_Y 0
112 #define EDIT_RIGHT_EXTREME option_edit_right_extreme
113 #define EDIT_LEFT_EXTREME option_edit_left_extreme
114 #define EDIT_TOP_EXTREME option_edit_top_extreme
115 #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
117 /*there are a maximum of ... */
118 /*... edit buffers, each of which is ... */
119 #define EDIT_BUF_SIZE 0x10000
120 /* ...bytes in size. */
122 /*x / EDIT_BUF_SIZE equals x >> ... */
123 #define S_EDIT_BUF_SIZE 16
125 /* x % EDIT_BUF_SIZE is equal to x && ... */
126 #define M_EDIT_BUF_SIZE 0xFFFF
128 #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
129 /* Note a 16k stack is 64k of data and enough to hold (usually) around 10
130 pages of undo info. */
133 #define START_STACK_SIZE 32
136 /*some codes that may be pushed onto or returned from the undo stack: */
137 #define CURS_LEFT 601
138 #define CURS_RIGHT 602
140 #define BACKSPACE 604
141 #define STACK_BOTTOM 605
142 #define CURS_LEFT_LOTS 606
143 #define CURS_RIGHT_LOTS 607
144 #define COLUMN_ON 608
145 #define COLUMN_OFF 609
147 #define MARK_2 700000000
148 #define KEY_PRESS 1400000000
150 /*Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
151 #define TAB_SIZE option_tab_spacing
152 #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
155 unsigned char * text
;
159 #define MAX_WORDS_PER_CONTEXT 1024
160 #define MAX_CONTEXTS 128
165 char *whole_word_chars_left
;
166 char *whole_word_chars_right
;
168 #define NO_COLOR 0x7FFFFFFF
169 #define SPELLING_ERROR 0x7EFEFEFE
175 struct context_rule
{
177 unsigned char first_left
;
179 unsigned char first_right
;
180 char line_start_left
;
181 char line_start_right
;
183 int between_delimiters
;
184 char *whole_word_chars_left
;
185 char *whole_word_chars_right
;
186 char *keyword_first_chars
;
188 /* first word is word[1] */
189 struct key_word
**keyword
;
192 int edit_drop_hotkey_menu (WEdit
* e
, int key
);
193 void edit_menu_cmd (WEdit
* e
);
194 void edit_init_menu_emacs (void);
195 void edit_init_menu_normal (void);
196 void edit_done_menu (void);
197 int edit_raw_key_query (char *heading
, char *query
, int cancel
);
198 char *strcasechr (const unsigned char *s
, int c
);
199 int edit (const char *_file
, int line
);
200 int edit_translate_key (WEdit
* edit
, unsigned int x_keycode
, long x_key
, int x_state
, int *cmd
, int *ch
);
202 #ifndef NO_INLINE_GETBYTE
203 int edit_get_byte (WEdit
* edit
, long byte_index
);
205 static inline int edit_get_byte (WEdit
* edit
, long byte_index
)
208 if (byte_index
>= (edit
->curs1
+ edit
->curs2
) || byte_index
< 0)
211 if (byte_index
>= edit
->curs1
) {
212 p
= edit
->curs1
+ edit
->curs2
- byte_index
- 1;
213 return edit
->buffers2
[p
>> S_EDIT_BUF_SIZE
][EDIT_BUF_SIZE
- (p
& M_EDIT_BUF_SIZE
) - 1];
215 return edit
->buffers1
[byte_index
>> S_EDIT_BUF_SIZE
][byte_index
& M_EDIT_BUF_SIZE
];
220 char *edit_get_buffer_as_text (WEdit
* edit
);
221 int edit_count_lines (WEdit
* edit
, long current
, int upto
);
222 long edit_move_forward (WEdit
* edit
, long current
, int lines
, long upto
);
223 long edit_move_forward3 (WEdit
* edit
, long current
, int cols
, long upto
);
224 long edit_move_backward (WEdit
* edit
, long current
, int lines
);
225 void edit_scroll_screen_over_cursor (WEdit
* edit
);
226 void edit_render_keypress (WEdit
* edit
);
227 void edit_scroll_upward (WEdit
* edit
, unsigned long i
);
228 void edit_scroll_downward (WEdit
* edit
, int i
);
229 void edit_scroll_right (WEdit
* edit
, int i
);
230 void edit_scroll_left (WEdit
* edit
, int i
);
231 int edit_get_col (WEdit
* edit
);
232 long edit_bol (WEdit
* edit
, long current
);
233 long edit_eol (WEdit
* edit
, long current
);
234 void edit_update_curs_row (WEdit
* edit
);
235 void edit_update_curs_col (WEdit
* edit
);
237 void edit_block_copy_cmd (WEdit
* edit
);
238 void edit_block_move_cmd (WEdit
* edit
);
239 int edit_block_delete_cmd (WEdit
* edit
);
240 int edit_block_delete (WEdit
* edit
);
241 void edit_delete_line (WEdit
* edit
);
243 int edit_delete (WEdit
* edit
);
244 void edit_insert (WEdit
* edit
, int c
);
245 int edit_cursor_move (WEdit
* edit
, long increment
);
246 void edit_push_action (WEdit
* edit
, long c
, ...);
247 void edit_push_key_press (WEdit
* edit
);
248 void edit_insert_ahead (WEdit
* edit
, int c
);
249 int edit_save_file (WEdit
* edit
, const char *filename
);
250 long edit_write_stream (WEdit
* edit
, FILE * f
);
251 char *edit_get_write_filter (char *writename
, const char *filename
);
252 int edit_save_cmd (WEdit
* edit
);
253 int edit_save_confirm_cmd (WEdit
* edit
);
254 int edit_save_as_cmd (WEdit
* edit
);
255 WEdit
*edit_init (WEdit
* edit
, int lines
, int columns
, const char *filename
, const char *text
, const char *dir
, unsigned long text_size
);
256 int edit_clean (WEdit
* edit
);
257 int edit_renew (WEdit
* edit
);
258 int edit_new_cmd (WEdit
* edit
);
259 int edit_reload (WEdit
* edit
, const char *filename
, const char *text
, const char *dir
, unsigned long text_size
);
260 int edit_load_cmd (WEdit
* edit
);
261 void edit_mark_cmd (WEdit
* edit
, int unmark
);
262 void edit_set_markers (WEdit
* edit
, long m1
, long m2
, int c1
, int c2
);
263 void edit_push_markers (WEdit
* edit
);
264 void edit_quit_cmd (WEdit
* edit
);
265 void edit_replace_cmd (WEdit
* edit
, int again
);
266 void edit_search_cmd (WEdit
* edit
, int again
);
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 int edit_insert_file (WEdit
* edit
, const char *filename
);
271 void edit_block_process_cmd (WEdit
* edit
, const char *shell_cmd
, int block
);
272 char *catstrs (const char *first
, ...);
273 void edit_refresh_cmd (WEdit
* edit
);
274 void edit_date_cmd (WEdit
* edit
);
275 void edit_goto_cmd (WEdit
* edit
);
276 int eval_marks (WEdit
* edit
, long *start_mark
, long *end_mark
);
277 void edit_status (WEdit
* edit
);
278 int edit_execute_command (WEdit
* edit
, int command
, int char_for_insertion
);
279 int edit_execute_key_command (WEdit
* edit
, int command
, int char_for_insertion
);
280 void edit_update_screen (WEdit
* edit
);
281 int edit_printf (WEdit
* e
, const char *fmt
, ...)
282 __attribute__ ((format (printf
, 2, 3)));
283 int edit_print_string (WEdit
* e
, const char *s
);
284 void edit_move_to_line (WEdit
* e
, long line
);
285 void edit_move_display (WEdit
* e
, long line
);
286 void edit_word_wrap (WEdit
* edit
);
287 unsigned char *edit_get_block (WEdit
* edit
, long start
, long finish
, int *l
);
288 int edit_sort_cmd (WEdit
* edit
);
289 void edit_help_cmd (WEdit
* edit
);
290 void edit_left_word_move (WEdit
* edit
, int s
);
291 void edit_right_word_move (WEdit
* edit
, int s
);
292 void edit_get_selection (WEdit
* edit
);
294 int edit_save_macro_cmd (WEdit
* edit
, struct macro macro
[], int n
);
295 int edit_load_macro_cmd (WEdit
* edit
, struct macro macro
[], int *n
, int k
);
296 void edit_delete_macro_cmd (WEdit
* edit
);
298 int edit_copy_to_X_buf_cmd (WEdit
* edit
);
299 int edit_cut_to_X_buf_cmd (WEdit
* edit
);
300 void edit_paste_from_X_buf_cmd (WEdit
* edit
);
302 void edit_paste_from_history (WEdit
*edit
);
304 void edit_split_filename (WEdit
* edit
, const char *name
);
306 #define CWidget Widget
307 void edit_set_syntax_change_callback (void (*callback
) (CWidget
*));
308 void edit_load_syntax (WEdit
* edit
, char **names
, char *type
);
309 void edit_free_syntax_rules (WEdit
* edit
);
310 void edit_get_syntax_color (WEdit
* edit
, long byte_index
, int *fg
, int *bg
);
311 int edit_check_spelling (WEdit
* edit
);
314 void book_mark_insert (WEdit
* edit
, int line
, int c
);
315 int book_mark_query_color (WEdit
* edit
, int line
, int c
);
316 int book_mark_query_all (WEdit
* edit
, int line
, int *c
);
317 struct _book_mark
*book_mark_find (WEdit
* edit
, int line
);
318 int book_mark_clear (WEdit
* edit
, int line
, int c
);
319 void book_mark_flush (WEdit
* edit
, int c
);
320 void book_mark_inc (WEdit
* edit
, int line
);
321 void book_mark_dec (WEdit
* edit
, int line
);
323 void user_menu (WEdit
*edit
);
325 /* either command or char_for_insertion must be passed as -1 */
326 int edit_execute_cmd (WEdit
* edit
, int command
, int char_for_insertion
);
328 #define CPushFont(x,y)
332 /* put OS2/NT/WIN95 defines here */
335 # define MY_O_TEXT O_TEXT
340 #define FONT_PIX_PER_LINE 1
341 #define FONT_MEAN_WIDTH 1
343 #define get_sys_error(s) (s)
345 #define close(f) mc_close(f)
346 #define read(f,b,c) mc_read(f,b,c)
347 #define write(f,b,c) mc_write(f,b,c)
348 #define mkdir(s,m) mc_mkdir(s,m)
351 #define edit_get_load_file(d,f,h) input_dialog (h, " Enter file name: ", f)
352 #define edit_get_save_file(d,f,h) input_dialog (h, " Enter file name: ", f)
353 #define CMalloc(x) malloc(x)
355 #define edit_error_dialog(h,s) query_dialog (h, s, 0, 1, _("&Dismiss"))
357 #define edit_message_dialog(h,s) query_dialog (h, s, 0, 1, _("&Ok"))
358 #define edit_query_dialog2(h,t,a,b) query_dialog(h,t,0,2,a,b)
359 #define edit_query_dialog3(h,t,a,b,c) query_dialog(h,t,0,3,a,b,c)
360 #define edit_query_dialog4(h,t,a,b,c,d) query_dialog(h,t,0,4,a,b,c,d)
362 #define color_palette(x) win->color[x].pixel
364 extern char *home_dir
;
366 #define NUM_SELECTION_HISTORY 64
370 #define MAX_PATH_LEN PATH_MAX
372 #define MAX_PATH_LEN 1024
377 what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
378 or EDIT_KEY_EMULATION_EMACS
380 extern int edit_key_emulation
;
383 extern int option_word_wrap_line_length
;
384 extern int option_typewriter_wrap
;
385 extern int option_auto_para_formatting
;
386 extern int option_tab_spacing
;
387 extern int option_fill_tabs_with_spaces
;
388 extern int option_return_does_auto_indent
;
389 extern int option_backspace_through_tabs
;
390 extern int option_fake_half_tabs
;
391 extern int option_save_mode
;
392 extern int option_backup_ext_int
;
393 extern int option_max_undo
;
395 extern int option_edit_right_extreme
;
396 extern int option_edit_left_extreme
;
397 extern int option_edit_top_extreme
;
398 extern int option_edit_bottom_extreme
;
400 extern char *option_whole_chars_search
;
401 extern char *option_backup_ext
;
403 extern int edit_confirm_save
;
405 #endif /* __EDIT_H */