1 /* editor low level data handling and cursor fundamentals.
3 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
4 2007 Free Software Foundation, Inc.
6 Authors: 1996, 1997 Paul Sheer
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * \brief Source: editor low level data handling and cursor fundamentals
33 #include <sys/types.h>
42 #include "lib/global.h"
44 #include "lib/tty/color.h"
45 #include "lib/tty/tty.h" /* attrset() */
46 #include "lib/tty/key.h" /* is_idle() */
47 #include "lib/skin.h" /* EDITOR_NORMAL_COLOR */
48 #include "lib/vfs/mc-vfs/vfs.h"
49 #include "lib/strutil.h" /* utf string functions */
50 #include "lib/timefmt.h" /* time formatting */
53 #include "src/widget.h"
54 #include "src/cmd.h" /* view_other_cmd() */
55 #include "src/user.h" /* user_menu_cmd() */
56 #include "src/wtools.h" /* query_dialog() */
57 #include "src/charsets.h" /* get_codepage_id */
58 #include "src/main.h" /* source_codepage */
59 #include "src/setup.h" /* option_tab_spacing */
60 #include "src/learn.h" /* learn_keys */
61 #include "src/cmddef.h"
62 #include "src/keybind.h"
64 #include "edit-impl.h"
65 #include "edit-widget.h"
67 int option_word_wrap_line_length
= DEFAULT_WRAP_LINE_LENGTH
;
68 int option_typewriter_wrap
= 0;
69 int option_auto_para_formatting
= 0;
70 int option_fill_tabs_with_spaces
= 0;
71 int option_return_does_auto_indent
= 1;
72 int option_backspace_through_tabs
= 0;
73 int option_fake_half_tabs
= 1;
74 int option_save_mode
= EDIT_QUICK_SAVE
;
75 int option_save_position
= 1;
76 int option_max_undo
= 32768;
77 int option_persistent_selections
= 1;
78 int option_cursor_beyond_eol
= 0;
79 int option_line_state
= 0;
80 int option_line_state_width
= 0;
82 int option_edit_right_extreme
= 0;
83 int option_edit_left_extreme
= 0;
84 int option_edit_top_extreme
= 0;
85 int option_edit_bottom_extreme
= 0;
86 int enable_show_tabs_tws
= 1;
87 int option_check_nl_at_eof
= 0;
88 int show_right_margin
= 0;
90 const char *option_whole_chars_search
= "0123456789abcdefghijklmnopqrstuvwxyz_";
91 char *option_backup_ext
= NULL
;
93 int edit_stack_iterator
= 0;
94 edit_stack_type edit_history_moveto
[MAX_HISTORY_MOVETO
];
95 /* magic sequense for say than block is vertical */
96 const char VERTICAL_MAGIC
[] = { '\1', '\1', '\1', '\1', '\n' };
100 * here's a quick sketch of the layout: (don't run this through indent.)
102 * (b1 is buffers1 and b2 is buffers2)
105 * \0\0\0\0\0m e _ f i l e . \nf i n . \n|T h i s _ i s _ s o\0\0\0\0\0\0\0\0\0
106 * ______________________________________|______________________________________
108 * ... | b2[2] | b2[1] | b2[0] | b1[0] | b1[1] | b1[2] | ...
109 * |-> |-> |-> |-> |-> |-> |
111 * _<------------------------->|<----------------->_
112 * WEdit->curs2 | WEdit->curs1
117 * file end|||file beginning
126 static void user_menu (WEdit
* edit
);
131 const char *header
= N_("About");
132 const char *button_name
= N_("&OK");
133 const char * const version
= "MCEdit " VERSION
;
134 char text
[BUF_LARGE
];
136 int win_len
, version_len
, button_len
;
143 button_name
= _(button_name
);
146 button_len
= str_term_width1 (button_name
) + 5;
147 version_len
= str_term_width1 (version
);
149 g_snprintf (text
, sizeof (text
),
150 _("Copyright (C) 1996-2010 the Free Software Foundation\n\n"
151 " A user friendly text editor\n"
152 " written for the Midnight Commander"));
154 win_len
= str_term_width1 (header
);
155 win_len
= max (win_len
, version_len
);
156 win_len
= max (win_len
, button_len
);
158 /* count width and height of text */
159 str_msg_term_size (text
, &lines
, &cols
);
161 cols
= max (win_len
, cols
) + 6;
164 about_dlg
= create_dlg (TRUE
, 0, 0, lines
, cols
, dialog_colors
, NULL
,
165 "[Internal File Editor]", header
, DLG_CENTER
| DLG_TRYUP
);
167 add_widget (about_dlg
, label_new (3, (cols
- version_len
)/2, version
));
168 add_widget (about_dlg
, label_new (5, 3, text
));
169 add_widget (about_dlg
, button_new (lines
- 3, (cols
- button_len
)/2,
170 B_ENTER
, NORMAL_BUTTON
, button_name
, NULL
));
173 destroy_dlg (about_dlg
);
177 edit_get_byte (WEdit
* edit
, long byte_index
)
180 if (byte_index
>= (edit
->curs1
+ edit
->curs2
) || byte_index
< 0)
183 if (byte_index
>= edit
->curs1
)
185 p
= edit
->curs1
+ edit
->curs2
- byte_index
- 1;
186 return edit
->buffers2
[p
>> S_EDIT_BUF_SIZE
][EDIT_BUF_SIZE
- (p
& M_EDIT_BUF_SIZE
) - 1];
190 return edit
->buffers1
[byte_index
>> S_EDIT_BUF_SIZE
][byte_index
& M_EDIT_BUF_SIZE
];
195 edit_get_byte_ptr (WEdit
* edit
, long byte_index
)
198 if (byte_index
>= (edit
->curs1
+ edit
->curs2
) || byte_index
< 0)
201 if (byte_index
>= edit
->curs1
)
203 p
= edit
->curs1
+ edit
->curs2
- byte_index
- 1;
204 return (char *) (edit
->buffers2
[p
>> S_EDIT_BUF_SIZE
] +
205 (EDIT_BUF_SIZE
- (p
& M_EDIT_BUF_SIZE
) - 1));
209 return (char *) (edit
->buffers1
[byte_index
>> S_EDIT_BUF_SIZE
] +
210 (byte_index
& M_EDIT_BUF_SIZE
));
215 edit_get_buf_ptr (WEdit
* edit
, long byte_index
)
219 if (byte_index
>= (edit
->curs1
+ edit
->curs2
))
225 if (byte_index
>= edit
->curs1
)
227 p
= edit
->curs1
+ edit
->curs2
- 1;
228 return (char *) (edit
->buffers2
[p
>> S_EDIT_BUF_SIZE
] +
229 (EDIT_BUF_SIZE
- (p
& M_EDIT_BUF_SIZE
) - 1));
233 return (char *) (edit
->buffers1
[byte_index
>> S_EDIT_BUF_SIZE
] + (0 & M_EDIT_BUF_SIZE
));
238 edit_get_utf (WEdit
* edit
, long byte_index
, int *char_width
)
243 gchar
*next_ch
= NULL
;
246 if (byte_index
>= (edit
->curs1
+ edit
->curs2
) || byte_index
< 0)
252 str
= edit_get_byte_ptr (edit
, byte_index
);
260 res
= g_utf8_get_char_validated (str
, -1);
270 /* Calculate UTF-8 char width */
271 next_ch
= g_utf8_next_char (str
);
274 width
= next_ch
- str
;
287 edit_get_prev_utf (WEdit
* edit
, long byte_index
, int *char_width
)
289 gchar
*str
, *buf
= NULL
;
292 gchar
*next_ch
= NULL
;
298 if (byte_index
>= (edit
->curs1
+ edit
->curs2
) || byte_index
< 0)
304 ch
= edit_get_utf (edit
, byte_index
, &width
);
312 str
= edit_get_byte_ptr (edit
, byte_index
);
313 buf
= edit_get_buf_ptr (edit
, byte_index
);
314 if (str
== NULL
|| buf
== NULL
)
319 /* get prev utf8 char */
321 str
= g_utf8_find_prev_char (buf
, str
);
323 res
= g_utf8_get_char_validated (str
, -1);
333 /* Calculate UTF-8 char width */
334 next_ch
= g_utf8_next_char (str
);
337 width
= next_ch
- str
;
350 * Initialize the buffers for an empty files.
353 edit_init_buffers (WEdit
* edit
)
357 for (j
= 0; j
<= MAXBUFF
; j
++)
359 edit
->buffers1
[j
] = NULL
;
360 edit
->buffers2
[j
] = NULL
;
365 edit
->buffers2
[0] = g_malloc0 (EDIT_BUF_SIZE
);
369 * Load file OR text into buffers. Set cursor to the beginning of file.
373 edit_load_file_fast (WEdit
* edit
, const char *filename
)
379 edit
->curs2
= edit
->last_byte
;
380 buf2
= edit
->curs2
>> S_EDIT_BUF_SIZE
;
382 file
= mc_open (filename
, O_RDONLY
| O_BINARY
);
387 errmsg
= g_strdup_printf (_("Cannot open %s for reading"), filename
);
388 edit_error_dialog (_("Error"), errmsg
);
393 if (!edit
->buffers2
[buf2
])
394 edit
->buffers2
[buf2
] = g_malloc0 (EDIT_BUF_SIZE
);
399 (char *) edit
->buffers2
[buf2
] + EDIT_BUF_SIZE
-
400 (edit
->curs2
& M_EDIT_BUF_SIZE
), edit
->curs2
& M_EDIT_BUF_SIZE
) < 0)
403 for (buf
= buf2
- 1; buf
>= 0; buf
--)
405 /* edit->buffers2[0] is already allocated */
406 if (!edit
->buffers2
[buf
])
407 edit
->buffers2
[buf
] = g_malloc0 (EDIT_BUF_SIZE
);
408 if (mc_read (file
, (char *) edit
->buffers2
[buf
], EDIT_BUF_SIZE
) < 0)
416 char *err_str
= g_strdup_printf (_("Error reading %s"), filename
);
417 edit_error_dialog (_("Error"), err_str
);
424 /* detecting an error on save is easy: just check if every byte has been written. */
425 /* detecting an error on read, is not so easy 'cos there is not way to tell
426 whether you read everything or not. */
427 /* FIXME: add proper `triple_pipe_open' to read, write and check errors. */
428 static const struct edit_filters
430 const char *read
, *write
, *extension
;
434 { "xz -cd %s 2>&1", "xz > %s", ".xz"},
435 { "lzma -cd %s 2>&1", "lzma > %s", ".lzma" },
436 { "bzip2 -cd %s 2>&1", "bzip2 > %s", ".bz2" },
437 { "gzip -cd %s 2>&1", "gzip > %s", ".gz" },
438 { "gzip -cd %s 2>&1", "gzip > %s", ".Z" }
442 /* Return index of the filter or -1 is there is no appropriate filter */
444 edit_find_filter (const char *filename
)
448 if (filename
== NULL
)
451 l
= strlen (filename
);
452 for (i
= 0; i
< sizeof (all_filters
) / sizeof (all_filters
[0]); i
++)
454 e
= strlen (all_filters
[i
].extension
);
456 if (!strcmp (all_filters
[i
].extension
, filename
+ l
- e
))
463 edit_get_filter (const char *filename
)
466 char *p
, *quoted_name
;
468 i
= edit_find_filter (filename
);
472 quoted_name
= name_quote (filename
, 0);
473 p
= g_strdup_printf (all_filters
[i
].read
, quoted_name
);
474 g_free (quoted_name
);
479 edit_get_write_filter (const char *write_name
, const char *filename
)
484 i
= edit_find_filter (filename
);
488 writename
= name_quote (write_name
, 0);
489 p
= g_strdup_printf (all_filters
[i
].write
, writename
);
495 edit_insert_stream (WEdit
* edit
, FILE * f
)
499 while ((c
= fgetc (f
)) >= 0)
501 edit_insert (edit
, c
);
508 edit_write_stream (WEdit
* edit
, FILE * f
)
512 if (edit
->lb
== LB_ASIS
)
514 for (i
= 0; i
< edit
->last_byte
; i
++)
515 if (fputc (edit_get_byte (edit
, i
), f
) < 0)
520 /* change line breaks */
521 for (i
= 0; i
< edit
->last_byte
; i
++)
523 unsigned char c
= edit_get_byte (edit
, i
);
525 if (!(c
== '\n' || c
== '\r'))
528 if (fputc (c
, f
) < 0)
532 { /* (c == '\n' || c == '\r') */
533 unsigned char c1
= edit_get_byte (edit
, i
+ 1); /* next char */
537 case LB_UNIX
: /* replace "\r\n" or '\r' to '\n' */
538 /* put one line break unconditionally */
539 if (fputc ('\n', f
) < 0)
542 i
++; /* 2 chars are processed */
544 if (c
== '\r' && c1
== '\n')
545 /* Windows line break; go to the next char */
548 if (c
== '\r' && c1
== '\r')
550 /* two Macintosh line breaks; put second line break */
551 if (fputc ('\n', f
) < 0)
556 if (fputc (c1
, f
) < 0)
560 case LB_WIN
: /* replace '\n' or '\r' to "\r\n" */
561 /* put one line break unconditionally */
562 if (fputc ('\r', f
) < 0 || fputc ('\n', f
) < 0)
565 if (c
== '\r' && c1
== '\n')
566 /* Windows line break; go to the next char */
570 case LB_MAC
: /* replace "\r\n" or '\n' to '\r' */
571 /* put one line break unconditionally */
572 if (fputc ('\r', f
) < 0)
575 i
++; /* 2 chars are processed */
577 if (c
== '\r' && c1
== '\n')
578 /* Windows line break; go to the next char */
581 if (c
== '\n' && c1
== '\n')
583 /* two Windows line breaks; put second line break */
584 if (fputc ('\r', f
) < 0)
589 if (fputc (c1
, f
) < 0)
592 case LB_ASIS
: /* default without changes */
598 return edit
->last_byte
;
601 #define TEMP_BUF_LEN 1024
603 /* inserts a file at the cursor, returns 1 on success */
605 edit_insert_file (WEdit
* edit
, const char *filename
)
609 p
= edit_get_filter (filename
);
613 long current
= edit
->curs1
;
614 f
= (FILE *) popen (p
, "r");
617 edit_insert_stream (edit
, f
);
618 edit_cursor_move (edit
, current
- edit
->curs1
);
622 errmsg
= g_strdup_printf (_("Error reading from pipe: %s"), p
);
623 edit_error_dialog (_("Error"), errmsg
);
632 errmsg
= g_strdup_printf (_("Cannot open pipe for reading: %s"), p
);
633 edit_error_dialog (_("Error"), errmsg
);
642 int i
, file
, blocklen
;
643 long current
= edit
->curs1
;
644 int vertical_insertion
= 0;
646 file
= mc_open (filename
, O_RDONLY
| O_BINARY
);
649 buf
= g_malloc0 (TEMP_BUF_LEN
);
650 blocklen
= mc_read (file
, buf
, sizeof (VERTICAL_MAGIC
));
653 /* if contain signature VERTICAL_MAGIC tnen it vertical block */
654 if (memcmp (buf
, VERTICAL_MAGIC
, sizeof (VERTICAL_MAGIC
)) == 0)
655 vertical_insertion
= 1;
657 mc_lseek (file
, 0, SEEK_SET
);
659 if (vertical_insertion
)
660 blocklen
= edit_insert_column_of_text_from_file (edit
, file
);
662 while ((blocklen
= mc_read (file
, (char *) buf
, TEMP_BUF_LEN
)) > 0)
663 for (i
= 0; i
< blocklen
; i
++)
664 edit_insert (edit
, buf
[i
]);
665 edit_cursor_move (edit
, current
- edit
->curs1
);
674 /* Open file and create it if necessary. Return 0 for success, 1 for error. */
676 check_file_access (WEdit
* edit
, const char *filename
, struct stat
*st
)
679 gchar
*errmsg
= NULL
;
681 /* Try opening an existing file */
682 file
= mc_open (filename
, O_NONBLOCK
| O_RDONLY
| O_BINARY
, 0666);
687 * Try creating the file. O_EXCL prevents following broken links
688 * and opening existing files.
690 file
= mc_open (filename
, O_NONBLOCK
| O_RDONLY
| O_BINARY
| O_CREAT
| O_EXCL
, 0666);
693 errmsg
= g_strdup_printf (_("Cannot open %s for reading"), filename
);
698 /* New file, delete it if it's not modified or saved */
699 edit
->delete_file
= 1;
703 /* Check what we have opened */
704 if (mc_fstat (file
, st
) < 0)
706 errmsg
= g_strdup_printf (_("Cannot get size/permissions for %s"), filename
);
710 /* We want to open regular files only */
711 if (!S_ISREG (st
->st_mode
))
713 errmsg
= g_strdup_printf (_("\"%s\" is not a regular file"), filename
);
718 * Don't delete non-empty files.
719 * O_EXCL should prevent it, but let's be on the safe side.
722 edit
->delete_file
= 0;
724 if (st
->st_size
>= SIZE_LIMIT
)
725 errmsg
= g_strdup_printf (_("File \"%s\" is too large"), filename
);
728 (void) mc_close (file
);
732 edit_error_dialog (_("Error"), errmsg
);
740 * Open the file and load it into the buffers, either directly or using
741 * a filter. Return 0 on success, 1 on error.
743 * Fast loading (edit_load_file_fast) is used when the file size is
744 * known. In this case the data is read into the buffers by blocks.
745 * If the file size is not known, the data is loaded byte by byte in
749 edit_load_file (WEdit
* edit
)
753 /* Cannot do fast load if a filter is used */
754 if (edit_find_filter (edit
->filename
) >= 0)
758 * VFS may report file size incorrectly, and slow load is not a big
759 * deal considering overhead in VFS.
761 if (!vfs_file_is_local (edit
->filename
))
765 * FIXME: line end translation should disable fast loading as well
766 * Consider doing fseek() to the end and ftell() for the real size.
771 /* If we are dealing with a real file, check that it exists */
772 if (check_file_access (edit
, edit
->filename
, &edit
->stat1
))
777 /* nothing to load */
781 edit_init_buffers (edit
);
785 edit
->last_byte
= edit
->stat1
.st_size
;
786 edit_load_file_fast (edit
, edit
->filename
);
787 /* If fast load was used, the number of lines wasn't calculated */
788 edit
->total_lines
= edit_count_lines (edit
, 0, edit
->last_byte
);
795 edit
->stack_disable
= 1;
796 if (!edit_insert_file (edit
, edit
->filename
))
801 edit
->stack_disable
= 0;
808 /* Restore saved cursor position in the file */
810 edit_load_position (WEdit
* edit
)
816 if (!edit
->filename
|| !*edit
->filename
)
819 filename
= vfs_canon (edit
->filename
);
820 load_file_position (filename
, &line
, &column
, &offset
);
825 edit_move_to_line (edit
, line
- 1);
826 edit
->prev_col
= column
;
830 edit_cursor_move (edit
, offset
);
831 line
= edit
->curs_line
;
833 edit_move_to_prev_col (edit
, edit_bol (edit
, edit
->curs1
));
834 edit_move_display (edit
, line
- (edit
->num_widget_lines
/ 2));
837 /* Save cursor position in the file */
839 edit_save_position (WEdit
* edit
)
843 if (!edit
->filename
|| !*edit
->filename
)
846 filename
= vfs_canon (edit
->filename
);
847 save_file_position (filename
, edit
->curs_line
+ 1, edit
->curs_col
, edit
->curs1
);
851 /* Clean the WEdit stricture except the widget part */
853 edit_purge_widget (WEdit
* edit
)
855 size_t len
= sizeof (WEdit
) - sizeof (Widget
);
856 char *start
= (char *) edit
+ sizeof (Widget
);
857 memset (start
, 0, len
);
858 edit
->macro_i
= -1; /* not recording a macro */
862 edit_set_keymap (void)
864 editor_map
= default_editor_keymap
;
865 if (editor_keymap
&& editor_keymap
->len
> 0)
866 editor_map
= (global_keymap_t
*) editor_keymap
->data
;
868 editor_x_map
= default_editor_x_keymap
;
869 if (editor_x_keymap
&& editor_x_keymap
->len
> 0)
870 editor_x_map
= (global_keymap_t
*) editor_x_keymap
->data
;
874 #define space_width 1
877 * Fill in the edit structure. Return NULL on failure. Pass edit as
878 * NULL to allocate a new structure.
880 * If line is 0, try to restore saved position. Otherwise put the
881 * cursor on that line and show it in the middle of the screen.
884 edit_init (WEdit
* edit
, int lines
, int columns
, const char *filename
, long line
)
887 option_auto_syntax
= 1; /* Resetting to auto on every invokation */
888 if (option_line_state
)
890 option_line_state_width
= LINE_STATE_WIDTH
;
894 option_line_state_width
= 0;
900 * Expand option_whole_chars_search by national letters using
904 static char option_whole_chars_search_buf
[256];
906 if (option_whole_chars_search_buf
!= option_whole_chars_search
)
909 size_t len
= str_term_width1 (option_whole_chars_search
);
911 strcpy (option_whole_chars_search_buf
, option_whole_chars_search
);
913 for (i
= 1; i
<= sizeof (option_whole_chars_search_buf
); i
++)
915 if (g_ascii_islower ((gchar
) i
) && !strchr (option_whole_chars_search
, i
))
917 option_whole_chars_search_buf
[len
++] = i
;
921 option_whole_chars_search_buf
[len
] = 0;
922 option_whole_chars_search
= option_whole_chars_search_buf
;
924 #endif /* ENABLE_NLS */
925 edit
= g_malloc0 (sizeof (WEdit
));
929 edit_purge_widget (edit
);
930 edit
->num_widget_lines
= lines
;
932 edit
->num_widget_columns
= columns
;
933 edit
->stat1
.st_mode
= S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
;
934 edit
->stat1
.st_uid
= getuid ();
935 edit
->stat1
.st_gid
= getgid ();
936 edit
->stat1
.st_mtime
= 0;
938 edit
->force
|= REDRAW_PAGE
;
939 edit_set_filename (edit
, filename
);
940 edit
->stack_size
= START_STACK_SIZE
;
941 edit
->stack_size_mask
= START_STACK_SIZE
- 1;
942 edit
->undo_stack
= g_malloc0 ((edit
->stack_size
+ 10) * sizeof (long));
945 edit
->converter
= str_cnv_from_term
;
946 edit_set_codeset (edit
);
948 if (edit_load_file (edit
))
950 /* edit_load_file already gives an error message */
956 edit
->loading_done
= 1;
959 edit_load_syntax (edit
, NULL
, NULL
);
962 edit_get_syntax_color (edit
, -1, &color
);
965 /* load saved cursor position */
966 if ((line
== 0) && option_save_position
)
968 edit_load_position (edit
);
974 edit_move_display (edit
, line
- 1);
975 edit_move_to_line (edit
, line
- 1);
983 /* Clear the edit struct, freeing everything in it. Return 1 on success */
985 edit_clean (WEdit
* edit
)
992 /* a stale lock, remove it */
994 edit
->locked
= edit_unlock_file (edit
);
996 /* save cursor position */
997 if (option_save_position
)
998 edit_save_position (edit
);
1000 /* File specified on the mcedit command line and never saved */
1001 if (edit
->delete_file
)
1002 unlink (edit
->filename
);
1004 edit_free_syntax_rules (edit
);
1005 book_mark_flush (edit
, -1);
1006 for (; j
<= MAXBUFF
; j
++)
1008 g_free (edit
->buffers1
[j
]);
1009 g_free (edit
->buffers2
[j
]);
1012 g_free (edit
->undo_stack
);
1013 g_free (edit
->filename
);
1016 mc_search_free (edit
->search
);
1017 edit
->search
= NULL
;
1019 if (edit
->converter
!= str_cnv_from_term
)
1020 str_close_conv (edit
->converter
);
1022 edit_purge_widget (edit
);
1027 /* returns 1 on success */
1029 edit_renew (WEdit
* edit
)
1031 int lines
= edit
->num_widget_lines
;
1032 int columns
= edit
->num_widget_columns
;
1035 return (edit_init (edit
, lines
, columns
, "", 0) != NULL
);
1039 * Load a new file into the editor. If it fails, preserve the old file.
1040 * To do it, allocate a new widget, initialize it and, if the new file
1041 * was loaded, copy the data to the old widget.
1042 * Return 1 on success, 0 on failure.
1045 edit_reload (WEdit
* edit
, const char *filename
)
1048 int lines
= edit
->num_widget_lines
;
1049 int columns
= edit
->num_widget_columns
;
1051 e
= g_malloc0 (sizeof (WEdit
));
1052 e
->widget
= edit
->widget
;
1053 if (!edit_init (e
, lines
, columns
, filename
, 0))
1059 memcpy (edit
, e
, sizeof (WEdit
));
1065 * Load a new file into the editor and set line. If it fails, preserve the old file.
1066 * To do it, allocate a new widget, initialize it and, if the new file
1067 * was loaded, copy the data to the old widget.
1068 * Return 1 on success, 0 on failure.
1071 edit_reload_line (WEdit
* edit
, const char *filename
, long line
)
1074 int lines
= edit
->num_widget_lines
;
1075 int columns
= edit
->num_widget_columns
;
1077 e
= g_malloc0 (sizeof (WEdit
));
1078 e
->widget
= edit
->widget
;
1079 if (!edit_init (e
, lines
, columns
, filename
, line
))
1085 memcpy (edit
, e
, sizeof (WEdit
));
1091 edit_set_codeset (WEdit
*edit
)
1096 cp_id
= get_codepage_id (source_codepage
>= 0 ? source_codepage
: display_codepage
);
1101 conv
= str_crt_conv_from (cp_id
);
1102 if (conv
!= INVALID_CONV
)
1104 if (edit
->converter
!= str_cnv_from_term
)
1105 str_close_conv (edit
->converter
);
1106 edit
->converter
= conv
;
1111 edit
->utf8
= str_isutf8 (cp_id
);
1119 Recording stack for undo:
1120 The following is an implementation of a compressed stack. Identical
1121 pushes are recorded by a negative prefix indicating the number of times the
1122 same char was pushed. This saves space for repeated curs-left or curs-right
1139 If the stack long int is 0-255 it represents a normal insert (from a backspace),
1140 256-512 is an insert ahead (from a delete), If it is betwen 600 and 700 it is one
1141 of the cursor functions #define'd in edit-impl.h. 1000 through 700'000'000 is to
1142 set edit->mark1 position. 700'000'000 through 1400'000'000 is to set edit->mark2
1145 The only way the cursor moves or the buffer is changed is through the routines:
1146 insert, backspace, insert_ahead, delete, and cursor_move.
1147 These record the reverse undo movements onto the stack each time they are
1150 Each key press results in a set of actions (insert; delete ...). So each time
1151 a key is pressed the current position of start_display is pushed as
1152 KEY_PRESS + start_display. Then for undoing, we pop until we get to a number
1153 over KEY_PRESS. We then assign this number less KEY_PRESS to start_display. So undo
1154 tracks scrolling and key actions exactly. (KEY_PRESS is about (2^31) * (2/3) = 1400'000'000)
1159 edit_push_action (WEdit
* edit
, long c
, ...)
1161 unsigned long sp
= edit
->stack_pointer
;
1165 /* first enlarge the stack if necessary */
1166 if (sp
> edit
->stack_size
- 10)
1168 if (option_max_undo
< 256)
1169 option_max_undo
= 256;
1170 if (edit
->stack_size
< (unsigned long) option_max_undo
)
1172 t
= g_realloc (edit
->undo_stack
, (edit
->stack_size
* 2 + 10) * sizeof (long));
1175 edit
->undo_stack
= t
;
1176 edit
->stack_size
<<= 1;
1177 edit
->stack_size_mask
= edit
->stack_size
- 1;
1181 spm1
= (edit
->stack_pointer
- 1) & edit
->stack_size_mask
;
1182 if (edit
->stack_disable
)
1185 #ifdef FAST_MOVE_CURSOR
1186 if (c
== CURS_LEFT_LOTS
|| c
== CURS_RIGHT_LOTS
)
1189 edit
->undo_stack
[sp
] = (c
== CURS_LEFT_LOTS
) ? CURS_LEFT
: CURS_RIGHT
;
1190 edit
->stack_pointer
= (edit
->stack_pointer
+ 1) & edit
->stack_size_mask
;
1192 c
= -(va_arg (ap
, int));
1196 #endif /* ! FAST_MOVE_CURSOR */
1197 if (edit
->stack_bottom
!= sp
1198 && spm1
!= edit
->stack_bottom
1199 && ((sp
- 2) & edit
->stack_size_mask
) != edit
->stack_bottom
)
1202 if (edit
->undo_stack
[spm1
] < 0)
1204 d
= edit
->undo_stack
[(sp
- 2) & edit
->stack_size_mask
];
1207 if (edit
->undo_stack
[spm1
] > -1000000000)
1209 if (c
< KEY_PRESS
) /* --> no need to push multiple do-nothings */
1210 edit
->undo_stack
[spm1
]--;
1214 /* #define NO_STACK_CURSMOVE_ANIHILATION */
1215 #ifndef NO_STACK_CURSMOVE_ANIHILATION
1216 else if ((c
== CURS_LEFT
&& d
== CURS_RIGHT
) || (c
== CURS_RIGHT
&& d
== CURS_LEFT
))
1217 { /* a left then a right anihilate each other */
1218 if (edit
->undo_stack
[spm1
] == -2)
1219 edit
->stack_pointer
= spm1
;
1221 edit
->undo_stack
[spm1
]++;
1228 d
= edit
->undo_stack
[spm1
];
1232 return; /* --> no need to push multiple do-nothings */
1233 edit
->undo_stack
[sp
] = -2;
1236 #ifndef NO_STACK_CURSMOVE_ANIHILATION
1237 else if ((c
== CURS_LEFT
&& d
== CURS_RIGHT
) || (c
== CURS_RIGHT
&& d
== CURS_LEFT
))
1238 { /* a left then a right anihilate each other */
1239 edit
->stack_pointer
= spm1
;
1245 edit
->undo_stack
[sp
] = c
;
1248 edit
->stack_pointer
= (edit
->stack_pointer
+ 1) & edit
->stack_size_mask
;
1250 /* if the sp wraps round and catches the stack_bottom then erase
1251 * the first set of actions on the stack to make space - by moving
1252 * stack_bottom forward one "key press" */
1253 c
= (edit
->stack_pointer
+ 2) & edit
->stack_size_mask
;
1254 if ((unsigned long) c
== edit
->stack_bottom
||
1255 (((unsigned long) c
+ 1) & edit
->stack_size_mask
) == edit
->stack_bottom
)
1258 edit
->stack_bottom
= (edit
->stack_bottom
+ 1) & edit
->stack_size_mask
;
1260 while (edit
->undo_stack
[edit
->stack_bottom
] < KEY_PRESS
1261 && edit
->stack_bottom
!= edit
->stack_pointer
);
1263 /*If a single key produced enough pushes to wrap all the way round then we would notice that the [stack_bottom] does not contain KEY_PRESS. The stack is then initialised: */
1264 if (edit
->stack_pointer
!= edit
->stack_bottom
1265 && edit
->undo_stack
[edit
->stack_bottom
] < KEY_PRESS
)
1266 edit
->stack_bottom
= edit
->stack_pointer
= 0;
1270 TODO: if the user undos until the stack bottom, and the stack has not wrapped,
1271 then the file should be as it was when he loaded up. Then set edit->modified to 0.
1274 pop_action (WEdit
* edit
)
1277 unsigned long sp
= edit
->stack_pointer
;
1279 if (sp
== edit
->stack_bottom
)
1280 return STACK_BOTTOM
;
1282 sp
= (sp
- 1) & edit
->stack_size_mask
;
1283 c
= edit
->undo_stack
[sp
];
1286 /* edit->undo_stack[sp] = '@'; */
1287 edit
->stack_pointer
= (edit
->stack_pointer
- 1) & edit
->stack_size_mask
;
1291 if (sp
== edit
->stack_bottom
)
1292 return STACK_BOTTOM
;
1294 c
= edit
->undo_stack
[(sp
- 1) & edit
->stack_size_mask
];
1295 if (edit
->undo_stack
[sp
] == -2)
1297 /* edit->undo_stack[sp] = '@'; */
1298 edit
->stack_pointer
= sp
;
1301 edit
->undo_stack
[sp
]++;
1306 /* is called whenever a modification is made by one of the four routines below */
1308 edit_modification (WEdit
* edit
)
1310 edit
->caches_valid
= 0;
1311 edit
->screen_modified
= 1;
1313 /* raise lock when file modified */
1314 if (!edit
->modified
&& !edit
->delete_file
)
1315 edit
->locked
= edit_lock_file (edit
);
1320 Basic low level single character buffer alterations and movements at the cursor.
1321 Returns char passed over, inserted or removed.
1325 edit_insert (WEdit
* edit
, int c
)
1327 /* check if file has grown to large */
1328 if (edit
->last_byte
>= SIZE_LIMIT
)
1331 /* first we must update the position of the display window */
1332 if (edit
->curs1
< edit
->start_display
)
1334 edit
->start_display
++;
1339 /* Mark file as modified, unless the file hasn't been fully loaded */
1340 if (edit
->loading_done
)
1342 edit_modification (edit
);
1345 /* now we must update some info on the file and check if a redraw is required */
1348 if (edit
->book_mark
)
1349 book_mark_inc (edit
, edit
->curs_line
);
1351 edit
->total_lines
++;
1352 edit
->force
|= REDRAW_LINE_ABOVE
| REDRAW_AFTER_CURSOR
;
1355 /* save the reverse command onto the undo stack */
1356 edit_push_action (edit
, BACKSPACE
);
1358 /* update markers */
1359 edit
->mark1
+= (edit
->mark1
> edit
->curs1
);
1360 edit
->mark2
+= (edit
->mark2
> edit
->curs1
);
1361 edit
->last_get_rule
+= (edit
->last_get_rule
> edit
->curs1
);
1363 /* add a new buffer if we've reached the end of the last one */
1364 if (!(edit
->curs1
& M_EDIT_BUF_SIZE
))
1365 edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
] = g_malloc0 (EDIT_BUF_SIZE
);
1367 /* perform the insertion */
1368 edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
][edit
->curs1
& M_EDIT_BUF_SIZE
]
1369 = (unsigned char) c
;
1371 /* update file length */
1374 /* update cursor position */
1379 edit_insert_over (WEdit
* edit
)
1383 for (i
= 0; i
< edit
->over_col
; i
++)
1385 edit_insert (edit
, ' ');
1390 /* same as edit_insert and move left */
1392 edit_insert_ahead (WEdit
* edit
, int c
)
1394 if (edit
->last_byte
>= SIZE_LIMIT
)
1397 if (edit
->curs1
< edit
->start_display
)
1399 edit
->start_display
++;
1403 edit_modification (edit
);
1406 if (edit
->book_mark
)
1407 book_mark_inc (edit
, edit
->curs_line
);
1408 edit
->total_lines
++;
1409 edit
->force
|= REDRAW_AFTER_CURSOR
;
1411 edit_push_action (edit
, DELCHAR
);
1413 edit
->mark1
+= (edit
->mark1
>= edit
->curs1
);
1414 edit
->mark2
+= (edit
->mark2
>= edit
->curs1
);
1415 edit
->last_get_rule
+= (edit
->last_get_rule
>= edit
->curs1
);
1417 if (!((edit
->curs2
+ 1) & M_EDIT_BUF_SIZE
))
1418 edit
->buffers2
[(edit
->curs2
+ 1) >> S_EDIT_BUF_SIZE
] = g_malloc0 (EDIT_BUF_SIZE
);
1419 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
]
1420 [EDIT_BUF_SIZE
- (edit
->curs2
& M_EDIT_BUF_SIZE
) - 1] = c
;
1428 edit_delete (WEdit
* edit
, const int byte_delete
)
1438 /* if byte_delete = 1 then delete only one byte not multibyte char */
1439 if (edit
->utf8
&& byte_delete
== 0)
1441 edit_get_utf (edit
, edit
->curs1
, &cw
);
1445 for (i
= 1; i
<= cw
; i
++)
1447 if (edit
->mark1
> edit
->curs1
)
1449 if (edit
->mark2
> edit
->curs1
)
1451 if (edit
->last_get_rule
> edit
->curs1
)
1452 edit
->last_get_rule
--;
1454 p
= edit
->buffers2
[(edit
->curs2
- 1) >> S_EDIT_BUF_SIZE
][EDIT_BUF_SIZE
-
1456 1) & M_EDIT_BUF_SIZE
) - 1];
1458 if (!(edit
->curs2
& M_EDIT_BUF_SIZE
))
1460 g_free (edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
]);
1461 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
] = NULL
;
1465 edit_push_action (edit
, p
+ 256);
1468 edit_modification (edit
);
1471 if (edit
->book_mark
)
1472 book_mark_dec (edit
, edit
->curs_line
);
1473 edit
->total_lines
--;
1474 edit
->force
|= REDRAW_AFTER_CURSOR
;
1476 if (edit
->curs1
< edit
->start_display
)
1478 edit
->start_display
--;
1488 edit_backspace (WEdit
* edit
, const int byte_delete
)
1499 if (edit
->utf8
&& byte_delete
== 0)
1501 edit_get_prev_utf (edit
, edit
->curs1
, &cw
);
1505 for (i
= 1; i
<= cw
; i
++)
1507 if (edit
->mark1
>= edit
->curs1
)
1509 if (edit
->mark1
>= edit
->curs1
)
1511 if (edit
->last_get_rule
>= edit
->curs1
)
1512 edit
->last_get_rule
--;
1514 p
= *(edit
->buffers1
[(edit
->curs1
- 1) >> S_EDIT_BUF_SIZE
] +
1515 ((edit
->curs1
- 1) & M_EDIT_BUF_SIZE
));
1516 if (!((edit
->curs1
- 1) & M_EDIT_BUF_SIZE
))
1518 g_free (edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
]);
1519 edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
] = NULL
;
1523 edit_push_action (edit
, p
);
1525 edit_modification (edit
);
1528 if (edit
->book_mark
)
1529 book_mark_dec (edit
, edit
->curs_line
);
1531 edit
->total_lines
--;
1532 edit
->force
|= REDRAW_AFTER_CURSOR
;
1535 if (edit
->curs1
< edit
->start_display
)
1537 edit
->start_display
--;
1545 #ifdef FAST_MOVE_CURSOR
1548 memqcpy (WEdit
* edit
, unsigned char *dest
, unsigned char *src
, int n
)
1551 while ((next
= (unsigned long) memccpy (dest
, src
, '\n', n
)))
1554 next
-= (unsigned long) dest
;
1562 edit_move_backward_lots (WEdit
* edit
, long increment
)
1565 unsigned char *p
= NULL
;
1567 if (increment
> edit
->curs1
)
1568 increment
= edit
->curs1
;
1571 edit_push_action (edit
, CURS_RIGHT_LOTS
, increment
);
1573 t
= r
= EDIT_BUF_SIZE
- (edit
->curs2
& M_EDIT_BUF_SIZE
);
1576 s
= edit
->curs1
& M_EDIT_BUF_SIZE
;
1581 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
] + t
- r
,
1582 edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
] + s
- r
, r
);
1589 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
] + t
-
1590 s
, edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
], s
);
1591 p
= edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
];
1592 edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
] = 0;
1595 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
] + t
- r
,
1596 edit
->buffers1
[(edit
->curs1
>> S_EDIT_BUF_SIZE
) - 1] +
1597 EDIT_BUF_SIZE
- (r
- s
), r
- s
);
1602 if (!(edit
->curs2
& M_EDIT_BUF_SIZE
))
1605 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
] = p
;
1607 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
] = g_malloc0 (EDIT_BUF_SIZE
);
1614 s
= edit
->curs1
& M_EDIT_BUF_SIZE
;
1625 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
] +
1626 EDIT_BUF_SIZE
- t
, edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
] + s
- t
, t
);
1631 p
= edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
];
1632 edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
] = 0;
1635 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
] +
1637 edit
->buffers1
[(edit
->curs1
>> S_EDIT_BUF_SIZE
) - 1] +
1638 EDIT_BUF_SIZE
- (r
- s
), r
- s
);
1643 if (!(edit
->curs2
& M_EDIT_BUF_SIZE
))
1646 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
] = p
;
1648 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
] = g_malloc0 (EDIT_BUF_SIZE
);
1653 return edit_get_byte (edit
, edit
->curs1
);
1656 #endif /* ! FAST_MOVE_CURSOR */
1658 /* moves the cursor right or left: increment positive or negative respectively */
1660 edit_cursor_move (WEdit
* edit
, long increment
)
1662 /* this is the same as a combination of two of the above routines, with only one push onto the undo stack */
1664 #ifdef FAST_MOVE_CURSOR
1665 if (increment
< -256)
1667 edit
->force
|= REDRAW_PAGE
;
1668 edit_move_backward_lots (edit
, -increment
);
1671 #endif /* ! FAST_MOVE_CURSOR */
1675 for (; increment
< 0; increment
++)
1680 edit_push_action (edit
, CURS_RIGHT
);
1682 c
= edit_get_byte (edit
, edit
->curs1
- 1);
1683 if (!((edit
->curs2
+ 1) & M_EDIT_BUF_SIZE
))
1684 edit
->buffers2
[(edit
->curs2
+ 1) >> S_EDIT_BUF_SIZE
] = g_malloc0 (EDIT_BUF_SIZE
);
1685 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
][EDIT_BUF_SIZE
-
1686 (edit
->curs2
& M_EDIT_BUF_SIZE
) - 1] = c
;
1688 c
= edit
->buffers1
[(edit
->curs1
- 1) >> S_EDIT_BUF_SIZE
][(edit
->curs1
-
1689 1) & M_EDIT_BUF_SIZE
];
1690 if (!((edit
->curs1
- 1) & M_EDIT_BUF_SIZE
))
1692 g_free (edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
]);
1693 edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
] = NULL
;
1699 edit
->force
|= REDRAW_LINE_BELOW
;
1704 else if (increment
> 0)
1706 for (; increment
> 0; increment
--)
1711 edit_push_action (edit
, CURS_LEFT
);
1713 c
= edit_get_byte (edit
, edit
->curs1
);
1714 if (!(edit
->curs1
& M_EDIT_BUF_SIZE
))
1715 edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
] = g_malloc0 (EDIT_BUF_SIZE
);
1716 edit
->buffers1
[edit
->curs1
>> S_EDIT_BUF_SIZE
][edit
->curs1
& M_EDIT_BUF_SIZE
] = c
;
1718 c
= edit
->buffers2
[(edit
->curs2
- 1) >> S_EDIT_BUF_SIZE
][EDIT_BUF_SIZE
-
1720 1) & M_EDIT_BUF_SIZE
) - 1];
1721 if (!(edit
->curs2
& M_EDIT_BUF_SIZE
))
1723 g_free (edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
]);
1724 edit
->buffers2
[edit
->curs2
>> S_EDIT_BUF_SIZE
] = 0;
1730 edit
->force
|= REDRAW_LINE_ABOVE
;
1736 /* These functions return positions relative to lines */
1738 /* returns index of last char on line + 1 */
1740 edit_eol (WEdit
* edit
, long current
)
1742 if (current
>= edit
->last_byte
)
1743 return edit
->last_byte
;
1746 if (edit_get_byte (edit
, current
) == '\n')
1751 /* returns index of first char on line */
1753 edit_bol (WEdit
* edit
, long current
)
1759 if (edit_get_byte (edit
, current
- 1) == '\n')
1766 edit_count_lines (WEdit
* edit
, long current
, long upto
)
1769 if (upto
> edit
->last_byte
)
1770 upto
= edit
->last_byte
;
1773 while (current
< upto
)
1774 if (edit_get_byte (edit
, current
++) == '\n')
1780 /* If lines is zero this returns the count of lines from current to upto. */
1781 /* If upto is zero returns index of lines forward current. */
1783 edit_move_forward (WEdit
* edit
, long current
, long lines
, long upto
)
1787 return edit_count_lines (edit
, current
, upto
);
1796 next
= edit_eol (edit
, current
) + 1;
1797 if (next
> edit
->last_byte
)
1807 /* Returns offset of 'lines' lines up from current */
1809 edit_move_backward (WEdit
* edit
, long current
, long lines
)
1813 current
= edit_bol (edit
, current
);
1814 while ((lines
--) && current
!= 0)
1815 current
= edit_bol (edit
, current
- 1);
1819 /* If cols is zero this returns the count of columns from current to upto. */
1820 /* If upto is zero returns index of cols across from current. */
1822 edit_move_forward3 (WEdit
* edit
, long current
, int cols
, long upto
)
1833 q
= edit
->last_byte
+ 2;
1835 for (col
= 0, p
= current
; p
< q
; p
++)
1849 orig_c
= c
= edit_get_byte (edit
, p
);
1853 utf_ch
= edit_get_utf (edit
, p
, &cw
);
1858 if (g_unichar_iswide (utf_ch
))
1861 else if (cw
> 1 && g_unichar_isprint (utf_ch
))
1865 c
= convert_to_display_c (c
);
1867 col
+= TAB_SIZE
- col
% TAB_SIZE
;
1875 else if ((c
< 32 || c
== 127) && (orig_c
== c
|| (!utf8_display
&& !edit
->utf8
)))
1876 /* '\r' is shown as ^M, so we must advance 2 characters */
1877 /* Caret notation for control characters */
1885 /* returns the current column position of the cursor */
1887 edit_get_col (WEdit
* edit
)
1889 return edit_move_forward3 (edit
, edit_bol (edit
, edit
->curs1
), 0, edit
->curs1
);
1893 /* Scrolling functions */
1896 edit_update_curs_row (WEdit
* edit
)
1898 edit
->curs_row
= edit
->curs_line
- edit
->start_line
;
1902 edit_update_curs_col (WEdit
* edit
)
1904 edit
->curs_col
= edit_move_forward3 (edit
, edit_bol (edit
, edit
->curs1
), 0, edit
->curs1
);
1908 edit_get_curs_col (const WEdit
* edit
)
1910 return edit
->curs_col
;
1913 /*moves the display start position up by i lines */
1915 edit_scroll_upward (WEdit
* edit
, unsigned long i
)
1917 unsigned long lines_above
= edit
->start_line
;
1918 if (i
> lines_above
)
1922 edit
->start_line
-= i
;
1923 edit
->start_display
= edit_move_backward (edit
, edit
->start_display
, i
);
1924 edit
->force
|= REDRAW_PAGE
;
1925 edit
->force
&= (0xfff - REDRAW_CHAR_ONLY
);
1927 edit_update_curs_row (edit
);
1931 /* returns 1 if could scroll, 0 otherwise */
1933 edit_scroll_downward (WEdit
* edit
, int i
)
1936 lines_below
= edit
->total_lines
- edit
->start_line
- (edit
->num_widget_lines
- 1);
1937 if (lines_below
> 0)
1939 if (i
> lines_below
)
1941 edit
->start_line
+= i
;
1942 edit
->start_display
= edit_move_forward (edit
, edit
->start_display
, i
, 0);
1943 edit
->force
|= REDRAW_PAGE
;
1944 edit
->force
&= (0xfff - REDRAW_CHAR_ONLY
);
1946 edit_update_curs_row (edit
);
1950 edit_scroll_right (WEdit
* edit
, int i
)
1952 edit
->force
|= REDRAW_PAGE
;
1953 edit
->force
&= (0xfff - REDRAW_CHAR_ONLY
);
1954 edit
->start_col
-= i
;
1958 edit_scroll_left (WEdit
* edit
, int i
)
1960 if (edit
->start_col
)
1962 edit
->start_col
+= i
;
1963 if (edit
->start_col
> 0)
1964 edit
->start_col
= 0;
1965 edit
->force
|= REDRAW_PAGE
;
1966 edit
->force
&= (0xfff - REDRAW_CHAR_ONLY
);
1970 /* high level cursor movement commands */
1973 is_in_indent (WEdit
* edit
)
1975 long p
= edit_bol (edit
, edit
->curs1
);
1976 while (p
< edit
->curs1
)
1977 if (!strchr (" \t", edit_get_byte (edit
, p
++)))
1982 static int left_of_four_spaces (WEdit
* edit
);
1985 edit_move_to_prev_col (WEdit
* edit
, long p
)
1987 int prev
= edit
->prev_col
;
1988 int over
= edit
->over_col
;
1989 edit_cursor_move (edit
, edit_move_forward3 (edit
, p
, prev
+ edit
->over_col
, 0) - edit
->curs1
);
1991 if (option_cursor_beyond_eol
)
1993 long line_len
= edit_move_forward3 (edit
, edit_bol (edit
, edit
->curs1
), 0,
1994 edit_eol (edit
, edit
->curs1
));
1996 if (line_len
< prev
+ edit
->over_col
)
1998 edit
->over_col
= prev
+ over
- line_len
;
1999 edit
->prev_col
= line_len
;
2000 edit
->curs_col
= line_len
;
2004 edit
->curs_col
= prev
+ over
;
2005 edit
->prev_col
= edit
->curs_col
;
2012 if (is_in_indent (edit
) && option_fake_half_tabs
)
2014 edit_update_curs_col (edit
);
2016 if (edit
->curs_col
% (HALF_TAB_SIZE
* space_width
))
2018 int q
= edit
->curs_col
;
2019 edit
->curs_col
-= (edit
->curs_col
% (HALF_TAB_SIZE
* space_width
));
2020 p
= edit_bol (edit
, edit
->curs1
);
2021 edit_cursor_move (edit
,
2022 edit_move_forward3 (edit
, p
, edit
->curs_col
,
2024 if (!left_of_four_spaces (edit
))
2025 edit_cursor_move (edit
, edit_move_forward3 (edit
, p
, q
, 0) - edit
->curs1
);
2032 is_blank (WEdit
* edit
, long offset
)
2036 s
= edit_bol (edit
, offset
);
2037 f
= edit_eol (edit
, offset
) - 1;
2040 c
= edit_get_byte (edit
, s
++);
2048 /* returns the offset of line i */
2050 edit_find_line (WEdit
* edit
, int line
)
2054 if (!edit
->caches_valid
)
2056 for (i
= 0; i
< N_LINE_CACHES
; i
++)
2057 edit
->line_numbers
[i
] = edit
->line_offsets
[i
] = 0;
2058 /* three offsets that we *know* are line 0 at 0 and these two: */
2059 edit
->line_numbers
[1] = edit
->curs_line
;
2060 edit
->line_offsets
[1] = edit_bol (edit
, edit
->curs1
);
2061 edit
->line_numbers
[2] = edit
->total_lines
;
2062 edit
->line_offsets
[2] = edit_bol (edit
, edit
->last_byte
);
2063 edit
->caches_valid
= 1;
2065 if (line
>= edit
->total_lines
)
2066 return edit
->line_offsets
[2];
2069 /* find the closest known point */
2070 for (i
= 0; i
< N_LINE_CACHES
; i
++)
2073 n
= abs (edit
->line_numbers
[i
] - line
);
2081 return edit
->line_offsets
[j
]; /* know the offset exactly */
2082 if (m
== 1 && j
>= 3)
2083 i
= j
; /* one line different - caller might be looping, so stay in this cache */
2085 i
= 3 + (rand () % (N_LINE_CACHES
- 3));
2086 if (line
> edit
->line_numbers
[j
])
2087 edit
->line_offsets
[i
] =
2088 edit_move_forward (edit
, edit
->line_offsets
[j
], line
- edit
->line_numbers
[j
], 0);
2090 edit
->line_offsets
[i
] =
2091 edit_move_backward (edit
, edit
->line_offsets
[j
], edit
->line_numbers
[j
] - line
);
2092 edit
->line_numbers
[i
] = line
;
2093 return edit
->line_offsets
[i
];
2097 line_is_blank (WEdit
* edit
, long line
)
2099 return is_blank (edit
, edit_find_line (edit
, line
));
2102 /* moves up until a blank line is reached, or until just
2103 before a non-blank line is reached */
2105 edit_move_up_paragraph (WEdit
* edit
, int do_scroll
)
2108 if (edit
->curs_line
> 1)
2110 if (line_is_blank (edit
, edit
->curs_line
))
2112 if (line_is_blank (edit
, edit
->curs_line
- 1))
2114 for (i
= edit
->curs_line
- 1; i
; i
--)
2115 if (!line_is_blank (edit
, i
))
2123 for (i
= edit
->curs_line
- 1; i
; i
--)
2124 if (line_is_blank (edit
, i
))
2130 for (i
= edit
->curs_line
- 1; i
; i
--)
2131 if (line_is_blank (edit
, i
))
2135 edit_move_up (edit
, edit
->curs_line
- i
, do_scroll
);
2138 /* moves down until a blank line is reached, or until just
2139 before a non-blank line is reached */
2141 edit_move_down_paragraph (WEdit
* edit
, int do_scroll
)
2144 if (edit
->curs_line
>= edit
->total_lines
- 1)
2146 i
= edit
->total_lines
;
2150 if (line_is_blank (edit
, edit
->curs_line
))
2152 if (line_is_blank (edit
, edit
->curs_line
+ 1))
2154 for (i
= edit
->curs_line
+ 1; i
; i
++)
2155 if (!line_is_blank (edit
, i
) || i
> edit
->total_lines
)
2163 for (i
= edit
->curs_line
+ 1; i
; i
++)
2164 if (line_is_blank (edit
, i
) || i
>= edit
->total_lines
)
2170 for (i
= edit
->curs_line
+ 1; i
; i
++)
2171 if (line_is_blank (edit
, i
) || i
>= edit
->total_lines
)
2175 edit_move_down (edit
, i
- edit
->curs_line
, do_scroll
);
2179 edit_begin_page (WEdit
* edit
)
2181 edit_update_curs_row (edit
);
2182 edit_move_up (edit
, edit
->curs_row
, 0);
2186 edit_end_page (WEdit
* edit
)
2188 edit_update_curs_row (edit
);
2189 edit_move_down (edit
, edit
->num_widget_lines
- edit
->curs_row
- 1, 0);
2193 /* goto beginning of text */
2195 edit_move_to_top (WEdit
* edit
)
2197 if (edit
->curs_line
)
2199 edit_cursor_move (edit
, -edit
->curs1
);
2200 edit_move_to_prev_col (edit
, 0);
2201 edit
->force
|= REDRAW_PAGE
;
2202 edit
->search_start
= 0;
2203 edit_update_curs_row (edit
);
2208 /* goto end of text */
2210 edit_move_to_bottom (WEdit
* edit
)
2212 if (edit
->curs_line
< edit
->total_lines
)
2214 edit_move_down (edit
, edit
->total_lines
- edit
->curs_row
, 0);
2215 edit
->start_display
= edit
->last_byte
;
2216 edit
->start_line
= edit
->total_lines
;
2217 edit_scroll_upward (edit
, edit
->num_widget_lines
- 1);
2218 edit
->force
|= REDRAW_PAGE
;
2222 /* goto beginning of line */
2224 edit_cursor_to_bol (WEdit
* edit
)
2226 edit_cursor_move (edit
, edit_bol (edit
, edit
->curs1
) - edit
->curs1
);
2227 edit
->search_start
= edit
->curs1
;
2228 edit
->prev_col
= edit_get_col (edit
);
2232 /* goto end of line */
2234 edit_cursor_to_eol (WEdit
* edit
)
2236 edit_cursor_move (edit
, edit_eol (edit
, edit
->curs1
) - edit
->curs1
);
2237 edit
->search_start
= edit
->curs1
;
2238 edit
->prev_col
= edit_get_col (edit
);
2242 /* move cursor to line 'line' */
2244 edit_move_to_line (WEdit
* e
, long line
)
2246 if (line
< e
->curs_line
)
2247 edit_move_up (e
, e
->curs_line
- line
, 0);
2249 edit_move_down (e
, line
- e
->curs_line
, 0);
2250 edit_scroll_screen_over_cursor (e
);
2253 /* scroll window so that first visible line is 'line' */
2255 edit_move_display (WEdit
* e
, long line
)
2257 if (line
< e
->start_line
)
2258 edit_scroll_upward (e
, e
->start_line
- line
);
2260 edit_scroll_downward (e
, line
- e
->start_line
);
2263 /* save markers onto undo stack */
2265 edit_push_markers (WEdit
* edit
)
2267 edit_push_action (edit
, MARK_1
+ edit
->mark1
);
2268 edit_push_action (edit
, MARK_2
+ edit
->mark2
);
2272 edit_set_markers (WEdit
* edit
, long m1
, long m2
, int c1
, int c2
)
2281 /* highlight marker toggle */
2283 edit_mark_cmd (WEdit
* edit
, int unmark
)
2285 edit_push_markers (edit
);
2288 edit_set_markers (edit
, 0, 0, 0, 0);
2289 edit
->force
|= REDRAW_PAGE
;
2293 if (edit
->mark2
>= 0)
2295 edit_set_markers (edit
, edit
->curs1
, -1, edit
->curs_col
+ edit
->over_col
,
2296 edit
->curs_col
+ edit
->over_col
);
2297 edit
->force
|= REDRAW_PAGE
;
2300 edit_set_markers (edit
, edit
->mark1
, edit
->curs1
, edit
->column1
,
2301 edit
->curs_col
+ edit
->over_col
);
2305 static unsigned long
2310 const char option_chars_move_whole_word
[] =
2311 "!=&|<>^~ !:;, !'!`!.?!\"!( !) !Aa0 !+-*/= |<> ![ !] !\\#! ";
2317 if (*option_chars_move_whole_word
== '!')
2319 return 0x80000000UL
;
2321 if (g_ascii_isupper ((gchar
) c
))
2323 else if (g_ascii_islower ((gchar
) c
))
2325 else if (g_ascii_isalpha (c
))
2327 else if (isdigit (c
))
2329 else if (isspace (c
))
2331 q
= strchr (option_chars_move_whole_word
, c
);
2333 return 0xFFFFFFFFUL
;
2336 for (x
= 1, p
= option_chars_move_whole_word
; p
< q
; p
++)
2341 while ((q
= strchr (q
+ 1, c
)));
2346 edit_left_word_move (WEdit
* edit
, int s
)
2351 if (edit
->column_highlight
2352 && edit
->mark1
!= edit
->mark2
2353 && edit
->over_col
== 0 && edit
->curs1
== edit_bol (edit
, edit
->curs1
))
2355 edit_cursor_move (edit
, -1);
2358 c1
= edit_get_byte (edit
, edit
->curs1
- 1);
2359 c2
= edit_get_byte (edit
, edit
->curs1
);
2360 if (!(my_type_of (c1
) & my_type_of (c2
)))
2362 if (isspace (c1
) && !isspace (c2
))
2365 if (!isspace (c1
) && isspace (c2
))
2371 edit_left_word_move_cmd (WEdit
* edit
)
2373 edit_left_word_move (edit
, 0);
2374 edit
->force
|= REDRAW_PAGE
;
2378 edit_right_word_move (WEdit
* edit
, int s
)
2383 if (edit
->column_highlight
2384 && edit
->mark1
!= edit
->mark2
2385 && edit
->over_col
== 0 && edit
->curs1
== edit_eol (edit
, edit
->curs1
))
2387 edit_cursor_move (edit
, 1);
2388 if (edit
->curs1
>= edit
->last_byte
)
2390 c1
= edit_get_byte (edit
, edit
->curs1
- 1);
2391 c2
= edit_get_byte (edit
, edit
->curs1
);
2392 if (!(my_type_of (c1
) & my_type_of (c2
)))
2394 if (isspace (c1
) && !isspace (c2
))
2397 if (!isspace (c1
) && isspace (c2
))
2403 edit_right_word_move_cmd (WEdit
* edit
)
2405 edit_right_word_move (edit
, 0);
2406 edit
->force
|= REDRAW_PAGE
;
2410 edit_right_char_move_cmd (WEdit
* edit
)
2416 c
= edit_get_utf (edit
, edit
->curs1
, &cw
);
2422 c
= edit_get_byte (edit
, edit
->curs1
);
2424 if (option_cursor_beyond_eol
&& c
== '\n')
2430 edit_cursor_move (edit
, cw
);
2435 edit_left_char_move_cmd (WEdit
* edit
)
2438 if (edit
->column_highlight
2439 && option_cursor_beyond_eol
2440 && edit
->mark1
!= edit
->mark2
2441 && edit
->over_col
== 0 && edit
->curs1
== edit_bol (edit
, edit
->curs1
))
2445 edit_get_prev_utf (edit
, edit
->curs1
, &cw
);
2449 if (option_cursor_beyond_eol
&& edit
->over_col
> 0)
2455 edit_cursor_move (edit
, -cw
);
2459 /** Up or down cursor moving.
2460 direction = TRUE - move up
2464 edit_move_updown (WEdit
* edit
, unsigned long i
, int do_scroll
, gboolean direction
)
2467 unsigned long l
= (direction
) ? edit
->curs_line
: edit
->total_lines
- edit
->curs_line
;
2476 edit
->force
|= REDRAW_PAGE
;
2480 edit_scroll_upward (edit
, i
);
2482 edit_scroll_downward (edit
, i
);
2484 p
= edit_bol (edit
, edit
->curs1
);
2486 p
= (direction
) ? edit_move_backward (edit
, p
, i
) : edit_move_forward (edit
, p
, i
, 0);
2488 edit_cursor_move (edit
, p
- edit
->curs1
);
2490 edit_move_to_prev_col (edit
, p
);
2492 /* search start of current multibyte char (like CJK) */
2493 if (edit
->curs1
+ 1 < edit
->last_byte
)
2495 edit_right_char_move_cmd (edit
);
2496 edit_left_char_move_cmd (edit
);
2499 edit
->search_start
= edit
->curs1
;
2500 edit
->found_len
= 0;
2504 edit_right_delete_word (WEdit
* edit
)
2509 if (edit
->curs1
>= edit
->last_byte
)
2511 c1
= edit_delete (edit
, 1);
2512 c2
= edit_get_byte (edit
, edit
->curs1
);
2513 if ((isspace (c1
) == 0) != (isspace (c2
) == 0))
2515 if (!(my_type_of (c1
) & my_type_of (c2
)))
2521 edit_left_delete_word (WEdit
* edit
)
2526 if (edit
->curs1
<= 0)
2528 c1
= edit_backspace (edit
, 1);
2529 c2
= edit_get_byte (edit
, edit
->curs1
- 1);
2530 if ((isspace (c1
) == 0) != (isspace (c2
) == 0))
2532 if (!(my_type_of (c1
) & my_type_of (c2
)))
2538 the start column position is not recorded, and hence does not
2539 undo as it happed. But who would notice.
2542 edit_do_undo (WEdit
* edit
)
2547 edit
->stack_disable
= 1; /* don't record undo's onto undo stack! */
2549 while ((ac
= pop_action (edit
)) < KEY_PRESS
)
2556 edit_cursor_move (edit
, 1);
2559 edit_cursor_move (edit
, -1);
2562 edit_backspace (edit
, 1);
2565 edit_delete (edit
, 1);
2568 edit
->column_highlight
= 1;
2571 edit
->column_highlight
= 0;
2574 if (ac
>= 256 && ac
< 512)
2575 edit_insert_ahead (edit
, ac
- 256);
2576 if (ac
>= 0 && ac
< 256)
2577 edit_insert (edit
, ac
);
2579 if (ac
>= MARK_1
- 2 && ac
< MARK_2
- 2)
2581 edit
->mark1
= ac
- MARK_1
;
2582 edit
->column1
= edit_move_forward3 (edit
, edit_bol (edit
, edit
->mark1
), 0, edit
->mark1
);
2584 else if (ac
>= MARK_2
- 2 && ac
< KEY_PRESS
)
2586 edit
->mark2
= ac
- MARK_2
;
2587 edit
->column2
= edit_move_forward3 (edit
, edit_bol (edit
, edit
->mark2
), 0, edit
->mark2
);
2590 edit
->force
|= REDRAW_PAGE
; /* more than one pop usually means something big */
2593 if (edit
->start_display
> ac
- KEY_PRESS
)
2595 edit
->start_line
-= edit_count_lines (edit
, ac
- KEY_PRESS
, edit
->start_display
);
2596 edit
->force
|= REDRAW_PAGE
;
2598 else if (edit
->start_display
< ac
- KEY_PRESS
)
2600 edit
->start_line
+= edit_count_lines (edit
, edit
->start_display
, ac
- KEY_PRESS
);
2601 edit
->force
|= REDRAW_PAGE
;
2603 edit
->start_display
= ac
- KEY_PRESS
; /* see push and pop above */
2604 edit_update_curs_row (edit
);
2607 edit
->stack_disable
= 0;
2611 edit_delete_to_line_end (WEdit
* edit
)
2613 while (edit_get_byte (edit
, edit
->curs1
) != '\n')
2617 edit_delete (edit
, 1);
2622 edit_delete_to_line_begin (WEdit
* edit
)
2624 while (edit_get_byte (edit
, edit
->curs1
- 1) != '\n')
2628 edit_backspace (edit
, 1);
2633 edit_delete_line (WEdit
* edit
)
2636 * Delete right part of the line.
2637 * Note that edit_get_byte() returns '\n' when byte position is
2640 while (edit_get_byte (edit
, edit
->curs1
) != '\n')
2642 (void) edit_delete (edit
, 1);
2647 * Note that edit_delete() will not corrupt anything if called while
2648 * cursor position is EOF.
2650 (void) edit_delete (edit
, 1);
2653 * Delete left part of the line.
2654 * Note, that edit_get_byte() returns '\n' when byte position is < 0.
2656 while (edit_get_byte (edit
, edit
->curs1
- 1) != '\n')
2658 (void) edit_backspace (edit
, 1);
2663 insert_spaces_tab (WEdit
* edit
, int half
)
2666 edit_update_curs_col (edit
);
2667 i
= ((edit
->curs_col
/ (option_tab_spacing
* space_width
/ (half
+ 1))) +
2668 1) * (option_tab_spacing
* space_width
/ (half
+ 1)) - edit
->curs_col
;
2671 edit_insert (edit
, ' ');
2677 is_aligned_on_a_tab (WEdit
* edit
)
2679 edit_update_curs_col (edit
);
2680 return !((edit
->curs_col
% (TAB_SIZE
* space_width
))
2681 && edit
->curs_col
% (TAB_SIZE
* space_width
) != (HALF_TAB_SIZE
* space_width
));
2685 right_of_four_spaces (WEdit
* edit
)
2688 for (i
= 1; i
<= HALF_TAB_SIZE
; i
++)
2689 ch
|= edit_get_byte (edit
, edit
->curs1
- i
);
2691 return is_aligned_on_a_tab (edit
);
2696 left_of_four_spaces (WEdit
* edit
)
2699 for (i
= 0; i
< HALF_TAB_SIZE
; i
++)
2700 ch
|= edit_get_byte (edit
, edit
->curs1
+ i
);
2702 return is_aligned_on_a_tab (edit
);
2707 edit_indent_width (WEdit
* edit
, long p
)
2710 while (strchr ("\t ", edit_get_byte (edit
, q
)) && q
< edit
->last_byte
- 1) /* move to the end of the leading whitespace of the line */
2712 return edit_move_forward3 (edit
, p
, 0, q
); /* count the number of columns of indentation */
2716 edit_insert_indent (WEdit
* edit
, int indent
)
2718 if (!option_fill_tabs_with_spaces
)
2720 while (indent
>= TAB_SIZE
)
2722 edit_insert (edit
, '\t');
2726 while (indent
-- > 0)
2727 edit_insert (edit
, ' ');
2731 edit_auto_indent (WEdit
* edit
)
2736 /* use the previous line as a template */
2737 p
= edit_move_backward (edit
, p
, 1);
2738 /* copy the leading whitespace of the line */
2740 { /* no range check - the line _is_ \n-terminated */
2741 c
= edit_get_byte (edit
, p
++);
2742 if (c
!= ' ' && c
!= '\t')
2744 edit_insert (edit
, c
);
2749 edit_double_newline (WEdit
* edit
)
2751 edit_insert (edit
, '\n');
2752 if (edit_get_byte (edit
, edit
->curs1
) == '\n')
2754 if (edit_get_byte (edit
, edit
->curs1
- 2) == '\n')
2756 edit
->force
|= REDRAW_PAGE
;
2757 edit_insert (edit
, '\n');
2761 edit_tab_cmd (WEdit
* edit
)
2765 if (option_fake_half_tabs
)
2767 if (is_in_indent (edit
))
2769 /*insert a half tab (usually four spaces) unless there is a
2770 half tab already behind, then delete it and insert a
2772 if (!option_fill_tabs_with_spaces
&& right_of_four_spaces (edit
))
2774 for (i
= 1; i
<= HALF_TAB_SIZE
; i
++)
2775 edit_backspace (edit
, 1);
2776 edit_insert (edit
, '\t');
2780 insert_spaces_tab (edit
, 1);
2785 if (option_fill_tabs_with_spaces
)
2787 insert_spaces_tab (edit
, 0);
2791 edit_insert (edit
, '\t');
2796 check_and_wrap_line (WEdit
* edit
)
2799 if (!option_typewriter_wrap
)
2801 edit_update_curs_col (edit
);
2802 if (edit
->curs_col
< option_word_wrap_line_length
)
2808 c
= edit_get_byte (edit
, curs
);
2809 if (c
== '\n' || curs
<= 0)
2811 edit_insert (edit
, '\n');
2814 if (c
== ' ' || c
== '\t')
2816 int current
= edit
->curs1
;
2817 edit_cursor_move (edit
, curs
- edit
->curs1
+ 1);
2818 edit_insert (edit
, '\n');
2819 edit_cursor_move (edit
, current
- edit
->curs1
+ 1);
2825 static inline void edit_execute_macro (WEdit
* edit
, struct macro macro
[], int n
);
2828 edit_push_key_press (WEdit
* edit
)
2830 edit_push_action (edit
, KEY_PRESS
+ edit
->start_display
);
2831 if (edit
->mark2
== -1)
2832 edit_push_action (edit
, MARK_1
+ edit
->mark1
);
2835 /* this find the matching bracket in either direction, and sets edit->bracket */
2837 edit_get_bracket (WEdit
* edit
, int in_screen
, unsigned long furthest_bracket_search
)
2839 const char *const b
= "{}{[][()(", *p
;
2840 int i
= 1, a
, inc
= -1, c
, d
, n
= 0;
2841 unsigned long j
= 0;
2843 edit_update_curs_row (edit
);
2844 c
= edit_get_byte (edit
, edit
->curs1
);
2847 if (!furthest_bracket_search
)
2848 furthest_bracket_search
--;
2849 /* not on a bracket at all */
2852 /* the matching bracket */
2854 /* going left or right? */
2855 if (strchr ("{[(", c
))
2857 for (q
= edit
->curs1
+ inc
;; q
+= inc
)
2859 /* out of buffer? */
2860 if (q
>= edit
->last_byte
|| q
< 0)
2862 a
= edit_get_byte (edit
, q
);
2863 /* don't want to eat CPU */
2864 if (j
++ > furthest_bracket_search
)
2866 /* out of screen? */
2869 if (q
< edit
->start_display
)
2871 /* count lines if searching downward */
2872 if (inc
> 0 && a
== '\n')
2873 if (n
++ >= edit
->num_widget_lines
- edit
->curs_row
) /* out of screen */
2876 /* count bracket depth */
2877 i
+= (a
== c
) - (a
== d
);
2878 /* return if bracket depth is zero */
2886 static long last_bracket
= -1;
2889 edit_find_bracket (WEdit
* edit
)
2891 edit
->bracket
= edit_get_bracket (edit
, 1, 10000);
2892 if (last_bracket
!= edit
->bracket
)
2893 edit
->force
|= REDRAW_PAGE
;
2894 last_bracket
= edit
->bracket
;
2898 edit_goto_matching_bracket (WEdit
* edit
)
2902 q
= edit_get_bracket (edit
, 0, 0);
2905 edit
->bracket
= edit
->curs1
;
2906 edit
->force
|= REDRAW_PAGE
;
2907 edit_cursor_move (edit
, q
- edit
->curs1
);
2912 * This executes a command as though the user initiated it through a key
2913 * press. Callback with WIDGET_KEY as a message calls this after
2914 * translating the key press. This function can be used to pass any
2915 * command to the editor. Note that the screen wouldn't update
2916 * automatically. Either of command or char_for_insertion must be
2917 * passed as -1. Commands are executed, and char_for_insertion is
2918 * inserted at the cursor.
2921 edit_execute_key_command (WEdit
* edit
, unsigned long command
, int char_for_insertion
)
2923 if (command
== CK_Begin_Record_Macro
)
2926 edit
->force
|= REDRAW_CHAR_ONLY
| REDRAW_LINE
;
2929 if (command
== CK_End_Record_Macro
&& edit
->macro_i
!= -1)
2931 edit
->force
|= REDRAW_COMPLETELY
;
2932 edit_save_macro_cmd (edit
, edit
->macro
, edit
->macro_i
);
2936 if (edit
->macro_i
>= 0 && edit
->macro_i
< MAX_MACRO_LENGTH
- 1)
2938 edit
->macro
[edit
->macro_i
].command
= command
;
2939 edit
->macro
[edit
->macro_i
++].ch
= char_for_insertion
;
2941 /* record the beginning of a set of editing actions initiated by a key press */
2942 if (command
!= CK_Undo
&& command
!= CK_Ext_Mode
)
2943 edit_push_key_press (edit
);
2945 edit_execute_cmd (edit
, command
, char_for_insertion
);
2946 if (edit
->column_highlight
)
2947 edit
->force
|= REDRAW_PAGE
;
2950 static const char *const shell_cmd
[] = SHELL_COMMANDS_i
;
2953 This executes a command at a lower level than macro recording.
2954 It also does not push a key_press onto the undo stack. This means
2955 that if it is called many times, a single undo command will undo
2956 all of them. It also does not check for the Undo command.
2959 edit_execute_cmd (WEdit
* edit
, unsigned long command
, int char_for_insertion
)
2961 edit
->force
|= REDRAW_LINE
;
2963 /* The next key press will unhighlight the found string, so update
2965 if (edit
->found_len
|| edit
->column_highlight
)
2966 edit
->force
|= REDRAW_PAGE
;
2968 if (command
/ 100 == 6)
2969 { /* a highlight command like shift-arrow */
2970 edit
->column_highlight
= 0;
2971 if (!edit
->highlight
|| (edit
->mark2
!= -1 && edit
->mark1
!= edit
->mark2
))
2973 edit_mark_cmd (edit
, 1); /* clear */
2974 edit_mark_cmd (edit
, 0); /* marking on */
2976 edit
->highlight
= 1;
2979 { /* any other command */
2980 if (edit
->highlight
)
2981 edit_mark_cmd (edit
, 0); /* clear */
2982 edit
->highlight
= 0;
2985 /* first check for undo */
2986 if (command
== CK_Undo
)
2988 edit_do_undo (edit
);
2989 edit
->found_len
= 0;
2990 edit
->prev_col
= edit_get_col (edit
);
2991 edit
->search_start
= edit
->curs1
;
2995 /* An ordinary key press */
2996 if (char_for_insertion
>= 0)
2998 /* if non persistent selection and text selected */
2999 if (!option_persistent_selections
)
3001 if (edit
->mark1
!= edit
->mark2
)
3002 edit_block_delete_cmd (edit
);
3004 if (edit
->overwrite
)
3006 /* remove char only one time, after input first byte, multibyte chars */
3007 if ((!utf8_display
|| edit
->charpoint
== 0)
3008 && edit_get_byte (edit
, edit
->curs1
) != '\n')
3009 edit_delete (edit
, 0);
3011 if (option_cursor_beyond_eol
&& edit
->over_col
> 0)
3012 edit_insert_over (edit
);
3014 if (char_for_insertion
> 255 && utf8_display
== 0)
3016 unsigned char str
[6 + 1];
3018 int res
= g_unichar_to_utf8 (char_for_insertion
, (char *) str
);
3028 while (str
[i
] != 0 && i
<= 6)
3030 char_for_insertion
= str
[i
];
3031 edit_insert (edit
, char_for_insertion
);
3037 edit_insert (edit
, char_for_insertion
);
3039 if (option_auto_para_formatting
)
3041 format_paragraph (edit
, 0);
3042 edit
->force
|= REDRAW_PAGE
;
3045 check_and_wrap_line (edit
);
3046 edit
->found_len
= 0;
3047 edit
->prev_col
= edit_get_col (edit
);
3048 edit
->search_start
= edit
->curs1
;
3049 edit_find_bracket (edit
);
3057 case CK_Begin_Page_Highlight
:
3058 case CK_End_Page_Highlight
:
3065 if (edit
->mark2
>= 0)
3067 if (!option_persistent_selections
)
3069 if (edit
->column_highlight
)
3070 edit_push_action (edit
, COLUMN_ON
);
3071 edit
->column_highlight
= 0;
3072 edit_mark_cmd (edit
, 1);
3081 case CK_Begin_Page_Highlight
:
3082 case CK_End_Page_Highlight
:
3087 case CK_Word_Left_Highlight
:
3088 case CK_Word_Right_Highlight
:
3089 case CK_Up_Highlight
:
3090 case CK_Down_Highlight
:
3091 case CK_Up_Alt_Highlight
:
3092 case CK_Down_Alt_Highlight
:
3093 if (edit
->mark2
== -1)
3094 break; /*marking is following the cursor: may need to highlight a whole line */
3097 case CK_Left_Highlight
:
3098 case CK_Right_Highlight
:
3099 edit
->force
|= REDRAW_CHAR_ONLY
;
3102 /* basic cursor key commands */
3106 /* if non persistent selection and text selected */
3107 if (!option_persistent_selections
)
3109 if (edit
->mark1
!= edit
->mark2
)
3111 edit_block_delete_cmd (edit
);
3115 if (option_cursor_beyond_eol
&& edit
->over_col
> 0)
3120 if (option_backspace_through_tabs
&& is_in_indent (edit
))
3122 while (edit_get_byte (edit
, edit
->curs1
- 1) != '\n' && edit
->curs1
> 0)
3123 edit_backspace (edit
, 1);
3128 if (option_fake_half_tabs
)
3131 if (is_in_indent (edit
) && right_of_four_spaces (edit
))
3133 for (i
= 0; i
< HALF_TAB_SIZE
; i
++)
3134 edit_backspace (edit
, 1);
3139 edit_backspace (edit
, 0);
3142 /* if non persistent selection and text selected */
3143 if (!option_persistent_selections
)
3145 if (edit
->mark1
!= edit
->mark2
)
3147 edit_block_delete_cmd (edit
);
3152 if (option_cursor_beyond_eol
&& edit
->over_col
> 0)
3153 edit_insert_over (edit
);
3155 if (option_fake_half_tabs
)
3158 if (is_in_indent (edit
) && left_of_four_spaces (edit
))
3160 for (i
= 1; i
<= HALF_TAB_SIZE
; i
++)
3161 edit_delete (edit
, 1);
3165 edit_delete (edit
, 0);
3167 case CK_Delete_Word_Left
:
3169 edit_left_delete_word (edit
);
3171 case CK_Delete_Word_Right
:
3172 if (option_cursor_beyond_eol
&& edit
->over_col
> 0)
3173 edit_insert_over (edit
);
3175 edit_right_delete_word (edit
);
3177 case CK_Delete_Line
:
3178 edit_delete_line (edit
);
3180 case CK_Delete_To_Line_End
:
3181 edit_delete_to_line_end (edit
);
3183 case CK_Delete_To_Line_Begin
:
3184 edit_delete_to_line_begin (edit
);
3188 if (option_auto_para_formatting
)
3190 edit_double_newline (edit
);
3191 if (option_return_does_auto_indent
)
3192 edit_auto_indent (edit
);
3193 format_paragraph (edit
, 0);
3197 edit_insert (edit
, '\n');
3198 if (option_return_does_auto_indent
)
3200 edit_auto_indent (edit
);
3205 edit_insert (edit
, '\n');
3208 case CK_Page_Up_Alt_Highlight
:
3209 edit
->column_highlight
= 1;
3211 case CK_Page_Up_Highlight
:
3212 edit_move_up (edit
, edit
->num_widget_lines
- 1, 1);
3214 case CK_Page_Down_Alt_Highlight
:
3215 edit
->column_highlight
= 1;
3217 case CK_Page_Down_Highlight
:
3218 edit_move_down (edit
, edit
->num_widget_lines
- 1, 1);
3220 case CK_Left_Alt_Highlight
:
3221 edit
->column_highlight
= 1;
3223 case CK_Left_Highlight
:
3224 if (option_fake_half_tabs
)
3226 if (is_in_indent (edit
) && right_of_four_spaces (edit
))
3228 if (option_cursor_beyond_eol
&& edit
->over_col
> 0)
3231 edit_cursor_move (edit
, -HALF_TAB_SIZE
);
3232 edit
->force
&= (0xFFF - REDRAW_CHAR_ONLY
);
3236 edit_left_char_move_cmd (edit
);
3238 case CK_Right_Alt_Highlight
:
3239 edit
->column_highlight
= 1;
3241 case CK_Right_Highlight
:
3242 if (option_fake_half_tabs
)
3244 if (is_in_indent (edit
) && left_of_four_spaces (edit
))
3246 edit_cursor_move (edit
, HALF_TAB_SIZE
);
3247 edit
->force
&= (0xFFF - REDRAW_CHAR_ONLY
);
3251 edit_right_char_move_cmd (edit
);
3254 case CK_Begin_Page_Highlight
:
3255 edit_begin_page (edit
);
3258 case CK_End_Page_Highlight
:
3259 edit_end_page (edit
);
3262 case CK_Word_Left_Highlight
:
3264 edit_left_word_move_cmd (edit
);
3267 case CK_Word_Right_Highlight
:
3269 edit_right_word_move_cmd (edit
);
3271 case CK_Up_Alt_Highlight
:
3272 edit
->column_highlight
= 1;
3274 case CK_Up_Highlight
:
3275 edit_move_up (edit
, 1, 0);
3277 case CK_Down_Alt_Highlight
:
3278 edit
->column_highlight
= 1;
3280 case CK_Down_Highlight
:
3281 edit_move_down (edit
, 1, 0);
3283 case CK_Paragraph_Up_Alt_Highlight
:
3284 edit
->column_highlight
= 1;
3285 case CK_Paragraph_Up
:
3286 case CK_Paragraph_Up_Highlight
:
3287 edit_move_up_paragraph (edit
, 0);
3289 case CK_Paragraph_Down_Alt_Highlight
:
3290 edit
->column_highlight
= 1;
3291 case CK_Paragraph_Down
:
3292 case CK_Paragraph_Down_Highlight
:
3293 edit_move_down_paragraph (edit
, 0);
3295 case CK_Scroll_Up_Alt_Highlight
:
3296 edit
->column_highlight
= 1;
3298 case CK_Scroll_Up_Highlight
:
3299 edit_move_up (edit
, 1, 1);
3301 case CK_Scroll_Down_Alt_Highlight
:
3302 edit
->column_highlight
= 1;
3303 case CK_Scroll_Down
:
3304 case CK_Scroll_Down_Highlight
:
3305 edit_move_down (edit
, 1, 1);
3308 case CK_Home_Highlight
:
3309 edit_cursor_to_bol (edit
);
3312 case CK_End_Highlight
:
3313 edit_cursor_to_eol (edit
);
3316 /* if text marked shift block */
3317 if (edit
->mark1
!= edit
->mark2
&& !option_persistent_selections
)
3319 if (edit
->mark2
< 0)
3320 edit_mark_cmd (edit
, 0);
3321 edit_move_block_to_right (edit
);
3325 if (option_cursor_beyond_eol
)
3326 edit_insert_over (edit
);
3327 edit_tab_cmd (edit
);
3328 if (option_auto_para_formatting
)
3330 format_paragraph (edit
, 0);
3331 edit
->force
|= REDRAW_PAGE
;
3335 check_and_wrap_line (edit
);
3340 case CK_Toggle_Insert
:
3341 edit
->overwrite
= (edit
->overwrite
== 0);
3345 if (edit
->mark2
>= 0)
3347 if (edit
->column_highlight
)
3348 edit_push_action (edit
, COLUMN_ON
);
3349 edit
->column_highlight
= 0;
3351 edit_mark_cmd (edit
, 0);
3353 case CK_Column_Mark
:
3354 if (!edit
->column_highlight
)
3355 edit_push_action (edit
, COLUMN_OFF
);
3356 edit
->column_highlight
= 1;
3357 edit_mark_cmd (edit
, 0);
3360 edit_set_markers (edit
, 0, edit
->last_byte
, 0, 0);
3361 edit
->force
|= REDRAW_PAGE
;
3364 if (edit
->column_highlight
)
3365 edit_push_action (edit
, COLUMN_ON
);
3366 edit
->column_highlight
= 0;
3367 edit_mark_cmd (edit
, 1);
3370 case CK_Toggle_Line_State
:
3371 option_line_state
= !option_line_state
;
3372 if (option_line_state
)
3374 option_line_state_width
= LINE_STATE_WIDTH
;
3378 option_line_state_width
= 0;
3380 edit
->force
|= REDRAW_PAGE
;
3383 case CK_Toggle_Show_Margin
:
3384 show_right_margin
= !show_right_margin
;
3385 edit
->force
|= REDRAW_PAGE
;
3388 case CK_Toggle_Bookmark
:
3389 book_mark_clear (edit
, edit
->curs_line
, BOOK_MARK_FOUND_COLOR
);
3390 if (book_mark_query_color (edit
, edit
->curs_line
, BOOK_MARK_COLOR
))
3391 book_mark_clear (edit
, edit
->curs_line
, BOOK_MARK_COLOR
);
3393 book_mark_insert (edit
, edit
->curs_line
, BOOK_MARK_COLOR
);
3395 case CK_Flush_Bookmarks
:
3396 book_mark_flush (edit
, BOOK_MARK_COLOR
);
3397 book_mark_flush (edit
, BOOK_MARK_FOUND_COLOR
);
3398 edit
->force
|= REDRAW_PAGE
;
3400 case CK_Next_Bookmark
:
3401 if (edit
->book_mark
)
3403 struct _book_mark
*p
;
3404 p
= (struct _book_mark
*) book_mark_find (edit
, edit
->curs_line
);
3408 if (p
->line
>= edit
->start_line
+ edit
->num_widget_lines
3409 || p
->line
< edit
->start_line
)
3410 edit_move_display (edit
, p
->line
- edit
->num_widget_lines
/ 2);
3411 edit_move_to_line (edit
, p
->line
);
3415 case CK_Prev_Bookmark
:
3416 if (edit
->book_mark
)
3418 struct _book_mark
*p
;
3419 p
= (struct _book_mark
*) book_mark_find (edit
, edit
->curs_line
);
3420 while (p
->line
== edit
->curs_line
)
3425 if (p
->line
>= edit
->start_line
+ edit
->num_widget_lines
3426 || p
->line
< edit
->start_line
)
3427 edit_move_display (edit
, p
->line
- edit
->num_widget_lines
/ 2);
3428 edit_move_to_line (edit
, p
->line
);
3433 case CK_Beginning_Of_Text
:
3434 case CK_Beginning_Of_Text_Highlight
:
3435 edit_move_to_top (edit
);
3437 case CK_End_Of_Text
:
3438 case CK_End_Of_Text_Highlight
:
3439 edit_move_to_bottom (edit
);
3443 if (option_cursor_beyond_eol
&& edit
->over_col
> 0)
3444 edit_insert_over (edit
);
3445 edit_block_copy_cmd (edit
);
3448 edit_block_delete_cmd (edit
);
3451 if (option_cursor_beyond_eol
&& edit
->over_col
> 0)
3452 edit_insert_over (edit
);
3453 edit_block_move_cmd (edit
);
3456 case CK_Shift_Block_Left
:
3457 if (edit
->mark1
!= edit
->mark2
)
3458 edit_move_block_to_left (edit
);
3460 case CK_Shift_Block_Right
:
3461 if (edit
->mark1
!= edit
->mark2
)
3462 edit_move_block_to_right (edit
);
3465 edit_copy_to_X_buf_cmd (edit
);
3468 edit_cut_to_X_buf_cmd (edit
);
3471 /* if non persistent selection and text selected */
3472 if (!option_persistent_selections
)
3474 if (edit
->mark1
!= edit
->mark2
)
3475 edit_block_delete_cmd (edit
);
3477 if (option_cursor_beyond_eol
&& edit
->over_col
> 0)
3478 edit_insert_over (edit
);
3479 edit_paste_from_X_buf_cmd (edit
);
3481 case CK_Selection_History
:
3482 edit_paste_from_history (edit
);
3486 edit_save_as_cmd (edit
);
3489 edit_save_confirm_cmd (edit
);
3492 edit_load_cmd (edit
, EDIT_FILE_COMMON
);
3495 edit_save_block_cmd (edit
);
3497 case CK_Insert_File
:
3498 edit_insert_file_cmd (edit
);
3501 case CK_Load_Prev_File
:
3502 edit_load_back_cmd (edit
);
3504 case CK_Load_Next_File
:
3505 edit_load_forward_cmd (edit
);
3508 case CK_Load_Syntax_File
:
3509 edit_load_cmd (edit
, EDIT_FILE_SYNTAX
);
3511 case CK_Choose_Syntax
:
3512 edit_syntax_dialog (edit
, edit
->syntax_type
);
3515 case CK_Load_Menu_File
:
3516 edit_load_cmd (edit
, EDIT_FILE_MENU
);
3519 case CK_Toggle_Syntax
:
3520 option_syntax_highlighting
^= 1;
3521 if (option_syntax_highlighting
== 1)
3522 edit_load_syntax (edit
, NULL
, edit
->syntax_type
);
3523 edit
->force
|= REDRAW_PAGE
;
3526 case CK_Toggle_Tab_TWS
:
3527 enable_show_tabs_tws
^= 1;
3528 edit
->force
|= REDRAW_PAGE
;
3532 edit_search_cmd (edit
, 0);
3535 edit_search_cmd (edit
, 1);
3538 edit_replace_cmd (edit
, 0);
3540 case CK_Replace_Again
:
3541 edit_replace_cmd (edit
, 1);
3543 case CK_Complete_Word
:
3544 /* if text marked shift block */
3545 if (edit
->mark1
!= edit
->mark2
&& !option_persistent_selections
)
3547 edit_move_block_to_left (edit
);
3551 edit_complete_word_cmd (edit
);
3554 case CK_Find_Definition
:
3555 edit_get_match_keyword_cmd (edit
);
3558 dlg_stop (edit
->widget
.owner
);
3561 edit_new_cmd (edit
);
3564 edit_help_cmd (edit
);
3567 edit_refresh_cmd (edit
);
3569 case CK_SaveSetupCmd
:
3578 case CK_Edit_Options
:
3579 edit_options_dialog (edit
);
3581 case CK_Edit_Save_Mode
:
3582 menu_save_mode_cmd ();
3587 /* fool gcc to prevent a Y2K warning */
3588 char time_format
[] = "_c";
3589 time_format
[0] = '%';
3591 FMT_LOCALTIME_CURRENT (s
, sizeof (s
), time_format
);
3592 edit_print_string (edit
, s
);
3593 edit
->force
|= REDRAW_PAGE
;
3598 edit_goto_cmd (edit
);
3600 case CK_Paragraph_Format
:
3601 format_paragraph (edit
, 1);
3602 edit
->force
|= REDRAW_PAGE
;
3604 case CK_Delete_Macro
:
3605 edit_delete_macro_cmd (edit
);
3607 case CK_Match_Bracket
:
3608 edit_goto_matching_bracket (edit
);
3614 edit_sort_cmd (edit
);
3617 edit_ext_cmd (edit
);
3620 edit_mail_dialog (edit
);
3625 case CK_SelectCodepage
:
3626 edit_select_codepage_cmd (edit
);
3628 case CK_Insert_Literal
:
3629 edit_insert_literal_cmd (edit
);
3631 case CK_Execute_Macro
:
3632 edit_execute_macro_cmd (edit
);
3634 case CK_Begin_End_Macro
:
3635 edit_begin_end_macro_cmd (edit
);
3645 if ((command
/ 1000) == 1) /* a shell command */
3646 edit_block_process_cmd (edit
, shell_cmd
[command
- 1000], 1);
3647 if (command
> CK_Macro (0) && command
<= CK_Last_Macro
)
3648 { /* a macro command */
3649 struct macro m
[MAX_MACRO_LENGTH
];
3651 if (edit_load_macro_cmd (edit
, m
, &nm
, command
- 2000))
3652 edit_execute_macro (edit
, m
, nm
);
3655 /* keys which must set the col position, and the search vars */
3661 case CK_Replace_Again
:
3662 case CK_Complete_Word
:
3663 edit
->prev_col
= edit_get_col (edit
);
3666 case CK_Up_Highlight
:
3667 case CK_Up_Alt_Highlight
:
3669 case CK_Down_Highlight
:
3670 case CK_Down_Alt_Highlight
:
3672 case CK_Page_Up_Highlight
:
3673 case CK_Page_Up_Alt_Highlight
:
3675 case CK_Page_Down_Highlight
:
3676 case CK_Page_Down_Alt_Highlight
:
3677 case CK_Beginning_Of_Text
:
3678 case CK_Beginning_Of_Text_Highlight
:
3679 case CK_End_Of_Text
:
3680 case CK_End_Of_Text_Highlight
:
3681 case CK_Paragraph_Up
:
3682 case CK_Paragraph_Up_Highlight
:
3683 case CK_Paragraph_Up_Alt_Highlight
:
3684 case CK_Paragraph_Down
:
3685 case CK_Paragraph_Down_Highlight
:
3686 case CK_Paragraph_Down_Alt_Highlight
:
3688 case CK_Scroll_Up_Highlight
:
3689 case CK_Scroll_Up_Alt_Highlight
:
3690 case CK_Scroll_Down
:
3691 case CK_Scroll_Down_Highlight
:
3692 case CK_Scroll_Down_Alt_Highlight
:
3693 edit
->search_start
= edit
->curs1
;
3694 edit
->found_len
= 0;
3697 edit
->found_len
= 0;
3698 edit
->prev_col
= edit_get_col (edit
);
3699 edit
->search_start
= edit
->curs1
;
3701 edit_find_bracket (edit
);
3703 if (option_auto_para_formatting
)
3709 case CK_Delete_Word_Left
:
3710 case CK_Delete_Word_Right
:
3711 case CK_Delete_To_Line_End
:
3712 case CK_Delete_To_Line_Begin
:
3713 format_paragraph (edit
, 0);
3714 edit
->force
|= REDRAW_PAGE
;
3721 edit_execute_macro (WEdit
* edit
, struct macro macro
[], int n
)
3725 if (edit
->macro_depth
++ > 256)
3727 edit_error_dialog (_("Error"), _("Macro recursion is too deep"));
3728 edit
->macro_depth
--;
3731 edit
->force
|= REDRAW_PAGE
;
3734 edit_execute_cmd (edit
, macro
[i
].command
, macro
[i
].ch
);
3736 edit_update_screen (edit
);
3737 edit
->macro_depth
--;
3740 /* User edit menu, like user menu (F2) but only in editor. */
3742 user_menu (WEdit
* edit
)
3746 long start_mark
, end_mark
;
3749 block_file
= concat_dir_and_file (home_dir
, EDIT_BLOCK_FILE
);
3751 nomark
= eval_marks (edit
, &start_mark
, &end_mark
);
3753 edit_save_block (edit
, block_file
, start_mark
, end_mark
);
3755 /* run shell scripts from menu */
3756 user_menu_cmd (edit
);
3758 if ((mc_stat (block_file
, &status
) == 0) && (status
.st_size
!= 0))
3765 /* i.e. we have marked block */
3766 rc
= edit_block_delete_cmd (edit
);
3770 edit_insert_file (edit
, block_file
);
3772 /* truncate block file */
3773 fd
= fopen (block_file
, "w");
3777 edit_refresh_cmd (edit
);
3778 edit
->force
|= REDRAW_COMPLETELY
;
3780 g_free (block_file
);
3784 edit_stack_init (void)
3786 for (edit_stack_iterator
= 0; edit_stack_iterator
< MAX_HISTORY_MOVETO
; edit_stack_iterator
++)
3788 edit_history_moveto
[edit_stack_iterator
].filename
= NULL
;
3789 edit_history_moveto
[edit_stack_iterator
].line
= -1;
3792 edit_stack_iterator
= 0;
3796 edit_stack_free (void)
3798 for (edit_stack_iterator
= 0; edit_stack_iterator
< MAX_HISTORY_MOVETO
; edit_stack_iterator
++)
3799 g_free (edit_history_moveto
[edit_stack_iterator
].filename
);
3804 edit_move_up (WEdit
* edit
, unsigned long i
, int do_scroll
)
3806 edit_move_updown (edit
, i
, do_scroll
, TRUE
);
3811 edit_move_down (WEdit
* edit
, unsigned long i
, int do_scroll
)
3813 edit_move_updown (edit
, i
, do_scroll
, FALSE
);
3817 edit_unlock_file (WEdit
* edit
)
3822 fullpath
= g_build_filename (edit
->dir
, edit
->filename
, (char *) NULL
);
3823 ret
= unlock_file (fullpath
);
3830 edit_lock_file (WEdit
* edit
)
3835 fullpath
= g_build_filename (edit
->dir
, edit
->filename
, (char *) NULL
);
3836 ret
= lock_file (fullpath
);