edit-impl.h 11 KB

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