edit.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /* edit.h - main include file
  2. Copyright (C) 1996, 1997 Free Software Foundation, Inc.
  3. Authors: 1996, 1997 Paul Sheer
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301, USA.
  16. */
  17. #ifndef MC_EDIT_H
  18. #define MC_EDIT_H
  19. #include <stdio.h>
  20. #define N_menus 5
  21. #define SEARCH_DIALOG_OPTION_NO_SCANF (1 << 0)
  22. #define SEARCH_DIALOG_OPTION_NO_REGEX (1 << 1)
  23. #define SEARCH_DIALOG_OPTION_NO_CASE (1 << 2)
  24. #define SEARCH_DIALOG_OPTION_BACKWARDS (1 << 3)
  25. #define SEARCH_DIALOG_OPTION_BOOKMARK (1 << 4)
  26. #define EDIT_KEY_EMULATION_NORMAL 0
  27. #define EDIT_KEY_EMULATION_EMACS 1
  28. #define EDIT_KEY_EMULATION_USER 2
  29. #define REDRAW_LINE (1 << 0)
  30. #define REDRAW_LINE_ABOVE (1 << 1)
  31. #define REDRAW_LINE_BELOW (1 << 2)
  32. #define REDRAW_AFTER_CURSOR (1 << 3)
  33. #define REDRAW_BEFORE_CURSOR (1 << 4)
  34. #define REDRAW_PAGE (1 << 5)
  35. #define REDRAW_IN_BOUNDS (1 << 6)
  36. #define REDRAW_CHAR_ONLY (1 << 7)
  37. #define REDRAW_COMPLETELY (1 << 8)
  38. #define EDIT_TEXT_HORIZONTAL_OFFSET 0
  39. #define EDIT_TEXT_VERTICAL_OFFSET 1
  40. #define EDIT_RIGHT_EXTREME option_edit_right_extreme
  41. #define EDIT_LEFT_EXTREME option_edit_left_extreme
  42. #define EDIT_TOP_EXTREME option_edit_top_extreme
  43. #define EDIT_BOTTOM_EXTREME option_edit_bottom_extreme
  44. /*
  45. * The editor keeps data in two arrays of buffers.
  46. * All buffers have the same size, which must be a power of 2.
  47. */
  48. /* Configurable: log2 of the buffer size in bytes */
  49. #ifndef S_EDIT_BUF_SIZE
  50. #define S_EDIT_BUF_SIZE 16
  51. #endif
  52. /* Size of the buffer */
  53. #define EDIT_BUF_SIZE (((off_t) 1) << S_EDIT_BUF_SIZE)
  54. /* Buffer mask (used to find cursor position relative to the buffer) */
  55. #define M_EDIT_BUF_SIZE (EDIT_BUF_SIZE - 1)
  56. /*
  57. * Configurable: Maximal allowed number of buffers in each buffer array.
  58. * This number can be increased for systems with enough physical memory.
  59. */
  60. #ifndef MAXBUFF
  61. #define MAXBUFF 1024
  62. #endif
  63. /* Maximal length of file that can be opened */
  64. #define SIZE_LIMIT (EDIT_BUF_SIZE * (MAXBUFF - 2))
  65. /* Initial size of the undo stack, in bytes */
  66. #define START_STACK_SIZE 32
  67. /* Some codes that may be pushed onto or returned from the undo stack */
  68. #define CURS_LEFT 601
  69. #define CURS_RIGHT 602
  70. #define DELCHAR 603
  71. #define BACKSPACE 604
  72. #define STACK_BOTTOM 605
  73. #define CURS_LEFT_LOTS 606
  74. #define CURS_RIGHT_LOTS 607
  75. #define COLUMN_ON 608
  76. #define COLUMN_OFF 609
  77. #define MARK_1 1000
  78. #define MARK_2 700000000
  79. #define KEY_PRESS 1400000000
  80. /* Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
  81. #define TAB_SIZE option_tab_spacing
  82. #define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
  83. struct macro {
  84. short command;
  85. short ch;
  86. };
  87. struct WEdit;
  88. typedef struct WEdit WEdit;
  89. struct Menu;
  90. int edit_drop_hotkey_menu (WEdit *e, int key);
  91. void edit_menu_cmd (WEdit *e);
  92. struct WMenu *edit_init_menu (void);
  93. void edit_done_menu (struct WMenu *wmenu);
  94. void edit_reload_menu (void);
  95. void menu_save_mode_cmd (void);
  96. int edit_raw_key_query (const char *heading, const char *query, int cancel);
  97. int edit_file (const char *_file, int line);
  98. int edit_translate_key (WEdit *edit, long x_key, int *cmd, int *ch);
  99. int edit_get_byte (WEdit * edit, long byte_index);
  100. int edit_count_lines (WEdit * edit, long current, int upto);
  101. long edit_move_forward (WEdit * edit, long current, int lines, long upto);
  102. long edit_move_forward3 (WEdit * edit, long current, int cols, long upto);
  103. long edit_move_backward (WEdit * edit, long current, int lines);
  104. void edit_scroll_screen_over_cursor (WEdit * edit);
  105. void edit_render_keypress (WEdit * edit);
  106. void edit_scroll_upward (WEdit * edit, unsigned long i);
  107. void edit_scroll_downward (WEdit * edit, int i);
  108. void edit_scroll_right (WEdit * edit, int i);
  109. void edit_scroll_left (WEdit * edit, int i);
  110. void edit_move_up (WEdit * edit, unsigned long i, int scroll);
  111. void edit_move_down (WEdit * edit, int i, int scroll);
  112. void edit_move_to_prev_col (WEdit *edit, long p);
  113. int edit_get_col (WEdit * edit);
  114. long edit_bol (WEdit * edit, long current);
  115. long edit_eol (WEdit * edit, long current);
  116. void edit_update_curs_row (WEdit * edit);
  117. void edit_update_curs_col (WEdit * edit);
  118. void edit_find_bracket (WEdit * edit);
  119. void edit_block_copy_cmd (WEdit * edit);
  120. void edit_block_move_cmd (WEdit * edit);
  121. int edit_block_delete_cmd (WEdit * edit);
  122. void edit_delete_line (WEdit * edit);
  123. int edit_delete (WEdit * edit);
  124. void edit_insert (WEdit * edit, int c);
  125. void edit_cursor_move (WEdit * edit, long increment);
  126. void edit_push_action (WEdit * edit, long c, ...);
  127. void edit_push_key_press (WEdit * edit);
  128. void edit_insert_ahead (WEdit * edit, int c);
  129. long edit_write_stream (WEdit * edit, FILE * f);
  130. char *edit_get_write_filter (const char *writename, const char *filename);
  131. int edit_save_confirm_cmd (WEdit * edit);
  132. int edit_save_as_cmd (WEdit * edit);
  133. WEdit *edit_init (WEdit *edit, int lines, int columns,
  134. const char *filename, long line);
  135. int edit_clean (WEdit * edit);
  136. int edit_ok_to_exit (WEdit *edit);
  137. int edit_renew (WEdit * edit);
  138. int edit_new_cmd (WEdit * edit);
  139. int edit_reload (WEdit *edit, const char *filename);
  140. int edit_load_cmd (WEdit * edit);
  141. void edit_mark_cmd (WEdit * edit, int unmark);
  142. void edit_set_markers (WEdit * edit, long m1, long m2, int c1, int c2);
  143. void edit_push_markers (WEdit * edit);
  144. void edit_replace_cmd (WEdit * edit, int again);
  145. void edit_search_cmd (WEdit * edit, int again);
  146. void edit_complete_word_cmd (WEdit * edit);
  147. int edit_save_block (WEdit * edit, const char *filename, long start, long finish);
  148. int edit_save_block_cmd (WEdit * edit);
  149. int edit_insert_file_cmd (WEdit * edit);
  150. int edit_insert_file (WEdit * edit, const char *filename);
  151. void edit_block_process_cmd (WEdit * edit, const char *shell_cmd, int block);
  152. void freestrs (void);
  153. void edit_refresh_cmd (WEdit * edit);
  154. void edit_date_cmd (WEdit * edit);
  155. void edit_goto_cmd (WEdit * edit);
  156. int eval_marks (WEdit * edit, long *start_mark, long *end_mark);
  157. void edit_status (WEdit * edit);
  158. void edit_execute_key_command (WEdit *edit, int command,
  159. int char_for_insertion);
  160. void edit_update_screen (WEdit * edit);
  161. int edit_print_string (WEdit * e, const char *s);
  162. void edit_move_to_line (WEdit * e, long line);
  163. void edit_move_display (WEdit * e, long line);
  164. void edit_word_wrap (WEdit * edit);
  165. int edit_sort_cmd (WEdit * edit);
  166. int edit_ext_cmd (WEdit * edit);
  167. void edit_help_cmd (WEdit * edit);
  168. int edit_save_macro_cmd (WEdit * edit, struct macro macro[], int n);
  169. int edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k);
  170. void edit_delete_macro_cmd (WEdit * edit);
  171. int edit_copy_to_X_buf_cmd (WEdit * edit);
  172. int edit_cut_to_X_buf_cmd (WEdit * edit);
  173. void edit_paste_from_X_buf_cmd (WEdit * edit);
  174. void edit_select_codepage_cmd (WEdit *edit);
  175. void edit_insert_literal_cmd (WEdit *edit);
  176. void edit_execute_macro_cmd (WEdit *edit);
  177. void edit_begin_end_macro_cmd(WEdit *edit);
  178. void edit_paste_from_history (WEdit *edit);
  179. void edit_set_filename (WEdit *edit, const char *name);
  180. void edit_load_syntax (WEdit * edit, char ***pnames, const char *type);
  181. void edit_free_syntax_rules (WEdit * edit);
  182. void edit_get_syntax_color (WEdit * edit, long byte_index, int *color);
  183. void book_mark_insert (WEdit * edit, int line, int c);
  184. int book_mark_query_color (WEdit * edit, int line, int c);
  185. int book_mark_query_all (WEdit * edit, int line, int *c);
  186. struct _book_mark *book_mark_find (WEdit * edit, int line);
  187. int book_mark_clear (WEdit * edit, int line, int c);
  188. void book_mark_flush (WEdit * edit, int c);
  189. void book_mark_inc (WEdit * edit, int line);
  190. void book_mark_dec (WEdit * edit, int line);
  191. int line_is_blank (WEdit *edit, long line);
  192. int edit_indent_width (WEdit *edit, long p);
  193. void edit_insert_indent (WEdit *edit, int indent);
  194. void edit_options_dialog (void);
  195. void edit_syntax_dialog (void);
  196. void edit_mail_dialog (WEdit *edit);
  197. void format_paragraph (WEdit *edit, int force);
  198. /* either command or char_for_insertion must be passed as -1 */
  199. void edit_execute_cmd (WEdit *edit, int command, int char_for_insertion);
  200. #define get_sys_error(s) (s)
  201. #define edit_error_dialog(h,s) query_dialog (h, s, D_ERROR, 1, _("&Dismiss"))
  202. #define edit_query_dialog2(h,t,a,b) query_dialog (h, t, D_NORMAL, 2, a, b)
  203. #define edit_query_dialog3(h,t,a,b,c) query_dialog (h, t, D_NORMAL, 3, a, b, c)
  204. #define color_palette(x) win->color[x].pixel
  205. #define NUM_SELECTION_HISTORY 64
  206. #ifndef MAX_PATH_LEN
  207. #ifdef PATH_MAX
  208. #define MAX_PATH_LEN PATH_MAX
  209. #else
  210. #define MAX_PATH_LEN 1024
  211. #endif
  212. #endif
  213. /*
  214. what editor are we going to emulate? one of EDIT_KEY_EMULATION_NORMAL
  215. or EDIT_KEY_EMULATION_EMACS
  216. */
  217. extern int edit_key_emulation;
  218. extern WEdit *wedit;
  219. struct WMenu;
  220. extern struct WMenu *edit_menubar;
  221. extern int option_word_wrap_line_length;
  222. extern int option_typewriter_wrap;
  223. extern int option_auto_para_formatting;
  224. extern int option_tab_spacing;
  225. extern int option_fill_tabs_with_spaces;
  226. extern int option_return_does_auto_indent;
  227. extern int option_backspace_through_tabs;
  228. extern int option_fake_half_tabs;
  229. typedef enum {
  230. EDIT_QUICK_SAVE = 0,
  231. EDIT_SAFE_SAVE,
  232. EDIT_DO_BACKUP
  233. } edit_save_mode_t;
  234. extern int option_save_mode;
  235. extern int option_save_position;
  236. extern int option_max_undo;
  237. extern int option_syntax_highlighting;
  238. extern int option_auto_syntax;
  239. extern char *option_syntax_type;
  240. extern int editor_option_check_nl_at_eof;
  241. extern int option_edit_right_extreme;
  242. extern int option_edit_left_extreme;
  243. extern int option_edit_top_extreme;
  244. extern int option_edit_bottom_extreme;
  245. extern const char *option_whole_chars_search;
  246. extern char *option_backup_ext;
  247. extern int edit_confirm_save;
  248. extern int column_highlighting;
  249. /* File names */
  250. #define EDIT_DIR ".mc" PATH_SEP_STR "cedit"
  251. #define SYNTAX_FILE EDIT_DIR PATH_SEP_STR "Syntax"
  252. #define CLIP_FILE EDIT_DIR PATH_SEP_STR "cooledit.clip"
  253. #define MACRO_FILE EDIT_DIR PATH_SEP_STR "cooledit.macros"
  254. #define BLOCK_FILE EDIT_DIR PATH_SEP_STR "cooledit.block"
  255. #define TEMP_FILE EDIT_DIR PATH_SEP_STR "cooledit.temp"
  256. #endif