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
26 #define HAVE_SYNTAXH 1
30 #include <sys/types.h>
43 #if !defined(STDC_HEADERS) && defined(HAVE_MALLOC_H)
47 #if defined(HAVE_RX_H) && defined(HAVE_REGCOMP)
50 # include "src/eregex.h"
53 #include "src/global.h"
55 #include "src/main.h" /* for char *shell */
57 #include "src/widget.h"
58 #include "src/color.h"
59 #include "src/dialog.h"
60 #include "src/mouse.h"
63 #include "src/wtools.h" /* for QuickWidgets */
64 #include "src/cmd.h" /* for menu_edit_cmd */
68 #include "edit-widget.h"
69 #include "src/user.h" /* for user_menu_cmd, must be after edit-widget.h */
73 # define WIDGET_COMMAND (WIDGET_USER + 10)
76 #define SEARCH_DIALOG_OPTION_NO_SCANF 1
77 #define SEARCH_DIALOG_OPTION_NO_REGEX 2
78 #define SEARCH_DIALOG_OPTION_NO_CASE 4
79 #define SEARCH_DIALOG_OPTION_BACKWARDS 8
80 #define SEARCH_DIALOG_OPTION_BOOKMARK 16
82 #define EDIT_KEY_EMULATION_NORMAL 0
83 #define EDIT_KEY_EMULATION_EMACS 1
85 #define REDRAW_LINE (1 << 0)
86 #define REDRAW_LINE_ABOVE (1 << 1)
87 #define REDRAW_LINE_BELOW (1 << 2)
88 #define REDRAW_AFTER_CURSOR (1 << 3)
89 #define REDRAW_BEFORE_CURSOR (1 << 4)
90 #define REDRAW_PAGE (1 << 5)
91 #define REDRAW_IN_BOUNDS (1 << 6)
92 #define REDRAW_CHAR_ONLY (1 << 7)
93 #define REDRAW_COMPLETELY (1 << 8)
95 #define MOD_ABNORMAL (1 << 0)
96 #define MOD_UNDERLINED (1 << 1)
97 #define MOD_BOLD (1 << 2)
98 #define MOD_HIGHLIGHTED (1 << 3)
99 #define MOD_MARKED (1 << 4)
100 #define MOD_ITALIC (1 << 5)
101 #define MOD_CURSOR (1 << 6)
102 #define MOD_INVERSE (1 << 7)
104 #define EDIT_TEXT_HORIZONTAL_OFFSET 0
105 #define EDIT_TEXT_VERTICAL_OFFSET 1
106 #define FONT_OFFSET_X 0
107 #define FONT_OFFSET_Y 0
109 #define EDIT_RIGHT_EXTREME option_edit_right_extreme
110 #define EDIT_LEFT_EXTREME option_edit_left_extreme
111 #define EDIT_TOP_EXTREME option_edit_top_extreme
112 #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
114 /*there are a maximum of ... */
115 /*... edit buffers, each of which is ... */
116 #define EDIT_BUF_SIZE 0x10000
117 /* ...bytes in size. */
119 /*x / EDIT_BUF_SIZE equals x >> ... */
120 #define S_EDIT_BUF_SIZE 16
122 /* x % EDIT_BUF_SIZE is equal to x && ... */
123 #define M_EDIT_BUF_SIZE 0xFFFF
125 #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
126 /* Note a 16k stack is 64k of data and enough to hold (usually) around 10
127 pages of undo info. */
130 #define START_STACK_SIZE 32
133 /*some codes that may be pushed onto or returned from the undo stack: */
134 #define CURS_LEFT 601
135 #define CURS_RIGHT 602
137 #define BACKSPACE 604
138 #define STACK_BOTTOM 605
139 #define CURS_LEFT_LOTS 606
140 #define CURS_RIGHT_LOTS 607
141 #define COLUMN_ON 608
142 #define COLUMN_OFF 609
144 #define MARK_2 700000000
145 #define KEY_PRESS 1400000000
147 /*Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
148 #define TAB_SIZE option_tab_spacing
149 #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
152 unsigned char * text
;
156 #define MAX_WORDS_PER_CONTEXT 1024
157 #define MAX_CONTEXTS 128
162 char *whole_word_chars_left
;
163 char *whole_word_chars_right
;
165 #define NO_COLOR 0x7FFFFFFF
166 #define SPELLING_ERROR 0x7EFEFEFE
171 struct context_rule
{
173 unsigned char first_left
;
175 unsigned char first_right
;
176 char line_start_left
;
177 char line_start_right
;
181 int between_delimiters
;
182 char *whole_word_chars_left
;
183 char *whole_word_chars_right
;
184 char *keyword_first_chars
;
186 /* first word is word[1] */
187 struct key_word
**keyword
;
190 int edit_drop_hotkey_menu (WEdit
* e
, int key
);
191 void edit_menu_cmd (WEdit
* e
);
192 void edit_init_menu_emacs (void);
193 void edit_init_menu_normal (void);
194 void edit_done_menu (void);
195 int edit_raw_key_query (char *heading
, char *query
, int cancel
);
196 char *strcasechr (const unsigned char *s
, int c
);
197 int edit (const char *_file
, int line
);
198 int edit_translate_key (WEdit
* edit
, unsigned int x_keycode
, long x_key
, int x_state
, int *cmd
, int *ch
);
200 #ifndef NO_INLINE_GETBYTE
201 int edit_get_byte (WEdit
* edit
, long byte_index
);
203 static inline int edit_get_byte (WEdit
* edit
, long byte_index
)
206 if (byte_index
>= (edit
->curs1
+ edit
->curs2
) || byte_index
< 0)
209 if (byte_index
>= edit
->curs1
) {
210 p
= edit
->curs1
+ edit
->curs2
- byte_index
- 1;
211 return edit
->buffers2
[p
>> S_EDIT_BUF_SIZE
][EDIT_BUF_SIZE
- (p
& M_EDIT_BUF_SIZE
) - 1];
213 return edit
->buffers1
[byte_index
>> S_EDIT_BUF_SIZE
][byte_index
& M_EDIT_BUF_SIZE
];
218 char *edit_get_buffer_as_text (WEdit
* edit
);
219 int edit_count_lines (WEdit
* edit
, long current
, int upto
);
220 long edit_move_forward (WEdit
* edit
, long current
, int lines
, long upto
);
221 long edit_move_forward3 (WEdit
* edit
, long current
, int cols
, long upto
);
222 long edit_move_backward (WEdit
* edit
, long current
, int lines
);
223 void edit_scroll_screen_over_cursor (WEdit
* edit
);
224 void edit_render_keypress (WEdit
* edit
);
225 void edit_scroll_upward (WEdit
* edit
, unsigned long i
);
226 void edit_scroll_downward (WEdit
* edit
, int i
);
227 void edit_scroll_right (WEdit
* edit
, int i
);
228 void edit_scroll_left (WEdit
* edit
, int i
);
229 int edit_get_col (WEdit
* edit
);
230 long edit_bol (WEdit
* edit
, long current
);
231 long edit_eol (WEdit
* edit
, long current
);
232 void edit_update_curs_row (WEdit
* edit
);
233 void edit_update_curs_col (WEdit
* edit
);
235 void edit_block_copy_cmd (WEdit
* edit
);
236 void edit_block_move_cmd (WEdit
* edit
);
237 int edit_block_delete_cmd (WEdit
* edit
);
238 int edit_block_delete (WEdit
* edit
);
239 void edit_delete_line (WEdit
* edit
);
241 int edit_delete (WEdit
* edit
);
242 void edit_insert (WEdit
* edit
, int c
);
243 int edit_cursor_move (WEdit
* edit
, long increment
);
244 void edit_push_action (WEdit
* edit
, long c
, ...);
245 void edit_push_key_press (WEdit
* edit
);
246 void edit_insert_ahead (WEdit
* edit
, int c
);
247 int edit_save_file (WEdit
* edit
, const char *filename
);
248 long edit_write_stream (WEdit
* edit
, FILE * f
);
249 char *edit_get_write_filter (char *writename
, const char *filename
);
250 int edit_save_cmd (WEdit
* edit
);
251 int edit_save_confirm_cmd (WEdit
* edit
);
252 int edit_save_as_cmd (WEdit
* edit
);
253 WEdit
*edit_init (WEdit
* edit
, int lines
, int columns
, const char *filename
, const char *text
, const char *dir
, unsigned long text_size
);
254 int edit_clean (WEdit
* edit
);
255 int edit_renew (WEdit
* edit
);
256 int edit_new_cmd (WEdit
* edit
);
257 int edit_reload (WEdit
* edit
, const char *filename
, const char *text
, const char *dir
, unsigned long text_size
);
258 int edit_load_cmd (WEdit
* edit
);
259 void edit_mark_cmd (WEdit
* edit
, int unmark
);
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_quit_cmd (WEdit
* edit
);
263 void edit_replace_cmd (WEdit
* edit
, int again
);
264 void edit_search_cmd (WEdit
* edit
, int again
);
265 void edit_complete_word_cmd (WEdit
* edit
);
266 int edit_save_block (WEdit
* edit
, const char *filename
, long start
, long finish
);
267 int edit_save_block_cmd (WEdit
* edit
);
268 int edit_insert_file_cmd (WEdit
* edit
);
269 int edit_insert_file (WEdit
* edit
, const char *filename
);
270 void edit_block_process_cmd (WEdit
* edit
, const char *shell_cmd
, int block
);
271 char *catstrs (const char *first
, ...);
272 void edit_refresh_cmd (WEdit
* edit
);
273 void edit_date_cmd (WEdit
* edit
);
274 void edit_goto_cmd (WEdit
* edit
);
275 int eval_marks (WEdit
* edit
, long *start_mark
, long *end_mark
);
276 void edit_status (WEdit
* edit
);
277 int edit_execute_command (WEdit
* edit
, int command
, int char_for_insertion
);
278 int edit_execute_key_command (WEdit
* edit
, int command
, int char_for_insertion
);
279 void edit_update_screen (WEdit
* edit
);
280 int edit_printf (WEdit
* e
, const char *fmt
, ...)
281 __attribute__ ((format (printf
, 2, 3)));
282 int edit_print_string (WEdit
* e
, const char *s
);
283 void edit_move_to_line (WEdit
* e
, long line
);
284 void edit_move_display (WEdit
* e
, long line
);
285 void edit_word_wrap (WEdit
* edit
);
286 unsigned char *edit_get_block (WEdit
* edit
, long start
, long finish
, int *l
);
287 int edit_sort_cmd (WEdit
* edit
);
288 void edit_help_cmd (WEdit
* edit
);
289 void edit_left_word_move (WEdit
* edit
, int s
);
290 void edit_right_word_move (WEdit
* edit
, int s
);
291 void edit_get_selection (WEdit
* edit
);
293 int edit_save_macro_cmd (WEdit
* edit
, struct macro macro
[], int n
);
294 int edit_load_macro_cmd (WEdit
* edit
, struct macro macro
[], int *n
, int k
);
295 void edit_delete_macro_cmd (WEdit
* edit
);
297 int edit_copy_to_X_buf_cmd (WEdit
* edit
);
298 int edit_cut_to_X_buf_cmd (WEdit
* edit
);
299 void edit_paste_from_X_buf_cmd (WEdit
* edit
);
301 void edit_paste_from_history (WEdit
*edit
);
303 void edit_split_filename (WEdit
* edit
, const char *name
);
305 #define CWidget Widget
306 void edit_set_syntax_change_callback (void (*callback
) (CWidget
*));
307 void edit_load_syntax (WEdit
* edit
, char **names
, char *type
);
308 void edit_free_syntax_rules (WEdit
* edit
);
309 void edit_get_syntax_color (WEdit
* edit
, long byte_index
, int *color
);
310 int edit_check_spelling (WEdit
* edit
);
313 void book_mark_insert (WEdit
* edit
, int line
, int c
);
314 int book_mark_query_color (WEdit
* edit
, int line
, int c
);
315 int book_mark_query_all (WEdit
* edit
, int line
, int *c
);
316 struct _book_mark
*book_mark_find (WEdit
* edit
, int line
);
317 int book_mark_clear (WEdit
* edit
, int line
, int c
);
318 void book_mark_flush (WEdit
* edit
, int c
);
319 void book_mark_inc (WEdit
* edit
, int line
);
320 void book_mark_dec (WEdit
* edit
, int line
);
322 void user_menu (WEdit
*edit
);
324 /* either command or char_for_insertion must be passed as -1 */
325 int edit_execute_cmd (WEdit
* edit
, int command
, int char_for_insertion
);
327 #define CPushFont(x,y)
331 /* put OS2/NT/WIN95 defines here */
334 # define MY_O_TEXT O_TEXT
339 #define FONT_PIX_PER_LINE 1
340 #define FONT_MEAN_WIDTH 1
342 #define get_sys_error(s) (s)
345 #define edit_get_load_file(d,f,h) input_dialog (h, _(" Enter file name: "), f)
346 #define edit_get_save_file(d,f,h) input_dialog (h, _(" Enter file name: "), f)
347 #define CMalloc(x) malloc(x)
349 #define edit_error_dialog(h,s) query_dialog (h, s, 0, 1, _("&Dismiss"))
351 #define edit_message_dialog(h,s) query_dialog (h, s, 0, 1, _("&Ok"))
352 #define edit_query_dialog2(h,t,a,b) query_dialog(h,t,0,2,a,b)
353 #define edit_query_dialog3(h,t,a,b,c) query_dialog(h,t,0,3,a,b,c)
354 #define edit_query_dialog4(h,t,a,b,c,d) query_dialog(h,t,0,4,a,b,c,d)
356 #define color_palette(x) win->color[x].pixel
358 extern char *home_dir
;
360 #define NUM_SELECTION_HISTORY 64
364 #define MAX_PATH_LEN PATH_MAX
366 #define MAX_PATH_LEN 1024
371 what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
372 or EDIT_KEY_EMULATION_EMACS
374 extern int edit_key_emulation
;
377 extern int option_word_wrap_line_length
;
378 extern int option_typewriter_wrap
;
379 extern int option_auto_para_formatting
;
380 extern int option_tab_spacing
;
381 extern int option_fill_tabs_with_spaces
;
382 extern int option_return_does_auto_indent
;
383 extern int option_backspace_through_tabs
;
384 extern int option_fake_half_tabs
;
385 extern int option_save_mode
;
386 extern int option_backup_ext_int
;
387 extern int option_max_undo
;
389 extern int option_edit_right_extreme
;
390 extern int option_edit_left_extreme
;
391 extern int option_edit_top_extreme
;
392 extern int option_edit_bottom_extreme
;
394 extern char *option_whole_chars_search
;
395 extern char *option_backup_ext
;
397 extern int edit_confirm_save
;
399 #endif /* __EDIT_H */