mcedit: rename functions:
[midnight-commander.git] / src / editor / edit.c
bloba95512264ffdd63bee44bae2d36126b0d9a11011
1 /*
2 Editor low level data handling and cursor fundamentals.
4 Copyright (C) 1996-2016
5 Free Software Foundation, Inc.
7 Written by:
8 Paul Sheer 1996, 1997
9 Ilia Maslakov <il.smind@gmail.com> 2009, 2010, 2011
10 Andrew Borodin <aborodin@vmail.ru> 2012, 2013
12 This file is part of the Midnight Commander.
14 The Midnight Commander is free software: you can redistribute it
15 and/or modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation, either version 3 of the License,
17 or (at your option) any later version.
19 The Midnight Commander is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 /** \file
29 * \brief Source: editor low level data handling and cursor fundamentals
30 * \author Paul Sheer
31 * \date 1996, 1997
34 #include <config.h>
35 #include <stdio.h>
36 #include <stdarg.h>
37 #include <sys/types.h>
38 #include <unistd.h>
39 #include <string.h>
40 #include <ctype.h>
41 #include <errno.h>
42 #include <sys/stat.h>
43 #include <stdint.h> /* UINTMAX_MAX */
44 #include <stdlib.h>
46 #include "lib/global.h"
48 #include "lib/tty/color.h"
49 #include "lib/tty/tty.h" /* attrset() */
50 #include "lib/tty/key.h" /* is_idle() */
51 #include "lib/skin.h" /* EDITOR_NORMAL_COLOR */
52 #include "lib/fileloc.h" /* EDIT_BLOCK_FILE */
53 #include "lib/vfs/vfs.h"
54 #include "lib/strutil.h" /* utf string functions */
55 #include "lib/util.h" /* load_file_position(), save_file_position() */
56 #include "lib/timefmt.h" /* time formatting */
57 #include "lib/lock.h"
58 #include "lib/widget.h"
60 #ifdef HAVE_CHARSET
61 #include "lib/charsets.h" /* get_codepage_id */
62 #endif
64 #include "src/filemanager/usermenu.h" /* user_menu_cmd() */
66 #include "src/setup.h" /* option_tab_spacing */
67 #include "src/learn.h" /* learn_keys */
68 #include "src/keybind-defaults.h"
70 #include "edit-impl.h"
71 #include "editwidget.h"
72 #ifdef HAVE_ASPELL
73 #include "spell.h"
74 #endif
76 /*** global variables ****************************************************************************/
78 int option_word_wrap_line_length = DEFAULT_WRAP_LINE_LENGTH;
79 int option_typewriter_wrap = 0;
80 int option_auto_para_formatting = 0;
81 int option_fill_tabs_with_spaces = 0;
82 int option_return_does_auto_indent = 1;
83 int option_backspace_through_tabs = 0;
84 int option_fake_half_tabs = 1;
85 int option_save_mode = EDIT_QUICK_SAVE;
86 int option_save_position = 1;
87 int option_max_undo = 32768;
88 int option_persistent_selections = 1;
89 int option_cursor_beyond_eol = 0;
90 int option_line_state = 0;
91 int option_line_state_width = 0;
92 gboolean option_cursor_after_inserted_block = FALSE;
93 int option_state_full_filename = 0;
95 int enable_show_tabs_tws = 1;
96 int option_check_nl_at_eof = 0;
97 int option_group_undo = 0;
98 int show_right_margin = 0;
100 char *option_backup_ext = NULL;
101 char *option_filesize_threshold = NULL;
103 unsigned int edit_stack_iterator = 0;
104 edit_stack_type edit_history_moveto[MAX_HISTORY_MOVETO];
105 /* magic sequense for say than block is vertical */
106 const char VERTICAL_MAGIC[] = { '\1', '\1', '\1', '\1', '\n' };
108 /*** file scope macro definitions ****************************************************************/
110 #define TEMP_BUF_LEN 1024
112 #define space_width 1
114 /*** file scope type declarations ****************************************************************/
116 /*** file scope variables ************************************************************************/
118 /* detecting an error on save is easy: just check if every byte has been written. */
119 /* detecting an error on read, is not so easy 'cos there is not way to tell
120 whether you read everything or not. */
121 /* FIXME: add proper 'triple_pipe_open' to read, write and check errors. */
122 static const struct edit_filters
124 const char *read, *write, *extension;
125 } all_filters[] =
127 /* *INDENT-OFF* */
128 { "xz -cd %s 2>&1", "xz > %s", ".xz"},
129 { "lz4 -cd %s 2>&1", "lz4 > %s", ".lz4" },
130 { "lzip -cd %s 2>&1", "lzip > %s", ".lz"},
131 { "lzma -cd %s 2>&1", "lzma > %s", ".lzma" },
132 { "bzip2 -cd %s 2>&1", "bzip2 > %s", ".bz2" },
133 { "gzip -cd %s 2>&1", "gzip > %s", ".gz" },
134 { "gzip -cd %s 2>&1", "gzip > %s", ".Z" }
135 /* *INDENT-ON* */
138 static const off_t option_filesize_default_threshold = 64 * 1024 * 1024; /* 64 MB */
140 /* --------------------------------------------------------------------------------------------- */
141 /*** file scope functions ************************************************************************/
142 /* --------------------------------------------------------------------------------------------- */
144 static int
145 edit_load_status_update_cb (status_msg_t * sm)
147 simple_status_msg_t *ssm = SIMPLE_STATUS_MSG (sm);
148 edit_buffer_read_file_status_msg_t *rsm = (edit_buffer_read_file_status_msg_t *) sm;
149 Widget *wd = WIDGET (sm->dlg);
151 if (verbose)
152 label_set_textv (ssm->label, _("Loading: %3d%%"),
153 edit_buffer_calc_percent (rsm->buf, rsm->loaded));
154 else
155 label_set_text (ssm->label, _("Loading..."));
157 if (rsm->first)
159 int wd_width;
160 Widget *lw = WIDGET (ssm->label);
162 wd_width = max (wd->cols, lw->cols + 6);
163 widget_set_size (wd, wd->y, wd->x, wd->lines, wd_width);
164 widget_set_size (lw, lw->y, wd->x + (wd->cols - lw->cols) / 2, lw->lines, lw->cols);
165 rsm->first = FALSE;
168 return status_msg_common_update (sm);
171 /* --------------------------------------------------------------------------------------------- */
173 * Load file OR text into buffers. Set cursor to the beginning of file.
175 * @return FALSE on error.
178 static gboolean
179 edit_load_file_fast (edit_buffer_t * buf, const vfs_path_t * filename_vpath)
181 int file;
182 gboolean ret;
183 edit_buffer_read_file_status_msg_t rsm;
184 gboolean aborted;
186 file = mc_open (filename_vpath, O_RDONLY | O_BINARY);
187 if (file < 0)
189 gchar *errmsg;
191 errmsg =
192 g_strdup_printf (_("Cannot open %s for reading"), vfs_path_as_str (filename_vpath));
193 edit_error_dialog (_("Error"), errmsg);
194 g_free (errmsg);
195 return FALSE;
198 rsm.first = TRUE;
199 rsm.buf = buf;
200 rsm.loaded = 0;
202 status_msg_init (STATUS_MSG (&rsm), _("Load file"), 1.0, simple_status_msg_init_cb,
203 edit_load_status_update_cb, NULL);
205 ret = (edit_buffer_read_file (buf, file, buf->size, &rsm, &aborted) == buf->size);
207 status_msg_deinit (STATUS_MSG (&rsm));
209 if (!ret && !aborted)
211 gchar *errmsg;
213 errmsg = g_strdup_printf (_("Error reading %s"), vfs_path_as_str (filename_vpath));
214 edit_error_dialog (_("Error"), errmsg);
215 g_free (errmsg);
218 mc_close (file);
219 return ret;
222 /* --------------------------------------------------------------------------------------------- */
223 /** Return index of the filter or -1 is there is no appropriate filter */
225 static int
226 edit_find_filter (const vfs_path_t * filename_vpath)
228 size_t i, l;
230 if (filename_vpath == NULL)
231 return -1;
233 l = strlen (vfs_path_as_str (filename_vpath));
234 for (i = 0; i < G_N_ELEMENTS (all_filters); i++)
236 size_t e;
238 e = strlen (all_filters[i].extension);
239 if (l > e)
240 if (!strcmp (all_filters[i].extension, vfs_path_as_str (filename_vpath) + l - e))
241 return i;
243 return -1;
246 /* --------------------------------------------------------------------------------------------- */
248 static char *
249 edit_get_filter (const vfs_path_t * filename_vpath)
251 int i;
252 char *p, *quoted_name;
254 i = edit_find_filter (filename_vpath);
255 if (i < 0)
256 return NULL;
258 quoted_name = name_quote (vfs_path_as_str (filename_vpath), FALSE);
259 p = g_strdup_printf (all_filters[i].read, quoted_name);
260 g_free (quoted_name);
261 return p;
264 /* --------------------------------------------------------------------------------------------- */
266 static off_t
267 edit_insert_stream (WEdit * edit, FILE * f)
269 int c;
270 off_t i = 0;
272 while ((c = fgetc (f)) >= 0)
274 edit_insert (edit, c);
275 i++;
277 return i;
280 /* --------------------------------------------------------------------------------------------- */
282 * Open file and create it if necessary.
284 * @param edit editor object
285 * @param filename_vpath file name
286 * @param st buffer for store stat info
287 * @return TRUE for success, FALSE for error.
290 static gboolean
291 check_file_access (WEdit * edit, const vfs_path_t * filename_vpath, struct stat *st)
293 static uintmax_t threshold = UINTMAX_MAX;
294 int file;
295 gchar *errmsg = NULL;
296 gboolean ret = TRUE;
298 /* Try opening an existing file */
299 file = mc_open (filename_vpath, O_NONBLOCK | O_RDONLY | O_BINARY, 0666);
300 if (file < 0)
303 * Try creating the file. O_EXCL prevents following broken links
304 * and opening existing files.
306 file = mc_open (filename_vpath, O_NONBLOCK | O_RDONLY | O_BINARY | O_CREAT | O_EXCL, 0666);
307 if (file < 0)
309 errmsg =
310 g_strdup_printf (_("Cannot open %s for reading"), vfs_path_as_str (filename_vpath));
311 goto cleanup;
314 /* New file, delete it if it's not modified or saved */
315 edit->delete_file = 1;
318 /* Check what we have opened */
319 if (mc_fstat (file, st) < 0)
321 errmsg =
322 g_strdup_printf (_("Cannot get size/permissions for %s"),
323 vfs_path_as_str (filename_vpath));
324 goto cleanup;
327 /* We want to open regular files only */
328 if (!S_ISREG (st->st_mode))
330 errmsg =
331 g_strdup_printf (_("\"%s\" is not a regular file"), vfs_path_as_str (filename_vpath));
332 goto cleanup;
335 /* get file size threshold for alarm */
336 if (threshold == UINTMAX_MAX)
338 gboolean err = FALSE;
340 threshold = parse_integer (option_filesize_threshold, &err);
341 if (err)
342 threshold = option_filesize_default_threshold;
346 * Don't delete non-empty files.
347 * O_EXCL should prevent it, but let's be on the safe side.
349 if (st->st_size > 0)
350 edit->delete_file = 0;
352 if ((uintmax_t) st->st_size > threshold)
354 int act;
356 errmsg = g_strdup_printf (_("File \"%s\" is too large.\nOpen it anyway?"),
357 vfs_path_as_str (filename_vpath));
358 act = edit_query_dialog2 (_("Warning"), errmsg, _("&Yes"), _("&No"));
359 MC_PTR_FREE (errmsg);
361 if (act != 0)
362 ret = FALSE;
365 cleanup:
366 (void) mc_close (file);
368 if (errmsg != NULL)
370 edit_error_dialog (_("Error"), errmsg);
371 g_free (errmsg);
372 ret = FALSE;
375 return ret;
378 /* --------------------------------------------------------------------------------------------- */
381 * Open the file and load it into the buffers, either directly or using
382 * a filter. Return TRUE on success, FALSE on error.
384 * Fast loading (edit_load_file_fast) is used when the file size is
385 * known. In this case the data is read into the buffers by blocks.
386 * If the file size is not known, the data is loaded byte by byte in
387 * edit_insert_file.
389 * @param edit editor object
390 * @return TRUE if file was successfully opened and loaded to buffers, FALSE otherwise
392 static gboolean
393 edit_load_file (WEdit * edit)
395 gboolean fast_load = TRUE;
397 /* Cannot do fast load if a filter is used */
398 if (edit_find_filter (edit->filename_vpath) >= 0)
399 fast_load = FALSE;
402 * FIXME: line end translation should disable fast loading as well
403 * Consider doing fseek() to the end and ftell() for the real size.
405 if (edit->filename_vpath != NULL)
408 * VFS may report file size incorrectly, and slow load is not a big
409 * deal considering overhead in VFS.
411 if (!vfs_file_is_local (edit->filename_vpath))
412 fast_load = FALSE;
414 /* If we are dealing with a real file, check that it exists */
415 if (!check_file_access (edit, edit->filename_vpath, &edit->stat1))
417 edit_clean (edit);
418 return FALSE;
421 else
423 /* nothing to load */
424 fast_load = FALSE;
427 if (fast_load)
429 edit_buffer_init (&edit->buffer, edit->stat1.st_size);
431 if (!edit_load_file_fast (&edit->buffer, edit->filename_vpath))
433 edit_clean (edit);
434 return FALSE;
437 else
439 edit_buffer_init (&edit->buffer, 0);
441 if (edit->filename_vpath != NULL
442 && *(vfs_path_get_by_index (edit->filename_vpath, 0)->path) != '\0')
444 edit->undo_stack_disable = 1;
445 if (edit_insert_file (edit, edit->filename_vpath) < 0)
447 edit_clean (edit);
448 return FALSE;
450 edit->undo_stack_disable = 0;
453 edit->lb = LB_ASIS;
454 return TRUE;
457 /* --------------------------------------------------------------------------------------------- */
458 /** Restore saved cursor position in the file */
460 static void
461 edit_load_position (WEdit * edit)
463 long line, column;
464 off_t offset;
466 if (edit->filename_vpath == NULL
467 || *(vfs_path_get_by_index (edit->filename_vpath, 0)->path) == '\0')
468 return;
470 load_file_position (edit->filename_vpath, &line, &column, &offset, &edit->serialized_bookmarks);
472 if (line > 0)
474 edit_move_to_line (edit, line - 1);
475 edit->prev_col = column;
477 else if (offset > 0)
479 edit_cursor_move (edit, offset);
480 line = edit->buffer.curs_line;
481 edit->search_start = edit->buffer.curs1;
484 book_mark_restore (edit, BOOK_MARK_COLOR);
486 edit_move_to_prev_col (edit, edit_buffer_get_current_bol (&edit->buffer));
487 edit_move_display (edit, line - (WIDGET (edit)->lines / 2));
490 /* --------------------------------------------------------------------------------------------- */
491 /** Save cursor position in the file */
493 static void
494 edit_save_position (WEdit * edit)
496 if (edit->filename_vpath == NULL
497 || *(vfs_path_get_by_index (edit->filename_vpath, 0)->path) == '\0')
498 return;
500 book_mark_serialize (edit, BOOK_MARK_COLOR);
501 save_file_position (edit->filename_vpath, edit->buffer.curs_line + 1, edit->curs_col,
502 edit->buffer.curs1, edit->serialized_bookmarks);
503 edit->serialized_bookmarks = NULL;
506 /* --------------------------------------------------------------------------------------------- */
507 /** Clean the WEdit stricture except the widget part */
509 static void
510 edit_purge_widget (WEdit * edit)
512 size_t len = sizeof (WEdit) - sizeof (Widget);
513 char *start = (char *) edit + sizeof (Widget);
514 memset (start, 0, len);
517 /* --------------------------------------------------------------------------------------------- */
520 TODO: if the user undos until the stack bottom, and the stack has not wrapped,
521 then the file should be as it was when he loaded up. Then set edit->modified to 0.
524 static long
525 edit_pop_undo_action (WEdit * edit)
527 long c;
528 unsigned long sp = edit->undo_stack_pointer;
530 if (sp == edit->undo_stack_bottom)
531 return STACK_BOTTOM;
533 sp = (sp - 1) & edit->undo_stack_size_mask;
534 c = edit->undo_stack[sp];
535 if (c >= 0)
537 /* edit->undo_stack[sp] = '@'; */
538 edit->undo_stack_pointer = (edit->undo_stack_pointer - 1) & edit->undo_stack_size_mask;
539 return c;
542 if (sp == edit->undo_stack_bottom)
543 return STACK_BOTTOM;
545 c = edit->undo_stack[(sp - 1) & edit->undo_stack_size_mask];
546 if (edit->undo_stack[sp] == -2)
548 /* edit->undo_stack[sp] = '@'; */
549 edit->undo_stack_pointer = sp;
551 else
552 edit->undo_stack[sp]++;
554 return c;
557 static long
558 edit_pop_redo_action (WEdit * edit)
560 long c;
561 unsigned long sp = edit->redo_stack_pointer;
563 if (sp == edit->redo_stack_bottom)
564 return STACK_BOTTOM;
566 sp = (sp - 1) & edit->redo_stack_size_mask;
567 c = edit->redo_stack[sp];
568 if (c >= 0)
570 edit->redo_stack_pointer = (edit->redo_stack_pointer - 1) & edit->redo_stack_size_mask;
571 return c;
574 if (sp == edit->redo_stack_bottom)
575 return STACK_BOTTOM;
577 c = edit->redo_stack[(sp - 1) & edit->redo_stack_size_mask];
578 if (edit->redo_stack[sp] == -2)
579 edit->redo_stack_pointer = sp;
580 else
581 edit->redo_stack[sp]++;
583 return c;
586 static long
587 get_prev_undo_action (WEdit * edit)
589 long c;
590 unsigned long sp = edit->undo_stack_pointer;
592 if (sp == edit->undo_stack_bottom)
593 return STACK_BOTTOM;
595 sp = (sp - 1) & edit->undo_stack_size_mask;
596 c = edit->undo_stack[sp];
597 if (c >= 0)
598 return c;
600 if (sp == edit->undo_stack_bottom)
601 return STACK_BOTTOM;
603 c = edit->undo_stack[(sp - 1) & edit->undo_stack_size_mask];
604 return c;
607 /* --------------------------------------------------------------------------------------------- */
608 /** is called whenever a modification is made by one of the four routines below */
610 static void
611 edit_modification (WEdit * edit)
613 edit->caches_valid = FALSE;
615 /* raise lock when file modified */
616 if (!edit->modified && !edit->delete_file)
617 edit->locked = lock_file (edit->filename_vpath);
618 edit->modified = 1;
621 /* --------------------------------------------------------------------------------------------- */
622 /* high level cursor movement commands */
623 /* --------------------------------------------------------------------------------------------- */
624 /** check whether cursor is in indent part of line
626 * @param edit editor object
628 * @return TRUE if cursor is in indent, FALSE otherwise
631 static gboolean
632 is_in_indent (const edit_buffer_t * buf)
634 off_t p;
636 for (p = edit_buffer_get_current_bol (buf); p < buf->curs1; p++)
637 if (strchr (" \t", edit_buffer_get_byte (buf, p)) == NULL)
638 return FALSE;
640 return TRUE;
643 /* --------------------------------------------------------------------------------------------- */
644 /** check whether line in editor is blank or not
646 * @param edit editor object
647 * @param offset position in file
649 * @return TRUE if line in blank, FALSE otherwise
652 static gboolean
653 is_blank (const edit_buffer_t * buf, off_t offset)
655 off_t s, f;
657 s = edit_buffer_get_bol (buf, offset);
658 f = edit_buffer_get_eol (buf, offset) - 1;
659 while (s <= f)
661 int c;
663 c = edit_buffer_get_byte (buf, s++);
664 if (!isspace (c))
665 return FALSE;
667 return TRUE;
670 /* --------------------------------------------------------------------------------------------- */
671 /** returns the offset of line i */
673 static off_t
674 edit_find_line (WEdit * edit, long line)
676 long i, j = 0;
677 long m = 2000000000; /* what is the magic number? */
679 if (!edit->caches_valid)
681 memset (edit->line_numbers, 0, sizeof (edit->line_numbers));
682 memset (edit->line_offsets, 0, sizeof (edit->line_offsets));
683 /* three offsets that we *know* are line 0 at 0 and these two: */
684 edit->line_numbers[1] = edit->buffer.curs_line;
685 edit->line_offsets[1] = edit_buffer_get_current_bol (&edit->buffer);
686 edit->line_numbers[2] = edit->buffer.lines;
687 edit->line_offsets[2] = edit_buffer_get_bol (&edit->buffer, edit->buffer.size);
688 edit->caches_valid = TRUE;
690 if (line >= edit->buffer.lines)
691 return edit->line_offsets[2];
692 if (line <= 0)
693 return 0;
694 /* find the closest known point */
695 for (i = 0; i < N_LINE_CACHES; i++)
697 long n;
699 n = labs (edit->line_numbers[i] - line);
700 if (n < m)
702 m = n;
703 j = i;
706 if (m == 0)
707 return edit->line_offsets[j]; /* know the offset exactly */
708 if (m == 1 && j >= 3)
709 i = j; /* one line different - caller might be looping, so stay in this cache */
710 else
711 i = 3 + (rand () % (N_LINE_CACHES - 3));
712 if (line > edit->line_numbers[j])
713 edit->line_offsets[i] =
714 edit_buffer_get_forward_offset (&edit->buffer, edit->line_offsets[j],
715 line - edit->line_numbers[j], 0);
716 else
717 edit->line_offsets[i] =
718 edit_buffer_get_backward_offset (&edit->buffer, edit->line_offsets[j],
719 edit->line_numbers[j] - line);
720 edit->line_numbers[i] = line;
721 return edit->line_offsets[i];
724 /* --------------------------------------------------------------------------------------------- */
725 /** moves up until a blank line is reached, or until just
726 before a non-blank line is reached */
728 static void
729 edit_move_up_paragraph (WEdit * edit, gboolean do_scroll)
731 long i = 0;
733 if (edit->buffer.curs_line > 1)
735 if (!edit_line_is_blank (edit, edit->buffer.curs_line))
737 for (i = edit->buffer.curs_line - 1; i != 0; i--)
738 if (edit_line_is_blank (edit, i))
739 break;
741 else if (edit_line_is_blank (edit, edit->buffer.curs_line - 1))
743 for (i = edit->buffer.curs_line - 1; i != 0; i--)
744 if (!edit_line_is_blank (edit, i))
746 i++;
747 break;
750 else
752 for (i = edit->buffer.curs_line - 1; i != 0; i--)
753 if (edit_line_is_blank (edit, i))
754 break;
758 edit_move_up (edit, edit->buffer.curs_line - i, do_scroll);
761 /* --------------------------------------------------------------------------------------------- */
762 /** moves down until a blank line is reached, or until just
763 before a non-blank line is reached */
765 static void
766 edit_move_down_paragraph (WEdit * edit, gboolean do_scroll)
768 long i;
770 if (edit->buffer.curs_line >= edit->buffer.lines - 1)
771 i = edit->buffer.lines;
772 else if (!edit_line_is_blank (edit, edit->buffer.curs_line))
774 for (i = edit->buffer.curs_line + 1; i != 0; i++)
775 if (edit_line_is_blank (edit, i) || i >= edit->buffer.lines)
776 break;
778 else if (edit_line_is_blank (edit, edit->buffer.curs_line + 1))
780 for (i = edit->buffer.curs_line + 1; i != 0; i++)
781 if (!edit_line_is_blank (edit, i) || i > edit->buffer.lines)
783 i--;
784 break;
787 else
789 for (i = edit->buffer.curs_line + 1; i != 0; i++)
790 if (edit_line_is_blank (edit, i) || i >= edit->buffer.lines)
791 break;
793 edit_move_down (edit, i - edit->buffer.curs_line, do_scroll);
796 /* --------------------------------------------------------------------------------------------- */
798 static void
799 edit_begin_page (WEdit * edit)
801 edit_update_curs_row (edit);
802 edit_move_up (edit, edit->curs_row, 0);
805 /* --------------------------------------------------------------------------------------------- */
807 static void
808 edit_end_page (WEdit * edit)
810 edit_update_curs_row (edit);
811 edit_move_down (edit, WIDGET (edit)->lines - edit->curs_row - 1, 0);
815 /* --------------------------------------------------------------------------------------------- */
816 /** goto beginning of text */
818 static void
819 edit_move_to_top (WEdit * edit)
821 if (edit->buffer.curs_line != 0)
823 edit_cursor_move (edit, -edit->buffer.curs1);
824 edit_move_to_prev_col (edit, 0);
825 edit->force |= REDRAW_PAGE;
826 edit->search_start = 0;
827 edit_update_curs_row (edit);
831 /* --------------------------------------------------------------------------------------------- */
832 /** goto end of text */
834 static void
835 edit_move_to_bottom (WEdit * edit)
837 if (edit->buffer.curs_line < edit->buffer.lines)
839 edit_move_down (edit, edit->buffer.lines - edit->curs_row, 0);
840 edit->start_display = edit->buffer.size;
841 edit->start_line = edit->buffer.lines;
842 edit_scroll_upward (edit, WIDGET (edit)->lines - 1);
843 edit->force |= REDRAW_PAGE;
847 /* --------------------------------------------------------------------------------------------- */
848 /** goto beginning of line */
850 static void
851 edit_cursor_to_bol (WEdit * edit)
853 edit_cursor_move (edit, edit_buffer_get_current_bol (&edit->buffer) - edit->buffer.curs1);
854 edit->search_start = edit->buffer.curs1;
855 edit->prev_col = edit_get_col (edit);
856 edit->over_col = 0;
859 /* --------------------------------------------------------------------------------------------- */
860 /** goto end of line */
862 static void
863 edit_cursor_to_eol (WEdit * edit)
865 edit_cursor_move (edit, edit_buffer_get_current_eol (&edit->buffer) - edit->buffer.curs1);
866 edit->search_start = edit->buffer.curs1;
867 edit->prev_col = edit_get_col (edit);
868 edit->over_col = 0;
871 /* --------------------------------------------------------------------------------------------- */
873 static unsigned long
874 my_type_of (int c)
876 unsigned long x, r = 0;
877 const char *p, *q;
878 const char option_chars_move_whole_word[] =
879 "!=&|<>^~ !:;, !'!`!.?!\"!( !) !{ !} !Aa0 !+-*/= |<> ![ !] !\\#! ";
881 if (c == 0)
882 return 0;
883 if (c == '!')
885 if (*option_chars_move_whole_word == '!')
886 return 2;
887 return 0x80000000UL;
889 if (g_ascii_isupper ((gchar) c))
890 c = 'A';
891 else if (g_ascii_islower ((gchar) c))
892 c = 'a';
893 else if (g_ascii_isalpha (c))
894 c = 'a';
895 else if (isdigit (c))
896 c = '0';
897 else if (isspace (c))
898 c = ' ';
899 q = strchr (option_chars_move_whole_word, c);
900 if (!q)
901 return 0xFFFFFFFFUL;
904 for (x = 1, p = option_chars_move_whole_word; p < q; p++)
905 if (*p == '!')
906 x <<= 1;
907 r |= x;
909 while ((q = strchr (q + 1, c)));
910 return r;
913 /* --------------------------------------------------------------------------------------------- */
915 static void
916 edit_left_word_move (WEdit * edit, int s)
918 while (TRUE)
920 int c1, c2;
922 if (edit->column_highlight
923 && edit->mark1 != edit->mark2
924 && edit->over_col == 0
925 && edit->buffer.curs1 == edit_buffer_get_current_bol (&edit->buffer))
926 break;
927 edit_cursor_move (edit, -1);
928 if (edit->buffer.curs1 == 0)
929 break;
930 c1 = edit_buffer_get_previous_byte (&edit->buffer);
931 c2 = edit_buffer_get_current_byte (&edit->buffer);
932 if (c1 == '\n' || c2 == '\n')
933 break;
934 if ((my_type_of (c1) & my_type_of (c2)) == 0)
935 break;
936 if (isspace (c1) && !isspace (c2))
937 break;
938 if (s != 0 && !isspace (c1) && isspace (c2))
939 break;
943 /* --------------------------------------------------------------------------------------------- */
945 static void
946 edit_left_word_move_cmd (WEdit * edit)
948 edit_left_word_move (edit, 0);
949 edit->force |= REDRAW_PAGE;
952 /* --------------------------------------------------------------------------------------------- */
954 static void
955 edit_right_word_move (WEdit * edit, int s)
957 while (TRUE)
959 int c1, c2;
961 if (edit->column_highlight
962 && edit->mark1 != edit->mark2
963 && edit->over_col == 0
964 && edit->buffer.curs1 == edit_buffer_get_current_eol (&edit->buffer))
965 break;
966 edit_cursor_move (edit, 1);
967 if (edit->buffer.curs1 >= edit->buffer.size)
968 break;
969 c1 = edit_buffer_get_previous_byte (&edit->buffer);
970 c2 = edit_buffer_get_current_byte (&edit->buffer);
971 if (c1 == '\n' || c2 == '\n')
972 break;
973 if ((my_type_of (c1) & my_type_of (c2)) == 0)
974 break;
975 if (isspace (c1) && !isspace (c2))
976 break;
977 if (s != 0 && !isspace (c1) && isspace (c2))
978 break;
982 /* --------------------------------------------------------------------------------------------- */
984 static void
985 edit_right_word_move_cmd (WEdit * edit)
987 edit_right_word_move (edit, 0);
988 edit->force |= REDRAW_PAGE;
991 /* --------------------------------------------------------------------------------------------- */
993 static void
994 edit_right_char_move_cmd (WEdit * edit)
996 int char_length = 1;
997 int c;
999 #ifdef HAVE_CHARSET
1000 if (edit->utf8)
1002 c = edit_buffer_get_utf (&edit->buffer, edit->buffer.curs1, &char_length);
1003 if (char_length < 1)
1004 char_length = 1;
1006 else
1007 #endif
1008 c = edit_buffer_get_current_byte (&edit->buffer);
1010 if (option_cursor_beyond_eol && c == '\n')
1011 edit->over_col++;
1012 else
1013 edit_cursor_move (edit, char_length);
1016 /* --------------------------------------------------------------------------------------------- */
1018 static void
1019 edit_left_char_move_cmd (WEdit * edit)
1021 int char_length = 1;
1023 if (edit->column_highlight
1024 && option_cursor_beyond_eol
1025 && edit->mark1 != edit->mark2
1026 && edit->over_col == 0 && edit->buffer.curs1 == edit_buffer_get_current_bol (&edit->buffer))
1027 return;
1028 #ifdef HAVE_CHARSET
1029 if (edit->utf8)
1031 edit_buffer_get_prev_utf (&edit->buffer, edit->buffer.curs1, &char_length);
1032 if (char_length < 1)
1033 char_length = 1;
1035 #endif
1037 if (option_cursor_beyond_eol && edit->over_col > 0)
1038 edit->over_col--;
1039 else
1040 edit_cursor_move (edit, -char_length);
1043 /* --------------------------------------------------------------------------------------------- */
1044 /** Up or down cursor moving.
1045 direction = TRUE - move up
1046 = FALSE - move down
1049 static void
1050 edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean direction)
1052 long p;
1053 long l = direction ? edit->buffer.curs_line : edit->buffer.lines - edit->buffer.curs_line;
1055 if (lines > l)
1056 lines = l;
1058 if (lines == 0)
1059 return;
1061 if (lines > 1)
1062 edit->force |= REDRAW_PAGE;
1063 if (do_scroll)
1065 if (direction)
1066 edit_scroll_upward (edit, lines);
1067 else
1068 edit_scroll_downward (edit, lines);
1070 p = edit_buffer_get_current_bol (&edit->buffer);
1071 p = direction ? edit_buffer_get_backward_offset (&edit->buffer, p, lines) :
1072 edit_buffer_get_forward_offset (&edit->buffer, p, lines, 0);
1073 edit_cursor_move (edit, p - edit->buffer.curs1);
1074 edit_move_to_prev_col (edit, p);
1076 #ifdef HAVE_CHARSET
1077 /* search start of current multibyte char (like CJK) */
1078 if (edit->buffer.curs1 > 0 && edit->buffer.curs1 + 1 < edit->buffer.size
1079 && edit_buffer_get_current_byte (&edit->buffer) >= 256)
1081 edit_right_char_move_cmd (edit);
1082 edit_left_char_move_cmd (edit);
1084 #endif
1086 edit->search_start = edit->buffer.curs1;
1087 edit->found_len = 0;
1090 /* --------------------------------------------------------------------------------------------- */
1092 static void
1093 edit_right_delete_word (WEdit * edit)
1095 while (edit->buffer.curs1 < edit->buffer.size)
1097 int c1, c2;
1099 c1 = edit_delete (edit, TRUE);
1100 c2 = edit_buffer_get_current_byte (&edit->buffer);
1101 if (c1 == '\n' || c2 == '\n')
1102 break;
1103 if ((isspace (c1) == 0) != (isspace (c2) == 0))
1104 break;
1105 if ((my_type_of (c1) & my_type_of (c2)) == 0)
1106 break;
1110 /* --------------------------------------------------------------------------------------------- */
1112 static void
1113 edit_left_delete_word (WEdit * edit)
1115 while (edit->buffer.curs1 > 0)
1117 int c1, c2;
1119 c1 = edit_backspace (edit, TRUE);
1120 c2 = edit_buffer_get_previous_byte (&edit->buffer);
1121 if (c1 == '\n' || c2 == '\n')
1122 break;
1123 if ((isspace (c1) == 0) != (isspace (c2) == 0))
1124 break;
1125 if ((my_type_of (c1) & my_type_of (c2)) == 0)
1126 break;
1130 /* --------------------------------------------------------------------------------------------- */
1132 the start column position is not recorded, and hence does not
1133 undo as it happed. But who would notice.
1136 static void
1137 edit_do_undo (WEdit * edit)
1139 long ac;
1140 long count = 0;
1142 edit->undo_stack_disable = 1; /* don't record undo's onto undo stack! */
1143 edit->over_col = 0;
1144 while ((ac = edit_pop_undo_action (edit)) < KEY_PRESS)
1146 switch ((int) ac)
1148 case STACK_BOTTOM:
1149 goto done_undo;
1150 case CURS_RIGHT:
1151 edit_cursor_move (edit, 1);
1152 break;
1153 case CURS_LEFT:
1154 edit_cursor_move (edit, -1);
1155 break;
1156 case BACKSPACE:
1157 case BACKSPACE_BR:
1158 edit_backspace (edit, TRUE);
1159 break;
1160 case DELCHAR:
1161 case DELCHAR_BR:
1162 edit_delete (edit, TRUE);
1163 break;
1164 case COLUMN_ON:
1165 edit->column_highlight = 1;
1166 break;
1167 case COLUMN_OFF:
1168 edit->column_highlight = 0;
1169 break;
1170 default:
1171 break;
1173 if (ac >= 256 && ac < 512)
1174 edit_insert_ahead (edit, ac - 256);
1175 if (ac >= 0 && ac < 256)
1176 edit_insert (edit, ac);
1178 if (ac >= MARK_1 - 2 && ac < MARK_2 - 2)
1180 edit->mark1 = ac - MARK_1;
1181 edit->column1 =
1182 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1),
1183 0, edit->mark1);
1185 if (ac >= MARK_2 - 2 && ac < MARK_CURS - 2)
1187 edit->mark2 = ac - MARK_2;
1188 edit->column2 =
1189 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2),
1190 0, edit->mark2);
1192 else if (ac >= MARK_CURS - 2 && ac < KEY_PRESS)
1194 edit->end_mark_curs = ac - MARK_CURS;
1196 if (count++)
1197 edit->force |= REDRAW_PAGE; /* more than one pop usually means something big */
1200 if (edit->start_display > ac - KEY_PRESS)
1202 edit->start_line -=
1203 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display);
1204 edit->force |= REDRAW_PAGE;
1206 else if (edit->start_display < ac - KEY_PRESS)
1208 edit->start_line +=
1209 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS);
1210 edit->force |= REDRAW_PAGE;
1212 edit->start_display = ac - KEY_PRESS; /* see push and pop above */
1213 edit_update_curs_row (edit);
1215 done_undo:
1216 edit->undo_stack_disable = 0;
1219 /* --------------------------------------------------------------------------------------------- */
1221 static void
1222 edit_do_redo (WEdit * edit)
1224 long ac;
1225 long count = 0;
1227 if (edit->redo_stack_reset)
1228 return;
1230 edit->over_col = 0;
1231 while ((ac = edit_pop_redo_action (edit)) < KEY_PRESS)
1233 switch ((int) ac)
1235 case STACK_BOTTOM:
1236 goto done_redo;
1237 case CURS_RIGHT:
1238 edit_cursor_move (edit, 1);
1239 break;
1240 case CURS_LEFT:
1241 edit_cursor_move (edit, -1);
1242 break;
1243 case BACKSPACE:
1244 edit_backspace (edit, TRUE);
1245 break;
1246 case DELCHAR:
1247 edit_delete (edit, TRUE);
1248 break;
1249 case COLUMN_ON:
1250 edit->column_highlight = 1;
1251 break;
1252 case COLUMN_OFF:
1253 edit->column_highlight = 0;
1254 break;
1255 default:
1256 break;
1258 if (ac >= 256 && ac < 512)
1259 edit_insert_ahead (edit, ac - 256);
1260 if (ac >= 0 && ac < 256)
1261 edit_insert (edit, ac);
1263 if (ac >= MARK_1 - 2 && ac < MARK_2 - 2)
1265 edit->mark1 = ac - MARK_1;
1266 edit->column1 =
1267 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark1),
1268 0, edit->mark1);
1270 else if (ac >= MARK_2 - 2 && ac < KEY_PRESS)
1272 edit->mark2 = ac - MARK_2;
1273 edit->column2 =
1274 (long) edit_move_forward3 (edit, edit_buffer_get_bol (&edit->buffer, edit->mark2),
1275 0, edit->mark2);
1277 /* more than one pop usually means something big */
1278 if (count++)
1279 edit->force |= REDRAW_PAGE;
1282 if (edit->start_display > ac - KEY_PRESS)
1284 edit->start_line -=
1285 edit_buffer_count_lines (&edit->buffer, ac - KEY_PRESS, edit->start_display);
1286 edit->force |= REDRAW_PAGE;
1288 else if (edit->start_display < ac - KEY_PRESS)
1290 edit->start_line +=
1291 edit_buffer_count_lines (&edit->buffer, edit->start_display, ac - KEY_PRESS);
1292 edit->force |= REDRAW_PAGE;
1294 edit->start_display = ac - KEY_PRESS; /* see push and pop above */
1295 edit_update_curs_row (edit);
1297 done_redo:
1301 /* --------------------------------------------------------------------------------------------- */
1303 static void
1304 edit_group_undo (WEdit * edit)
1306 long ac = KEY_PRESS;
1307 long cur_ac = KEY_PRESS;
1308 while (ac != STACK_BOTTOM && ac == cur_ac)
1310 cur_ac = get_prev_undo_action (edit);
1311 edit_do_undo (edit);
1312 ac = get_prev_undo_action (edit);
1313 /* exit from cycle if option_group_undo is not set,
1314 * and make single UNDO operation
1316 if (!option_group_undo)
1317 ac = STACK_BOTTOM;
1321 /* --------------------------------------------------------------------------------------------- */
1323 static void
1324 edit_delete_to_line_end (WEdit * edit)
1326 while (edit_buffer_get_current_byte (&edit->buffer) != '\n' && edit->buffer.curs2 != 0)
1327 edit_delete (edit, TRUE);
1330 /* --------------------------------------------------------------------------------------------- */
1332 static void
1333 edit_delete_to_line_begin (WEdit * edit)
1335 while (edit_buffer_get_previous_byte (&edit->buffer) != '\n' && edit->buffer.curs1 != 0)
1336 edit_backspace (edit, TRUE);
1339 /* --------------------------------------------------------------------------------------------- */
1341 static gboolean
1342 is_aligned_on_a_tab (WEdit * edit)
1344 long curs_col;
1346 edit_update_curs_col (edit);
1347 curs_col = edit->curs_col % (TAB_SIZE * space_width);
1348 return (curs_col == 0 || curs_col == (HALF_TAB_SIZE * space_width));
1351 /* --------------------------------------------------------------------------------------------- */
1353 static gboolean
1354 right_of_four_spaces (WEdit * edit)
1356 int i, ch = 0;
1358 for (i = 1; i <= HALF_TAB_SIZE; i++)
1359 ch |= edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1 - i);
1361 return (ch == ' ' && is_aligned_on_a_tab (edit));
1364 /* --------------------------------------------------------------------------------------------- */
1366 static gboolean
1367 left_of_four_spaces (WEdit * edit)
1369 int i, ch = 0;
1371 for (i = 0; i < HALF_TAB_SIZE; i++)
1372 ch |= edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1 + i);
1374 return (ch == ' ' && is_aligned_on_a_tab (edit));
1377 /* --------------------------------------------------------------------------------------------- */
1379 static void
1380 edit_auto_indent (WEdit * edit)
1382 off_t p;
1384 p = edit->buffer.curs1;
1385 /* use the previous line as a template */
1386 p = edit_buffer_get_backward_offset (&edit->buffer, p, 1);
1387 /* copy the leading whitespace of the line */
1388 while (TRUE)
1389 { /* no range check - the line _is_ \n-terminated */
1390 char c;
1392 c = edit_buffer_get_byte (&edit->buffer, p++);
1393 if (c != ' ' && c != '\t')
1394 break;
1395 edit_insert (edit, c);
1399 /* --------------------------------------------------------------------------------------------- */
1401 static inline void
1402 edit_double_newline (WEdit * edit)
1404 edit_insert (edit, '\n');
1405 if (edit_buffer_get_current_byte (&edit->buffer) == '\n'
1406 || edit_buffer_get_byte (&edit->buffer, edit->buffer.curs1 - 2) == '\n')
1407 return;
1408 edit->force |= REDRAW_PAGE;
1409 edit_insert (edit, '\n');
1412 /* --------------------------------------------------------------------------------------------- */
1414 static void
1415 insert_spaces_tab (WEdit * edit, gboolean half)
1417 long i;
1419 edit_update_curs_col (edit);
1420 i = option_tab_spacing * space_width;
1421 if (half)
1422 i /= 2;
1423 if (i != 0)
1425 i = ((edit->curs_col / i) + 1) * i - edit->curs_col;
1426 while (i > 0)
1428 edit_insert (edit, ' ');
1429 i -= space_width;
1434 /* --------------------------------------------------------------------------------------------- */
1436 static inline void
1437 edit_tab_cmd (WEdit * edit)
1439 if (option_fake_half_tabs && is_in_indent (&edit->buffer))
1441 /* insert a half tab (usually four spaces) unless there is a
1442 half tab already behind, then delete it and insert a
1443 full tab. */
1444 if (option_fill_tabs_with_spaces || !right_of_four_spaces (edit))
1445 insert_spaces_tab (edit, TRUE);
1446 else
1448 int i;
1450 for (i = 1; i <= HALF_TAB_SIZE; i++)
1451 edit_backspace (edit, TRUE);
1452 edit_insert (edit, '\t');
1455 else if (option_fill_tabs_with_spaces)
1456 insert_spaces_tab (edit, FALSE);
1457 else
1458 edit_insert (edit, '\t');
1461 /* --------------------------------------------------------------------------------------------- */
1463 static void
1464 check_and_wrap_line (WEdit * edit)
1466 off_t curs;
1468 if (!option_typewriter_wrap)
1469 return;
1470 edit_update_curs_col (edit);
1471 if (edit->curs_col < option_word_wrap_line_length)
1472 return;
1473 curs = edit->buffer.curs1;
1474 while (TRUE)
1476 int c;
1478 curs--;
1479 c = edit_buffer_get_byte (&edit->buffer, curs);
1480 if (c == '\n' || curs <= 0)
1482 edit_insert (edit, '\n');
1483 return;
1485 if (c == ' ' || c == '\t')
1487 off_t current = edit->buffer.curs1;
1488 edit_cursor_move (edit, curs - edit->buffer.curs1 + 1);
1489 edit_insert (edit, '\n');
1490 edit_cursor_move (edit, current - edit->buffer.curs1 + 1);
1491 return;
1496 /* --------------------------------------------------------------------------------------------- */
1497 /** this find the matching bracket in either direction, and sets edit->bracket
1499 * @param edit editor object
1500 * @param in_screen seach only on the current screen
1501 * @param furthest_bracket_search count of the bytes for search
1503 * @return position of the found bracket (-1 if no match)
1506 static off_t
1507 edit_get_bracket (WEdit * edit, gboolean in_screen, unsigned long furthest_bracket_search)
1509 const char *const b = "{}{[][()(", *p;
1510 int i = 1, inc = -1, c, d, n = 0;
1511 unsigned long j = 0;
1512 off_t q;
1514 edit_update_curs_row (edit);
1515 c = edit_buffer_get_current_byte (&edit->buffer);
1516 p = strchr (b, c);
1517 /* not on a bracket at all */
1518 if (p == NULL || *p == '\0')
1519 return -1;
1520 /* the matching bracket */
1521 d = p[1];
1522 /* going left or right? */
1523 if (strchr ("{[(", c) != NULL)
1524 inc = 1;
1525 /* no limit */
1526 if (furthest_bracket_search == 0)
1527 furthest_bracket_search--; /* ULONG_MAX */
1528 for (q = edit->buffer.curs1 + inc;; q += inc)
1530 int a;
1532 /* out of buffer? */
1533 if (q >= edit->buffer.size || q < 0)
1534 break;
1535 a = edit_buffer_get_byte (&edit->buffer, q);
1536 /* don't want to eat CPU */
1537 if (j++ > furthest_bracket_search)
1538 break;
1539 /* out of screen? */
1540 if (in_screen)
1542 if (q < edit->start_display)
1543 break;
1544 /* count lines if searching downward */
1545 if (inc > 0 && a == '\n')
1546 if (n++ >= WIDGET (edit)->lines - edit->curs_row) /* out of screen */
1547 break;
1549 /* count bracket depth */
1550 i += (a == c) - (a == d);
1551 /* return if bracket depth is zero */
1552 if (i == 0)
1553 return q;
1555 /* no match */
1556 return -1;
1559 /* --------------------------------------------------------------------------------------------- */
1561 static inline void
1562 edit_goto_matching_bracket (WEdit * edit)
1564 off_t q;
1566 q = edit_get_bracket (edit, 0, 0);
1567 if (q >= 0)
1569 edit->bracket = edit->buffer.curs1;
1570 edit->force |= REDRAW_PAGE;
1571 edit_cursor_move (edit, q - edit->buffer.curs1);
1575 /* --------------------------------------------------------------------------------------------- */
1577 static void
1578 edit_move_block_to_right (WEdit * edit)
1580 off_t start_mark, end_mark;
1581 long cur_bol, start_bol;
1583 if (!eval_marks (edit, &start_mark, &end_mark))
1584 return;
1586 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark);
1587 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1);
1591 edit_cursor_move (edit, cur_bol - edit->buffer.curs1);
1592 if (!edit_line_is_blank (edit, edit->buffer.curs_line))
1594 if (option_fill_tabs_with_spaces)
1595 insert_spaces_tab (edit, option_fake_half_tabs);
1596 else
1597 edit_insert (edit, '\t');
1598 edit_cursor_move (edit,
1599 edit_buffer_get_bol (&edit->buffer, cur_bol) - edit->buffer.curs1);
1602 if (cur_bol == 0)
1603 break;
1605 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1);
1607 while (cur_bol >= start_bol);
1609 edit->force |= REDRAW_PAGE;
1612 /* --------------------------------------------------------------------------------------------- */
1614 static void
1615 edit_move_block_to_left (WEdit * edit)
1617 off_t start_mark, end_mark;
1618 off_t cur_bol, start_bol;
1619 int i;
1621 if (!eval_marks (edit, &start_mark, &end_mark))
1622 return;
1624 start_bol = edit_buffer_get_bol (&edit->buffer, start_mark);
1625 cur_bol = edit_buffer_get_bol (&edit->buffer, end_mark - 1);
1629 int del_tab_width;
1630 int next_char;
1632 edit_cursor_move (edit, cur_bol - edit->buffer.curs1);
1634 if (option_fake_half_tabs)
1635 del_tab_width = HALF_TAB_SIZE;
1636 else
1637 del_tab_width = option_tab_spacing;
1639 next_char = edit_buffer_get_current_byte (&edit->buffer);
1640 if (next_char == '\t')
1641 edit_delete (edit, TRUE);
1642 else if (next_char == ' ')
1643 for (i = 1; i <= del_tab_width; i++)
1645 if (next_char == ' ')
1646 edit_delete (edit, TRUE);
1647 next_char = edit_buffer_get_current_byte (&edit->buffer);
1650 if (cur_bol == 0)
1651 break;
1653 cur_bol = edit_buffer_get_bol (&edit->buffer, cur_bol - 1);
1655 while (cur_bol >= start_bol);
1657 edit->force |= REDRAW_PAGE;
1660 /* --------------------------------------------------------------------------------------------- */
1662 * prints at the cursor
1663 * @return number of chars printed
1666 static size_t
1667 edit_print_string (WEdit * e, const char *s)
1669 size_t i = 0;
1671 while (s[i] != '\0')
1672 edit_execute_cmd (e, CK_InsertChar, (unsigned char) s[i++]);
1673 e->force |= REDRAW_COMPLETELY;
1674 edit_update_screen (e);
1675 return i;
1678 /* --------------------------------------------------------------------------------------------- */
1680 static off_t
1681 edit_insert_column_from_file (WEdit * edit, int file, off_t * start_pos, off_t * end_pos,
1682 long *col1, long *col2)
1684 off_t cursor;
1685 long col;
1686 off_t blocklen = -1, width = 0;
1687 unsigned char *data;
1689 cursor = edit->buffer.curs1;
1690 col = edit_get_col (edit);
1691 data = g_malloc0 (TEMP_BUF_LEN);
1693 while ((blocklen = mc_read (file, (char *) data, TEMP_BUF_LEN)) > 0)
1695 off_t i;
1696 char *pn;
1698 pn = strchr ((char *) data, '\n');
1699 width = pn == NULL ? blocklen : pn - (char *) data;
1701 for (i = 0; i < blocklen; i++)
1703 if (data[i] != '\n')
1704 edit_insert (edit, data[i]);
1705 else
1706 { /* fill in and move to next line */
1707 long l;
1708 off_t p;
1710 if (edit_buffer_get_current_byte (&edit->buffer) != '\n')
1711 for (l = width - (edit_get_col (edit) - col); l > 0; l -= space_width)
1712 edit_insert (edit, ' ');
1714 for (p = edit->buffer.curs1;; p++)
1716 if (p == edit->buffer.size)
1718 edit_cursor_move (edit, edit->buffer.size - edit->buffer.curs1);
1719 edit_insert_ahead (edit, '\n');
1720 p++;
1721 break;
1723 if (edit_buffer_get_byte (&edit->buffer, p) == '\n')
1725 p++;
1726 break;
1730 edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->buffer.curs1);
1732 for (l = col - edit_get_col (edit); l >= space_width; l -= space_width)
1733 edit_insert (edit, ' ');
1737 *col1 = col;
1738 *col2 = col + width;
1739 *start_pos = cursor;
1740 *end_pos = edit->buffer.curs1;
1741 edit_cursor_move (edit, cursor - edit->buffer.curs1);
1742 g_free (data);
1744 return blocklen;
1747 /* --------------------------------------------------------------------------------------------- */
1748 /*** public functions ****************************************************************************/
1749 /* --------------------------------------------------------------------------------------------- */
1751 /** User edit menu, like user menu (F2) but only in editor. */
1753 void
1754 user_menu (WEdit * edit, const char *menu_file, int selected_entry)
1756 char *block_file;
1757 gboolean nomark;
1758 off_t curs;
1759 off_t start_mark, end_mark;
1760 struct stat status;
1761 vfs_path_t *block_file_vpath;
1763 block_file = mc_config_get_full_path (EDIT_BLOCK_FILE);
1764 block_file_vpath = vfs_path_from_str (block_file);
1765 curs = edit->buffer.curs1;
1766 nomark = !eval_marks (edit, &start_mark, &end_mark);
1767 if (!nomark)
1768 edit_save_block (edit, block_file, start_mark, end_mark);
1770 /* run shell scripts from menu */
1771 if (user_menu_cmd (edit, menu_file, selected_entry)
1772 && (mc_stat (block_file_vpath, &status) == 0) && (status.st_size != 0))
1774 int rc = 0;
1775 FILE *fd;
1777 /* i.e. we have marked block */
1778 if (!nomark)
1779 rc = edit_block_delete_cmd (edit);
1781 if (rc == 0)
1783 off_t ins_len;
1785 ins_len = edit_insert_file (edit, block_file_vpath);
1786 if (!nomark && ins_len > 0)
1787 edit_set_markers (edit, start_mark, start_mark + ins_len, 0, 0);
1789 /* truncate block file */
1790 fd = fopen (block_file, "w");
1791 if (fd != NULL)
1792 fclose (fd);
1794 g_free (block_file);
1795 vfs_path_free (block_file_vpath);
1797 edit_cursor_move (edit, curs - edit->buffer.curs1);
1798 edit->force |= REDRAW_PAGE;
1799 widget_redraw (WIDGET (edit));
1802 /* --------------------------------------------------------------------------------------------- */
1804 char *
1805 edit_get_write_filter (const vfs_path_t * write_name_vpath, const vfs_path_t * filename_vpath)
1807 int i;
1808 char *p, *writename;
1809 const vfs_path_element_t *path_element;
1811 i = edit_find_filter (filename_vpath);
1812 if (i < 0)
1813 return NULL;
1815 path_element = vfs_path_get_by_index (write_name_vpath, -1);
1816 writename = name_quote (path_element->path, FALSE);
1817 p = g_strdup_printf (all_filters[i].write, writename);
1818 g_free (writename);
1819 return p;
1822 /* --------------------------------------------------------------------------------------------- */
1824 * @param edit editor object
1825 * @param f value of stream file
1826 * @return the length of the file
1829 off_t
1830 edit_write_stream (WEdit * edit, FILE * f)
1832 long i;
1834 if (edit->lb == LB_ASIS)
1836 for (i = 0; i < edit->buffer.size; i++)
1837 if (fputc (edit_buffer_get_byte (&edit->buffer, i), f) < 0)
1838 break;
1839 return i;
1842 /* change line breaks */
1843 for (i = 0; i < edit->buffer.size; i++)
1845 unsigned char c;
1847 c = edit_buffer_get_byte (&edit->buffer, i);
1848 if (!(c == '\n' || c == '\r'))
1850 /* not line break */
1851 if (fputc (c, f) < 0)
1852 return i;
1854 else
1855 { /* (c == '\n' || c == '\r') */
1856 unsigned char c1;
1858 c1 = edit_buffer_get_byte (&edit->buffer, i + 1); /* next char */
1860 switch (edit->lb)
1862 case LB_UNIX: /* replace "\r\n" or '\r' to '\n' */
1863 /* put one line break unconditionally */
1864 if (fputc ('\n', f) < 0)
1865 return i;
1867 i++; /* 2 chars are processed */
1869 if (c == '\r' && c1 == '\n')
1870 /* Windows line break; go to the next char */
1871 break;
1873 if (c == '\r' && c1 == '\r')
1875 /* two Macintosh line breaks; put second line break */
1876 if (fputc ('\n', f) < 0)
1877 return i;
1878 break;
1881 if (fputc (c1, f) < 0)
1882 return i;
1883 break;
1885 case LB_WIN: /* replace '\n' or '\r' to "\r\n" */
1886 /* put one line break unconditionally */
1887 if (fputc ('\r', f) < 0 || fputc ('\n', f) < 0)
1888 return i;
1890 if (c == '\r' && c1 == '\n')
1891 /* Windows line break; go to the next char */
1892 i++;
1893 break;
1895 case LB_MAC: /* replace "\r\n" or '\n' to '\r' */
1896 /* put one line break unconditionally */
1897 if (fputc ('\r', f) < 0)
1898 return i;
1900 i++; /* 2 chars are processed */
1902 if (c == '\r' && c1 == '\n')
1903 /* Windows line break; go to the next char */
1904 break;
1906 if (c == '\n' && c1 == '\n')
1908 /* two Windows line breaks; put second line break */
1909 if (fputc ('\r', f) < 0)
1910 return i;
1911 break;
1914 if (fputc (c1, f) < 0)
1915 return i;
1916 break;
1917 case LB_ASIS: /* default without changes */
1918 default:
1919 break;
1924 return edit->buffer.size;
1927 /* --------------------------------------------------------------------------------------------- */
1929 gboolean
1930 is_break_char (char c)
1932 return (isspace (c) || strchr ("{}[]()<>=|/\\!?~-+`'\",.;:#$%^&*", c));
1935 /* --------------------------------------------------------------------------------------------- */
1936 /** inserts a file at the cursor, returns count of inserted bytes on success */
1938 off_t
1939 edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath)
1941 char *p;
1942 off_t current;
1943 off_t ins_len = 0;
1945 p = edit_get_filter (filename_vpath);
1946 current = edit->buffer.curs1;
1948 if (p != NULL)
1950 FILE *f;
1952 f = (FILE *) popen (p, "r");
1953 if (f != NULL)
1955 edit_insert_stream (edit, f);
1957 /* Place cursor at the end of text selection */
1958 if (!option_cursor_after_inserted_block)
1960 ins_len = edit->buffer.curs1 - current;
1961 edit_cursor_move (edit, -ins_len);
1963 if (pclose (f) > 0)
1965 char *errmsg;
1967 errmsg = g_strdup_printf (_("Error reading from pipe: %s"), p);
1968 edit_error_dialog (_("Error"), errmsg);
1969 g_free (errmsg);
1970 ins_len = -1;
1973 else
1975 char *errmsg;
1977 errmsg = g_strdup_printf (_("Cannot open pipe for reading: %s"), p);
1978 edit_error_dialog (_("Error"), errmsg);
1979 g_free (errmsg);
1980 ins_len = -1;
1982 g_free (p);
1984 else
1986 int file;
1987 off_t blocklen;
1988 int vertical_insertion = 0;
1989 char *buf;
1991 file = mc_open (filename_vpath, O_RDONLY | O_BINARY);
1992 if (file == -1)
1993 return -1;
1995 buf = g_malloc0 (TEMP_BUF_LEN);
1996 blocklen = mc_read (file, buf, sizeof (VERTICAL_MAGIC));
1997 if (blocklen > 0)
1999 /* if contain signature VERTICAL_MAGIC then it vertical block */
2000 if (memcmp (buf, VERTICAL_MAGIC, sizeof (VERTICAL_MAGIC)) == 0)
2001 vertical_insertion = 1;
2002 else
2003 mc_lseek (file, 0, SEEK_SET);
2006 if (vertical_insertion)
2008 off_t mark1, mark2;
2009 long c1, c2;
2011 blocklen = edit_insert_column_from_file (edit, file, &mark1, &mark2, &c1, &c2);
2012 edit_set_markers (edit, edit->buffer.curs1, mark2, c1, c2);
2014 /* highlight inserted text then not persistent blocks */
2015 if (!option_persistent_selections && edit->modified)
2017 if (!edit->column_highlight)
2018 edit_push_undo_action (edit, COLUMN_OFF);
2019 edit->column_highlight = 1;
2022 else
2024 off_t i;
2026 while ((blocklen = mc_read (file, (char *) buf, TEMP_BUF_LEN)) > 0)
2028 for (i = 0; i < blocklen; i++)
2029 edit_insert (edit, buf[i]);
2031 /* highlight inserted text then not persistent blocks */
2032 if (!option_persistent_selections && edit->modified)
2034 edit_set_markers (edit, edit->buffer.curs1, current, 0, 0);
2035 if (edit->column_highlight)
2036 edit_push_undo_action (edit, COLUMN_ON);
2037 edit->column_highlight = 0;
2040 /* Place cursor at the end of text selection */
2041 if (!option_cursor_after_inserted_block)
2043 ins_len = edit->buffer.curs1 - current;
2044 edit_cursor_move (edit, -ins_len);
2048 edit->force |= REDRAW_PAGE;
2049 g_free (buf);
2050 mc_close (file);
2051 if (blocklen != 0)
2052 ins_len = 0;
2055 return ins_len;
2058 /* --------------------------------------------------------------------------------------------- */
2060 * Fill in the edit structure. Return NULL on failure. Pass edit as
2061 * NULL to allocate a new structure.
2063 * If line is 0, try to restore saved position. Otherwise put the
2064 * cursor on that line and show it in the middle of the screen.
2067 WEdit *
2068 edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * filename_vpath,
2069 long line)
2071 gboolean to_free = FALSE;
2073 option_auto_syntax = 1; /* Resetting to auto on every invokation */
2074 option_line_state_width = option_line_state ? LINE_STATE_WIDTH : 0;
2076 if (edit != NULL)
2078 /* save some widget parameters */
2079 gboolean fullscreen = edit->fullscreen;
2080 int y_prev = edit->y_prev;
2081 int x_prev = edit->x_prev;
2082 int lines_prev = edit->lines_prev;
2083 int cols_prev = edit->cols_prev;
2085 edit_purge_widget (edit);
2087 /* restore saved parameters */
2088 edit->fullscreen = fullscreen;
2089 edit->y_prev = y_prev;
2090 edit->x_prev = x_prev;
2091 edit->lines_prev = lines_prev;
2092 edit->cols_prev = cols_prev;
2094 else
2096 edit = g_malloc0 (sizeof (WEdit));
2097 to_free = TRUE;
2099 widget_init (WIDGET (edit), y, x, lines, cols, NULL, NULL);
2100 edit->fullscreen = TRUE;
2101 edit_save_size (edit);
2104 edit->drag_state = MCEDIT_DRAG_NONE;
2106 edit->stat1.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
2107 edit->stat1.st_uid = getuid ();
2108 edit->stat1.st_gid = getgid ();
2109 edit->stat1.st_mtime = 0;
2111 edit->over_col = 0;
2112 edit->bracket = -1;
2113 edit->last_bracket = -1;
2114 edit->force |= REDRAW_PAGE;
2116 /* set file name before load file */
2117 edit_set_filename (edit, filename_vpath);
2119 edit->undo_stack_size = START_STACK_SIZE;
2120 edit->undo_stack_size_mask = START_STACK_SIZE - 1;
2121 edit->undo_stack = g_malloc0 ((edit->undo_stack_size + 10) * sizeof (long));
2123 edit->redo_stack_size = START_STACK_SIZE;
2124 edit->redo_stack_size_mask = START_STACK_SIZE - 1;
2125 edit->redo_stack = g_malloc0 ((edit->redo_stack_size + 10) * sizeof (long));
2127 #ifdef HAVE_CHARSET
2128 edit->utf8 = FALSE;
2129 edit->converter = str_cnv_from_term;
2130 edit_set_codeset (edit);
2131 #endif
2133 if (!edit_load_file (edit))
2135 /* edit_load_file already gives an error message */
2136 if (to_free)
2137 g_free (edit);
2138 return NULL;
2141 edit->loading_done = 1;
2142 edit->modified = 0;
2143 edit->locked = 0;
2144 edit_load_syntax (edit, NULL, NULL);
2145 edit_get_syntax_color (edit, -1);
2147 /* load saved cursor position */
2148 if ((line == 0) && option_save_position)
2149 edit_load_position (edit);
2150 else
2152 if (line <= 0)
2153 line = 1;
2154 edit_move_display (edit, line - 1);
2155 edit_move_to_line (edit, line - 1);
2158 edit_load_macro_cmd (edit);
2160 return edit;
2163 /* --------------------------------------------------------------------------------------------- */
2165 /** Clear the edit struct, freeing everything in it. Return TRUE on success */
2166 gboolean
2167 edit_clean (WEdit * edit)
2169 if (edit == NULL)
2170 return FALSE;
2172 /* a stale lock, remove it */
2173 if (edit->locked)
2174 edit->locked = unlock_file (edit->filename_vpath);
2176 /* save cursor position */
2177 if (option_save_position)
2178 edit_save_position (edit);
2179 else if (edit->serialized_bookmarks != NULL)
2180 edit->serialized_bookmarks = (GArray *) g_array_free (edit->serialized_bookmarks, TRUE);
2182 /* File specified on the mcedit command line and never saved */
2183 if (edit->delete_file)
2184 unlink (vfs_path_get_last_path_str (edit->filename_vpath));
2186 edit_free_syntax_rules (edit);
2187 book_mark_flush (edit, -1);
2189 edit_buffer_clean (&edit->buffer);
2191 g_free (edit->undo_stack);
2192 g_free (edit->redo_stack);
2193 vfs_path_free (edit->filename_vpath);
2194 vfs_path_free (edit->dir_vpath);
2195 mc_search_free (edit->search);
2196 edit->search = NULL;
2197 MC_PTR_FREE (edit->last_search_string);
2199 #ifdef HAVE_CHARSET
2200 if (edit->converter != str_cnv_from_term)
2201 str_close_conv (edit->converter);
2202 #endif
2204 edit_purge_widget (edit);
2206 return TRUE;
2209 /* --------------------------------------------------------------------------------------------- */
2212 * Load a new file into the editor and set line. If it fails, preserve the old file.
2213 * To do it, allocate a new widget, initialize it and, if the new file
2214 * was loaded, copy the data to the old widget.
2216 * @return TRUE on success, FALSE on failure.
2218 gboolean
2219 edit_reload_line (WEdit * edit, const vfs_path_t * filename_vpath, long line)
2221 Widget *w = WIDGET (edit);
2222 WEdit *e;
2224 e = g_malloc0 (sizeof (WEdit));
2225 *WIDGET (e) = *w;
2226 /* save some widget parameters */
2227 e->fullscreen = edit->fullscreen;
2228 e->y_prev = edit->y_prev;
2229 e->x_prev = edit->x_prev;
2230 e->lines_prev = edit->lines_prev;
2231 e->cols_prev = edit->cols_prev;
2233 if (edit_init (e, w->y, w->x, w->lines, w->cols, filename_vpath, line) == NULL)
2235 g_free (e);
2236 return FALSE;
2239 edit_clean (edit);
2240 memcpy (edit, e, sizeof (*edit));
2241 g_free (e);
2243 return TRUE;
2246 /* --------------------------------------------------------------------------------------------- */
2248 #ifdef HAVE_CHARSET
2249 void
2250 edit_set_codeset (WEdit * edit)
2252 const char *cp_id;
2254 cp_id =
2255 get_codepage_id (mc_global.source_codepage >=
2256 0 ? mc_global.source_codepage : mc_global.display_codepage);
2258 if (cp_id != NULL)
2260 GIConv conv;
2261 conv = str_crt_conv_from (cp_id);
2262 if (conv != INVALID_CONV)
2264 if (edit->converter != str_cnv_from_term)
2265 str_close_conv (edit->converter);
2266 edit->converter = conv;
2270 if (cp_id != NULL)
2271 edit->utf8 = str_isutf8 (cp_id);
2273 #endif
2275 /* --------------------------------------------------------------------------------------------- */
2278 * Recording stack for undo:
2279 * The following is an implementation of a compressed stack. Identical
2280 * pushes are recorded by a negative prefix indicating the number of times the
2281 * same char was pushed. This saves space for repeated curs-left or curs-right
2282 * delete etc.
2284 * eg:
2286 * pushed: stored:
2289 * b a
2290 * b -3
2291 * b b
2292 * c --> -4
2293 * c c
2294 * c d
2298 * If the stack long int is 0-255 it represents a normal insert (from a backspace),
2299 * 256-512 is an insert ahead (from a delete), If it is betwen 600 and 700 it is one
2300 * of the cursor functions define'd in edit-impl.h. 1000 through 700'000'000 is to
2301 * set edit->mark1 position. 700'000'000 through 1400'000'000 is to set edit->mark2
2302 * position.
2304 * The only way the cursor moves or the buffer is changed is through the routines:
2305 * insert, backspace, insert_ahead, delete, and cursor_move.
2306 * These record the reverse undo movements onto the stack each time they are
2307 * called.
2309 * Each key press results in a set of actions (insert; delete ...). So each time
2310 * a key is pressed the current position of start_display is pushed as
2311 * KEY_PRESS + start_display. Then for undoing, we pop until we get to a number
2312 * over KEY_PRESS. We then assign this number less KEY_PRESS to start_display. So undo
2313 * tracks scrolling and key actions exactly. (KEY_PRESS is about (2^31) * (2/3) = 1400'000'000)
2317 * @param edit editor object
2318 * @param c code of the action
2321 void
2322 edit_push_undo_action (WEdit * edit, long c)
2324 unsigned long sp = edit->undo_stack_pointer;
2325 unsigned long spm1;
2326 long *t;
2328 /* first enlarge the stack if necessary */
2329 if (sp > edit->undo_stack_size - 10)
2330 { /* say */
2331 if (option_max_undo < 256)
2332 option_max_undo = 256;
2333 if (edit->undo_stack_size < (unsigned long) option_max_undo)
2335 t = g_realloc (edit->undo_stack, (edit->undo_stack_size * 2 + 10) * sizeof (long));
2336 if (t)
2338 edit->undo_stack = t;
2339 edit->undo_stack_size <<= 1;
2340 edit->undo_stack_size_mask = edit->undo_stack_size - 1;
2344 spm1 = (edit->undo_stack_pointer - 1) & edit->undo_stack_size_mask;
2345 if (edit->undo_stack_disable)
2347 edit_push_redo_action (edit, KEY_PRESS);
2348 edit_push_redo_action (edit, c);
2349 return;
2352 if (edit->redo_stack_reset)
2353 edit->redo_stack_bottom = edit->redo_stack_pointer = 0;
2355 if (edit->undo_stack_bottom != sp
2356 && spm1 != edit->undo_stack_bottom
2357 && ((sp - 2) & edit->undo_stack_size_mask) != edit->undo_stack_bottom)
2359 long d;
2360 if (edit->undo_stack[spm1] < 0)
2362 d = edit->undo_stack[(sp - 2) & edit->undo_stack_size_mask];
2363 if (d == c && edit->undo_stack[spm1] > -1000000000)
2365 if (c < KEY_PRESS) /* --> no need to push multiple do-nothings */
2366 edit->undo_stack[spm1]--;
2367 return;
2370 else
2372 d = edit->undo_stack[spm1];
2373 if (d == c)
2375 if (c >= KEY_PRESS)
2376 return; /* --> no need to push multiple do-nothings */
2377 edit->undo_stack[sp] = -2;
2378 goto check_bottom;
2382 edit->undo_stack[sp] = c;
2384 check_bottom:
2385 edit->undo_stack_pointer = (edit->undo_stack_pointer + 1) & edit->undo_stack_size_mask;
2387 /* if the sp wraps round and catches the undo_stack_bottom then erase
2388 * the first set of actions on the stack to make space - by moving
2389 * undo_stack_bottom forward one "key press" */
2390 c = (edit->undo_stack_pointer + 2) & edit->undo_stack_size_mask;
2391 if ((unsigned long) c == edit->undo_stack_bottom ||
2392 (((unsigned long) c + 1) & edit->undo_stack_size_mask) == edit->undo_stack_bottom)
2395 edit->undo_stack_bottom = (edit->undo_stack_bottom + 1) & edit->undo_stack_size_mask;
2397 while (edit->undo_stack[edit->undo_stack_bottom] < KEY_PRESS
2398 && edit->undo_stack_bottom != edit->undo_stack_pointer);
2400 /*If a single key produced enough pushes to wrap all the way round then we would notice that the [undo_stack_bottom] does not contain KEY_PRESS. The stack is then initialised: */
2401 if (edit->undo_stack_pointer != edit->undo_stack_bottom
2402 && edit->undo_stack[edit->undo_stack_bottom] < KEY_PRESS)
2404 edit->undo_stack_bottom = edit->undo_stack_pointer = 0;
2408 /* --------------------------------------------------------------------------------------------- */
2410 void
2411 edit_push_redo_action (WEdit * edit, long c)
2413 unsigned long sp = edit->redo_stack_pointer;
2414 unsigned long spm1;
2415 long *t;
2416 /* first enlarge the stack if necessary */
2417 if (sp > edit->redo_stack_size - 10)
2418 { /* say */
2419 if (option_max_undo < 256)
2420 option_max_undo = 256;
2421 if (edit->redo_stack_size < (unsigned long) option_max_undo)
2423 t = g_realloc (edit->redo_stack, (edit->redo_stack_size * 2 + 10) * sizeof (long));
2424 if (t)
2426 edit->redo_stack = t;
2427 edit->redo_stack_size <<= 1;
2428 edit->redo_stack_size_mask = edit->redo_stack_size - 1;
2432 spm1 = (edit->redo_stack_pointer - 1) & edit->redo_stack_size_mask;
2434 if (edit->redo_stack_bottom != sp
2435 && spm1 != edit->redo_stack_bottom
2436 && ((sp - 2) & edit->redo_stack_size_mask) != edit->redo_stack_bottom)
2438 long d;
2439 if (edit->redo_stack[spm1] < 0)
2441 d = edit->redo_stack[(sp - 2) & edit->redo_stack_size_mask];
2442 if (d == c && edit->redo_stack[spm1] > -1000000000)
2444 if (c < KEY_PRESS) /* --> no need to push multiple do-nothings */
2445 edit->redo_stack[spm1]--;
2446 return;
2449 else
2451 d = edit->redo_stack[spm1];
2452 if (d == c)
2454 if (c >= KEY_PRESS)
2455 return; /* --> no need to push multiple do-nothings */
2456 edit->redo_stack[sp] = -2;
2457 goto redo_check_bottom;
2461 edit->redo_stack[sp] = c;
2463 redo_check_bottom:
2464 edit->redo_stack_pointer = (edit->redo_stack_pointer + 1) & edit->redo_stack_size_mask;
2466 /* if the sp wraps round and catches the redo_stack_bottom then erase
2467 * the first set of actions on the stack to make space - by moving
2468 * redo_stack_bottom forward one "key press" */
2469 c = (edit->redo_stack_pointer + 2) & edit->redo_stack_size_mask;
2470 if ((unsigned long) c == edit->redo_stack_bottom ||
2471 (((unsigned long) c + 1) & edit->redo_stack_size_mask) == edit->redo_stack_bottom)
2474 edit->redo_stack_bottom = (edit->redo_stack_bottom + 1) & edit->redo_stack_size_mask;
2476 while (edit->redo_stack[edit->redo_stack_bottom] < KEY_PRESS
2477 && edit->redo_stack_bottom != edit->redo_stack_pointer);
2480 * If a single key produced enough pushes to wrap all the way round then
2481 * we would notice that the [redo_stack_bottom] does not contain KEY_PRESS.
2482 * The stack is then initialised:
2485 if (edit->redo_stack_pointer != edit->redo_stack_bottom
2486 && edit->redo_stack[edit->redo_stack_bottom] < KEY_PRESS)
2487 edit->redo_stack_bottom = edit->redo_stack_pointer = 0;
2490 /* --------------------------------------------------------------------------------------------- */
2492 Basic low level single character buffer alterations and movements at the cursor.
2495 void
2496 edit_insert (WEdit * edit, int c)
2498 /* first we must update the position of the display window */
2499 if (edit->buffer.curs1 < edit->start_display)
2501 edit->start_display++;
2502 if (c == '\n')
2503 edit->start_line++;
2506 /* Mark file as modified, unless the file hasn't been fully loaded */
2507 if (edit->loading_done)
2508 edit_modification (edit);
2510 /* now we must update some info on the file and check if a redraw is required */
2511 if (c == '\n')
2513 book_mark_inc (edit, edit->buffer.curs_line);
2514 edit->buffer.curs_line++;
2515 edit->buffer.lines++;
2516 edit->force |= REDRAW_LINE_ABOVE | REDRAW_AFTER_CURSOR;
2519 /* save the reverse command onto the undo stack */
2520 /* ordinary char and not space */
2521 if (c > 32)
2522 edit_push_undo_action (edit, BACKSPACE);
2523 else
2524 edit_push_undo_action (edit, BACKSPACE_BR);
2525 /* update markers */
2526 edit->mark1 += (edit->mark1 > edit->buffer.curs1) ? 1 : 0;
2527 edit->mark2 += (edit->mark2 > edit->buffer.curs1) ? 1 : 0;
2528 edit->last_get_rule += (edit->last_get_rule > edit->buffer.curs1) ? 1 : 0;
2530 edit_buffer_insert (&edit->buffer, c);
2533 /* --------------------------------------------------------------------------------------------- */
2534 /** same as edit_insert and move left */
2536 void
2537 edit_insert_ahead (WEdit * edit, int c)
2539 if (edit->buffer.curs1 < edit->start_display)
2541 edit->start_display++;
2542 if (c == '\n')
2543 edit->start_line++;
2545 edit_modification (edit);
2546 if (c == '\n')
2548 book_mark_inc (edit, edit->buffer.curs_line);
2549 edit->buffer.lines++;
2550 edit->force |= REDRAW_AFTER_CURSOR;
2552 /* ordinary char and not space */
2553 if (c > 32)
2554 edit_push_undo_action (edit, DELCHAR);
2555 else
2556 edit_push_undo_action (edit, DELCHAR_BR);
2558 edit->mark1 += (edit->mark1 >= edit->buffer.curs1) ? 1 : 0;
2559 edit->mark2 += (edit->mark2 >= edit->buffer.curs1) ? 1 : 0;
2560 edit->last_get_rule += (edit->last_get_rule >= edit->buffer.curs1) ? 1 : 0;
2562 edit_buffer_insert_ahead (&edit->buffer, c);
2565 /* --------------------------------------------------------------------------------------------- */
2567 void
2568 edit_insert_over (WEdit * edit)
2570 long i;
2572 for (i = 0; i < edit->over_col; i++)
2573 edit_insert (edit, ' ');
2575 edit->over_col = 0;
2578 /* --------------------------------------------------------------------------------------------- */
2581 edit_delete (WEdit * edit, gboolean byte_delete)
2583 int p = 0;
2584 int char_length = 1;
2585 int i;
2587 if (edit->buffer.curs2 == 0)
2588 return 0;
2590 #ifdef HAVE_CHARSET
2591 /* if byte_delete == TRUE then delete only one byte not multibyte char */
2592 if (edit->utf8 && !byte_delete)
2594 edit_buffer_get_utf (&edit->buffer, edit->buffer.curs1, &char_length);
2595 if (char_length < 1)
2596 char_length = 1;
2598 #else
2599 (void) byte_delete;
2600 #endif
2602 if (edit->mark2 != edit->mark1)
2603 edit_push_markers (edit);
2605 for (i = 1; i <= char_length; i++)
2607 if (edit->mark1 > edit->buffer.curs1)
2609 edit->mark1--;
2610 edit->end_mark_curs--;
2612 if (edit->mark2 > edit->buffer.curs1)
2613 edit->mark2--;
2614 if (edit->last_get_rule > edit->buffer.curs1)
2615 edit->last_get_rule--;
2617 p = edit_buffer_delete (&edit->buffer);
2619 edit_push_undo_action (edit, p + 256);
2622 edit_modification (edit);
2623 if (p == '\n')
2625 book_mark_dec (edit, edit->buffer.curs_line);
2626 edit->buffer.lines--;
2627 edit->force |= REDRAW_AFTER_CURSOR;
2629 if (edit->buffer.curs1 < edit->start_display)
2631 edit->start_display--;
2632 if (p == '\n')
2633 edit->start_line--;
2636 return p;
2639 /* --------------------------------------------------------------------------------------------- */
2642 edit_backspace (WEdit * edit, gboolean byte_delete)
2644 int p = 0;
2645 int char_length = 1;
2646 int i;
2648 if (edit->buffer.curs1 == 0)
2649 return 0;
2651 if (edit->mark2 != edit->mark1)
2652 edit_push_markers (edit);
2654 #ifdef HAVE_CHARSET
2655 if (edit->utf8 && !byte_delete)
2657 edit_buffer_get_prev_utf (&edit->buffer, edit->buffer.curs1, &char_length);
2658 if (char_length < 1)
2659 char_length = 1;
2661 #else
2662 (void) byte_delete;
2663 #endif
2665 for (i = 1; i <= char_length; i++)
2667 if (edit->mark1 >= edit->buffer.curs1)
2669 edit->mark1--;
2670 edit->end_mark_curs--;
2672 if (edit->mark2 >= edit->buffer.curs1)
2673 edit->mark2--;
2674 if (edit->last_get_rule >= edit->buffer.curs1)
2675 edit->last_get_rule--;
2677 p = edit_buffer_backspace (&edit->buffer);
2679 edit_push_undo_action (edit, p);
2681 edit_modification (edit);
2682 if (p == '\n')
2684 book_mark_dec (edit, edit->buffer.curs_line);
2685 edit->buffer.curs_line--;
2686 edit->buffer.lines--;
2687 edit->force |= REDRAW_AFTER_CURSOR;
2690 if (edit->buffer.curs1 < edit->start_display)
2692 edit->start_display--;
2693 if (p == '\n')
2694 edit->start_line--;
2697 return p;
2700 /* --------------------------------------------------------------------------------------------- */
2701 /** moves the cursor right or left: increment positive or negative respectively */
2703 void
2704 edit_cursor_move (WEdit * edit, off_t increment)
2706 if (increment < 0)
2708 for (; increment < 0 && edit->buffer.curs1 != 0; increment++)
2710 int c;
2712 edit_push_undo_action (edit, CURS_RIGHT);
2714 c = edit_buffer_get_previous_byte (&edit->buffer);
2715 edit_buffer_insert_ahead (&edit->buffer, c);
2716 c = edit_buffer_backspace (&edit->buffer);
2717 if (c == '\n')
2719 edit->buffer.curs_line--;
2720 edit->force |= REDRAW_LINE_BELOW;
2724 else
2726 for (; increment > 0 && edit->buffer.curs2 != 0; increment--)
2728 int c;
2730 edit_push_undo_action (edit, CURS_LEFT);
2732 c = edit_buffer_get_current_byte (&edit->buffer);
2733 edit_buffer_insert (&edit->buffer, c);
2734 c = edit_buffer_delete (&edit->buffer);
2735 if (c == '\n')
2737 edit->buffer.curs_line++;
2738 edit->force |= REDRAW_LINE_ABOVE;
2744 /* --------------------------------------------------------------------------------------------- */
2745 /* If cols is zero this returns the count of columns from current to upto. */
2746 /* If upto is zero returns index of cols across from current. */
2748 off_t
2749 edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto)
2751 off_t p, q;
2752 long col;
2754 if (upto != 0)
2756 q = upto;
2757 cols = -10;
2759 else
2760 q = edit->buffer.size + 2;
2762 for (col = 0, p = current; p < q; p++)
2764 int c, orig_c;
2766 if (cols != -10)
2768 if (col == cols)
2769 return p;
2770 if (col > cols)
2771 return p - 1;
2774 orig_c = c = edit_buffer_get_byte (&edit->buffer, p);
2776 #ifdef HAVE_CHARSET
2777 if (edit->utf8)
2779 int utf_ch;
2780 int char_length = 1;
2782 utf_ch = edit_buffer_get_utf (&edit->buffer, p, &char_length);
2783 if (mc_global.utf8_display)
2785 if (char_length > 1)
2786 col -= char_length - 1;
2787 if (g_unichar_iswide (utf_ch))
2788 col++;
2790 else if (char_length > 1 && g_unichar_isprint (utf_ch))
2791 col -= char_length - 1;
2794 c = convert_to_display_c (c);
2795 #endif
2797 if (c == '\n')
2798 return (upto != 0 ? (off_t) col : p);
2799 if (c == '\t')
2800 col += TAB_SIZE - col % TAB_SIZE;
2801 else if ((c < 32 || c == 127) && (orig_c == c
2802 #ifdef HAVE_CHARSET
2803 || (!mc_global.utf8_display && !edit->utf8)
2804 #endif
2806 /* '\r' is shown as ^M, so we must advance 2 characters */
2807 /* Caret notation for control characters */
2808 col += 2;
2809 else
2810 col++;
2812 return (off_t) col;
2815 /* --------------------------------------------------------------------------------------------- */
2816 /** returns the current column position of the cursor */
2818 long
2819 edit_get_col (const WEdit * edit)
2821 return (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0,
2822 edit->buffer.curs1);
2825 /* --------------------------------------------------------------------------------------------- */
2826 /* Scrolling functions */
2827 /* --------------------------------------------------------------------------------------------- */
2829 void
2830 edit_update_curs_row (WEdit * edit)
2832 edit->curs_row = edit->buffer.curs_line - edit->start_line;
2835 /* --------------------------------------------------------------------------------------------- */
2837 void
2838 edit_update_curs_col (WEdit * edit)
2840 edit->curs_col = (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer),
2841 0, edit->buffer.curs1);
2844 /* --------------------------------------------------------------------------------------------- */
2846 long
2847 edit_get_curs_col (const WEdit * edit)
2849 return edit->curs_col;
2852 /* --------------------------------------------------------------------------------------------- */
2853 /** moves the display start position up by i lines */
2855 void
2856 edit_scroll_upward (WEdit * edit, long i)
2858 long lines_above = edit->start_line;
2860 if (i > lines_above)
2861 i = lines_above;
2862 if (i != 0)
2864 edit->start_line -= i;
2865 edit->start_display =
2866 edit_buffer_get_backward_offset (&edit->buffer, edit->start_display, i);
2867 edit->force |= REDRAW_PAGE;
2868 edit->force &= (0xfff - REDRAW_CHAR_ONLY);
2870 edit_update_curs_row (edit);
2874 /* --------------------------------------------------------------------------------------------- */
2876 void
2877 edit_scroll_downward (WEdit * edit, long i)
2879 long lines_below;
2881 lines_below = edit->buffer.lines - edit->start_line - (WIDGET (edit)->lines - 1);
2882 if (lines_below > 0)
2884 if (i > lines_below)
2885 i = lines_below;
2886 edit->start_line += i;
2887 edit->start_display =
2888 edit_buffer_get_forward_offset (&edit->buffer, edit->start_display, i, 0);
2889 edit->force |= REDRAW_PAGE;
2890 edit->force &= (0xfff - REDRAW_CHAR_ONLY);
2892 edit_update_curs_row (edit);
2895 /* --------------------------------------------------------------------------------------------- */
2897 void
2898 edit_scroll_right (WEdit * edit, long i)
2900 edit->force |= REDRAW_PAGE;
2901 edit->force &= (0xfff - REDRAW_CHAR_ONLY);
2902 edit->start_col -= i;
2905 /* --------------------------------------------------------------------------------------------- */
2907 void
2908 edit_scroll_left (WEdit * edit, long i)
2910 if (edit->start_col)
2912 edit->start_col += i;
2913 if (edit->start_col > 0)
2914 edit->start_col = 0;
2915 edit->force |= REDRAW_PAGE;
2916 edit->force &= (0xfff - REDRAW_CHAR_ONLY);
2920 /* --------------------------------------------------------------------------------------------- */
2921 /* high level cursor movement commands */
2922 /* --------------------------------------------------------------------------------------------- */
2924 void
2925 edit_move_to_prev_col (WEdit * edit, off_t p)
2927 long prev = edit->prev_col;
2928 long over = edit->over_col;
2930 edit_cursor_move (edit,
2931 edit_move_forward3 (edit, p, prev + edit->over_col, 0) - edit->buffer.curs1);
2933 if (option_cursor_beyond_eol)
2935 long line_len;
2937 line_len = (long) edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0,
2938 edit_buffer_get_current_eol (&edit->buffer));
2939 if (line_len < prev + edit->over_col)
2941 edit->over_col = prev + over - line_len;
2942 edit->prev_col = line_len;
2943 edit->curs_col = line_len;
2945 else
2947 edit->curs_col = prev + over;
2948 edit->prev_col = edit->curs_col;
2949 edit->over_col = 0;
2952 else
2954 edit->over_col = 0;
2955 if (option_fake_half_tabs && is_in_indent (&edit->buffer))
2957 long fake_half_tabs;
2959 edit_update_curs_col (edit);
2961 fake_half_tabs = HALF_TAB_SIZE * space_width;
2962 if (fake_half_tabs != 0 && edit->curs_col % fake_half_tabs != 0)
2964 long q;
2966 q = edit->curs_col;
2967 edit->curs_col -= (edit->curs_col % fake_half_tabs);
2968 p = edit_buffer_get_current_bol (&edit->buffer);
2969 edit_cursor_move (edit,
2970 edit_move_forward3 (edit, p, edit->curs_col,
2971 0) - edit->buffer.curs1);
2972 if (!left_of_four_spaces (edit))
2973 edit_cursor_move (edit,
2974 edit_move_forward3 (edit, p, q, 0) - edit->buffer.curs1);
2980 /* --------------------------------------------------------------------------------------------- */
2981 /** check whether line in editor is blank or not
2983 * @param edit editor object
2984 * @param line number of line
2986 * @return TRUE if line in blank, FALSE otherwise
2989 gboolean
2990 edit_line_is_blank (WEdit * edit, long line)
2992 return is_blank (&edit->buffer, edit_find_line (edit, line));
2995 /* --------------------------------------------------------------------------------------------- */
2996 /** move cursor to line 'line' */
2998 void
2999 edit_move_to_line (WEdit * e, long line)
3001 if (line < e->buffer.curs_line)
3002 edit_move_up (e, e->buffer.curs_line - line, 0);
3003 else
3004 edit_move_down (e, line - e->buffer.curs_line, 0);
3005 edit_scroll_screen_over_cursor (e);
3008 /* --------------------------------------------------------------------------------------------- */
3009 /** scroll window so that first visible line is 'line' */
3011 void
3012 edit_move_display (WEdit * e, long line)
3014 if (line < e->start_line)
3015 edit_scroll_upward (e, e->start_line - line);
3016 else
3017 edit_scroll_downward (e, line - e->start_line);
3020 /* --------------------------------------------------------------------------------------------- */
3021 /** save markers onto undo stack */
3023 void
3024 edit_push_markers (WEdit * edit)
3026 edit_push_undo_action (edit, MARK_1 + edit->mark1);
3027 edit_push_undo_action (edit, MARK_2 + edit->mark2);
3028 edit_push_undo_action (edit, MARK_CURS + edit->end_mark_curs);
3031 /* --------------------------------------------------------------------------------------------- */
3033 void
3034 edit_set_markers (WEdit * edit, off_t m1, off_t m2, long c1, long c2)
3036 edit->mark1 = m1;
3037 edit->mark2 = m2;
3038 edit->column1 = c1;
3039 edit->column2 = c2;
3043 /* --------------------------------------------------------------------------------------------- */
3044 /** highlight marker toggle */
3046 void
3047 edit_mark_cmd (WEdit * edit, gboolean unmark)
3049 edit_push_markers (edit);
3050 if (unmark)
3052 edit_set_markers (edit, 0, 0, 0, 0);
3053 edit->force |= REDRAW_PAGE;
3055 else if (edit->mark2 >= 0)
3057 edit->end_mark_curs = -1;
3058 edit_set_markers (edit, edit->buffer.curs1, -1, edit->curs_col + edit->over_col,
3059 edit->curs_col + edit->over_col);
3060 edit->force |= REDRAW_PAGE;
3062 else
3064 edit->end_mark_curs = edit->buffer.curs1;
3065 edit_set_markers (edit, edit->mark1, edit->buffer.curs1, edit->column1,
3066 edit->curs_col + edit->over_col);
3070 /* --------------------------------------------------------------------------------------------- */
3071 /** highlight the word under cursor */
3073 void
3074 edit_mark_current_word_cmd (WEdit * edit)
3076 long pos;
3078 for (pos = edit->buffer.curs1; pos != 0; pos--)
3080 int c1, c2;
3082 c1 = edit_buffer_get_byte (&edit->buffer, pos);
3083 c2 = edit_buffer_get_byte (&edit->buffer, pos - 1);
3084 if (!isspace (c1) && isspace (c2))
3085 break;
3086 if ((my_type_of (c1) & my_type_of (c2)) == 0)
3087 break;
3089 edit->mark1 = pos;
3091 for (; pos < edit->buffer.size; pos++)
3093 int c1, c2;
3095 c1 = edit_buffer_get_byte (&edit->buffer, pos);
3096 c2 = edit_buffer_get_byte (&edit->buffer, pos + 1);
3097 if (!isspace (c1) && isspace (c2))
3098 break;
3099 if ((my_type_of (c1) & my_type_of (c2)) == 0)
3100 break;
3102 edit->mark2 = min (pos + 1, edit->buffer.size);
3104 edit->force |= REDRAW_LINE_ABOVE | REDRAW_AFTER_CURSOR;
3107 /* --------------------------------------------------------------------------------------------- */
3109 void
3110 edit_mark_current_line_cmd (WEdit * edit)
3112 edit->mark1 = edit_buffer_get_current_bol (&edit->buffer);
3113 edit->mark2 = edit_buffer_get_current_eol (&edit->buffer);
3115 edit->force |= REDRAW_LINE_ABOVE | REDRAW_AFTER_CURSOR;
3118 /* --------------------------------------------------------------------------------------------- */
3120 void
3121 edit_delete_line (WEdit * edit)
3124 * Delete right part of the line.
3125 * Note that edit_buffer_get_byte() returns '\n' when byte position is
3126 * beyond EOF.
3128 while (edit_buffer_get_current_byte (&edit->buffer) != '\n')
3129 (void) edit_delete (edit, TRUE);
3132 * Delete '\n' char.
3133 * Note that edit_delete() will not corrupt anything if called while
3134 * cursor position is EOF.
3136 (void) edit_delete (edit, TRUE);
3139 * Delete left part of the line.
3140 * Note, that edit_buffer_get_byte() returns '\n' when byte position is < 0.
3142 while (edit_buffer_get_previous_byte (&edit->buffer) != '\n')
3143 (void) edit_backspace (edit, TRUE);
3146 /* --------------------------------------------------------------------------------------------- */
3148 void
3149 edit_push_key_press (WEdit * edit)
3151 edit_push_undo_action (edit, KEY_PRESS + edit->start_display);
3152 if (edit->mark2 == -1)
3154 edit_push_undo_action (edit, MARK_1 + edit->mark1);
3155 edit_push_undo_action (edit, MARK_CURS + edit->end_mark_curs);
3159 /* --------------------------------------------------------------------------------------------- */
3161 void
3162 edit_find_bracket (WEdit * edit)
3164 edit->bracket = edit_get_bracket (edit, 1, 10000);
3165 if (edit->last_bracket != edit->bracket)
3166 edit->force |= REDRAW_PAGE;
3167 edit->last_bracket = edit->bracket;
3170 /* --------------------------------------------------------------------------------------------- */
3172 * This executes a command as though the user initiated it through a key
3173 * press. Callback with MSG_KEY as a message calls this after
3174 * translating the key press. This function can be used to pass any
3175 * command to the editor. Note that the screen wouldn't update
3176 * automatically. Either of command or char_for_insertion must be
3177 * passed as -1. Commands are executed, and char_for_insertion is
3178 * inserted at the cursor.
3181 void
3182 edit_execute_key_command (WEdit * edit, long command, int char_for_insertion)
3184 if (command == CK_MacroStartRecord || command == CK_RepeatStartRecord
3185 || (macro_index < 0
3186 && (command == CK_MacroStartStopRecord || command == CK_RepeatStartStopRecord)))
3188 macro_index = 0;
3189 edit->force |= REDRAW_CHAR_ONLY | REDRAW_LINE;
3190 return;
3192 if (macro_index != -1)
3194 edit->force |= REDRAW_COMPLETELY;
3195 if (command == CK_MacroStopRecord || command == CK_MacroStartStopRecord)
3197 edit_store_macro_cmd (edit);
3198 macro_index = -1;
3199 return;
3201 if (command == CK_RepeatStopRecord || command == CK_RepeatStartStopRecord)
3203 edit_repeat_macro_cmd (edit);
3204 macro_index = -1;
3205 return;
3209 if (macro_index >= 0 && macro_index < MAX_MACRO_LENGTH - 1)
3211 record_macro_buf[macro_index].action = command;
3212 record_macro_buf[macro_index++].ch = char_for_insertion;
3214 /* record the beginning of a set of editing actions initiated by a key press */
3215 if (command != CK_Undo && command != CK_ExtendedKeyMap)
3216 edit_push_key_press (edit);
3218 edit_execute_cmd (edit, command, char_for_insertion);
3219 if (edit->column_highlight)
3220 edit->force |= REDRAW_PAGE;
3223 /* --------------------------------------------------------------------------------------------- */
3225 This executes a command at a lower level than macro recording.
3226 It also does not push a key_press onto the undo stack. This means
3227 that if it is called many times, a single undo command will undo
3228 all of them. It also does not check for the Undo command.
3230 void
3231 edit_execute_cmd (WEdit * edit, long command, int char_for_insertion)
3233 Widget *w = WIDGET (edit);
3235 if (command == CK_WindowFullscreen)
3237 edit_toggle_fullscreen (edit);
3238 return;
3241 /* handle window state */
3242 if (edit_handle_move_resize (edit, command))
3243 return;
3245 edit->force |= REDRAW_LINE;
3247 /* The next key press will unhighlight the found string, so update
3248 * the whole page */
3249 if (edit->found_len || edit->column_highlight)
3250 edit->force |= REDRAW_PAGE;
3252 switch (command)
3254 /* a mark command with shift-arrow */
3255 case CK_MarkLeft:
3256 case CK_MarkRight:
3257 case CK_MarkToWordBegin:
3258 case CK_MarkToWordEnd:
3259 case CK_MarkToHome:
3260 case CK_MarkToEnd:
3261 case CK_MarkUp:
3262 case CK_MarkDown:
3263 case CK_MarkPageUp:
3264 case CK_MarkPageDown:
3265 case CK_MarkToFileBegin:
3266 case CK_MarkToFileEnd:
3267 case CK_MarkToPageBegin:
3268 case CK_MarkToPageEnd:
3269 case CK_MarkScrollUp:
3270 case CK_MarkScrollDown:
3271 case CK_MarkParagraphUp:
3272 case CK_MarkParagraphDown:
3273 /* a mark command with alt-arrow */
3274 case CK_MarkColumnPageUp:
3275 case CK_MarkColumnPageDown:
3276 case CK_MarkColumnLeft:
3277 case CK_MarkColumnRight:
3278 case CK_MarkColumnUp:
3279 case CK_MarkColumnDown:
3280 case CK_MarkColumnScrollUp:
3281 case CK_MarkColumnScrollDown:
3282 case CK_MarkColumnParagraphUp:
3283 case CK_MarkColumnParagraphDown:
3284 edit->column_highlight = 0;
3285 if (edit->highlight == 0 || (edit->mark2 != -1 && edit->mark1 != edit->mark2))
3287 edit_mark_cmd (edit, TRUE); /* clear */
3288 edit_mark_cmd (edit, FALSE); /* marking on */
3290 edit->highlight = 1;
3291 break;
3293 /* any other command */
3294 default:
3295 if (edit->highlight)
3296 edit_mark_cmd (edit, FALSE); /* clear */
3297 edit->highlight = 0;
3300 /* first check for undo */
3301 if (command == CK_Undo)
3303 edit->redo_stack_reset = 0;
3304 edit_group_undo (edit);
3305 edit->found_len = 0;
3306 edit->prev_col = edit_get_col (edit);
3307 edit->search_start = edit->buffer.curs1;
3308 return;
3310 /* check for redo */
3311 if (command == CK_Redo)
3313 edit->redo_stack_reset = 0;
3314 edit_do_redo (edit);
3315 edit->found_len = 0;
3316 edit->prev_col = edit_get_col (edit);
3317 edit->search_start = edit->buffer.curs1;
3318 return;
3321 edit->redo_stack_reset = 1;
3323 /* An ordinary key press */
3324 if (char_for_insertion >= 0)
3326 /* if non persistent selection and text selected */
3327 if (!option_persistent_selections && edit->mark1 != edit->mark2)
3328 edit_block_delete_cmd (edit);
3330 if (edit->overwrite)
3332 /* remove char only one time, after input first byte, multibyte chars */
3333 #ifdef HAVE_CHARSET
3334 if (!mc_global.utf8_display || edit->charpoint == 0)
3335 #endif
3336 if (edit_buffer_get_current_byte (&edit->buffer) != '\n')
3338 edit_delete (edit, FALSE);
3340 if (option_cursor_beyond_eol && edit->over_col > 0)
3341 edit_insert_over (edit);
3342 #ifdef HAVE_CHARSET
3343 if (char_for_insertion > 255 && !mc_global.utf8_display)
3345 unsigned char str[UTF8_CHAR_LEN + 1];
3346 size_t i = 0;
3347 int res;
3349 res = g_unichar_to_utf8 (char_for_insertion, (char *) str);
3350 if (res == 0)
3352 str[0] = '.';
3353 str[1] = '\0';
3355 else
3357 str[res] = '\0';
3359 while (i <= UTF8_CHAR_LEN && str[i] != '\0')
3361 char_for_insertion = str[i];
3362 edit_insert (edit, char_for_insertion);
3363 i++;
3366 else
3367 #endif
3368 edit_insert (edit, char_for_insertion);
3370 if (option_auto_para_formatting)
3372 format_paragraph (edit, FALSE);
3373 edit->force |= REDRAW_PAGE;
3375 else
3376 check_and_wrap_line (edit);
3377 edit->found_len = 0;
3378 edit->prev_col = edit_get_col (edit);
3379 edit->search_start = edit->buffer.curs1;
3380 edit_find_bracket (edit);
3381 return;
3384 switch (command)
3386 case CK_TopOnScreen:
3387 case CK_BottomOnScreen:
3388 case CK_Top:
3389 case CK_Bottom:
3390 case CK_PageUp:
3391 case CK_PageDown:
3392 case CK_Home:
3393 case CK_End:
3394 case CK_Up:
3395 case CK_Down:
3396 case CK_Left:
3397 case CK_Right:
3398 case CK_WordLeft:
3399 case CK_WordRight:
3400 if (!option_persistent_selections && edit->mark2 >= 0)
3402 if (edit->column_highlight)
3403 edit_push_undo_action (edit, COLUMN_ON);
3404 edit->column_highlight = 0;
3405 edit_mark_cmd (edit, TRUE);
3407 default:
3408 break;
3411 switch (command)
3413 case CK_TopOnScreen:
3414 case CK_BottomOnScreen:
3415 case CK_MarkToPageBegin:
3416 case CK_MarkToPageEnd:
3417 case CK_Up:
3418 case CK_Down:
3419 case CK_WordLeft:
3420 case CK_WordRight:
3421 case CK_MarkToWordBegin:
3422 case CK_MarkToWordEnd:
3423 case CK_MarkUp:
3424 case CK_MarkDown:
3425 case CK_MarkColumnUp:
3426 case CK_MarkColumnDown:
3427 if (edit->mark2 == -1)
3428 break; /*marking is following the cursor: may need to highlight a whole line */
3429 case CK_Left:
3430 case CK_Right:
3431 case CK_MarkLeft:
3432 case CK_MarkRight:
3433 edit->force |= REDRAW_CHAR_ONLY;
3434 default:
3435 break;
3438 /* basic cursor key commands */
3439 switch (command)
3441 case CK_BackSpace:
3442 /* if non persistent selection and text selected */
3443 if (!option_persistent_selections && edit->mark1 != edit->mark2)
3444 edit_block_delete_cmd (edit);
3445 else if (option_cursor_beyond_eol && edit->over_col > 0)
3446 edit->over_col--;
3447 else if (option_backspace_through_tabs && is_in_indent (&edit->buffer))
3449 while (edit_buffer_get_previous_byte (&edit->buffer) != '\n' && edit->buffer.curs1 > 0)
3450 edit_backspace (edit, TRUE);
3452 else if (option_fake_half_tabs && is_in_indent (&edit->buffer)
3453 && right_of_four_spaces (edit))
3455 int i;
3457 for (i = 0; i < HALF_TAB_SIZE; i++)
3458 edit_backspace (edit, TRUE);
3460 else
3461 edit_backspace (edit, FALSE);
3462 break;
3463 case CK_Delete:
3464 /* if non persistent selection and text selected */
3465 if (!option_persistent_selections && edit->mark1 != edit->mark2)
3466 edit_block_delete_cmd (edit);
3467 else
3469 if (option_cursor_beyond_eol && edit->over_col > 0)
3470 edit_insert_over (edit);
3472 if (option_fake_half_tabs && is_in_indent (&edit->buffer) && left_of_four_spaces (edit))
3474 int i;
3476 for (i = 1; i <= HALF_TAB_SIZE; i++)
3477 edit_delete (edit, TRUE);
3479 else
3480 edit_delete (edit, FALSE);
3482 break;
3483 case CK_DeleteToWordBegin:
3484 edit->over_col = 0;
3485 edit_left_delete_word (edit);
3486 break;
3487 case CK_DeleteToWordEnd:
3488 if (option_cursor_beyond_eol && edit->over_col > 0)
3489 edit_insert_over (edit);
3491 edit_right_delete_word (edit);
3492 break;
3493 case CK_DeleteLine:
3494 edit_delete_line (edit);
3495 break;
3496 case CK_DeleteToHome:
3497 edit_delete_to_line_begin (edit);
3498 break;
3499 case CK_DeleteToEnd:
3500 edit_delete_to_line_end (edit);
3501 break;
3502 case CK_Enter:
3503 edit->over_col = 0;
3504 if (option_auto_para_formatting)
3506 edit_double_newline (edit);
3507 if (option_return_does_auto_indent && !bracketed_pasting_in_progress)
3508 edit_auto_indent (edit);
3509 format_paragraph (edit, FALSE);
3511 else
3513 edit_insert (edit, '\n');
3514 if (option_return_does_auto_indent && !bracketed_pasting_in_progress)
3515 edit_auto_indent (edit);
3517 break;
3518 case CK_Return:
3519 edit_insert (edit, '\n');
3520 break;
3522 case CK_MarkColumnPageUp:
3523 edit->column_highlight = 1;
3524 case CK_PageUp:
3525 case CK_MarkPageUp:
3526 edit_move_up (edit, w->lines - 1, 1);
3527 break;
3528 case CK_MarkColumnPageDown:
3529 edit->column_highlight = 1;
3530 case CK_PageDown:
3531 case CK_MarkPageDown:
3532 edit_move_down (edit, w->lines - 1, 1);
3533 break;
3534 case CK_MarkColumnLeft:
3535 edit->column_highlight = 1;
3536 case CK_Left:
3537 case CK_MarkLeft:
3538 if (option_fake_half_tabs && is_in_indent (&edit->buffer) && right_of_four_spaces (edit))
3540 if (option_cursor_beyond_eol && edit->over_col > 0)
3541 edit->over_col--;
3542 else
3543 edit_cursor_move (edit, -HALF_TAB_SIZE);
3544 edit->force &= (0xFFF - REDRAW_CHAR_ONLY);
3546 else
3547 edit_left_char_move_cmd (edit);
3548 break;
3549 case CK_MarkColumnRight:
3550 edit->column_highlight = 1;
3551 case CK_Right:
3552 case CK_MarkRight:
3553 if (option_fake_half_tabs && is_in_indent (&edit->buffer) && left_of_four_spaces (edit))
3555 edit_cursor_move (edit, HALF_TAB_SIZE);
3556 edit->force &= (0xFFF - REDRAW_CHAR_ONLY);
3558 else
3559 edit_right_char_move_cmd (edit);
3560 break;
3561 case CK_TopOnScreen:
3562 case CK_MarkToPageBegin:
3563 edit_begin_page (edit);
3564 break;
3565 case CK_BottomOnScreen:
3566 case CK_MarkToPageEnd:
3567 edit_end_page (edit);
3568 break;
3569 case CK_WordLeft:
3570 case CK_MarkToWordBegin:
3571 edit->over_col = 0;
3572 edit_left_word_move_cmd (edit);
3573 break;
3574 case CK_WordRight:
3575 case CK_MarkToWordEnd:
3576 edit->over_col = 0;
3577 edit_right_word_move_cmd (edit);
3578 break;
3579 case CK_MarkColumnUp:
3580 edit->column_highlight = 1;
3581 case CK_Up:
3582 case CK_MarkUp:
3583 edit_move_up (edit, 1, 0);
3584 break;
3585 case CK_MarkColumnDown:
3586 edit->column_highlight = 1;
3587 case CK_Down:
3588 case CK_MarkDown:
3589 edit_move_down (edit, 1, 0);
3590 break;
3591 case CK_MarkColumnParagraphUp:
3592 edit->column_highlight = 1;
3593 case CK_ParagraphUp:
3594 case CK_MarkParagraphUp:
3595 edit_move_up_paragraph (edit, 0);
3596 break;
3597 case CK_MarkColumnParagraphDown:
3598 edit->column_highlight = 1;
3599 case CK_ParagraphDown:
3600 case CK_MarkParagraphDown:
3601 edit_move_down_paragraph (edit, 0);
3602 break;
3603 case CK_MarkColumnScrollUp:
3604 edit->column_highlight = 1;
3605 case CK_ScrollUp:
3606 case CK_MarkScrollUp:
3607 edit_move_up (edit, 1, 1);
3608 break;
3609 case CK_MarkColumnScrollDown:
3610 edit->column_highlight = 1;
3611 case CK_ScrollDown:
3612 case CK_MarkScrollDown:
3613 edit_move_down (edit, 1, 1);
3614 break;
3615 case CK_Home:
3616 case CK_MarkToHome:
3617 edit_cursor_to_bol (edit);
3618 break;
3619 case CK_End:
3620 case CK_MarkToEnd:
3621 edit_cursor_to_eol (edit);
3622 break;
3623 case CK_Tab:
3624 /* if text marked shift block */
3625 if (edit->mark1 != edit->mark2 && !option_persistent_selections)
3627 if (edit->mark2 < 0)
3628 edit_mark_cmd (edit, FALSE);
3629 edit_move_block_to_right (edit);
3631 else
3633 if (option_cursor_beyond_eol)
3634 edit_insert_over (edit);
3635 edit_tab_cmd (edit);
3636 if (option_auto_para_formatting)
3638 format_paragraph (edit, FALSE);
3639 edit->force |= REDRAW_PAGE;
3641 else
3642 check_and_wrap_line (edit);
3644 break;
3646 case CK_InsertOverwrite:
3647 edit->overwrite = !edit->overwrite;
3648 break;
3650 case CK_Mark:
3651 if (edit->mark2 >= 0)
3653 if (edit->column_highlight)
3654 edit_push_undo_action (edit, COLUMN_ON);
3655 edit->column_highlight = 0;
3657 edit_mark_cmd (edit, FALSE);
3658 break;
3659 case CK_MarkColumn:
3660 if (!edit->column_highlight)
3661 edit_push_undo_action (edit, COLUMN_OFF);
3662 edit->column_highlight = 1;
3663 edit_mark_cmd (edit, FALSE);
3664 break;
3665 case CK_MarkAll:
3666 edit_set_markers (edit, 0, edit->buffer.size, 0, 0);
3667 edit->force |= REDRAW_PAGE;
3668 break;
3669 case CK_Unmark:
3670 if (edit->column_highlight)
3671 edit_push_undo_action (edit, COLUMN_ON);
3672 edit->column_highlight = 0;
3673 edit_mark_cmd (edit, TRUE);
3674 break;
3675 case CK_MarkWord:
3676 if (edit->column_highlight)
3677 edit_push_undo_action (edit, COLUMN_ON);
3678 edit->column_highlight = 0;
3679 edit_mark_current_word_cmd (edit);
3680 break;
3681 case CK_MarkLine:
3682 if (edit->column_highlight)
3683 edit_push_undo_action (edit, COLUMN_ON);
3684 edit->column_highlight = 0;
3685 edit_mark_current_line_cmd (edit);
3686 break;
3688 case CK_Bookmark:
3689 book_mark_clear (edit, edit->buffer.curs_line, BOOK_MARK_FOUND_COLOR);
3690 if (book_mark_query_color (edit, edit->buffer.curs_line, BOOK_MARK_COLOR))
3691 book_mark_clear (edit, edit->buffer.curs_line, BOOK_MARK_COLOR);
3692 else
3693 book_mark_insert (edit, edit->buffer.curs_line, BOOK_MARK_COLOR);
3694 break;
3695 case CK_BookmarkFlush:
3696 book_mark_flush (edit, BOOK_MARK_COLOR);
3697 book_mark_flush (edit, BOOK_MARK_FOUND_COLOR);
3698 edit->force |= REDRAW_PAGE;
3699 break;
3700 case CK_BookmarkNext:
3701 if (edit->book_mark != NULL)
3703 edit_book_mark_t *p;
3705 p = book_mark_find (edit, edit->buffer.curs_line);
3706 if (p->next != NULL)
3708 p = p->next;
3709 if (p->line >= edit->start_line + w->lines || p->line < edit->start_line)
3710 edit_move_display (edit, p->line - w->lines / 2);
3711 edit_move_to_line (edit, p->line);
3714 break;
3715 case CK_BookmarkPrev:
3716 if (edit->book_mark != NULL)
3718 edit_book_mark_t *p;
3720 p = book_mark_find (edit, edit->buffer.curs_line);
3721 while (p->line == edit->buffer.curs_line)
3722 if (p->prev != NULL)
3723 p = p->prev;
3724 if (p->line >= 0)
3726 if (p->line >= edit->start_line + w->lines || p->line < edit->start_line)
3727 edit_move_display (edit, p->line - w->lines / 2);
3728 edit_move_to_line (edit, p->line);
3731 break;
3733 case CK_Top:
3734 case CK_MarkToFileBegin:
3735 edit_move_to_top (edit);
3736 break;
3737 case CK_Bottom:
3738 case CK_MarkToFileEnd:
3739 edit_move_to_bottom (edit);
3740 break;
3742 case CK_Copy:
3743 if (option_cursor_beyond_eol && edit->over_col > 0)
3744 edit_insert_over (edit);
3745 edit_block_copy_cmd (edit);
3746 break;
3747 case CK_Remove:
3748 edit_block_delete_cmd (edit);
3749 break;
3750 case CK_Move:
3751 edit_block_move_cmd (edit);
3752 break;
3754 case CK_BlockShiftLeft:
3755 if (edit->mark1 != edit->mark2)
3756 edit_move_block_to_left (edit);
3757 break;
3758 case CK_BlockShiftRight:
3759 if (edit->mark1 != edit->mark2)
3760 edit_move_block_to_right (edit);
3761 break;
3762 case CK_Store:
3763 edit_copy_to_X_buf_cmd (edit);
3764 break;
3765 case CK_Cut:
3766 edit_cut_to_X_buf_cmd (edit);
3767 break;
3768 case CK_Paste:
3769 /* if non persistent selection and text selected */
3770 if (!option_persistent_selections && edit->mark1 != edit->mark2)
3771 edit_block_delete_cmd (edit);
3772 if (option_cursor_beyond_eol && edit->over_col > 0)
3773 edit_insert_over (edit);
3774 edit_paste_from_X_buf_cmd (edit);
3775 if (!option_persistent_selections && edit->mark2 >= 0)
3777 if (edit->column_highlight)
3778 edit_push_undo_action (edit, COLUMN_ON);
3779 edit->column_highlight = 0;
3780 edit_mark_cmd (edit, TRUE);
3782 break;
3783 case CK_History:
3784 edit_paste_from_history (edit);
3785 break;
3787 case CK_SaveAs:
3788 edit_save_as_cmd (edit);
3789 break;
3790 case CK_Save:
3791 edit_save_confirm_cmd (edit);
3792 break;
3793 case CK_BlockSave:
3794 edit_save_block_cmd (edit);
3795 break;
3796 case CK_InsertFile:
3797 edit_insert_file_cmd (edit);
3798 break;
3800 case CK_FilePrev:
3801 edit_load_back_cmd (edit);
3802 break;
3803 case CK_FileNext:
3804 edit_load_forward_cmd (edit);
3805 break;
3807 case CK_SyntaxChoose:
3808 edit_syntax_dialog (edit);
3809 break;
3811 case CK_Search:
3812 edit_search_cmd (edit, FALSE);
3813 break;
3814 case CK_SearchContinue:
3815 edit_search_cmd (edit, TRUE);
3816 break;
3817 case CK_Replace:
3818 edit_replace_cmd (edit, 0);
3819 break;
3820 case CK_ReplaceContinue:
3821 edit_replace_cmd (edit, 1);
3822 break;
3823 case CK_Complete:
3824 /* if text marked shift block */
3825 if (edit->mark1 != edit->mark2 && !option_persistent_selections)
3826 edit_move_block_to_left (edit);
3827 else
3828 edit_complete_word_cmd (edit);
3829 break;
3830 case CK_Find:
3831 edit_get_match_keyword_cmd (edit);
3832 break;
3834 #ifdef HAVE_ASPELL
3835 case CK_SpellCheckCurrentWord:
3836 edit_suggest_current_word (edit);
3837 break;
3838 case CK_SpellCheck:
3839 edit_spellcheck_file (edit);
3840 break;
3841 case CK_SpellCheckSelectLang:
3842 edit_set_spell_lang ();
3843 break;
3844 #endif
3846 case CK_Date:
3848 char s[BUF_MEDIUM];
3849 /* fool gcc to prevent a Y2K warning */
3850 char time_format[] = "_c";
3851 time_format[0] = '%';
3853 FMT_LOCALTIME_CURRENT (s, sizeof (s), time_format);
3854 edit_print_string (edit, s);
3855 edit->force |= REDRAW_PAGE;
3857 break;
3858 case CK_Goto:
3859 edit_goto_cmd (edit);
3860 break;
3861 case CK_ParagraphFormat:
3862 format_paragraph (edit, TRUE);
3863 edit->force |= REDRAW_PAGE;
3864 break;
3865 case CK_MacroDelete:
3866 edit_delete_macro_cmd (edit);
3867 break;
3868 case CK_MatchBracket:
3869 edit_goto_matching_bracket (edit);
3870 break;
3871 case CK_UserMenu:
3872 user_menu (edit, NULL, -1);
3873 break;
3874 case CK_Sort:
3875 edit_sort_cmd (edit);
3876 break;
3877 case CK_ExternalCommand:
3878 edit_ext_cmd (edit);
3879 break;
3880 case CK_Mail:
3881 edit_mail_dialog (edit);
3882 break;
3883 #ifdef HAVE_CHARSET
3884 case CK_SelectCodepage:
3885 edit_select_codepage_cmd (edit);
3886 break;
3887 #endif
3888 case CK_InsertLiteral:
3889 edit_insert_literal_cmd (edit);
3890 break;
3891 case CK_MacroStartStopRecord:
3892 edit_begin_end_macro_cmd (edit);
3893 break;
3894 case CK_RepeatStartStopRecord:
3895 edit_begin_end_repeat_cmd (edit);
3896 break;
3897 case CK_ExtendedKeyMap:
3898 edit->extmod = TRUE;
3899 break;
3900 default:
3901 break;
3904 /* CK_PipeBlock */
3905 if ((command / CK_PipeBlock (0)) == 1)
3906 edit_block_process_cmd (edit, command - CK_PipeBlock (0));
3908 /* keys which must set the col position, and the search vars */
3909 switch (command)
3911 case CK_Search:
3912 case CK_SearchContinue:
3913 case CK_Replace:
3914 case CK_ReplaceContinue:
3915 case CK_Complete:
3916 edit->prev_col = edit_get_col (edit);
3917 break;
3918 case CK_Up:
3919 case CK_MarkUp:
3920 case CK_MarkColumnUp:
3921 case CK_Down:
3922 case CK_MarkDown:
3923 case CK_MarkColumnDown:
3924 case CK_PageUp:
3925 case CK_MarkPageUp:
3926 case CK_MarkColumnPageUp:
3927 case CK_PageDown:
3928 case CK_MarkPageDown:
3929 case CK_MarkColumnPageDown:
3930 case CK_Top:
3931 case CK_MarkToFileBegin:
3932 case CK_Bottom:
3933 case CK_MarkToFileEnd:
3934 case CK_ParagraphUp:
3935 case CK_MarkParagraphUp:
3936 case CK_MarkColumnParagraphUp:
3937 case CK_ParagraphDown:
3938 case CK_MarkParagraphDown:
3939 case CK_MarkColumnParagraphDown:
3940 case CK_ScrollUp:
3941 case CK_MarkScrollUp:
3942 case CK_MarkColumnScrollUp:
3943 case CK_ScrollDown:
3944 case CK_MarkScrollDown:
3945 case CK_MarkColumnScrollDown:
3946 edit->search_start = edit->buffer.curs1;
3947 edit->found_len = 0;
3948 break;
3949 default:
3950 edit->found_len = 0;
3951 edit->prev_col = edit_get_col (edit);
3952 edit->search_start = edit->buffer.curs1;
3954 edit_find_bracket (edit);
3956 if (option_auto_para_formatting)
3958 switch (command)
3960 case CK_BackSpace:
3961 case CK_Delete:
3962 case CK_DeleteToWordBegin:
3963 case CK_DeleteToWordEnd:
3964 case CK_DeleteToHome:
3965 case CK_DeleteToEnd:
3966 format_paragraph (edit, FALSE);
3967 edit->force |= REDRAW_PAGE;
3968 default:
3969 break;
3974 /* --------------------------------------------------------------------------------------------- */
3976 void
3977 edit_stack_init (void)
3979 for (edit_stack_iterator = 0; edit_stack_iterator < MAX_HISTORY_MOVETO; edit_stack_iterator++)
3981 edit_history_moveto[edit_stack_iterator].filename_vpath = NULL;
3982 edit_history_moveto[edit_stack_iterator].line = -1;
3985 edit_stack_iterator = 0;
3988 /* --------------------------------------------------------------------------------------------- */
3990 void
3991 edit_stack_free (void)
3993 for (edit_stack_iterator = 0; edit_stack_iterator < MAX_HISTORY_MOVETO; edit_stack_iterator++)
3994 vfs_path_free (edit_history_moveto[edit_stack_iterator].filename_vpath);
3997 /* --------------------------------------------------------------------------------------------- */
3998 /** move i lines */
4000 void
4001 edit_move_up (WEdit * edit, long i, gboolean do_scroll)
4003 edit_move_updown (edit, i, do_scroll, TRUE);
4006 /* --------------------------------------------------------------------------------------------- */
4007 /** move i lines */
4009 void
4010 edit_move_down (WEdit * edit, long i, gboolean do_scroll)
4012 edit_move_updown (edit, i, do_scroll, FALSE);
4015 /* --------------------------------------------------------------------------------------------- */