2 Editor high level editing commands
4 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
6 The Free Software Foundation, Inc.
10 Andrew Borodin <aborodin@vmail.ru>, 2012, 2013
11 Ilia Maslakov <il.smind@gmail.com>, 2012
13 This file is part of the Midnight Commander.
15 The Midnight Commander is free software: you can redistribute it
16 and/or modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation, either version 3 of the License,
18 or (at your option) any later version.
20 The Midnight Commander is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 * \brief Source: editor high level editing commands
35 /* #define PIPE_BLOCKS_SO_READ_BYTE_BY_BYTE */
46 #include <sys/types.h>
54 #include "lib/global.h"
55 #include "lib/tty/tty.h"
56 #include "lib/tty/key.h" /* XCTRL */
57 #include "lib/mcconfig.h"
59 #include "lib/strutil.h" /* utf string functions */
61 #include "lib/util.h" /* tilde_expand() */
62 #include "lib/vfs/vfs.h"
63 #include "lib/widget.h"
64 #include "lib/event.h" /* mc_event_raise() */
66 #include "lib/charsets.h"
69 #include "src/history.h"
70 #include "src/setup.h" /* option_tab_spacing */
72 #include "src/selcodepage.h"
74 #include "src/keybind-defaults.h"
75 #include "src/util.h" /* check_for_default() */
77 #include "edit-impl.h"
78 #include "editwidget.h"
79 #include "editcmd_dialogs.h"
82 #include "spell_dialogs.h"
86 /*** global variables ****************************************************************************/
88 /* search and replace: */
89 int search_create_bookmark
= FALSE
;
91 /* queries on a save */
92 int edit_confirm_save
= 1;
94 /*** file scope macro definitions ****************************************************************/
98 #define TEMP_BUF_LEN 1024
100 #define INPUT_INDEX 9
102 /* thanks to Liviu Daia <daia@stoilow.imar.ro> for getting this
103 (and the above) routines to work properly - paul */
105 #define is_digit(x) ((x) >= '0' && (x) <= '9')
107 #define MAX_WORD_COMPLETIONS 100 /* in listbox */
109 /*** file scope type declarations ****************************************************************/
111 /*** file scope variables ************************************************************************/
113 static unsigned long edit_save_mode_radio_id
, edit_save_mode_input_id
;
115 /* --------------------------------------------------------------------------------------------- */
116 /*** file scope functions ************************************************************************/
117 /* --------------------------------------------------------------------------------------------- */
120 edit_save_mode_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
125 if (sender
!= NULL
&& sender
->id
== edit_save_mode_radio_id
)
129 ww
= dlg_find_by_id (DIALOG (w
), edit_save_mode_input_id
);
130 widget_disable (ww
, RADIO (sender
)->sel
!= 2);
134 return MSG_NOT_HANDLED
;
137 return dlg_default_callback (w
, sender
, msg
, parm
, data
);
141 /* --------------------------------------------------------------------------------------------- */
143 /* If 0 (quick save) then a) create/truncate <filename> file,
144 b) save to <filename>;
145 if 1 (safe save) then a) save to <tempnam>,
146 b) rename <tempnam> to <filename>;
147 if 2 (do backups) then a) save to <tempnam>,
148 b) rename <filename> to <filename.backup_ext>,
149 c) rename <tempnam> to <filename>. */
151 /* returns 0 on error, -1 on abort */
154 edit_save_file (WEdit
* edit
, const vfs_path_t
* filename_vpath
)
159 int this_save_mode
, fd
= -1;
160 vfs_path_t
*real_filename_vpath
;
161 vfs_path_t
*savename_vpath
= NULL
;
162 const char *start_filename
;
163 const vfs_path_element_t
*vpath_element
;
165 vpath_element
= vfs_path_get_by_index (filename_vpath
, 0);
166 if (vpath_element
== NULL
)
169 start_filename
= vpath_element
->path
;
170 if (*start_filename
== '\0')
173 if (*start_filename
!= PATH_SEP
&& edit
->dir_vpath
!= NULL
)
175 real_filename_vpath
= vfs_path_append_vpath_new (edit
->dir_vpath
, filename_vpath
, NULL
);
179 real_filename_vpath
= vfs_path_clone (filename_vpath
);
182 this_save_mode
= option_save_mode
;
183 if (this_save_mode
!= EDIT_QUICK_SAVE
)
185 if (!vfs_file_is_local (real_filename_vpath
)
186 || (fd
= mc_open (real_filename_vpath
, O_RDONLY
| O_BINARY
)) == -1)
189 * The file does not exists yet, so no safe save or
190 * backup are necessary.
192 this_save_mode
= EDIT_QUICK_SAVE
;
198 if (this_save_mode
== EDIT_QUICK_SAVE
&& !edit
->skip_detach_prompt
)
203 rv
= mc_stat (real_filename_vpath
, &sb
);
204 if (rv
== 0 && sb
.st_nlink
> 1)
206 rv
= edit_query_dialog3 (_("Warning"),
207 _("File has hard-links. Detach before saving?"),
208 _("&Yes"), _("&No"), _("&Cancel"));
212 this_save_mode
= EDIT_SAFE_SAVE
;
215 edit
->skip_detach_prompt
= 1;
218 vfs_path_free (real_filename_vpath
);
223 /* Prevent overwriting changes from other editor sessions. */
224 if (rv
== 0 && edit
->stat1
.st_mtime
!= 0 && edit
->stat1
.st_mtime
!= sb
.st_mtime
)
226 /* The default action is "Cancel". */
229 rv
= edit_query_dialog2 (_("Warning"),
230 _("The file has been modified in the meantime. Save anyway?"),
231 _("&Yes"), _("&Cancel"));
234 vfs_path_free (real_filename_vpath
);
240 if (this_save_mode
!= EDIT_QUICK_SAVE
)
242 char *savedir
, *saveprefix
;
244 savedir
= vfs_path_tokens_get (real_filename_vpath
, 0, -1);
246 savedir
= g_strdup (".");
248 /* Token-related function never return leading slash, so we need add it manually */
249 saveprefix
= mc_build_filename ("/", savedir
, "cooledit", NULL
);
251 fd
= mc_mkstemps (&savename_vpath
, saveprefix
, NULL
);
253 if (savename_vpath
== NULL
)
255 vfs_path_free (real_filename_vpath
);
259 * Close for now because mc_mkstemps use pure open system call
260 * to create temporary file and it needs to be reopened by
261 * VFS-aware mc_open().
266 savename_vpath
= vfs_path_clone (real_filename_vpath
);
268 (void) mc_chown (savename_vpath
, edit
->stat1
.st_uid
, edit
->stat1
.st_gid
);
269 (void) mc_chmod (savename_vpath
, edit
->stat1
.st_mode
);
271 fd
= mc_open (savename_vpath
, O_CREAT
| O_WRONLY
| O_TRUNC
| O_BINARY
, edit
->stat1
.st_mode
);
276 p
= edit_get_write_filter (savename_vpath
, real_filename_vpath
);
282 file
= (FILE *) popen (p
, "w");
286 filelen
= edit_write_stream (edit
, file
);
290 if (pclose (file
) != 0)
292 tmp
= g_strdup_printf (_("Error writing to pipe: %s"), p
);
293 edit_error_dialog (_("Error"), tmp
);
302 tmp
= g_strdup_printf (_("Cannot open pipe for writing: %s"), p
);
303 edit_error_dialog (_("Error"), get_sys_error (tmp
));
310 else if (edit
->lb
== LB_ASIS
)
311 { /* do not change line breaks */
312 filelen
= edit_buffer_write_file (&edit
->buffer
, fd
);
314 if (filelen
!= edit
->buffer
.size
)
319 if (mc_close (fd
) != 0)
321 /* Update the file information, especially the mtime. */
322 if (mc_stat (savename_vpath
, &edit
->stat1
) == -1)
326 { /* change line breaks */
328 const vfs_path_element_t
*path_element
;
332 path_element
= vfs_path_get_by_index (savename_vpath
, -1);
333 file
= (FILE *) fopen (path_element
->path
, "w");
336 filelen
= edit_write_stream (edit
, file
);
343 msg
= g_strdup_printf (_("Cannot open file for writing: %s"), path_element
->path
);
344 edit_error_dialog (_("Error"), msg
);
350 if (filelen
!= edit
->buffer
.size
)
353 if (this_save_mode
== EDIT_DO_BACKUP
)
355 char *tmp_store_filename
;
356 vfs_path_element_t
*last_vpath_element
;
357 vfs_path_t
*tmp_vpath
;
361 assert (option_backup_ext
!= NULL
);
363 /* add backup extension to the path */
364 tmp_vpath
= vfs_path_clone (real_filename_vpath
);
365 last_vpath_element
= (vfs_path_element_t
*) vfs_path_get_by_index (tmp_vpath
, -1);
366 tmp_store_filename
= last_vpath_element
->path
;
367 last_vpath_element
->path
= g_strdup_printf ("%s%s", tmp_store_filename
, option_backup_ext
);
368 g_free (tmp_store_filename
);
370 ok
= (mc_rename (real_filename_vpath
, tmp_vpath
) != -1);
371 vfs_path_free (tmp_vpath
);
376 if (this_save_mode
!= EDIT_QUICK_SAVE
)
377 if (mc_rename (savename_vpath
, real_filename_vpath
) == -1)
380 vfs_path_free (real_filename_vpath
);
381 vfs_path_free (savename_vpath
);
384 /* FIXME: Is this safe ?
385 * if (this_save_mode != EDIT_QUICK_SAVE)
386 * mc_unlink (savename);
388 vfs_path_free (real_filename_vpath
);
389 vfs_path_free (savename_vpath
);
393 /* --------------------------------------------------------------------------------------------- */
396 edit_check_newline (const edit_buffer_t
* buf
)
398 return !(option_check_nl_at_eof
&& buf
->size
> 0
399 && edit_buffer_get_byte (buf
, buf
->size
- 1) != '\n'
400 && edit_query_dialog2 (_("Warning"),
401 _("The file you are saving is not finished with a newline"),
402 _("C&ontinue"), _("&Cancel")) != 0);
405 /* --------------------------------------------------------------------------------------------- */
408 edit_get_save_file_as (WEdit
* edit
)
410 static LineBreaks cur_lb
= LB_ASIS
;
412 vfs_path_t
*ret_vpath
= NULL
;
414 const char *lb_names
[LB_NAMES
] = {
415 N_("&Do not change"),
416 N_("&Unix format (LF)"),
417 N_("&Windows/DOS format (CR LF)"),
418 N_("&Macintosh format (CR)")
421 quick_widget_t quick_widgets
[] = {
423 QUICK_LABELED_INPUT (N_("Enter file name:"), input_label_above
,
424 vfs_path_as_str (edit
->filename_vpath
), "save-as",
425 &filename_res
, NULL
, FALSE
, FALSE
, INPUT_COMPLETE_FILENAMES
),
426 QUICK_SEPARATOR (TRUE
),
427 QUICK_LABEL (N_("Change line breaks to:"), NULL
),
428 QUICK_RADIO (LB_NAMES
, lb_names
, (int *) &cur_lb
, NULL
),
429 QUICK_BUTTONS_OK_CANCEL
,
434 quick_dialog_t qdlg
= {
436 N_("Save As"), "[Save File As]",
437 quick_widgets
, NULL
, NULL
440 if (quick_dialog (&qdlg
) != B_CANCEL
)
445 fname
= tilde_expand (filename_res
);
446 g_free (filename_res
);
447 ret_vpath
= vfs_path_from_str (fname
);
454 /* --------------------------------------------------------------------------------------------- */
456 /** returns TRUE on success */
459 edit_save_cmd (WEdit
* edit
)
461 int res
, save_lock
= 0;
463 if (!edit
->locked
&& !edit
->delete_file
)
464 save_lock
= lock_file (edit
->filename_vpath
);
465 res
= edit_save_file (edit
, edit
->filename_vpath
);
467 /* Maintain modify (not save) lock on failure */
468 if ((res
> 0 && edit
->locked
) || save_lock
)
469 edit
->locked
= unlock_file (edit
->filename_vpath
);
471 /* On failure try 'save as', it does locking on its own */
473 return edit_save_as_cmd (edit
);
474 edit
->force
|= REDRAW_COMPLETELY
;
477 edit
->delete_file
= 0;
484 /* --------------------------------------------------------------------------------------------- */
488 * @param h screen the owner of editor window
489 * @param vpath vfs file path
490 * @return TRUE if file content was successfully loaded, FALSE otherwise
493 static inline gboolean
494 edit_load_file_from_filename (WDialog
* h
, const vfs_path_t
* vpath
)
496 Widget
*w
= WIDGET (h
);
498 return edit_add_window (h
, w
->y
+ 1, w
->x
, w
->lines
- 2, w
->cols
, vpath
, 0);
501 /* --------------------------------------------------------------------------------------------- */
504 edit_delete_column_of_text (WEdit
* edit
)
511 eval_marks (edit
, &m1
, &m2
);
512 n
= edit_buffer_move_forward (&edit
->buffer
, m1
, 0, m2
) + 1;
513 c
= (long) edit_move_forward3 (edit
, edit_buffer_get_bol (&edit
->buffer
, m1
), 0, m1
);
514 d
= (long) edit_move_forward3 (edit
, edit_buffer_get_bol (&edit
->buffer
, m2
), 0, m2
);
515 b
= max (min (c
, d
), min (edit
->column1
, edit
->column2
));
516 c
= max (c
, max (edit
->column1
, edit
->column2
));
520 r
= edit_buffer_get_current_bol (&edit
->buffer
);
521 p
= edit_move_forward3 (edit
, r
, b
, 0);
522 q
= edit_move_forward3 (edit
, r
, c
, 0);
527 edit_cursor_move (edit
, p
- edit
->buffer
.curs1
);
530 /* delete line between margins */
531 if (edit_buffer_get_current_byte (&edit
->buffer
) != '\n')
532 edit_delete (edit
, TRUE
);
536 /* move to next line except on the last delete */
537 edit_cursor_move (edit
,
538 edit_buffer_move_forward (&edit
->buffer
, edit
->buffer
.curs1
, 1,
539 0) - edit
->buffer
.curs1
);
543 /* --------------------------------------------------------------------------------------------- */
544 /** if success return 0 */
547 edit_block_delete (WEdit
* edit
)
549 off_t start_mark
, end_mark
;
551 long curs_line
, c1
, c2
;
553 if (!eval_marks (edit
, &start_mark
, &end_mark
))
556 if (edit
->column_highlight
&& edit
->mark2
< 0)
557 edit_mark_cmd (edit
, FALSE
);
558 if ((end_mark
- start_mark
) > option_max_undo
/ 2)
560 /* Warning message with a query to continue or cancel the operation */
561 if (edit_query_dialog2
564 ("Block is large, you may not be able to undo this action"),
565 _("C&ontinue"), _("&Cancel")))
570 c1
= min (edit
->column1
, edit
->column2
);
571 c2
= max (edit
->column1
, edit
->column2
);
575 edit_push_markers (edit
);
577 curs_line
= edit
->buffer
.curs_line
;
579 curs_pos
= edit
->curs_col
+ edit
->over_col
;
581 /* move cursor to start of selection */
582 edit_cursor_move (edit
, start_mark
- edit
->buffer
.curs1
);
583 edit_scroll_screen_over_cursor (edit
);
585 if (start_mark
< end_mark
)
587 if (edit
->column_highlight
)
592 edit_mark_cmd (edit
, FALSE
);
593 edit_delete_column_of_text (edit
);
594 /* move cursor to the saved position */
595 edit_move_to_line (edit
, curs_line
);
596 /* calculate line width and cursor position before cut */
597 line_width
= edit_move_forward3 (edit
, edit_buffer_get_current_bol (&edit
->buffer
), 0,
598 edit_buffer_get_current_eol (&edit
->buffer
));
599 if (option_cursor_beyond_eol
&& curs_pos
> line_width
)
600 edit
->over_col
= curs_pos
- line_width
;
606 for (count
= start_mark
; count
< end_mark
; count
++)
607 edit_delete (edit
, TRUE
);
610 edit_set_markers (edit
, 0, 0, 0, 0);
611 edit
->force
|= REDRAW_PAGE
;
615 /* --------------------------------------------------------------------------------------------- */
617 * Get EOL symbol for searching.
619 * @param edit editor object
624 edit_search_get_current_end_line_char (const WEdit
* edit
)
635 /* --------------------------------------------------------------------------------------------- */
637 * Checking if search condition have BOL(^) or EOL ($) regexp special characters.
639 * @param search search object
640 * @return result of checks.
643 static edit_search_line_t
644 edit_get_search_line_type (mc_search_t
* search
)
646 edit_search_line_t search_line_type
= 0;
648 if (search
->search_type
!= MC_SEARCH_T_REGEX
)
649 return search_line_type
;
651 if (*search
->original
== '^')
652 search_line_type
|= AT_START_LINE
;
654 if (search
->original
[search
->original_len
- 1] == '$')
655 search_line_type
|= AT_END_LINE
;
656 return search_line_type
;
659 /* --------------------------------------------------------------------------------------------- */
661 * Calculating the start position of next line.
663 * @param buf editor buffer object
664 * @param current_pos current position
665 * @param max_pos max position
666 * @param end_string_symbol end of line symbol
667 * @return start position of next line
671 edit_calculate_start_of_next_line (const edit_buffer_t
* buf
, off_t current_pos
, off_t max_pos
,
672 char end_string_symbol
)
676 for (i
= current_pos
; i
< max_pos
; i
++)
679 if (edit_buffer_get_byte (buf
, i
) == end_string_symbol
)
686 /* --------------------------------------------------------------------------------------------- */
688 * Calculating the end position of previous line.
690 * @param buf editor buffer object
691 * @param current_pos current position
692 * @param end_string_symbol end of line symbol
693 * @return end position of previous line
697 edit_calculate_end_of_previous_line (const edit_buffer_t
* buf
, off_t current_pos
,
698 char end_string_symbol
)
702 for (i
= current_pos
- 1; i
>= 0; i
--)
703 if (edit_buffer_get_byte (buf
, i
) == end_string_symbol
)
709 /* --------------------------------------------------------------------------------------------- */
711 * Calculating the start position of previous line.
713 * @param buf editor buffer object
714 * @param current_pos current position
715 * @param end_string_symbol end of line symbol
716 * @return start position of previous line
720 edit_calculate_start_of_previous_line (const edit_buffer_t
* buf
, off_t current_pos
,
721 char end_string_symbol
)
723 current_pos
= edit_calculate_end_of_previous_line (buf
, current_pos
, end_string_symbol
);
724 current_pos
= edit_calculate_end_of_previous_line (buf
, current_pos
, end_string_symbol
);
726 return (current_pos
+ 1);
729 /* --------------------------------------------------------------------------------------------- */
731 * Calculating the start position of current line.
733 * @param buf editor buffer object
734 * @param current_pos current position
735 * @param end_string_symbol end of line symbol
736 * @return start position of current line
740 edit_calculate_start_of_current_line (const edit_buffer_t
* buf
, off_t current_pos
,
741 char end_string_symbol
)
743 current_pos
= edit_calculate_end_of_previous_line (buf
, current_pos
, end_string_symbol
);
745 return (current_pos
+ 1);
748 /* --------------------------------------------------------------------------------------------- */
750 * Fixing (if needed) search start position if 'only in selection' option present.
752 * @param edit editor object
756 edit_search_fix_search_start_if_selection (WEdit
* edit
)
758 off_t start_mark
= 0;
761 if (!edit_search_options
.only_in_selection
)
764 if (!eval_marks (edit
, &start_mark
, &end_mark
) != 0)
767 if (edit_search_options
.backwards
)
769 if (edit
->search_start
> end_mark
|| edit
->search_start
<= start_mark
)
770 edit
->search_start
= end_mark
;
774 if (edit
->search_start
< start_mark
|| edit
->search_start
>= end_mark
)
775 edit
->search_start
= start_mark
;
779 /* --------------------------------------------------------------------------------------------- */
782 editcmd_find (WEdit
* edit
, gsize
* len
)
784 off_t search_start
= edit
->search_start
;
786 off_t start_mark
= 0;
787 off_t end_mark
= edit
->buffer
.size
;
788 char end_string_symbol
;
790 end_string_symbol
= edit_search_get_current_end_line_char (edit
);
792 /* prepare for search */
793 if (edit_search_options
.only_in_selection
)
795 if (!eval_marks (edit
, &start_mark
, &end_mark
))
797 edit
->search
->error
= MC_SEARCH_E_NOTFOUND
;
798 edit
->search
->error_str
= g_strdup (_("Search string not found"));
802 /* fix the start and the end of search block positions */
803 if ((edit
->search_line_type
& AT_START_LINE
) != 0
805 || edit_buffer_get_byte (&edit
->buffer
, start_mark
- 1) != end_string_symbol
))
808 edit_calculate_start_of_next_line (&edit
->buffer
, start_mark
, edit
->buffer
.size
,
811 if ((edit
->search_line_type
& AT_END_LINE
) != 0
812 && (end_mark
- 1 != edit
->buffer
.size
813 || edit_buffer_get_byte (&edit
->buffer
, end_mark
) != end_string_symbol
))
815 edit_calculate_end_of_previous_line (&edit
->buffer
, end_mark
, end_string_symbol
);
816 if (start_mark
>= end_mark
)
818 edit
->search
->error
= MC_SEARCH_E_NOTFOUND
;
819 edit
->search
->error_str
= g_strdup (_("Search string not found"));
825 if (edit_search_options
.backwards
)
826 end_mark
= max (1, edit
->buffer
.curs1
) - 1;
830 if (edit_search_options
.backwards
)
832 /* backward search */
833 search_end
= end_mark
;
835 if ((edit
->search_line_type
& AT_START_LINE
) != 0)
837 edit_calculate_start_of_current_line (&edit
->buffer
, search_start
,
840 while (search_start
>= start_mark
)
842 if (search_end
> (off_t
) (search_start
+ edit
->search
->original_len
)
843 && mc_search_is_fixed_search_str (edit
->search
))
845 search_end
= search_start
+ edit
->search
->original_len
;
847 if (mc_search_run (edit
->search
, (void *) edit
, search_start
, search_end
, len
)
848 && edit
->search
->normal_offset
== search_start
)
854 if ((edit
->search_line_type
& AT_START_LINE
) != 0)
856 edit_calculate_start_of_previous_line (&edit
->buffer
, search_start
,
861 edit
->search
->error_str
= g_strdup (_("Search string not found"));
866 if ((edit
->search_line_type
& AT_START_LINE
) != 0 && search_start
!= start_mark
)
868 edit_calculate_start_of_next_line (&edit
->buffer
, search_start
, end_mark
,
870 return mc_search_run (edit
->search
, (void *) edit
, search_start
, end_mark
, len
);
875 /* --------------------------------------------------------------------------------------------- */
878 edit_replace_cmd__conv_to_display (char *str
)
883 tmp
= str_convert_to_display (str
);
887 return g_string_free (tmp
, FALSE
);
888 g_string_free (tmp
, TRUE
);
891 return g_strdup (str
);
894 /* --------------------------------------------------------------------------------------------- */
897 edit_replace_cmd__conv_to_input (char *str
)
902 tmp
= str_convert_to_input (str
);
906 return g_string_free (tmp
, FALSE
);
907 g_string_free (tmp
, TRUE
);
910 return g_strdup (str
);
913 /* --------------------------------------------------------------------------------------------- */
916 edit_do_search (WEdit
* edit
)
920 if (edit
->search
== NULL
)
921 edit
->search_start
= edit
->buffer
.curs1
;
923 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
925 if (search_create_bookmark
)
927 int found
= 0, books
= 0;
928 long l
= 0, l_last
= -1;
931 search_create_bookmark
= FALSE
;
932 book_mark_flush (edit
, -1);
934 while (mc_search_run (edit
->search
, (void *) edit
, q
, edit
->buffer
.size
, &len
))
937 edit
->search_start
= edit
->search
->normal_offset
;
939 l
+= edit_buffer_count_lines (&edit
->buffer
, q
, edit
->search
->normal_offset
);
942 book_mark_insert (edit
, l
, BOOK_MARK_FOUND_COLOR
);
946 q
= edit
->search
->normal_offset
+ 1;
950 edit_error_dialog (_("Search"), _("Search string not found"));
952 edit_cursor_move (edit
, edit
->search_start
- edit
->buffer
.curs1
);
956 if (edit
->found_len
!= 0 && edit
->search_start
== edit
->found_start
+ 1
957 && edit_search_options
.backwards
)
958 edit
->search_start
--;
960 if (edit
->found_len
!= 0 && edit
->search_start
== edit
->found_start
- 1
961 && !edit_search_options
.backwards
)
962 edit
->search_start
++;
964 if (editcmd_find (edit
, &len
))
966 edit
->found_start
= edit
->search_start
= edit
->search
->normal_offset
;
967 edit
->found_len
= len
;
969 edit_cursor_move (edit
, edit
->search_start
- edit
->buffer
.curs1
);
970 edit_scroll_screen_over_cursor (edit
);
971 if (edit_search_options
.backwards
)
972 edit
->search_start
--;
974 edit
->search_start
++;
978 edit
->search_start
= edit
->buffer
.curs1
;
979 if (edit
->search
->error_str
!= NULL
)
980 edit_error_dialog (_("Search"), edit
->search
->error_str
);
984 edit
->force
|= REDRAW_COMPLETELY
;
985 edit_scroll_screen_over_cursor (edit
);
988 /* --------------------------------------------------------------------------------------------- */
991 edit_search (WEdit
* edit
)
993 if (editcmd_dialog_search_show (edit
))
995 edit
->search_line_type
= edit_get_search_line_type (edit
->search
);
996 edit_search_fix_search_start_if_selection (edit
);
997 edit_do_search (edit
);
1001 /* --------------------------------------------------------------------------------------------- */
1002 /** Return a null terminated length of text. Result must be g_free'd */
1004 static unsigned char *
1005 edit_get_block (WEdit
* edit
, off_t start
, off_t finish
, off_t
* l
)
1007 unsigned char *s
, *r
;
1009 r
= s
= g_malloc0 (finish
- start
+ 1);
1010 if (edit
->column_highlight
)
1013 /* copy from buffer, excluding chars that are out of the column 'margins' */
1014 while (start
< finish
)
1019 x
= edit_move_forward3 (edit
, edit_buffer_get_bol (&edit
->buffer
, start
), 0, start
);
1020 c
= edit_buffer_get_byte (&edit
->buffer
, start
);
1021 if ((x
>= edit
->column1
&& x
< edit
->column2
)
1022 || (x
>= edit
->column2
&& x
< edit
->column1
) || c
== '\n')
1032 *l
= finish
- start
;
1033 while (start
< finish
)
1034 *s
++ = edit_buffer_get_byte (&edit
->buffer
, start
++);
1040 /* --------------------------------------------------------------------------------------------- */
1041 /** copies a block to clipboard file */
1044 edit_save_block_to_clip_file (WEdit
* edit
, off_t start
, off_t finish
)
1049 tmp
= mc_config_get_full_path (EDIT_CLIP_FILE
);
1050 ret
= edit_save_block (edit
, tmp
, start
, finish
);
1055 /* --------------------------------------------------------------------------------------------- */
1058 pipe_mail (const edit_buffer_t
* buf
, char *to
, char *subject
, char *cc
)
1063 to
= name_quote (to
, 0);
1064 subject
= name_quote (subject
, 0);
1065 cc
= name_quote (cc
, 0);
1066 s
= g_strconcat ("mail -s ", subject
, *cc
? " -c " : "", cc
, " ", to
, (char *) NULL
);
1081 for (i
= 0; i
< buf
->size
; i
++)
1082 fputc (edit_buffer_get_byte (buf
, i
), p
);
1087 /* --------------------------------------------------------------------------------------------- */
1088 /** find first character of current word */
1091 edit_find_word_start (const edit_buffer_t
* buf
, off_t
* word_start
, gsize
* word_len
)
1096 /* return if at begin of file */
1097 if (buf
->curs1
<= 0)
1100 c
= edit_buffer_get_previous_byte (buf
);
1101 /* return if not at end or in word */
1102 if (is_break_char (c
))
1105 /* search start of word to be completed */
1111 c
= edit_buffer_get_byte (buf
, buf
->curs1
- i
- 1);
1113 if (is_break_char (c
))
1115 /* return if word starts with digit */
1124 *word_start
= buf
->curs1
- i
; /* start found */
1125 *word_len
= (gsize
) i
;
1129 /* --------------------------------------------------------------------------------------------- */
1131 * Get current word under cursor
1133 * @param edit editor object
1134 * @param srch mc_search object
1135 * @param word_start start word position
1137 * @return newly allocated string or NULL if no any words under cursor
1141 edit_collect_completions_get_current_word (WEdit
* edit
, mc_search_t
* srch
, off_t word_start
)
1147 if (!mc_search_run (srch
, (void *) edit
, word_start
, edit
->buffer
.size
, &len
))
1150 temp
= g_string_sized_new (len
);
1152 for (i
= 0; i
< (off_t
) len
; i
++)
1156 chr
= edit_buffer_get_byte (&edit
->buffer
, word_start
+ i
);
1158 g_string_append_c (temp
, chr
);
1161 return g_string_free (temp
, temp
->len
== 0);
1164 /* --------------------------------------------------------------------------------------------- */
1165 /** collect the possible completions */
1168 edit_collect_completions (WEdit
* edit
, off_t word_start
, gsize word_len
,
1169 char *match_expr
, GString
** compl, gsize
* num
)
1177 off_t last_byte
, start
= -1;
1181 srch
= mc_search_new (match_expr
, -1, cp_source
);
1183 srch
= mc_search_new (match_expr
, -1, NULL
);
1188 if (mc_config_get_bool
1189 (mc_main_config
, CONFIG_APP_SECTION
, "editor_wordcompletion_collect_entire_file", 0))
1191 last_byte
= edit
->buffer
.size
;
1195 last_byte
= word_start
;
1198 srch
->search_type
= MC_SEARCH_T_REGEX
;
1199 srch
->is_case_sensitive
= TRUE
;
1200 srch
->search_fn
= edit_search_cmd_callback
;
1202 current_word
= edit_collect_completions_get_current_word (edit
, srch
, word_start
);
1204 temp
= g_string_new ("");
1206 /* collect max MAX_WORD_COMPLETIONS completions */
1207 while (mc_search_run (srch
, (void *) edit
, start
+ 1, last_byte
, &len
))
1209 g_string_set_size (temp
, 0);
1210 start
= srch
->normal_offset
;
1212 /* add matched completion if not yet added */
1213 for (i
= 0; i
< len
; i
++)
1215 skip
= edit_buffer_get_byte (&edit
->buffer
, start
+ i
);
1219 /* skip current word */
1220 if (start
+ (off_t
) i
== word_start
)
1223 g_string_append_c (temp
, skip
);
1229 if (current_word
!= NULL
&& strcmp (current_word
, temp
->str
) == 0)
1234 for (i
= 0; i
< *num
; i
++)
1237 ((char *) &compl[i
]->str
[word_len
],
1238 (char *) &temp
->str
[word_len
], max (len
, compl[i
]->len
) - word_len
) == 0)
1240 GString
*this = compl[i
];
1241 for (++i
; i
< *num
; i
++)
1242 compl[i
- 1] = compl[i
];
1243 compl[*num
- 1] = this;
1245 break; /* skip it, already added */
1251 if (*num
== MAX_WORD_COMPLETIONS
)
1253 g_string_free (compl[0], TRUE
);
1254 for (i
= 1; i
< *num
; i
++)
1255 compl[i
- 1] = compl[i
];
1261 recoded
= str_convert_to_display (temp
->str
);
1263 if (recoded
&& recoded
->len
)
1264 g_string_assign (temp
, recoded
->str
);
1266 g_string_free (recoded
, TRUE
);
1269 compl[(*num
)++] = g_string_new_len (temp
->str
, temp
->len
);
1272 /* note the maximal length needed for the completion dialog */
1277 mc_search_free (srch
);
1278 g_string_free (temp
, TRUE
);
1279 g_free (current_word
);
1284 /* --------------------------------------------------------------------------------------------- */
1287 edit_insert_column_of_text (WEdit
* edit
, unsigned char *data
, off_t size
, long width
,
1288 off_t
* start_pos
, off_t
* end_pos
, long *col1
, long *col2
)
1293 cursor
= edit
->buffer
.curs1
;
1294 col
= edit_get_col (edit
);
1296 for (i
= 0; i
< size
; i
++)
1298 if (data
[i
] != '\n')
1299 edit_insert (edit
, data
[i
]);
1301 { /* fill in and move to next line */
1305 if (edit_buffer_get_current_byte (&edit
->buffer
) != '\n')
1307 for (l
= width
- (edit_get_col (edit
) - col
); l
> 0; l
-= space_width
)
1308 edit_insert (edit
, ' ');
1310 for (p
= edit
->buffer
.curs1
;; p
++)
1312 if (p
== edit
->buffer
.size
)
1314 edit_cursor_move (edit
, edit
->buffer
.size
- edit
->buffer
.curs1
);
1315 edit_insert_ahead (edit
, '\n');
1319 if (edit_buffer_get_byte (&edit
->buffer
, p
) == '\n')
1325 edit_cursor_move (edit
, edit_move_forward3 (edit
, p
, col
, 0) - edit
->buffer
.curs1
);
1327 for (l
= col
- edit_get_col (edit
); l
>= space_width
; l
-= space_width
)
1328 edit_insert (edit
, ' ');
1333 *col2
= col
+ width
;
1334 *start_pos
= cursor
;
1335 *end_pos
= edit
->buffer
.curs1
;
1336 edit_cursor_move (edit
, cursor
- edit
->buffer
.curs1
);
1339 /* --------------------------------------------------------------------------------------------- */
1342 edit_macro_comparator (gconstpointer
* macro1
, gconstpointer
* macro2
)
1344 const macros_t
*m1
= (const macros_t
*) macro1
;
1345 const macros_t
*m2
= (const macros_t
*) macro2
;
1347 return m1
->hotkey
- m2
->hotkey
;
1350 /* --------------------------------------------------------------------------------------------- */
1353 edit_macro_sort_by_hotkey (void)
1355 if (macros_list
!= NULL
&& macros_list
->len
!= 0)
1356 g_array_sort (macros_list
, (GCompareFunc
) edit_macro_comparator
);
1359 /* --------------------------------------------------------------------------------------------- */
1362 edit_get_macro (WEdit
* edit
, int hotkey
, const macros_t
** macros
, guint
* indx
)
1364 const macros_t
*array_start
= &g_array_index (macros_list
, struct macros_t
, 0);
1366 macros_t search_macro
;
1370 search_macro
.hotkey
= hotkey
;
1371 result
= bsearch (&search_macro
, macros_list
->data
, macros_list
->len
,
1372 sizeof (macros_t
), (GCompareFunc
) edit_macro_comparator
);
1374 if (result
!= NULL
&& result
->macro
!= NULL
)
1376 *indx
= (result
- array_start
);
1384 /* --------------------------------------------------------------------------------------------- */
1385 /** returns FALSE on error */
1388 edit_delete_macro (WEdit
* edit
, int hotkey
)
1390 mc_config_t
*macros_config
= NULL
;
1391 const char *section_name
= "editor";
1392 gchar
*macros_fname
;
1395 const macros_t
*macros
= NULL
;
1397 /* clear array of actions for current hotkey */
1398 while (edit_get_macro (edit
, hotkey
, ¯os
, &indx
))
1400 if (macros
->macro
!= NULL
)
1401 g_array_free (macros
->macro
, TRUE
);
1403 g_array_remove_index (macros_list
, indx
);
1404 edit_macro_sort_by_hotkey ();
1407 macros_fname
= mc_config_get_full_path (MC_MACRO_FILE
);
1408 macros_config
= mc_config_init (macros_fname
, FALSE
);
1409 g_free (macros_fname
);
1411 if (macros_config
== NULL
)
1414 skeyname
= lookup_key_by_code (hotkey
);
1415 while (mc_config_del_key (macros_config
, section_name
, skeyname
))
1418 mc_config_save_file (macros_config
, NULL
);
1419 mc_config_deinit (macros_config
);
1423 /* --------------------------------------------------------------------------------------------- */
1425 * Callback for the iteration of objects in the 'editors' array.
1426 * Toggle syntax highlighting in editor object.
1428 * @param data probably WEdit object
1429 * @param user_data unused
1433 edit_syntax_onoff_cb (void *data
, void *user_data
)
1437 if (edit_widget_is_editor ((const Widget
*) data
))
1439 WEdit
*edit
= (WEdit
*) data
;
1441 if (option_syntax_highlighting
)
1442 edit_load_syntax (edit
, NULL
, edit
->syntax_type
);
1443 edit
->force
|= REDRAW_PAGE
;
1447 /* --------------------------------------------------------------------------------------------- */
1449 * Callback for the iteration of objects in the 'editors' array.
1450 * Redraw editor object.
1452 * @param data probably WEdit object
1453 * @param user_data unused
1457 edit_redraw_page_cb (void *data
, void *user_data
)
1461 if (edit_widget_is_editor ((const Widget
*) data
))
1462 ((WEdit
*) data
)->force
|= REDRAW_PAGE
;
1465 /* --------------------------------------------------------------------------------------------- */
1467 * Insert autocompleted word into editor.
1469 * @param edit editor object
1470 * @param completion word for completion
1471 * @param word_len offset from beginning for insert
1475 edit_complete_word_insert_recoded_completion (WEdit
* edit
, char *completion
, gsize word_len
)
1480 temp
= str_convert_to_input (completion
);
1482 for (completion
= temp
->str
+ word_len
; *completion
!= '\0'; completion
++)
1483 edit_insert (edit
, *completion
);
1484 g_string_free (temp
, TRUE
);
1486 for (completion
+= word_len
; *completion
!= '\0'; completion
++)
1487 edit_insert (edit
, *completion
);
1491 /* --------------------------------------------------------------------------------------------- */
1492 /*** public functions ****************************************************************************/
1493 /* --------------------------------------------------------------------------------------------- */
1496 edit_refresh_cmd (void)
1503 /* --------------------------------------------------------------------------------------------- */
1505 * Toggle syntax highlighting in all editor windows.
1507 * @param h root widget for all windows
1511 edit_syntax_onoff_cmd (WDialog
* h
)
1513 option_syntax_highlighting
= !option_syntax_highlighting
;
1514 g_list_foreach (h
->widgets
, edit_syntax_onoff_cb
, NULL
);
1518 /* --------------------------------------------------------------------------------------------- */
1520 * Toggle tabs showing in all editor windows.
1522 * @param h root widget for all windows
1526 edit_show_tabs_tws_cmd (WDialog
* h
)
1528 enable_show_tabs_tws
= !enable_show_tabs_tws
;
1529 g_list_foreach (h
->widgets
, edit_redraw_page_cb
, NULL
);
1533 /* --------------------------------------------------------------------------------------------- */
1535 * Toggle right margin showing in all editor windows.
1537 * @param h root widget for all windows
1541 edit_show_margin_cmd (WDialog
* h
)
1543 show_right_margin
= !show_right_margin
;
1544 g_list_foreach (h
->widgets
, edit_redraw_page_cb
, NULL
);
1548 /* --------------------------------------------------------------------------------------------- */
1550 * Toggle line numbers showing in all editor windows.
1552 * @param h root widget for all windows
1556 edit_show_numbers_cmd (WDialog
* h
)
1558 option_line_state
= !option_line_state
;
1559 option_line_state_width
= option_line_state
? LINE_STATE_WIDTH
: 0;
1560 g_list_foreach (h
->widgets
, edit_redraw_page_cb
, NULL
);
1564 /* --------------------------------------------------------------------------------------------- */
1567 edit_save_mode_cmd (void)
1569 char *str_result
= NULL
;
1571 const char *str
[] = {
1574 N_("&Do backups with following extension:")
1577 #ifdef HAVE_ASSERT_H
1578 assert (option_backup_ext
!= NULL
);
1584 for (i
= 0; i
< 3; i
++)
1589 quick_widget_t quick_widgets
[] = {
1591 QUICK_RADIO (3, str
, &option_save_mode
, &edit_save_mode_radio_id
),
1592 QUICK_INPUT (option_backup_ext
, "edit-backup-ext", &str_result
,
1593 &edit_save_mode_input_id
, FALSE
, FALSE
, INPUT_COMPLETE_NONE
),
1594 QUICK_SEPARATOR (TRUE
),
1595 QUICK_CHECKBOX (N_("Check &POSIX new line"), &option_check_nl_at_eof
, NULL
),
1596 QUICK_BUTTONS_OK_CANCEL
,
1601 quick_dialog_t qdlg
= {
1603 N_("Edit Save Mode"), "[Edit Save Mode]",
1604 quick_widgets
, edit_save_mode_callback
, NULL
1607 if (quick_dialog (&qdlg
) != B_CANCEL
)
1609 g_free (option_backup_ext
);
1610 option_backup_ext
= str_result
;
1615 /* --------------------------------------------------------------------------------------------- */
1618 edit_set_filename (WEdit
* edit
, const vfs_path_t
* name_vpath
)
1620 vfs_path_free (edit
->filename_vpath
);
1621 edit
->filename_vpath
= vfs_path_clone (name_vpath
);
1623 if (edit
->dir_vpath
== NULL
)
1624 edit
->dir_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
1627 /* --------------------------------------------------------------------------------------------- */
1628 /* Here we want to warn the users of overwriting an existing file,
1629 but only if they have made a change to the filename */
1630 /* returns TRUE on success */
1632 edit_save_as_cmd (WEdit
* edit
)
1634 /* This heads the 'Save As' dialog box */
1635 vfs_path_t
*exp_vpath
;
1637 int different_filename
= 0;
1639 if (!edit_check_newline (&edit
->buffer
))
1642 exp_vpath
= edit_get_save_file_as (edit
);
1643 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
1645 if (exp_vpath
!= NULL
)
1647 if (vfs_path_len (exp_vpath
) == 0)
1653 if (!vfs_path_equal (edit
->filename_vpath
, exp_vpath
))
1658 if (mc_stat (exp_vpath
, &sb
) == 0 && !S_ISREG (sb
.st_mode
))
1660 edit_error_dialog (_("Save as"),
1662 ("Cannot save: destination is not a regular file")));
1666 different_filename
= 1;
1667 file
= mc_open (exp_vpath
, O_RDONLY
| O_BINARY
);
1671 /* the file exists */
1673 /* Overwrite the current file or cancel the operation */
1674 if (edit_query_dialog2
1676 _("A file already exists with this name"), _("&Overwrite"), _("&Cancel")))
1681 edit
->stat1
.st_mode
|= S_IWUSR
;
1683 save_lock
= lock_file (exp_vpath
);
1687 /* filenames equal, check if already locked */
1688 if (!edit
->locked
&& !edit
->delete_file
)
1689 save_lock
= lock_file (exp_vpath
);
1692 if (different_filename
)
1695 * Allow user to write into saved (under another name) file
1696 * even if original file had r/o user permissions.
1698 edit
->stat1
.st_mode
|= S_IWRITE
;
1701 rv
= edit_save_file (edit
, exp_vpath
);
1705 /* Successful, so unlock both files */
1706 if (different_filename
)
1709 unlock_file (exp_vpath
);
1711 edit
->locked
= unlock_file (edit
->filename_vpath
);
1715 if (edit
->locked
|| save_lock
)
1716 edit
->locked
= unlock_file (edit
->filename_vpath
);
1719 edit_set_filename (edit
, exp_vpath
);
1720 if (edit
->lb
!= LB_ASIS
)
1721 edit_reload (edit
, exp_vpath
);
1723 edit
->delete_file
= 0;
1724 if (different_filename
)
1725 edit_load_syntax (edit
, NULL
, edit
->syntax_type
);
1726 vfs_path_free (exp_vpath
);
1727 edit
->force
|= REDRAW_COMPLETELY
;
1730 edit_error_dialog (_("Save as"), get_sys_error (_("Cannot save file")));
1733 /* Failed, so maintain modify (not save) lock */
1735 unlock_file (exp_vpath
);
1742 vfs_path_free (exp_vpath
);
1743 edit
->force
|= REDRAW_COMPLETELY
;
1747 /* {{{ Macro stuff starts here */
1748 /* --------------------------------------------------------------------------------------------- */
1751 edit_delete_macro_cmd (WEdit
* edit
)
1755 hotkey
= editcmd_dialog_raw_key_query (_("Delete macro"), _("Press macro hotkey:"), TRUE
);
1757 if (hotkey
!= 0 && !edit_delete_macro (edit
, hotkey
))
1758 message (D_ERROR
, _("Delete macro"), _("Macro not deleted"));
1761 /* --------------------------------------------------------------------------------------------- */
1763 /** returns FALSE on error */
1765 edit_execute_macro (WEdit
* edit
, int hotkey
)
1767 gboolean res
= FALSE
;
1771 const macros_t
*macros
;
1774 if (edit_get_macro (edit
, hotkey
, ¯os
, &indx
) &&
1775 macros
->macro
!= NULL
&& macros
->macro
->len
!= 0)
1779 edit
->force
|= REDRAW_PAGE
;
1781 for (i
= 0; i
< macros
->macro
->len
; i
++)
1783 const macro_action_t
*m_act
;
1785 m_act
= &g_array_index (macros
->macro
, struct macro_action_t
, i
);
1786 edit_execute_cmd (edit
, m_act
->action
, m_act
->ch
);
1795 /* --------------------------------------------------------------------------------------------- */
1797 /** returns FALSE on error */
1799 edit_store_macro_cmd (WEdit
* edit
)
1803 GString
*marcros_string
;
1804 mc_config_t
*macros_config
= NULL
;
1805 const char *section_name
= "editor";
1806 gchar
*macros_fname
;
1807 GArray
*macros
; /* current macro */
1809 gboolean have_macro
= FALSE
;
1810 char *skeyname
= NULL
;
1813 editcmd_dialog_raw_key_query (_("Save macro"), _("Press the macro's new hotkey:"), TRUE
);
1814 if (hotkey
== ESC_CHAR
)
1817 tmp_act
= keybind_lookup_keymap_command (editor_map
, hotkey
);
1819 /* return FALSE if try assign macro into restricted hotkeys */
1820 if (tmp_act
== CK_MacroStartRecord
1821 || tmp_act
== CK_MacroStopRecord
|| tmp_act
== CK_MacroStartStopRecord
)
1824 edit_delete_macro (edit
, hotkey
);
1826 macros_fname
= mc_config_get_full_path (MC_MACRO_FILE
);
1827 macros_config
= mc_config_init (macros_fname
, FALSE
);
1828 g_free (macros_fname
);
1830 if (macros_config
== NULL
)
1833 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
1835 marcros_string
= g_string_sized_new (250);
1836 macros
= g_array_new (TRUE
, FALSE
, sizeof (macro_action_t
));
1838 skeyname
= lookup_key_by_code (hotkey
);
1840 for (i
= 0; i
< macro_index
; i
++)
1842 macro_action_t m_act
;
1843 const char *action_name
;
1845 action_name
= keybind_lookup_actionname (record_macro_buf
[i
].action
);
1847 if (action_name
== NULL
)
1850 m_act
.action
= record_macro_buf
[i
].action
;
1851 m_act
.ch
= record_macro_buf
[i
].ch
;
1852 g_array_append_val (macros
, m_act
);
1854 g_string_append_printf (marcros_string
, "%s:%i;", action_name
,
1855 (int) record_macro_buf
[i
].ch
);
1860 macro
.hotkey
= hotkey
;
1861 macro
.macro
= macros
;
1862 g_array_append_val (macros_list
, macro
);
1863 mc_config_set_string (macros_config
, section_name
, skeyname
, marcros_string
->str
);
1866 mc_config_del_key (macros_config
, section_name
, skeyname
);
1869 edit_macro_sort_by_hotkey ();
1871 g_string_free (marcros_string
, TRUE
);
1872 mc_config_save_file (macros_config
, NULL
);
1873 mc_config_deinit (macros_config
);
1877 /* --------------------------------------------------------------------------------------------- */
1880 edit_repeat_macro_cmd (WEdit
* edit
)
1887 f
= input_dialog (_("Repeat last commands"), _("Repeat times:"), MC_HISTORY_EDIT_REPEAT
, NULL
,
1888 INPUT_COMPLETE_NONE
);
1889 if (f
== NULL
|| *f
== '\0')
1895 count_repeat
= strtol (f
, &error
, 0);
1905 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
1906 edit
->force
|= REDRAW_PAGE
;
1908 for (j
= 0; j
< count_repeat
; j
++)
1909 for (i
= 0; i
< macro_index
; i
++)
1910 edit_execute_cmd (edit
, record_macro_buf
[i
].action
, record_macro_buf
[i
].ch
);
1911 edit_update_screen (edit
);
1915 /* --------------------------------------------------------------------------------------------- */
1916 /** return FALSE on error */
1919 edit_load_macro_cmd (WEdit
* edit
)
1921 mc_config_t
*macros_config
= NULL
;
1922 gchar
**profile_keys
, **keys
;
1923 gchar
**values
, **curr_values
;
1924 gsize len
, values_len
;
1925 const char *section_name
= "editor";
1926 gchar
*macros_fname
;
1930 macros_fname
= mc_config_get_full_path (MC_MACRO_FILE
);
1931 macros_config
= mc_config_init (macros_fname
, TRUE
);
1932 g_free (macros_fname
);
1934 if (macros_config
== NULL
|| macros_list
== NULL
|| macros_list
->len
!= 0)
1937 keys
= mc_config_get_keys (macros_config
, section_name
, &len
);
1938 for (profile_keys
= keys
; *profile_keys
!= NULL
; profile_keys
++)
1941 gboolean have_macro
= FALSE
;
1945 macros
= g_array_new (TRUE
, FALSE
, sizeof (macro_action_t
));
1947 mc_config_get_string_list (macros_config
, section_name
, *profile_keys
, &values_len
);
1948 hotkey
= lookup_key (*profile_keys
, NULL
);
1950 for (curr_values
= values
; *curr_values
!= NULL
&& *curr_values
[0] != '\0'; curr_values
++)
1952 char **macro_pair
= NULL
;
1954 macro_pair
= g_strsplit (*curr_values
, ":", 2);
1955 if (macro_pair
!= NULL
)
1957 macro_action_t m_act
;
1958 if (macro_pair
[0] == NULL
|| macro_pair
[0][0] == '\0')
1962 m_act
.action
= keybind_lookup_action (macro_pair
[0]);
1963 g_free (macro_pair
[0]);
1964 macro_pair
[0] = NULL
;
1966 if (macro_pair
[1] == NULL
|| macro_pair
[1][0] == '\0')
1970 m_act
.ch
= strtol (macro_pair
[1], NULL
, 0);
1971 g_free (macro_pair
[1]);
1972 macro_pair
[1] = NULL
;
1974 if (m_act
.action
!= 0)
1976 /* a shell command */
1977 if ((m_act
.action
/ CK_PipeBlock (0)) == 1)
1979 m_act
.action
= CK_PipeBlock (0) + (m_act
.ch
> 0 ? m_act
.ch
: 0);
1982 g_array_append_val (macros
, m_act
);
1985 g_strfreev (macro_pair
);
1991 macro
.hotkey
= hotkey
;
1992 macro
.macro
= macros
;
1993 g_array_append_val (macros_list
, macro
);
1995 g_strfreev (values
);
1998 mc_config_deinit (macros_config
);
1999 edit_macro_sort_by_hotkey ();
2003 /* }}} Macro stuff end here */
2005 /* --------------------------------------------------------------------------------------------- */
2006 /** returns TRUE on success */
2009 edit_save_confirm_cmd (WEdit
* edit
)
2011 if (edit
->filename_vpath
== NULL
)
2012 return edit_save_as_cmd (edit
);
2014 if (!edit_check_newline (&edit
->buffer
))
2017 if (edit_confirm_save
)
2022 f
= g_strdup_printf (_("Confirm save file: \"%s\""),
2023 vfs_path_as_str (edit
->filename_vpath
));
2024 ok
= (edit_query_dialog2 (_("Save file"), f
, _("&Save"), _("&Cancel")) == 0);
2029 return edit_save_cmd (edit
);
2032 /* --------------------------------------------------------------------------------------------- */
2034 * Ask file to edit and load it.
2036 * @return TRUE on success or cancel of ask.
2040 edit_load_cmd (WDialog
* h
)
2043 gboolean ret
= TRUE
; /* possible cancel */
2045 exp
= input_expand_dialog (_("Load"), _("Enter file name:"),
2046 MC_HISTORY_EDIT_LOAD
, INPUT_LAST_TEXT
,
2047 INPUT_COMPLETE_FILENAMES
| INPUT_COMPLETE_CD
);
2049 if (exp
!= NULL
&& *exp
!= '\0')
2051 vfs_path_t
*exp_vpath
;
2053 exp_vpath
= vfs_path_from_str (exp
);
2054 ret
= edit_load_file_from_filename (h
, exp_vpath
);
2055 vfs_path_free (exp_vpath
);
2063 /* --------------------------------------------------------------------------------------------- */
2065 * Load syntax file to edit.
2067 * @return TRUE on success
2071 edit_load_syntax_file (WDialog
* h
)
2073 vfs_path_t
*extdir_vpath
;
2075 gboolean ret
= FALSE
;
2077 if (geteuid () == 0)
2078 dir
= query_dialog (_("Syntax file edit"),
2079 _("Which syntax file you want to edit?"), D_NORMAL
, 2,
2080 _("&User"), _("&System wide"));
2083 vfs_path_build_filename (mc_global
.sysconfig_dir
, "syntax", "Syntax", (char *) NULL
);
2084 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath
)))
2086 vfs_path_free (extdir_vpath
);
2088 vfs_path_build_filename (mc_global
.share_data_dir
, "syntax", "Syntax", (char *) NULL
);
2093 vfs_path_t
*user_syntax_file_vpath
;
2095 user_syntax_file_vpath
= mc_config_get_full_vpath (EDIT_SYNTAX_FILE
);
2096 check_for_default (extdir_vpath
, user_syntax_file_vpath
);
2097 ret
= edit_load_file_from_filename (h
, user_syntax_file_vpath
);
2098 vfs_path_free (user_syntax_file_vpath
);
2101 ret
= edit_load_file_from_filename (h
, extdir_vpath
);
2103 vfs_path_free (extdir_vpath
);
2108 /* --------------------------------------------------------------------------------------------- */
2110 * Load menu file to edit.
2112 * @return TRUE on success
2116 edit_load_menu_file (WDialog
* h
)
2118 vfs_path_t
*buffer_vpath
;
2119 vfs_path_t
*menufile_vpath
;
2123 dir
= query_dialog (_("Menu edit"),
2124 _("Which menu file do you want to edit?"), D_NORMAL
,
2125 geteuid () != 0 ? 2 : 3, _("&Local"), _("&User"), _("&System wide"));
2127 menufile_vpath
= vfs_path_build_filename (mc_global
.sysconfig_dir
, EDIT_GLOBAL_MENU
, NULL
);
2128 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath
)))
2130 vfs_path_free (menufile_vpath
);
2131 menufile_vpath
= vfs_path_build_filename (mc_global
.share_data_dir
, EDIT_GLOBAL_MENU
, NULL
);
2137 buffer_vpath
= vfs_path_from_str (EDIT_LOCAL_MENU
);
2138 check_for_default (menufile_vpath
, buffer_vpath
);
2139 chmod (vfs_path_get_last_path_str (buffer_vpath
), 0600);
2143 buffer_vpath
= mc_config_get_full_vpath (EDIT_HOME_MENU
);
2144 check_for_default (menufile_vpath
, buffer_vpath
);
2148 buffer_vpath
= vfs_path_build_filename (mc_global
.sysconfig_dir
, EDIT_GLOBAL_MENU
, NULL
);
2149 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath
)))
2151 vfs_path_free (buffer_vpath
);
2153 vfs_path_build_filename (mc_global
.share_data_dir
, EDIT_GLOBAL_MENU
, NULL
);
2158 vfs_path_free (menufile_vpath
);
2162 ret
= edit_load_file_from_filename (h
, buffer_vpath
);
2164 vfs_path_free (buffer_vpath
);
2165 vfs_path_free (menufile_vpath
);
2170 /* --------------------------------------------------------------------------------------------- */
2172 * Close window with opened file.
2174 * @return TRUE if file was closed.
2178 edit_close_cmd (WEdit
* edit
)
2182 ret
= (edit
!= NULL
) && edit_ok_to_exit (edit
);
2186 WDialog
*h
= WIDGET (edit
)->owner
;
2188 if (edit
->locked
!= 0)
2189 unlock_file (edit
->filename_vpath
);
2193 if (edit_widget_is_editor (WIDGET (h
->current
->data
)))
2194 edit
= (WEdit
*) h
->current
->data
;
2197 edit
= find_editor (h
);
2199 dlg_set_top_widget (edit
);
2204 edit
->force
|= REDRAW_COMPLETELY
;
2209 /* --------------------------------------------------------------------------------------------- */
2211 if mark2 is -1 then marking is from mark1 to the cursor.
2212 Otherwise its between the markers. This handles this.
2213 Returns FALSE if no text is marked.
2217 eval_marks (WEdit
* edit
, off_t
* start_mark
, off_t
* end_mark
)
2221 if (edit
->mark1
== edit
->mark2
)
2223 *start_mark
= *end_mark
= 0;
2224 edit
->column2
= edit
->column1
= 0;
2228 if (edit
->end_mark_curs
< 0)
2229 end_mark_curs
= edit
->buffer
.curs1
;
2231 end_mark_curs
= edit
->end_mark_curs
;
2233 if (edit
->mark2
>= 0)
2235 *start_mark
= min (edit
->mark1
, edit
->mark2
);
2236 *end_mark
= max (edit
->mark1
, edit
->mark2
);
2240 *start_mark
= min (edit
->mark1
, end_mark_curs
);
2241 *end_mark
= max (edit
->mark1
, end_mark_curs
);
2242 edit
->column2
= edit
->curs_col
+ edit
->over_col
;
2245 if (edit
->column_highlight
2246 && ((edit
->mark1
> end_mark_curs
&& edit
->column1
< edit
->column2
)
2247 || (edit
->mark1
< end_mark_curs
&& edit
->column1
> edit
->column2
)))
2249 off_t start_bol
, start_eol
;
2250 off_t end_bol
, end_eol
;
2254 start_bol
= edit_buffer_get_bol (&edit
->buffer
, *start_mark
);
2255 start_eol
= edit_buffer_get_eol (&edit
->buffer
, start_bol
- 1) + 1;
2256 end_bol
= edit_buffer_get_bol (&edit
->buffer
, *end_mark
);
2257 end_eol
= edit_buffer_get_eol (&edit
->buffer
, *end_mark
);
2258 col1
= min (edit
->column1
, edit
->column2
);
2259 col2
= max (edit
->column1
, edit
->column2
);
2261 diff1
= edit_move_forward3 (edit
, start_bol
, col2
, 0) -
2262 edit_move_forward3 (edit
, start_bol
, col1
, 0);
2263 diff2
= edit_move_forward3 (edit
, end_bol
, col2
, 0) -
2264 edit_move_forward3 (edit
, end_bol
, col1
, 0);
2266 *start_mark
-= diff1
;
2268 *start_mark
= max (*start_mark
, start_eol
);
2269 *end_mark
= min (*end_mark
, end_eol
);
2274 /* --------------------------------------------------------------------------------------------- */
2277 edit_block_copy_cmd (WEdit
* edit
)
2279 off_t start_mark
, end_mark
, current
= edit
->buffer
.curs1
;
2283 unsigned char *copy_buf
;
2285 edit_update_curs_col (edit
);
2286 if (!eval_marks (edit
, &start_mark
, &end_mark
))
2289 copy_buf
= edit_get_block (edit
, start_mark
, end_mark
, &size
);
2291 /* all that gets pushed are deletes hence little space is used on the stack */
2293 edit_push_markers (edit
);
2295 if (edit
->column_highlight
)
2299 col_delta
= abs (edit
->column2
- edit
->column1
);
2300 edit_insert_column_of_text (edit
, copy_buf
, size
, col_delta
, &mark1
, &mark2
, &c1
, &c2
);
2304 int size_orig
= size
;
2307 edit_insert_ahead (edit
, copy_buf
[size
]);
2309 /* Place cursor at the end of text selection */
2310 if (option_cursor_after_inserted_block
)
2311 edit_cursor_move (edit
, size_orig
);
2315 edit_scroll_screen_over_cursor (edit
);
2317 if (edit
->column_highlight
)
2318 edit_set_markers (edit
, edit
->buffer
.curs1
, mark2
, c1
, c2
);
2319 else if (start_mark
< current
&& end_mark
> current
)
2320 edit_set_markers (edit
, start_mark
, end_mark
+ end_mark
- start_mark
, 0, 0);
2322 edit
->force
|= REDRAW_PAGE
;
2326 /* --------------------------------------------------------------------------------------------- */
2329 edit_block_move_cmd (WEdit
* edit
)
2332 unsigned char *copy_buf
= NULL
;
2333 off_t start_mark
, end_mark
;
2335 if (!eval_marks (edit
, &start_mark
, &end_mark
))
2338 if (!edit
->column_highlight
&& edit
->buffer
.curs1
> start_mark
&& edit
->buffer
.curs1
< end_mark
)
2341 if (edit
->mark2
< 0)
2342 edit_mark_cmd (edit
, FALSE
);
2343 edit_push_markers (edit
);
2345 if (edit
->column_highlight
)
2349 long c1
, c2
, b_width
;
2352 c1
= min (edit
->column1
, edit
->column2
);
2353 c2
= max (edit
->column1
, edit
->column2
);
2356 edit_update_curs_col (edit
);
2359 x2
= x
+ edit
->over_col
;
2361 /* do nothing when cursor inside first line of selected area */
2362 if ((edit_buffer_get_eol (&edit
->buffer
, edit
->buffer
.curs1
) ==
2363 edit_buffer_get_eol (&edit
->buffer
, start_mark
)) && x2
> c1
&& x2
<= c2
)
2366 if (edit
->buffer
.curs1
> start_mark
2367 && edit
->buffer
.curs1
< edit_buffer_get_eol (&edit
->buffer
, end_mark
))
2371 else if (x
> c1
&& x
<= c2
)
2374 /* save current selection into buffer */
2375 copy_buf
= edit_get_block (edit
, start_mark
, end_mark
, &size
);
2377 /* remove current selection */
2378 edit_block_delete_cmd (edit
);
2380 edit
->over_col
= max (0, edit
->over_col
- b_width
);
2381 /* calculate the cursor pos after delete block */
2382 current
= edit_move_forward3 (edit
, edit_buffer_get_current_bol (&edit
->buffer
), x
, 0);
2383 edit_cursor_move (edit
, current
- edit
->buffer
.curs1
);
2384 edit_scroll_screen_over_cursor (edit
);
2386 /* add TWS if need before block insertion */
2387 if (option_cursor_beyond_eol
&& edit
->over_col
> 0)
2388 edit_insert_over (edit
);
2390 edit_insert_column_of_text (edit
, copy_buf
, size
, b_width
, &mark1
, &mark2
, &c1
, &c2
);
2391 edit_set_markers (edit
, mark1
, mark2
, c1
, c2
);
2395 off_t count
, count_orig
;
2397 current
= edit
->buffer
.curs1
;
2398 copy_buf
= g_malloc0 (end_mark
- start_mark
);
2399 edit_cursor_move (edit
, start_mark
- edit
->buffer
.curs1
);
2400 edit_scroll_screen_over_cursor (edit
);
2402 for (count
= start_mark
; count
< end_mark
; count
++)
2403 copy_buf
[end_mark
- count
- 1] = edit_delete (edit
, TRUE
);
2405 edit_scroll_screen_over_cursor (edit
);
2406 edit_cursor_move (edit
,
2407 current
- edit
->buffer
.curs1
-
2408 (((current
- edit
->buffer
.curs1
) > 0) ? end_mark
- start_mark
: 0));
2409 edit_scroll_screen_over_cursor (edit
);
2411 while (count
-- > start_mark
)
2412 edit_insert_ahead (edit
, copy_buf
[end_mark
- count
- 1]);
2414 edit_set_markers (edit
, edit
->buffer
.curs1
, edit
->buffer
.curs1
+ end_mark
- start_mark
, 0,
2417 /* Place cursor at the end of text selection */
2418 if (option_cursor_after_inserted_block
)
2419 edit_cursor_move (edit
, count_orig
- start_mark
);
2422 edit_scroll_screen_over_cursor (edit
);
2424 edit
->force
|= REDRAW_PAGE
;
2427 /* --------------------------------------------------------------------------------------------- */
2428 /** returns 1 if canceelled by user */
2431 edit_block_delete_cmd (WEdit
* edit
)
2433 off_t start_mark
, end_mark
;
2435 if (eval_marks (edit
, &start_mark
, &end_mark
))
2436 return edit_block_delete (edit
);
2438 edit_delete_line (edit
);
2442 /* --------------------------------------------------------------------------------------------- */
2443 /** call with edit = 0 before shutdown to close memory leaks */
2446 edit_replace_cmd (WEdit
* edit
, int again
)
2448 /* 1 = search string, 2 = replace with */
2449 static char *saved1
= NULL
; /* saved default[123] */
2450 static char *saved2
= NULL
;
2451 char *input1
= NULL
; /* user input from the dialog */
2452 char *input2
= NULL
;
2453 GString
*input2_str
= NULL
;
2456 long times_replaced
= 0;
2457 gboolean once_found
= FALSE
;
2461 g_free (saved1
), saved1
= NULL
;
2462 g_free (saved2
), saved2
= NULL
;
2466 edit
->force
|= REDRAW_COMPLETELY
;
2468 if (again
&& !saved1
&& !saved2
)
2473 input1
= g_strdup (saved1
? saved1
: "");
2474 input2
= g_strdup (saved2
? saved2
: "");
2478 char *tmp_inp1
, *tmp_inp2
;
2480 disp1
= edit_replace_cmd__conv_to_display (saved1
? saved1
: (char *) "");
2481 disp2
= edit_replace_cmd__conv_to_display (saved2
? saved2
: (char *) "");
2483 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
2485 editcmd_dialog_replace_show (edit
, disp1
, disp2
, &input1
, &input2
);
2490 if (input1
== NULL
|| *input1
== '\0')
2492 edit
->force
= REDRAW_COMPLETELY
;
2498 input1
= edit_replace_cmd__conv_to_input (input1
);
2499 input2
= edit_replace_cmd__conv_to_input (input2
);
2503 g_free (saved1
), saved1
= g_strdup (input1
);
2504 g_free (saved2
), saved2
= g_strdup (input2
);
2506 mc_search_free (edit
->search
);
2507 edit
->search
= NULL
;
2510 input2_str
= g_string_new (input2
);
2512 if (edit
->search
== NULL
)
2515 edit
->search
= mc_search_new (input1
, -1, cp_source
);
2517 edit
->search
= mc_search_new (input1
, -1, NULL
);
2519 if (edit
->search
== NULL
)
2521 edit
->search_start
= edit
->buffer
.curs1
;
2524 edit
->search
->search_type
= edit_search_options
.type
;
2526 edit
->search
->is_all_charsets
= edit_search_options
.all_codepages
;
2528 edit
->search
->is_case_sensitive
= edit_search_options
.case_sens
;
2529 edit
->search
->whole_words
= edit_search_options
.whole_words
;
2530 edit
->search
->search_fn
= edit_search_cmd_callback
;
2531 edit
->search_line_type
= edit_get_search_line_type (edit
->search
);
2532 edit_search_fix_search_start_if_selection (edit
);
2535 if (edit
->found_len
&& edit
->search_start
== edit
->found_start
+ 1
2536 && edit_search_options
.backwards
)
2537 edit
->search_start
--;
2539 if (edit
->found_len
&& edit
->search_start
== edit
->found_start
- 1
2540 && !edit_search_options
.backwards
)
2541 edit
->search_start
++;
2547 if (!editcmd_find (edit
, &len
))
2549 if (!(edit
->search
->error
== MC_SEARCH_E_OK
||
2550 (once_found
&& edit
->search
->error
== MC_SEARCH_E_NOTFOUND
)))
2552 edit_error_dialog (_("Search"), edit
->search
->error_str
);
2558 edit
->search_start
= edit
->search
->normal_offset
;
2559 /*returns negative on not found or error in pattern */
2561 if ((edit
->search_start
>= 0) && (edit
->search_start
< edit
->buffer
.size
))
2566 edit
->found_start
= edit
->search_start
;
2567 i
= edit
->found_len
= len
;
2569 edit_cursor_move (edit
, edit
->search_start
- edit
->buffer
.curs1
);
2570 edit_scroll_screen_over_cursor (edit
);
2572 if (edit
->replace_mode
== 0)
2577 l
= edit
->curs_row
- WIDGET (edit
)->lines
/ 3;
2579 edit_scroll_downward (edit
, l
);
2581 edit_scroll_upward (edit
, -l
);
2583 edit_scroll_screen_over_cursor (edit
);
2584 edit
->force
|= REDRAW_PAGE
;
2585 edit_render_keypress (edit
);
2587 /*so that undo stops at each query */
2588 edit_push_key_press (edit
);
2589 /* and prompt 2/3 down */
2590 disp1
= edit_replace_cmd__conv_to_display (saved1
);
2591 disp2
= edit_replace_cmd__conv_to_display (saved2
);
2592 prompt
= editcmd_dialog_replace_prompt_show (edit
, disp1
, disp2
, -1, -1);
2596 if (prompt
== B_REPLACE_ALL
)
2597 edit
->replace_mode
= 1;
2598 else if (prompt
== B_SKIP_REPLACE
)
2600 if (edit_search_options
.backwards
)
2601 edit
->search_start
--;
2603 edit
->search_start
++;
2604 continue; /* loop */
2606 else if (prompt
== B_CANCEL
)
2608 edit
->replace_mode
= -1;
2613 repl_str
= mc_search_prepare_replace_str (edit
->search
, input2_str
);
2615 if (edit
->search
->error
!= MC_SEARCH_E_OK
)
2617 edit_error_dialog (_("Replace"), edit
->search
->error_str
);
2618 g_string_free (repl_str
, TRUE
);
2622 /* delete then insert new */
2623 for (i
= 0; i
< len
; i
++)
2624 edit_delete (edit
, TRUE
);
2626 for (i
= 0; i
< repl_str
->len
; i
++)
2627 edit_insert (edit
, repl_str
->str
[i
]);
2629 edit
->found_len
= repl_str
->len
;
2630 g_string_free (repl_str
, TRUE
);
2633 /* so that we don't find the same string again */
2634 if (edit_search_options
.backwards
)
2636 edit
->search_start
--;
2640 edit
->search_start
+= edit
->found_len
+ (len
== 0 ? 1 : 0);
2642 if (edit
->search_start
>= edit
->buffer
.size
)
2646 edit_scroll_screen_over_cursor (edit
);
2650 /* try and find from right here for next search */
2651 edit
->search_start
= edit
->buffer
.curs1
;
2652 edit_update_curs_col (edit
);
2654 edit
->force
|= REDRAW_PAGE
;
2655 edit_render_keypress (edit
);
2657 if (times_replaced
== 0)
2658 query_dialog (_("Replace"), _("Search string not found"), D_NORMAL
, 1, _("&OK"));
2662 while (edit
->replace_mode
>= 0);
2664 edit_scroll_screen_over_cursor (edit
);
2665 edit
->force
|= REDRAW_COMPLETELY
;
2666 edit_render_keypress (edit
);
2668 if ((edit
->replace_mode
== 1) && (times_replaced
!= 0))
2669 message (D_NORMAL
, _("Replace"), _("%ld replacements made"), times_replaced
);
2674 if (input2_str
!= NULL
)
2675 g_string_free (input2_str
, TRUE
);
2678 /* --------------------------------------------------------------------------------------------- */
2681 edit_search_cmd_callback (const void *user_data
, gsize char_offset
, int *current_char
)
2683 *current_char
= edit_buffer_get_byte (&((WEdit
*) user_data
)->buffer
, (off_t
) char_offset
);
2684 return MC_SEARCH_CB_OK
;
2687 /* --------------------------------------------------------------------------------------------- */
2690 edit_search_cmd (WEdit
* edit
, gboolean again
)
2698 else if (edit
->last_search_string
!= NULL
)
2699 edit_do_search (edit
);
2702 /* find last search string in history */
2705 history
= history_get (MC_HISTORY_SHARED_SEARCH
);
2706 if (history
!= NULL
&& history
->data
!= NULL
)
2708 edit
->last_search_string
= (char *) history
->data
;
2709 history
->data
= NULL
;
2710 history
= g_list_first (history
);
2711 g_list_foreach (history
, (GFunc
) g_free
, NULL
);
2712 g_list_free (history
);
2715 edit
->search
= mc_search_new (edit
->last_search_string
, -1, cp_source
);
2717 edit
->search
= mc_search_new (edit
->last_search_string
, -1, NULL
);
2719 if (edit
->search
== NULL
)
2721 /* if not... then ask for an expression */
2722 g_free (edit
->last_search_string
);
2723 edit
->last_search_string
= NULL
;
2728 edit
->search
->search_type
= edit_search_options
.type
;
2730 edit
->search
->is_all_charsets
= edit_search_options
.all_codepages
;
2732 edit
->search
->is_case_sensitive
= edit_search_options
.case_sens
;
2733 edit
->search
->whole_words
= edit_search_options
.whole_words
;
2734 edit
->search
->search_fn
= edit_search_cmd_callback
;
2735 edit
->search_line_type
= edit_get_search_line_type (edit
->search
);
2736 edit_do_search (edit
);
2741 /* if not... then ask for an expression */
2742 g_free (edit
->last_search_string
);
2743 edit
->last_search_string
= NULL
;
2750 /* --------------------------------------------------------------------------------------------- */
2752 * Check if it's OK to close the file. If there are unsaved changes, ask user.
2754 * @return TRUE if it's OK to exit, FALSE to continue editing.
2758 edit_ok_to_exit (WEdit
* edit
)
2760 const char *fname
= N_("[NoName]");
2764 if (!edit
->modified
)
2767 if (edit
->filename_vpath
!= NULL
)
2768 fname
= vfs_path_as_str (edit
->filename_vpath
);
2774 if (!mc_global
.midnight_shutdown
)
2776 if (!edit_check_newline (&edit
->buffer
))
2781 msg
= g_strdup_printf (_("File %s was modified.\nSave before close?"), fname
);
2782 act
= edit_query_dialog3 (_("Close file"), msg
, _("&Yes"), _("&No"), _("&Cancel"));
2786 msg
= g_strdup_printf (_("Midnight Commander is being shut down.\nSave modified file %s?"),
2788 act
= edit_query_dialog2 (_("Quit"), msg
, _("&Yes"), _("&No"));
2800 edit_push_markers (edit
);
2801 edit_set_markers (edit
, 0, 0, 0, 0);
2802 if (!edit_save_cmd (edit
) || mc_global
.midnight_shutdown
)
2803 return mc_global
.midnight_shutdown
;
2807 case 2: /* Cancel quit */
2815 /* --------------------------------------------------------------------------------------------- */
2816 /** save block, returns TRUE on success */
2819 edit_save_block (WEdit
* edit
, const char *filename
, off_t start
, off_t finish
)
2825 vpath
= vfs_path_from_str (filename
);
2826 file
= mc_open (vpath
, O_CREAT
| O_WRONLY
| O_TRUNC
,
2827 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
| O_BINARY
);
2828 vfs_path_free (vpath
);
2832 if (edit
->column_highlight
)
2836 r
= mc_write (file
, VERTICAL_MAGIC
, sizeof (VERTICAL_MAGIC
));
2839 unsigned char *block
, *p
;
2841 p
= block
= edit_get_block (edit
, start
, finish
, &len
);
2844 r
= mc_write (file
, p
, len
);
2859 len
= finish
- start
;
2860 buf
= g_malloc0 (TEMP_BUF_LEN
);
2861 while (start
!= finish
)
2863 end
= min (finish
, start
+ TEMP_BUF_LEN
);
2864 for (; i
< end
; i
++)
2865 buf
[i
- start
] = edit_buffer_get_byte (&edit
->buffer
, i
);
2866 len
-= mc_write (file
, (char *) buf
, end
- start
);
2876 /* --------------------------------------------------------------------------------------------- */
2879 edit_paste_from_history (WEdit
* edit
)
2882 edit_error_dialog (_("Error"), _("This function is not implemented"));
2885 /* --------------------------------------------------------------------------------------------- */
2888 edit_copy_to_X_buf_cmd (WEdit
* edit
)
2890 off_t start_mark
, end_mark
;
2892 if (!eval_marks (edit
, &start_mark
, &end_mark
))
2895 if (!edit_save_block_to_clip_file (edit
, start_mark
, end_mark
))
2897 edit_error_dialog (_("Copy to clipboard"), get_sys_error (_("Unable to save to file")));
2900 /* try use external clipboard utility */
2901 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_file_to_ext_clip", NULL
);
2906 /* --------------------------------------------------------------------------------------------- */
2909 edit_cut_to_X_buf_cmd (WEdit
* edit
)
2911 off_t start_mark
, end_mark
;
2913 if (!eval_marks (edit
, &start_mark
, &end_mark
))
2916 if (!edit_save_block_to_clip_file (edit
, start_mark
, end_mark
))
2918 edit_error_dialog (_("Cut to clipboard"), _("Unable to save to file"));
2921 /* try use external clipboard utility */
2922 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_file_to_ext_clip", NULL
);
2924 edit_block_delete_cmd (edit
);
2925 edit_mark_cmd (edit
, TRUE
);
2930 /* --------------------------------------------------------------------------------------------- */
2933 edit_paste_from_X_buf_cmd (WEdit
* edit
)
2938 /* try use external clipboard utility */
2939 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_file_from_ext_clip", NULL
);
2940 tmp
= mc_config_get_full_vpath (EDIT_CLIP_FILE
);
2941 ret
= (edit_insert_file (edit
, tmp
) >= 0);
2942 vfs_path_free (tmp
);
2947 /* --------------------------------------------------------------------------------------------- */
2949 * Ask user for the line and go to that line.
2950 * Negative numbers mean line from the end (i.e. -1 is the last line).
2954 edit_goto_cmd (WEdit
* edit
)
2957 static long line
= 0; /* line as typed, saved as default */
2962 g_snprintf (s
, sizeof (s
), "%ld", line
);
2963 f
= input_dialog (_("Goto line"), _("Enter line:"), MC_HISTORY_EDIT_GOTO_LINE
, line
? s
: "",
2964 INPUT_COMPLETE_NONE
);
2974 l
= strtol (f
, &error
, 0);
2983 l
= edit
->buffer
.lines
+ l
+ 2;
2984 edit_move_display (edit
, l
- WIDGET (edit
)->lines
/ 2 - 1);
2985 edit_move_to_line (edit
, l
- 1);
2986 edit
->force
|= REDRAW_COMPLETELY
;
2991 /* --------------------------------------------------------------------------------------------- */
2992 /** Return TRUE on success */
2995 edit_save_block_cmd (WEdit
* edit
)
2997 off_t start_mark
, end_mark
;
2999 gboolean ret
= FALSE
;
3001 if (!eval_marks (edit
, &start_mark
, &end_mark
))
3004 tmp
= mc_config_get_full_path (EDIT_CLIP_FILE
);
3006 input_expand_dialog (_("Save block"), _("Enter file name:"),
3007 MC_HISTORY_EDIT_SAVE_BLOCK
, tmp
, INPUT_COMPLETE_FILENAMES
);
3009 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
3011 if (exp
!= NULL
&& *exp
!= '\0')
3013 if (edit_save_block (edit
, exp
, start_mark
, end_mark
))
3016 edit_error_dialog (_("Save block"), get_sys_error (_("Cannot save file")));
3018 edit
->force
|= REDRAW_COMPLETELY
;
3027 /* --------------------------------------------------------------------------------------------- */
3029 /** returns TRUE on success */
3031 edit_insert_file_cmd (WEdit
* edit
)
3035 gboolean ret
= FALSE
;
3037 tmp
= mc_config_get_full_path (EDIT_CLIP_FILE
);
3038 exp
= input_expand_dialog (_("Insert file"), _("Enter file name:"),
3039 MC_HISTORY_EDIT_INSERT_FILE
, tmp
, INPUT_COMPLETE_FILENAMES
);
3042 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
3044 if (exp
!= NULL
&& *exp
!= '\0')
3046 vfs_path_t
*exp_vpath
;
3048 exp_vpath
= vfs_path_from_str (exp
);
3049 ret
= (edit_insert_file (edit
, exp_vpath
) >= 0);
3050 vfs_path_free (exp_vpath
);
3053 edit_error_dialog (_("Insert file"), get_sys_error (_("Cannot insert file")));
3058 edit
->force
|= REDRAW_COMPLETELY
;
3062 /* --------------------------------------------------------------------------------------------- */
3063 /** sorts a block, returns -1 on system fail, 1 on cancel and 0 on success */
3066 edit_sort_cmd (WEdit
* edit
)
3068 static char *old
= 0;
3069 char *exp
, *tmp
, *tmp_edit_block_name
, *tmp_edit_temp_name
;
3070 off_t start_mark
, end_mark
;
3073 if (!eval_marks (edit
, &start_mark
, &end_mark
))
3075 edit_error_dialog (_("Sort block"), _("You must first highlight a block of text"));
3079 tmp
= mc_config_get_full_path (EDIT_BLOCK_FILE
);
3080 edit_save_block (edit
, tmp
, start_mark
, end_mark
);
3083 exp
= input_dialog (_("Run sort"),
3084 _("Enter sort options (see manpage) separated by whitespace:"),
3085 MC_HISTORY_EDIT_SORT
, (old
!= NULL
) ? old
: "", INPUT_COMPLETE_NONE
);
3091 tmp_edit_block_name
= mc_config_get_full_path (EDIT_BLOCK_FILE
);
3092 tmp_edit_temp_name
= mc_config_get_full_path (EDIT_TEMP_FILE
);
3094 g_strconcat (" sort ", exp
, " ", tmp_edit_block_name
,
3095 " > ", tmp_edit_temp_name
, (char *) NULL
);
3096 g_free (tmp_edit_temp_name
);
3097 g_free (tmp_edit_block_name
);
3103 if (e
== -1 || e
== 127)
3105 edit_error_dialog (_("Sort"), get_sys_error (_("Cannot execute sort command")));
3110 sprintf (q
, "%d ", e
);
3111 tmp
= g_strdup_printf (_("Sort returned non-zero: %s"), q
);
3112 edit_error_dialog (_("Sort"), tmp
);
3118 edit
->force
|= REDRAW_COMPLETELY
;
3120 if (edit_block_delete_cmd (edit
))
3124 vfs_path_t
*tmp_vpath
;
3126 tmp_vpath
= mc_config_get_full_vpath (EDIT_TEMP_FILE
);
3127 edit_insert_file (edit
, tmp_vpath
);
3128 vfs_path_free (tmp_vpath
);
3133 /* --------------------------------------------------------------------------------------------- */
3135 * Ask user for a command, execute it and paste its output back to the
3140 edit_ext_cmd (WEdit
* edit
)
3142 char *exp
, *tmp
, *tmp_edit_temp_file
;
3146 input_dialog (_("Paste output of external command"),
3147 _("Enter shell command(s):"), MC_HISTORY_EDIT_PASTE_EXTCMD
, NULL
,
3148 INPUT_COMPLETE_FILENAMES
| INPUT_COMPLETE_VARIABLES
| INPUT_COMPLETE_USERNAMES
3149 | INPUT_COMPLETE_HOSTNAMES
| INPUT_COMPLETE_CD
| INPUT_COMPLETE_COMMANDS
|
3150 INPUT_COMPLETE_SHELL_ESC
);
3155 tmp_edit_temp_file
= mc_config_get_full_path (EDIT_TEMP_FILE
);
3156 tmp
= g_strconcat (exp
, " > ", tmp_edit_temp_file
, (char *) NULL
);
3157 g_free (tmp_edit_temp_file
);
3164 edit_error_dialog (_("External command"), get_sys_error (_("Cannot execute command")));
3168 edit
->force
|= REDRAW_COMPLETELY
;
3171 vfs_path_t
*tmp_vpath
;
3173 tmp_vpath
= mc_config_get_full_vpath (EDIT_TEMP_FILE
);
3174 edit_insert_file (edit
, tmp_vpath
);
3175 vfs_path_free (tmp_vpath
);
3180 /* --------------------------------------------------------------------------------------------- */
3181 /** if block is 1, a block must be highlighted and the shell command
3182 processes it. If block is 0 the shell command is a straight system
3183 command, that just produces some output which is to be inserted */
3186 edit_block_process_cmd (WEdit
* edit
, int macro_number
)
3189 char *macros_fname
= NULL
;
3191 fname
= g_strdup_printf ("%s.%i.sh", MC_EXTMACRO_FILE
, macro_number
);
3192 macros_fname
= g_build_filename (mc_config_get_data_path (), fname
, (char *) NULL
);
3193 user_menu (edit
, macros_fname
, 0);
3195 g_free (macros_fname
);
3196 edit
->force
|= REDRAW_COMPLETELY
;
3199 /* --------------------------------------------------------------------------------------------- */
3202 edit_mail_dialog (WEdit
* edit
)
3204 char *tmail_to
= NULL
;
3205 char *tmail_subject
= NULL
;
3206 char *tmail_cc
= NULL
;
3208 static char *mail_cc_last
= 0;
3209 static char *mail_subject_last
= 0;
3210 static char *mail_to_last
= 0;
3213 quick_widget_t quick_widgets
[] = {
3215 QUICK_LABEL (N_("mail -s <subject> -c <cc> <to>"), NULL
),
3216 QUICK_LABELED_INPUT (N_("To"), input_label_above
,
3217 mail_to_last
!= NULL
? mail_to_last
: "", "mail-dlg-input-3",
3218 &tmail_to
, NULL
, FALSE
, FALSE
, INPUT_COMPLETE_USERNAMES
),
3219 QUICK_LABELED_INPUT (N_("Subject"), input_label_above
,
3220 mail_subject_last
!= NULL
? mail_subject_last
: "", "mail-dlg-input-2",
3221 &tmail_subject
, NULL
, FALSE
, FALSE
, INPUT_COMPLETE_NONE
),
3222 QUICK_LABELED_INPUT (N_("Copies to"), input_label_above
,
3223 mail_cc_last
!= NULL
? mail_cc_last
: "", "mail-dlg-input",
3224 &tmail_cc
, NULL
, FALSE
, FALSE
, INPUT_COMPLETE_USERNAMES
),
3225 QUICK_BUTTONS_OK_CANCEL
,
3230 quick_dialog_t qdlg
= {
3232 N_("Mail"), "[Input Line Keys]",
3233 quick_widgets
, NULL
, NULL
3236 if (quick_dialog (&qdlg
) != B_CANCEL
)
3238 g_free (mail_cc_last
);
3239 g_free (mail_subject_last
);
3240 g_free (mail_to_last
);
3241 mail_cc_last
= tmail_cc
;
3242 mail_subject_last
= tmail_subject
;
3243 mail_to_last
= tmail_to
;
3244 pipe_mail (&edit
->buffer
, mail_to_last
, mail_subject_last
, mail_cc_last
);
3248 /* --------------------------------------------------------------------------------------------- */
3250 /*******************/
3251 /* Word Completion */
3252 /*******************/
3255 * Complete current word using regular expression search
3256 * backwards beginning at the current cursor position.
3260 edit_complete_word_cmd (WEdit
* edit
)
3262 gsize i
, max_len
, word_len
= 0, num_compl
= 0;
3263 off_t word_start
= 0;
3264 GString
*match_expr
;
3265 GString
*compl[MAX_WORD_COMPLETIONS
]; /* completions */
3267 /* search start of word to be completed */
3268 if (!edit_find_word_start (&edit
->buffer
, &word_start
, &word_len
))
3271 /* prepare match expression */
3272 /* match_expr = g_strdup_printf ("\\b%.*s[a-zA-Z_0-9]+", word_len, bufpos); */
3273 match_expr
= g_string_new ("(^|\\s+|\\b)");
3274 for (i
= 0; i
< word_len
; i
++)
3275 g_string_append_c (match_expr
, edit_buffer_get_byte (&edit
->buffer
, word_start
+ i
));
3276 g_string_append (match_expr
,
3277 "[^\\s\\.=\\+\\[\\]\\(\\)\\,\\;\\:\\\"\\'\\-\\?\\/\\|\\\\\\{\\}\\*\\&\\^\\%%\\$#@\\!]+");
3279 /* collect the possible completions */
3280 /* start search from begin to end of file */
3282 edit_collect_completions (edit
, word_start
, word_len
, match_expr
->str
, (GString
**) & compl,
3287 /* insert completed word if there is only one match */
3289 edit_complete_word_insert_recoded_completion (edit
, compl[0]->str
, word_len
);
3290 /* more than one possible completion => ask the user */
3295 /* !!! usually only a beep is expected and when <ALT-TAB> is !!! */
3296 /* !!! pressed again the selection dialog pops up, but that !!! */
3297 /* !!! seems to require a further internal state !!! */
3300 /* let the user select the preferred completion */
3301 curr_compl
= editcmd_dialog_completion_show (edit
, max_len
,
3302 (GString
**) & compl, num_compl
);
3304 if (curr_compl
!= NULL
)
3306 edit_complete_word_insert_recoded_completion (edit
, curr_compl
, word_len
);
3307 g_free (curr_compl
);
3312 g_string_free (match_expr
, TRUE
);
3313 /* release memory before return */
3314 for (i
= 0; i
< num_compl
; i
++)
3315 g_string_free (compl[i
], TRUE
);
3318 /* --------------------------------------------------------------------------------------------- */
3322 edit_select_codepage_cmd (WEdit
* edit
)
3324 if (do_select_codepage ())
3325 edit_set_codeset (edit
);
3327 edit
->force
= REDRAW_PAGE
;
3328 widget_redraw (WIDGET (edit
));
3332 /* --------------------------------------------------------------------------------------------- */
3335 edit_insert_literal_cmd (WEdit
* edit
)
3337 int char_for_insertion
;
3339 char_for_insertion
= editcmd_dialog_raw_key_query (_("Insert literal"),
3340 _("Press any key:"), FALSE
);
3341 edit_execute_key_command (edit
, -1, ascii_alpha_to_cntrl (char_for_insertion
));
3344 /* --------------------------------------------------------------------------------------------- */
3347 edit_begin_end_macro_cmd (WEdit
* edit
)
3349 /* edit is a pointer to the widget */
3352 unsigned long command
= macro_index
< 0 ? CK_MacroStartRecord
: CK_MacroStopRecord
;
3353 edit_execute_key_command (edit
, command
, -1);
3357 /* --------------------------------------------------------------------------------------------- */
3360 edit_begin_end_repeat_cmd (WEdit
* edit
)
3362 /* edit is a pointer to the widget */
3365 unsigned long command
= macro_index
< 0 ? CK_RepeatStartRecord
: CK_RepeatStopRecord
;
3366 edit_execute_key_command (edit
, command
, -1);
3370 /* --------------------------------------------------------------------------------------------- */
3373 edit_load_forward_cmd (WEdit
* edit
)
3376 && edit_query_dialog2 (_("Warning"),
3377 _("Current text was modified without a file save.\n"
3378 "Continue discards these changes"), _("C&ontinue"),
3381 edit
->force
|= REDRAW_COMPLETELY
;
3385 if (edit_stack_iterator
+ 1 >= MAX_HISTORY_MOVETO
)
3388 if (edit_history_moveto
[edit_stack_iterator
+ 1].line
< 1)
3391 edit_stack_iterator
++;
3392 if (edit_history_moveto
[edit_stack_iterator
].filename_vpath
!= NULL
)
3393 return edit_reload_line (edit
, edit_history_moveto
[edit_stack_iterator
].filename_vpath
,
3394 edit_history_moveto
[edit_stack_iterator
].line
);
3399 /* --------------------------------------------------------------------------------------------- */
3402 edit_load_back_cmd (WEdit
* edit
)
3405 && edit_query_dialog2 (_("Warning"),
3406 _("Current text was modified without a file save.\n"
3407 "Continue discards these changes"), _("C&ontinue"),
3410 edit
->force
|= REDRAW_COMPLETELY
;
3414 /* we are in the bottom of the stack, NO WAY! */
3415 if (edit_stack_iterator
== 0)
3418 edit_stack_iterator
--;
3419 if (edit_history_moveto
[edit_stack_iterator
].filename_vpath
!= NULL
)
3420 return edit_reload_line (edit
, edit_history_moveto
[edit_stack_iterator
].filename_vpath
,
3421 edit_history_moveto
[edit_stack_iterator
].line
);
3426 /* --------------------------------------------------------------------------------------------- */
3429 edit_get_match_keyword_cmd (WEdit
* edit
)
3431 gsize word_len
= 0, max_len
= 0;
3434 off_t word_start
= 0;
3435 GString
*match_expr
;
3438 char *tagfile
= NULL
;
3440 etags_hash_t def_hash
[MAX_DEFINITIONS
];
3442 for (i
= 0; i
< MAX_DEFINITIONS
; i
++)
3444 def_hash
[i
].filename
= NULL
;
3447 /* search start of word to be completed */
3448 if (!edit_find_word_start (&edit
->buffer
, &word_start
, &word_len
))
3451 /* prepare match expression */
3452 match_expr
= g_string_sized_new (word_len
);
3453 for (i
= 0; i
< word_len
; i
++)
3454 g_string_append_c (match_expr
, edit_buffer_get_byte (&edit
->buffer
, word_start
+ i
));
3456 ptr
= g_get_current_dir ();
3457 path
= g_strconcat (ptr
, G_DIR_SEPARATOR_S
, (char *) NULL
);
3460 /* Recursive search file 'TAGS' in parent dirs */
3463 ptr
= g_path_get_dirname (path
);
3467 tagfile
= mc_build_filename (path
, TAGS_NAME
, (char *) NULL
);
3468 if (exist_file (tagfile
))
3471 while (strcmp (path
, G_DIR_SEPARATOR_S
) != 0);
3476 etags_set_definition_hash (tagfile
, path
, match_expr
->str
, (etags_hash_t
*) & def_hash
);
3481 max_len
= MAX_WIDTH_DEF_DIALOG
;
3485 editcmd_dialog_select_definition_show (edit
, match_expr
->str
, max_len
, word_len
,
3486 (etags_hash_t
*) & def_hash
, num_def
);
3488 g_string_free (match_expr
, TRUE
);
3491 /* --------------------------------------------------------------------------------------------- */
3495 edit_suggest_current_word (WEdit
* edit
)
3499 off_t word_start
= 0;
3500 int retval
= B_SKIP_WORD
;
3501 GString
*match_word
;
3503 /* search start of word to spell check */
3504 match_word
= edit_buffer_get_word_from_pos (&edit
->buffer
, edit
->buffer
.curs1
, &word_start
,
3506 word_len
= match_word
->len
;
3509 if (mc_global
.source_codepage
>= 0 && (mc_global
.source_codepage
!= mc_global
.display_codepage
))
3513 tmp_word
= str_convert_to_display (match_word
->str
);
3514 g_string_free (match_word
, TRUE
);
3515 match_word
= tmp_word
;
3518 if (!aspell_check (match_word
->str
, (int) word_len
))
3523 suggest
= g_array_new (TRUE
, FALSE
, sizeof (char *));
3525 res
= aspell_suggest (suggest
, match_word
->str
, (int) word_len
);
3528 char *new_word
= NULL
;
3530 edit
->found_start
= word_start
;
3531 edit
->found_len
= word_len
;
3532 edit
->force
|= REDRAW_PAGE
;
3533 edit_scroll_screen_over_cursor (edit
);
3534 edit_render_keypress (edit
);
3536 retval
= spell_dialog_spell_suggest_show (edit
, match_word
->str
, &new_word
, suggest
);
3537 edit_cursor_move (edit
, word_len
- cut_len
);
3539 if (retval
== B_ENTER
&& new_word
!= NULL
)
3545 if (mc_global
.source_codepage
>= 0 &&
3546 (mc_global
.source_codepage
!= mc_global
.display_codepage
))
3550 tmp_word
= str_convert_to_input (new_word
);
3552 new_word
= g_string_free (tmp_word
, FALSE
);
3556 for (i
= 0; i
< word_len
; i
++)
3557 edit_backspace (edit
, TRUE
);
3558 for (; *new_word
; new_word
++)
3559 edit_insert (edit
, *new_word
);
3562 else if (retval
== B_ADD_WORD
&& match_word
!= NULL
)
3563 aspell_add_to_dict (match_word
->str
, (int) word_len
);
3566 g_array_free (suggest
, TRUE
);
3567 edit
->found_start
= 0;
3568 edit
->found_len
= 0;
3570 g_string_free (match_word
, TRUE
);
3574 /* --------------------------------------------------------------------------------------------- */
3577 edit_spellcheck_file (WEdit
* edit
)
3579 if (edit
->buffer
.curs_line
> 0)
3581 edit_cursor_move (edit
, -edit
->buffer
.curs1
);
3582 edit_move_to_prev_col (edit
, 0);
3583 edit_update_curs_row (edit
);
3590 c2
= edit_buffer_get_current_byte (&edit
->buffer
);
3594 if (edit
->buffer
.curs1
>= edit
->buffer
.size
)
3598 edit_cursor_move (edit
, 1);
3599 c2
= edit_buffer_get_current_byte (&edit
->buffer
);
3601 while (is_break_char (c1
) || is_break_char (c2
));
3603 while (edit_suggest_current_word (edit
) != B_CANCEL
);
3606 /* --------------------------------------------------------------------------------------------- */
3609 edit_set_spell_lang (void)
3613 lang_list
= g_array_new (TRUE
, FALSE
, sizeof (char *));
3614 if (aspell_get_lang_list (lang_list
) != 0)
3618 lang
= spell_dialog_lang_list_show (lang_list
);
3620 (void) aspell_set_lang (lang
);
3622 aspell_array_clean (lang_list
);
3624 #endif /* HAVE_ASPELL */
3626 /* --------------------------------------------------------------------------------------------- */