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
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 */
71 #include "src/main.h" /* mactos_t */
73 #include "src/selcodepage.h"
75 #include "src/keybind-defaults.h"
76 #include "src/util.h" /* check_for_default() */
77 #include "src/filemanager/layout.h" /* mc_refresh() */
79 #include "edit-impl.h"
80 #include "editwidget.h"
81 #include "editcmd_dialogs.h"
84 #include "spell_dialogs.h"
88 /*** global variables ****************************************************************************/
90 /* search and replace: */
91 int search_create_bookmark
= FALSE
;
93 /* queries on a save */
94 int edit_confirm_save
= 1;
96 /*** file scope macro definitions ****************************************************************/
100 #define TEMP_BUF_LEN 1024
102 #define INPUT_INDEX 9
104 /* thanks to Liviu Daia <daia@stoilow.imar.ro> for getting this
105 (and the above) routines to work properly - paul */
107 #define is_digit(x) ((x) >= '0' && (x) <= '9')
109 #define MAIL_DLG_HEIGHT 12
111 #define MAX_WORD_COMPLETIONS 100 /* in listbox */
113 /*** file scope type declarations ****************************************************************/
115 /*** file scope variables ************************************************************************/
117 /*** file scope functions ************************************************************************/
118 /* --------------------------------------------------------------------------------------------- */
120 /* If 0 (quick save) then a) create/truncate <filename> file,
121 b) save to <filename>;
122 if 1 (safe save) then a) save to <tempnam>,
123 b) rename <tempnam> to <filename>;
124 if 2 (do backups) then a) save to <tempnam>,
125 b) rename <filename> to <filename.backup_ext>,
126 c) rename <tempnam> to <filename>. */
128 /* returns 0 on error, -1 on abort */
131 edit_save_file (WEdit
* edit
, const vfs_path_t
* filename_vpath
)
136 int this_save_mode
, fd
= -1;
137 vfs_path_t
*real_filename_vpath
;
138 vfs_path_t
*savename_vpath
= NULL
;
139 const char *start_filename
;
140 const vfs_path_element_t
*vpath_element
;
142 vpath_element
= vfs_path_get_by_index (filename_vpath
, 0);
143 if (vpath_element
== NULL
)
146 start_filename
= vpath_element
->path
;
147 if (*start_filename
== '\0')
150 if (*start_filename
!= PATH_SEP
&& edit
->dir_vpath
!= NULL
)
152 real_filename_vpath
= vfs_path_append_vpath_new (edit
->dir_vpath
, filename_vpath
, NULL
);
156 real_filename_vpath
= vfs_path_clone (filename_vpath
);
159 this_save_mode
= option_save_mode
;
160 if (this_save_mode
!= EDIT_QUICK_SAVE
)
162 if (!vfs_file_is_local (real_filename_vpath
)
163 || (fd
= mc_open (real_filename_vpath
, O_RDONLY
| O_BINARY
)) == -1)
166 * The file does not exists yet, so no safe save or
167 * backup are necessary.
169 this_save_mode
= EDIT_QUICK_SAVE
;
175 if (this_save_mode
== EDIT_QUICK_SAVE
&& !edit
->skip_detach_prompt
)
180 rv
= mc_stat (real_filename_vpath
, &sb
);
181 if (rv
== 0 && sb
.st_nlink
> 1)
183 rv
= edit_query_dialog3 (_("Warning"),
184 _("File has hard-links. Detach before saving?"),
185 _("&Yes"), _("&No"), _("&Cancel"));
189 this_save_mode
= EDIT_SAFE_SAVE
;
192 edit
->skip_detach_prompt
= 1;
195 vfs_path_free (real_filename_vpath
);
200 /* Prevent overwriting changes from other editor sessions. */
201 if (rv
== 0 && edit
->stat1
.st_mtime
!= 0 && edit
->stat1
.st_mtime
!= sb
.st_mtime
)
203 /* The default action is "Cancel". */
206 rv
= edit_query_dialog2 (_("Warning"),
207 _("The file has been modified in the meantime. Save anyway?"),
208 _("&Yes"), _("&Cancel"));
211 vfs_path_free (real_filename_vpath
);
217 if (this_save_mode
!= EDIT_QUICK_SAVE
)
219 char *savedir
, *saveprefix
;
221 savedir
= vfs_path_tokens_get (real_filename_vpath
, 0, -1);
223 savedir
= g_strdup (".");
225 saveprefix
= mc_build_filename (savedir
, "cooledit", NULL
);
227 fd
= mc_mkstemps (&savename_vpath
, saveprefix
, NULL
);
229 if (savename_vpath
== NULL
)
231 vfs_path_free (real_filename_vpath
);
235 * Close for now because mc_mkstemps use pure open system call
236 * to create temporary file and it needs to be reopened by
237 * VFS-aware mc_open().
242 savename_vpath
= vfs_path_clone (real_filename_vpath
);
244 (void) mc_chown (savename_vpath
, edit
->stat1
.st_uid
, edit
->stat1
.st_gid
);
245 (void) mc_chmod (savename_vpath
, edit
->stat1
.st_mode
);
247 fd
= mc_open (savename_vpath
, O_CREAT
| O_WRONLY
| O_TRUNC
| O_BINARY
, edit
->stat1
.st_mode
);
252 p
= edit_get_write_filter (savename_vpath
, real_filename_vpath
);
258 file
= (FILE *) popen (p
, "w");
262 filelen
= edit_write_stream (edit
, file
);
266 if (pclose (file
) != 0)
268 tmp
= g_strdup_printf (_("Error writing to pipe: %s"), p
);
269 edit_error_dialog (_("Error"), tmp
);
278 tmp
= g_strdup_printf (_("Cannot open pipe for writing: %s"), p
);
279 edit_error_dialog (_("Error"), get_sys_error (tmp
));
286 else if (edit
->lb
== LB_ASIS
)
287 { /* do not change line breaks */
290 filelen
= edit
->last_byte
;
291 while (buf
<= (edit
->curs1
>> S_EDIT_BUF_SIZE
) - 1)
293 if (mc_write (fd
, (char *) edit
->buffers1
[buf
], EDIT_BUF_SIZE
) != EDIT_BUF_SIZE
)
301 (fd
, (char *) edit
->buffers1
[buf
],
302 edit
->curs1
& M_EDIT_BUF_SIZE
) != (edit
->curs1
& M_EDIT_BUF_SIZE
))
306 else if (edit
->curs2
)
309 buf
= (edit
->curs2
>> S_EDIT_BUF_SIZE
);
312 (char *) edit
->buffers2
[buf
] + EDIT_BUF_SIZE
-
313 (edit
->curs2
& M_EDIT_BUF_SIZE
) - 1,
314 1 + (edit
->curs2
& M_EDIT_BUF_SIZE
)) != 1 + (edit
->curs2
& M_EDIT_BUF_SIZE
))
322 if (mc_write (fd
, (char *) edit
->buffers2
[buf
], EDIT_BUF_SIZE
) != EDIT_BUF_SIZE
)
334 /* Update the file information, especially the mtime. */
335 if (mc_stat (savename_vpath
, &edit
->stat1
) == -1)
339 { /* change line breaks */
341 const vfs_path_element_t
*path_element
;
345 path_element
= vfs_path_get_by_index (savename_vpath
, -1);
346 file
= (FILE *) fopen (path_element
->path
, "w");
349 filelen
= edit_write_stream (edit
, file
);
356 msg
= g_strdup_printf (_("Cannot open file for writing: %s"), path_element
->path
);
357 edit_error_dialog (_("Error"), msg
);
363 if (filelen
!= edit
->last_byte
)
366 if (this_save_mode
== EDIT_DO_BACKUP
)
368 vfs_path_t
*tmp_vpath
;
372 assert (option_backup_ext
!= NULL
);
374 tmp_vpath
= vfs_path_append_new (real_filename_vpath
, option_backup_ext
, (char *) NULL
);
375 ok
= (mc_rename (real_filename_vpath
, tmp_vpath
) != -1);
376 vfs_path_free (tmp_vpath
);
381 if (this_save_mode
!= EDIT_QUICK_SAVE
)
382 if (mc_rename (savename_vpath
, real_filename_vpath
) == -1)
385 vfs_path_free (real_filename_vpath
);
386 vfs_path_free (savename_vpath
);
389 /* FIXME: Is this safe ?
390 * if (this_save_mode != EDIT_QUICK_SAVE)
391 * mc_unlink (savename);
393 vfs_path_free (real_filename_vpath
);
394 vfs_path_free (savename_vpath
);
398 /* --------------------------------------------------------------------------------------------- */
401 edit_check_newline (WEdit
* edit
)
403 return !(option_check_nl_at_eof
&& edit
->last_byte
> 0
404 && edit_get_byte (edit
, edit
->last_byte
- 1) != '\n'
405 && edit_query_dialog2 (_("Warning"),
406 _("The file you are saving is not finished with a newline"),
407 _("C&ontinue"), _("&Cancel")));
410 /* --------------------------------------------------------------------------------------------- */
413 edit_get_save_file_as (WEdit
* edit
)
416 #define DLG_HEIGHT 14
418 static LineBreaks cur_lb
= LB_ASIS
;
420 char *filename
= vfs_path_to_str (edit
->filename_vpath
);
423 const char *lb_names
[LB_NAMES
] = {
424 N_("&Do not change"),
425 N_("&Unix format (LF)"),
426 N_("&Windows/DOS format (CR LF)"),
427 N_("&Macintosh format (CR)")
430 QuickWidget quick_widgets
[] = {
431 QUICK_BUTTON (6, 10, DLG_HEIGHT
- 3, DLG_HEIGHT
, N_("&Cancel"), B_CANCEL
, NULL
),
432 QUICK_BUTTON (2, 10, DLG_HEIGHT
- 3, DLG_HEIGHT
, N_("&OK"), B_ENTER
, NULL
),
433 QUICK_RADIO (5, DLG_WIDTH
, DLG_HEIGHT
- 8, DLG_HEIGHT
, LB_NAMES
, lb_names
, (int *) &cur_lb
),
434 QUICK_LABEL (3, DLG_WIDTH
, DLG_HEIGHT
- 9, DLG_HEIGHT
, N_("Change line breaks to:")),
435 QUICK_INPUT (3, DLG_WIDTH
, DLG_HEIGHT
- 11, DLG_HEIGHT
, filename
, DLG_WIDTH
- 6, 0,
436 "save-as", &filename_res
),
437 QUICK_LABEL (3, DLG_WIDTH
, DLG_HEIGHT
- 12, DLG_HEIGHT
, N_("Enter file name:")),
441 QuickDialog Quick_options
= {
442 DLG_WIDTH
, DLG_HEIGHT
, -1, -1,
443 N_("Save As"), "[Save File As]",
444 quick_widgets
, NULL
, NULL
, FALSE
447 if (quick_dialog (&Quick_options
) != B_CANCEL
)
450 vfs_path_t
*ret_vpath
;
453 fname
= tilde_expand (filename_res
);
454 g_free (filename_res
);
455 ret_vpath
= vfs_path_from_str (fname
);
467 /* --------------------------------------------------------------------------------------------- */
469 /** returns 1 on success */
472 edit_save_cmd (WEdit
* edit
)
474 int res
, save_lock
= 0;
476 if (!edit
->locked
&& !edit
->delete_file
)
477 save_lock
= lock_file (edit
->filename_vpath
);
478 res
= edit_save_file (edit
, edit
->filename_vpath
);
480 /* Maintain modify (not save) lock on failure */
481 if ((res
> 0 && edit
->locked
) || save_lock
)
482 edit
->locked
= unlock_file (edit
->filename_vpath
);
484 /* On failure try 'save as', it does locking on its own */
486 return edit_save_as_cmd (edit
);
487 edit
->force
|= REDRAW_COMPLETELY
;
490 edit
->delete_file
= 0;
497 /* --------------------------------------------------------------------------------------------- */
501 * @param h screen the owner of editor window
502 * @param vpath vfs file path
503 * @return TRUE if file content was successfully loaded, FALSE otherwise
506 static inline gboolean
507 edit_load_file_from_filename (Dlg_head
*h
, const vfs_path_t
*vpath
)
509 return edit_add_window (h
, h
->y
+ 1, h
->x
, h
->lines
- 2, h
->cols
, vpath
, 0);
512 /* --------------------------------------------------------------------------------------------- */
515 edit_delete_column_of_text (WEdit
* edit
)
517 long p
, q
, r
, m1
, m2
;
520 eval_marks (edit
, &m1
, &m2
);
521 n
= edit_move_forward (edit
, m1
, 0, m2
) + 1;
522 c
= edit_move_forward3 (edit
, edit_bol (edit
, m1
), 0, m1
);
523 d
= edit_move_forward3 (edit
, edit_bol (edit
, m2
), 0, m2
);
524 b
= max (min (c
, d
), min (edit
->column1
, edit
->column2
));
525 c
= max (c
, max (edit
->column1
, edit
->column2
));
529 r
= edit_bol (edit
, edit
->curs1
);
530 p
= edit_move_forward3 (edit
, r
, b
, 0);
531 q
= edit_move_forward3 (edit
, r
, c
, 0);
536 edit_cursor_move (edit
, p
- edit
->curs1
);
539 /* delete line between margins */
540 if (edit_get_byte (edit
, edit
->curs1
) != '\n')
541 edit_delete (edit
, 1);
545 /* move to next line except on the last delete */
546 edit_cursor_move (edit
, edit_move_forward (edit
, edit
->curs1
, 1, 0) - edit
->curs1
);
550 /* --------------------------------------------------------------------------------------------- */
551 /** if success return 0 */
554 edit_block_delete (WEdit
* edit
)
557 long start_mark
, end_mark
;
558 int curs_pos
, line_width
;
559 long curs_line
, c1
, c2
;
561 if (eval_marks (edit
, &start_mark
, &end_mark
))
563 if (edit
->column_highlight
&& edit
->mark2
< 0)
564 edit_mark_cmd (edit
, 0);
565 if ((end_mark
- start_mark
) > option_max_undo
/ 2)
567 /* Warning message with a query to continue or cancel the operation */
568 if (edit_query_dialog2
571 ("Block is large, you may not be able to undo this action"),
572 _("C&ontinue"), _("&Cancel")))
577 c1
= min (edit
->column1
, edit
->column2
);
578 c2
= max (edit
->column1
, edit
->column2
);
582 edit_push_markers (edit
);
584 curs_line
= edit
->curs_line
;
586 /* calculate line width and cursor position before cut */
587 line_width
= edit_move_forward3 (edit
, edit_bol (edit
, edit
->curs1
), 0,
588 edit_eol (edit
, edit
->curs1
));
589 curs_pos
= edit
->curs_col
+ edit
->over_col
;
591 /* move cursor to start of selection */
592 edit_cursor_move (edit
, start_mark
- edit
->curs1
);
593 edit_scroll_screen_over_cursor (edit
);
595 if (start_mark
< end_mark
)
597 if (edit
->column_highlight
)
600 edit_mark_cmd (edit
, 0);
601 edit_delete_column_of_text (edit
);
602 /* move cursor to the saved position */
603 edit_move_to_line (edit
, curs_line
);
604 /* calculate line width after cut */
605 line_width
= edit_move_forward3 (edit
, edit_bol (edit
, edit
->curs1
), 0,
606 edit_eol (edit
, edit
->curs1
));
607 if (option_cursor_beyond_eol
&& curs_pos
> line_width
)
608 edit
->over_col
= curs_pos
- line_width
;
612 while (count
< end_mark
)
614 edit_delete (edit
, 1);
619 edit_set_markers (edit
, 0, 0, 0, 0);
620 edit
->force
|= REDRAW_PAGE
;
624 /* --------------------------------------------------------------------------------------------- */
626 * Get EOL symbol for searching.
628 * @param edit editor object
633 edit_search_get_current_end_line_char (const WEdit
* edit
)
644 /* --------------------------------------------------------------------------------------------- */
646 * Checking if search condition have BOL(^) or EOL ($) regexp special characters.
648 * @param search search object
649 * @return result of checks.
652 static edit_search_line_t
653 edit_get_search_line_type (mc_search_t
* search
)
655 edit_search_line_t search_line_type
= 0;
657 if (search
->search_type
!= MC_SEARCH_T_REGEX
)
658 return search_line_type
;
660 if (*search
->original
== '^')
661 search_line_type
|= AT_START_LINE
;
663 if (search
->original
[search
->original_len
- 1] == '$')
664 search_line_type
|= AT_END_LINE
;
665 return search_line_type
;
668 /* --------------------------------------------------------------------------------------------- */
670 * Calculating the start position of next line.
672 * @param edit editor object
673 * @param current_pos current position
674 * @param max_pos max position
675 * @param end_string_symbol end of line symbol
676 * @return start position of next line
680 edit_calculate_start_of_next_line (WEdit
* edit
, off_t current_pos
, off_t max_pos
,
681 char end_string_symbol
)
685 for (i
= current_pos
; i
< max_pos
; i
++)
688 if (edit_get_byte (edit
, i
) == end_string_symbol
)
695 /* --------------------------------------------------------------------------------------------- */
697 * Calculating the end position of previous line.
699 * @param edit editor object
700 * @param current_pos current position
701 * @param end_string_symbol end of line symbol
702 * @return end position of previous line
706 edit_calculate_end_of_previous_line (WEdit
* edit
, off_t current_pos
, char end_string_symbol
)
710 for (i
= current_pos
- 1; i
>= 0; i
--)
711 if (edit_get_byte (edit
, i
) == end_string_symbol
)
717 /* --------------------------------------------------------------------------------------------- */
719 * Calculating the start position of previous line.
721 * @param edit editor object
722 * @param current_pos current position
723 * @param end_string_symbol end of line symbol
724 * @return start position of previous line
728 edit_calculate_start_of_previous_line (WEdit
* edit
, off_t current_pos
, char end_string_symbol
)
730 current_pos
= edit_calculate_end_of_previous_line (edit
, current_pos
, end_string_symbol
);
731 current_pos
= edit_calculate_end_of_previous_line (edit
, current_pos
, end_string_symbol
);
733 return (current_pos
+ 1);
736 /* --------------------------------------------------------------------------------------------- */
738 * Calculating the start position of current line.
740 * @param edit editor object
741 * @param current_pos current position
742 * @param end_string_symbol end of line symbol
743 * @return start position of current line
747 edit_calculate_start_of_current_line (WEdit
* edit
, off_t current_pos
, char end_string_symbol
)
749 current_pos
= edit_calculate_end_of_previous_line (edit
, current_pos
, end_string_symbol
);
751 return (current_pos
+ 1);
754 /* --------------------------------------------------------------------------------------------- */
756 * Fixing (if needed) search start position if 'only in selection' option present.
758 * @param edit editor object
762 edit_search_fix_search_start_if_selection (WEdit
* edit
)
767 if (!edit_search_options
.only_in_selection
)
770 if (eval_marks (edit
, &start_mark
, &end_mark
) != 0)
773 if (edit_search_options
.backwards
)
775 if (edit
->search_start
> end_mark
|| edit
->search_start
<= start_mark
)
776 edit
->search_start
= end_mark
;
780 if (edit
->search_start
< start_mark
|| edit
->search_start
>= end_mark
)
781 edit
->search_start
= start_mark
;
785 /* --------------------------------------------------------------------------------------------- */
788 editcmd_find (WEdit
* edit
, gsize
* len
)
790 off_t search_start
= edit
->search_start
;
793 long end_mark
= edit
->last_byte
;
795 char end_string_symbol
;
797 end_string_symbol
= edit_search_get_current_end_line_char (edit
);
799 /* prepare for search */
800 if (edit_search_options
.only_in_selection
)
802 mark_res
= eval_marks (edit
, &start_mark
, &end_mark
);
805 edit
->search
->error
= MC_SEARCH_E_NOTFOUND
;
806 edit
->search
->error_str
= g_strdup (_("Search string not found"));
810 /* fix the start and the end of search block positions */
811 if ((edit
->search_line_type
& AT_START_LINE
) != 0
812 && (start_mark
!= 0 || edit_get_byte (edit
, start_mark
- 1) != end_string_symbol
))
815 edit_calculate_start_of_next_line (edit
, start_mark
, edit
->last_byte
,
818 if ((edit
->search_line_type
& AT_END_LINE
) != 0
819 && (end_mark
- 1 != edit
->last_byte
820 || edit_get_byte (edit
, end_mark
) != end_string_symbol
))
822 end_mark
= edit_calculate_end_of_previous_line (edit
, end_mark
, end_string_symbol
);
824 if (start_mark
>= end_mark
)
826 edit
->search
->error
= MC_SEARCH_E_NOTFOUND
;
827 edit
->search
->error_str
= g_strdup (_("Search string not found"));
833 if (edit_search_options
.backwards
)
834 end_mark
= max (1, edit
->curs1
) - 1;
838 if (edit_search_options
.backwards
)
840 /* backward search */
841 search_end
= end_mark
;
843 if ((edit
->search_line_type
& AT_START_LINE
) != 0)
845 edit_calculate_start_of_current_line (edit
, search_start
, end_string_symbol
);
847 while ((int) search_start
>= start_mark
)
849 if (search_end
> (off_t
) (search_start
+ edit
->search
->original_len
)
850 && mc_search_is_fixed_search_str (edit
->search
))
852 search_end
= search_start
+ edit
->search
->original_len
;
854 if (mc_search_run (edit
->search
, (void *) edit
, search_start
, search_end
, len
)
855 && edit
->search
->normal_offset
== search_start
)
861 if ((edit
->search_line_type
& AT_START_LINE
) != 0)
863 edit_calculate_start_of_previous_line (edit
, search_start
, end_string_symbol
);
867 edit
->search
->error_str
= g_strdup (_("Search string not found"));
872 if ((edit
->search_line_type
& AT_START_LINE
) != 0 && search_start
!= start_mark
)
874 edit_calculate_start_of_next_line (edit
, search_start
, end_mark
, end_string_symbol
);
875 return mc_search_run (edit
->search
, (void *) edit
, search_start
, end_mark
, len
);
880 /* --------------------------------------------------------------------------------------------- */
883 edit_replace_cmd__conv_to_display (char *str
)
888 tmp
= str_convert_to_display (str
);
892 return g_string_free (tmp
, FALSE
);
893 g_string_free (tmp
, TRUE
);
896 return g_strdup (str
);
899 /* --------------------------------------------------------------------------------------------- */
902 edit_replace_cmd__conv_to_input (char *str
)
907 tmp
= str_convert_to_input (str
);
911 return g_string_free (tmp
, FALSE
);
912 g_string_free (tmp
, TRUE
);
915 return g_strdup (str
);
918 /* --------------------------------------------------------------------------------------------- */
921 edit_do_search (WEdit
* edit
)
925 if (edit
->search
== NULL
)
926 edit
->search_start
= edit
->curs1
;
928 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
930 if (search_create_bookmark
)
932 int found
= 0, books
= 0;
933 long l
= 0, l_last
= -1;
936 search_create_bookmark
= FALSE
;
937 book_mark_flush (edit
, -1);
941 if (!mc_search_run (edit
->search
, (void *) edit
, q
, edit
->last_byte
, &len
))
944 edit
->search_start
= edit
->search
->normal_offset
;
946 l
+= edit_count_lines (edit
, q
, edit
->search
->normal_offset
);
949 book_mark_insert (edit
, l
, BOOK_MARK_FOUND_COLOR
);
953 q
= edit
->search
->normal_offset
+ 1;
957 edit_error_dialog (_("Search"), _("Search string not found"));
959 edit_cursor_move (edit
, edit
->search_start
- edit
->curs1
);
963 if (edit
->found_len
!= 0 && edit
->search_start
== edit
->found_start
+ 1
964 && edit_search_options
.backwards
)
965 edit
->search_start
--;
967 if (edit
->found_len
!= 0 && edit
->search_start
== edit
->found_start
- 1
968 && !edit_search_options
.backwards
)
969 edit
->search_start
++;
971 if (editcmd_find (edit
, &len
))
973 edit
->found_start
= edit
->search_start
= edit
->search
->normal_offset
;
974 edit
->found_len
= len
;
976 edit_cursor_move (edit
, edit
->search_start
- edit
->curs1
);
977 edit_scroll_screen_over_cursor (edit
);
978 if (edit_search_options
.backwards
)
979 edit
->search_start
--;
981 edit
->search_start
++;
985 edit
->search_start
= edit
->curs1
;
986 if (edit
->search
->error_str
!= NULL
)
987 edit_error_dialog (_("Search"), edit
->search
->error_str
);
991 edit
->force
|= REDRAW_COMPLETELY
;
992 edit_scroll_screen_over_cursor (edit
);
995 /* --------------------------------------------------------------------------------------------- */
998 edit_search (WEdit
* edit
)
1000 if (editcmd_dialog_search_show (edit
))
1002 edit
->search_line_type
= edit_get_search_line_type (edit
->search
);
1003 edit_search_fix_search_start_if_selection (edit
);
1004 edit_do_search (edit
);
1008 /* --------------------------------------------------------------------------------------------- */
1009 /** Return a null terminated length of text. Result must be g_free'd */
1011 static unsigned char *
1012 edit_get_block (WEdit
* edit
, long start
, long finish
, int *l
)
1014 unsigned char *s
, *r
;
1015 r
= s
= g_malloc0 (finish
- start
+ 1);
1016 if (edit
->column_highlight
)
1019 /* copy from buffer, excluding chars that are out of the column 'margins' */
1020 while (start
< finish
)
1024 x
= edit_move_forward3 (edit
, edit_bol (edit
, start
), 0, start
);
1025 c
= edit_get_byte (edit
, start
);
1026 if ((x
>= edit
->column1
&& x
< edit
->column2
)
1027 || (x
>= edit
->column2
&& x
< edit
->column1
) || c
== '\n')
1037 *l
= finish
- start
;
1038 while (start
< finish
)
1039 *s
++ = edit_get_byte (edit
, start
++);
1045 /* --------------------------------------------------------------------------------------------- */
1046 /** copies a block to clipboard file */
1049 edit_save_block_to_clip_file (WEdit
* edit
, long start
, long finish
)
1053 tmp
= mc_config_get_full_path (EDIT_CLIP_FILE
);
1054 ret
= edit_save_block (edit
, tmp
, start
, finish
);
1059 /* --------------------------------------------------------------------------------------------- */
1062 pipe_mail (WEdit
* edit
, char *to
, char *subject
, char *cc
)
1067 to
= name_quote (to
, 0);
1068 subject
= name_quote (subject
, 0);
1069 cc
= name_quote (cc
, 0);
1070 s
= g_strconcat ("mail -s ", subject
, *cc
? " -c " : "", cc
, " ", to
, (char *) NULL
);
1084 for (i
= 0; i
< edit
->last_byte
; i
++)
1085 fputc (edit_get_byte (edit
, i
), p
);
1090 /* --------------------------------------------------------------------------------------------- */
1091 /** find first character of current word */
1094 edit_find_word_start (WEdit
* edit
, long *word_start
, gsize
* word_len
)
1099 /* return if at begin of file */
1100 if (edit
->curs1
<= 0)
1103 c
= (unsigned char) edit_get_byte (edit
, edit
->curs1
- 1);
1104 /* return if not at end or in word */
1105 if (is_break_char (c
))
1108 /* search start of word to be completed */
1111 /* return if at begin of file */
1112 if ((gsize
) edit
->curs1
< i
)
1116 c
= (unsigned char) edit_get_byte (edit
, edit
->curs1
- i
);
1118 if (is_break_char (c
))
1120 /* return if word starts with digit */
1124 *word_start
= edit
->curs1
- (i
- 1); /* start found */
1133 /* --------------------------------------------------------------------------------------------- */
1135 * Get current word under cursor
1137 * @param edit editor object
1138 * @param srch mc_search object
1139 * @param word_start start word position
1141 * @return newly allocated string or NULL if no any words under cursor
1145 edit_collect_completions_get_current_word (WEdit
* edit
, mc_search_t
* srch
, long word_start
)
1150 if (!mc_search_run (srch
, (void *) edit
, word_start
, edit
->last_byte
, &len
))
1153 temp
= g_string_sized_new (len
);
1155 for (i
= 0; i
< len
; i
++)
1159 chr
= edit_get_byte (edit
, word_start
+ i
);
1161 g_string_append_c (temp
, chr
);
1164 return g_string_free (temp
, temp
->len
== 0);
1167 /* --------------------------------------------------------------------------------------------- */
1168 /** collect the possible completions */
1171 edit_collect_completions (WEdit
* edit
, long word_start
, gsize word_len
,
1172 char *match_expr
, struct selection
*compl, gsize
* num
)
1180 long last_byte
, start
= -1;
1183 srch
= mc_search_new (match_expr
, -1);
1187 if (mc_config_get_bool
1188 (mc_main_config
, CONFIG_APP_SECTION
, "editor_wordcompletion_collect_entire_file", 0))
1190 last_byte
= edit
->last_byte
;
1194 last_byte
= word_start
;
1197 srch
->search_type
= MC_SEARCH_T_REGEX
;
1198 srch
->is_case_sensitive
= TRUE
;
1199 srch
->search_fn
= edit_search_cmd_callback
;
1201 current_word
= edit_collect_completions_get_current_word (edit
, srch
, word_start
);
1203 temp
= g_string_new ("");
1205 /* collect max MAX_WORD_COMPLETIONS completions */
1206 while (mc_search_run (srch
, (void *) edit
, start
+ 1, last_byte
, &len
))
1208 g_string_set_size (temp
, 0);
1209 start
= srch
->normal_offset
;
1211 /* add matched completion if not yet added */
1212 for (i
= 0; i
< len
; i
++)
1214 skip
= edit_get_byte (edit
, start
+ i
);
1218 /* skip current word */
1219 if (start
+ (long) i
== word_start
)
1222 g_string_append_c (temp
, skip
);
1228 if (current_word
!= NULL
&& strcmp (current_word
, temp
->str
) == 0)
1233 for (i
= 0; i
< *num
; i
++)
1236 ((char *) &compl[i
].text
[word_len
],
1237 (char *) &temp
->str
[word_len
], max (len
, compl[i
].len
) - word_len
) == 0)
1239 struct selection
this = compl[i
];
1240 for (++i
; i
< *num
; i
++)
1242 compl[i
- 1] = compl[i
];
1244 compl[*num
- 1] = this;
1246 break; /* skip it, already added */
1252 if (*num
== MAX_WORD_COMPLETIONS
)
1254 g_free (compl[0].text
);
1255 for (i
= 1; i
< *num
; i
++)
1257 compl[i
- 1] = compl[i
];
1264 recoded
= str_convert_to_display (temp
->str
);
1266 if (recoded
&& recoded
->len
)
1267 g_string_assign (temp
, recoded
->str
);
1269 g_string_free (recoded
, TRUE
);
1272 compl[*num
].text
= g_strdup (temp
->str
);
1273 compl[*num
].len
= temp
->len
;
1277 /* note the maximal length needed for the completion dialog */
1282 mc_search_free (srch
);
1283 g_string_free (temp
, TRUE
);
1284 g_free (current_word
);
1289 /* --------------------------------------------------------------------------------------------- */
1292 edit_insert_column_of_text (WEdit
* edit
, unsigned char *data
, int size
, int width
,
1293 long *start_pos
, long *end_pos
, int *col1
, int *col2
)
1298 cursor
= edit
->curs1
;
1299 col
= edit_get_col (edit
);
1301 for (i
= 0; i
< size
; i
++)
1303 if (data
[i
] != '\n')
1304 edit_insert (edit
, data
[i
]);
1306 { /* fill in and move to next line */
1310 if (edit_get_byte (edit
, edit
->curs1
) != '\n')
1312 l
= width
- (edit_get_col (edit
) - col
);
1315 edit_insert (edit
, ' ');
1319 for (p
= edit
->curs1
;; p
++)
1321 if (p
== edit
->last_byte
)
1323 edit_cursor_move (edit
, edit
->last_byte
- edit
->curs1
);
1324 edit_insert_ahead (edit
, '\n');
1328 if (edit_get_byte (edit
, p
) == '\n')
1334 edit_cursor_move (edit
, edit_move_forward3 (edit
, p
, col
, 0) - edit
->curs1
);
1335 l
= col
- edit_get_col (edit
);
1336 while (l
>= space_width
)
1338 edit_insert (edit
, ' ');
1345 *col2
= col
+ width
;
1346 *start_pos
= cursor
;
1347 *end_pos
= edit
->curs1
;
1348 edit_cursor_move (edit
, cursor
- edit
->curs1
);
1351 /* --------------------------------------------------------------------------------------------- */
1354 edit_macro_comparator (gconstpointer
* macro1
, gconstpointer
* macro2
)
1356 const macros_t
*m1
= (const macros_t
*) macro1
;
1357 const macros_t
*m2
= (const macros_t
*) macro2
;
1359 return m1
->hotkey
- m2
->hotkey
;
1362 /* --------------------------------------------------------------------------------------------- */
1365 edit_macro_sort_by_hotkey (void)
1367 if (macros_list
!= NULL
&& macros_list
->len
!= 0)
1368 g_array_sort (macros_list
, (GCompareFunc
) edit_macro_comparator
);
1371 /* --------------------------------------------------------------------------------------------- */
1374 edit_get_macro (WEdit
* edit
, int hotkey
, const macros_t
** macros
, guint
* indx
)
1376 const macros_t
*array_start
= &g_array_index (macros_list
, struct macros_t
, 0);
1378 macros_t search_macro
;
1382 search_macro
.hotkey
= hotkey
;
1383 result
= bsearch (&search_macro
, macros_list
->data
, macros_list
->len
,
1384 sizeof (macros_t
), (GCompareFunc
) edit_macro_comparator
);
1386 if (result
!= NULL
&& result
->macro
!= NULL
)
1388 *indx
= (result
- array_start
);
1396 /* --------------------------------------------------------------------------------------------- */
1397 /** returns FALSE on error */
1400 edit_delete_macro (WEdit
* edit
, int hotkey
)
1402 mc_config_t
*macros_config
= NULL
;
1403 const char *section_name
= "editor";
1404 gchar
*macros_fname
;
1407 const macros_t
*macros
= NULL
;
1409 /* clear array of actions for current hotkey */
1410 while (edit_get_macro (edit
, hotkey
, ¯os
, &indx
))
1412 if (macros
->macro
!= NULL
)
1413 g_array_free (macros
->macro
, TRUE
);
1415 g_array_remove_index (macros_list
, indx
);
1416 edit_macro_sort_by_hotkey ();
1419 macros_fname
= mc_config_get_full_path (MC_MACRO_FILE
);
1420 macros_config
= mc_config_init (macros_fname
);
1421 g_free (macros_fname
);
1423 if (macros_config
== NULL
)
1426 skeyname
= lookup_key_by_code (hotkey
);
1427 while (mc_config_del_key (macros_config
, section_name
, skeyname
))
1430 mc_config_save_file (macros_config
, NULL
);
1431 mc_config_deinit (macros_config
);
1435 /* --------------------------------------------------------------------------------------------- */
1437 * Callback for the iteration of objects in the 'editors' array.
1438 * Toggle syntax highlighting in editor object.
1440 * @param data probably WEdit object
1441 * @param user_data unused
1445 edit_syntax_onoff_cb (void *data
, void *user_data
)
1449 if (edit_widget_is_editor ((const Widget
*) data
))
1451 WEdit
*edit
= (WEdit
*) data
;
1453 if (option_syntax_highlighting
)
1454 edit_load_syntax (edit
, NULL
, edit
->syntax_type
);
1455 edit
->force
|= REDRAW_PAGE
;
1459 /* --------------------------------------------------------------------------------------------- */
1461 * Callback for the iteration of objects in the 'editors' array.
1462 * Redraw editor object.
1464 * @param data probably WEdit object
1465 * @param user_data unused
1469 edit_redraw_page_cb (void *data
, void *user_data
)
1473 if (edit_widget_is_editor ((const Widget
*) data
))
1474 ((WEdit
*) data
)->force
|= REDRAW_PAGE
;
1477 /* --------------------------------------------------------------------------------------------- */
1478 /*** public functions ****************************************************************************/
1479 /* --------------------------------------------------------------------------------------------- */
1482 edit_refresh_cmd (void)
1489 /* --------------------------------------------------------------------------------------------- */
1491 * Toggle syntax highlighting in all editor windows.
1493 * @param h root widget for all windows
1497 edit_syntax_onoff_cmd (Dlg_head
* h
)
1499 option_syntax_highlighting
= !option_syntax_highlighting
;
1500 g_list_foreach (h
->widgets
, edit_syntax_onoff_cb
, NULL
);
1504 /* --------------------------------------------------------------------------------------------- */
1506 * Toggle tabs showing in all editor windows.
1508 * @param h root widget for all windows
1512 edit_show_tabs_tws_cmd (Dlg_head
* h
)
1514 enable_show_tabs_tws
= !enable_show_tabs_tws
;
1515 g_list_foreach (h
->widgets
, edit_redraw_page_cb
, NULL
);
1519 /* --------------------------------------------------------------------------------------------- */
1521 * Toggle right margin showing in all editor windows.
1523 * @param h root widget for all windows
1527 edit_show_margin_cmd (Dlg_head
* h
)
1529 show_right_margin
= !show_right_margin
;
1530 g_list_foreach (h
->widgets
, edit_redraw_page_cb
, NULL
);
1534 /* --------------------------------------------------------------------------------------------- */
1536 * Toggle line numbers showing in all editor windows.
1538 * @param h root widget for all windows
1542 edit_show_numbers_cmd (Dlg_head
* h
)
1544 option_line_state
= !option_line_state
;
1545 option_line_state_width
= option_line_state
? LINE_STATE_WIDTH
: 0;
1546 g_list_foreach (h
->widgets
, edit_redraw_page_cb
, NULL
);
1550 /* --------------------------------------------------------------------------------------------- */
1553 edit_save_mode_cmd (void)
1556 const int DLG_X
= 38;
1557 const int DLG_Y
= 13;
1561 const char *str
[] = {
1564 N_("&Do backups with following extension:")
1567 QuickWidget widgets
[] = {
1569 QUICK_BUTTON (18, DLG_X
, DLG_Y
- 3, DLG_Y
, N_("&Cancel"), B_CANCEL
, NULL
),
1571 QUICK_BUTTON (6, DLG_X
, DLG_Y
- 3, DLG_Y
, N_("&OK"), B_ENTER
, NULL
),
1573 QUICK_CHECKBOX (4, DLG_X
, 8, DLG_Y
, N_("Check &POSIX new line"), &option_check_nl_at_eof
),
1575 QUICK_INPUT (8, DLG_X
, 6, DLG_Y
, option_backup_ext
, 9, 0, "edit-backup-ext", &str_result
),
1577 QUICK_RADIO (4, DLG_X
, 3, DLG_Y
, 3, str
, &option_save_mode
),
1581 QuickDialog dialog
= {
1582 DLG_X
, DLG_Y
, -1, -1, N_("Edit Save Mode"),
1583 "[Edit Save Mode]", widgets
, NULL
, NULL
, FALSE
1588 size_t w0
, w1
, b_len
, w3
;
1590 #ifdef HAVE_ASSERT_H
1591 assert (option_backup_ext
!= NULL
);
1594 /* OK/Cancel buttons */
1595 w0
= str_term_width1 (_(widgets
[0].u
.button
.text
)) + 3;
1596 w1
= str_term_width1 (_(widgets
[1].u
.button
.text
)) + 5; /* default button */
1597 b_len
= w0
+ w1
+ 3;
1599 maxlen
= max (b_len
, (size_t) str_term_width1 (_(dialog
.title
)) + 2);
1602 for (i
= 0; i
< 3; i
++)
1607 w3
= max (w3
, (size_t) str_term_width1 (str
[i
]));
1610 maxlen
= max (maxlen
, w3
+ 4);
1612 dialog
.xlen
= min ((size_t) COLS
, maxlen
+ 8);
1614 widgets
[3].u
.input
.len
= w3
;
1615 widgets
[1].relative_x
= (dialog
.xlen
- b_len
) / 2;
1616 widgets
[0].relative_x
= widgets
[1].relative_x
+ w0
+ 2;
1618 for (i
= 0; i
< sizeof (widgets
) / sizeof (widgets
[0]); i
++)
1619 widgets
[i
].x_divisions
= dialog
.xlen
;
1621 if (quick_dialog (&dialog
) != B_CANCEL
)
1623 g_free (option_backup_ext
);
1624 option_backup_ext
= str_result
;
1628 /* --------------------------------------------------------------------------------------------- */
1631 edit_set_filename (WEdit
* edit
, const vfs_path_t
* name_vpath
)
1633 vfs_path_free (edit
->filename_vpath
);
1634 edit
->filename_vpath
= vfs_path_clone (name_vpath
);
1636 if (edit
->dir_vpath
== NULL
)
1637 edit
->dir_vpath
= vfs_path_clone (vfs_get_raw_current_dir ());
1640 /* --------------------------------------------------------------------------------------------- */
1641 /* Here we want to warn the users of overwriting an existing file,
1642 but only if they have made a change to the filename */
1643 /* returns 1 on success */
1645 edit_save_as_cmd (WEdit
* edit
)
1647 /* This heads the 'Save As' dialog box */
1648 vfs_path_t
*exp_vpath
;
1650 int different_filename
= 0;
1652 if (!edit_check_newline (edit
))
1655 exp_vpath
= edit_get_save_file_as (edit
);
1656 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
1658 if (exp_vpath
!= NULL
)
1660 if (vfs_path_len (exp_vpath
) == 0)
1666 if (vfs_path_cmp (edit
->filename_vpath
, exp_vpath
) != 0)
1671 if (mc_stat (exp_vpath
, &sb
) == 0 && !S_ISREG (sb
.st_mode
))
1673 edit_error_dialog (_("Save as"),
1675 ("Cannot save: destination is not a regular file")));
1679 different_filename
= 1;
1680 file
= mc_open (exp_vpath
, O_RDONLY
| O_BINARY
);
1684 /* the file exists */
1686 /* Overwrite the current file or cancel the operation */
1687 if (edit_query_dialog2
1689 _("A file already exists with this name"), _("&Overwrite"), _("&Cancel")))
1694 edit
->stat1
.st_mode
|= S_IWUSR
;
1696 save_lock
= lock_file (exp_vpath
);
1700 /* filenames equal, check if already locked */
1701 if (!edit
->locked
&& !edit
->delete_file
)
1702 save_lock
= lock_file (exp_vpath
);
1705 if (different_filename
)
1708 * Allow user to write into saved (under another name) file
1709 * even if original file had r/o user permissions.
1711 edit
->stat1
.st_mode
|= S_IWRITE
;
1714 rv
= edit_save_file (edit
, exp_vpath
);
1718 /* Succesful, so unlock both files */
1719 if (different_filename
)
1722 unlock_file (exp_vpath
);
1724 edit
->locked
= unlock_file (edit
->filename_vpath
);
1728 if (edit
->locked
|| save_lock
)
1729 edit
->locked
= unlock_file (edit
->filename_vpath
);
1732 edit_set_filename (edit
, exp_vpath
);
1733 if (edit
->lb
!= LB_ASIS
)
1734 edit_reload (edit
, exp_vpath
);
1736 edit
->delete_file
= 0;
1737 if (different_filename
)
1738 edit_load_syntax (edit
, NULL
, edit
->syntax_type
);
1739 vfs_path_free (exp_vpath
);
1740 edit
->force
|= REDRAW_COMPLETELY
;
1743 edit_error_dialog (_("Save as"), get_sys_error (_("Cannot save file")));
1746 /* Failed, so maintain modify (not save) lock */
1748 unlock_file (exp_vpath
);
1755 vfs_path_free (exp_vpath
);
1756 edit
->force
|= REDRAW_COMPLETELY
;
1760 /* {{{ Macro stuff starts here */
1761 /* --------------------------------------------------------------------------------------------- */
1764 edit_delete_macro_cmd (WEdit
* edit
)
1768 hotkey
= editcmd_dialog_raw_key_query (_("Delete macro"), _("Press macro hotkey:"), 1);
1770 if (hotkey
!= 0 && !edit_delete_macro (edit
, hotkey
))
1771 message (D_ERROR
, _("Delete macro"), _("Macro not deleted"));
1774 /* --------------------------------------------------------------------------------------------- */
1776 /** returns FALSE on error */
1778 edit_execute_macro (WEdit
* edit
, int hotkey
)
1780 gboolean res
= FALSE
;
1784 const macros_t
*macros
;
1787 if (edit_get_macro (edit
, hotkey
, ¯os
, &indx
) &&
1788 macros
->macro
!= NULL
&& macros
->macro
->len
!= 0)
1792 edit
->force
|= REDRAW_PAGE
;
1794 for (i
= 0; i
< macros
->macro
->len
; i
++)
1796 const macro_action_t
*m_act
;
1798 m_act
= &g_array_index (macros
->macro
, struct macro_action_t
, i
);
1799 edit_execute_cmd (edit
, m_act
->action
, m_act
->ch
);
1808 /* --------------------------------------------------------------------------------------------- */
1810 /** returns FALSE on error */
1812 edit_store_macro_cmd (WEdit
* edit
)
1816 GString
*marcros_string
;
1817 mc_config_t
*macros_config
= NULL
;
1818 const char *section_name
= "editor";
1819 gchar
*macros_fname
;
1820 GArray
*macros
; /* current macro */
1822 gboolean have_macro
= FALSE
;
1823 char *skeyname
= NULL
;
1825 hotkey
= editcmd_dialog_raw_key_query (_("Save macro"), _("Press the macro's new hotkey:"), 1);
1826 if (hotkey
== ESC_CHAR
)
1829 tmp_act
= keybind_lookup_keymap_command (editor_map
, hotkey
);
1831 /* return FALSE if try assign macro into restricted hotkeys */
1832 if (tmp_act
== CK_MacroStartRecord
1833 || tmp_act
== CK_MacroStopRecord
|| tmp_act
== CK_MacroStartStopRecord
)
1836 edit_delete_macro (edit
, hotkey
);
1838 macros_fname
= mc_config_get_full_path (MC_MACRO_FILE
);
1839 macros_config
= mc_config_init (macros_fname
);
1840 g_free (macros_fname
);
1842 if (macros_config
== NULL
)
1845 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
1847 marcros_string
= g_string_sized_new (250);
1848 macros
= g_array_new (TRUE
, FALSE
, sizeof (macro_action_t
));
1850 skeyname
= lookup_key_by_code (hotkey
);
1852 for (i
= 0; i
< macro_index
; i
++)
1854 macro_action_t m_act
;
1855 const char *action_name
;
1857 action_name
= keybind_lookup_actionname (record_macro_buf
[i
].action
);
1859 if (action_name
== NULL
)
1862 m_act
.action
= record_macro_buf
[i
].action
;
1863 m_act
.ch
= record_macro_buf
[i
].ch
;
1864 g_array_append_val (macros
, m_act
);
1866 g_string_append_printf (marcros_string
, "%s:%i;", action_name
,
1867 (int) record_macro_buf
[i
].ch
);
1872 macro
.hotkey
= hotkey
;
1873 macro
.macro
= macros
;
1874 g_array_append_val (macros_list
, macro
);
1875 mc_config_set_string (macros_config
, section_name
, skeyname
, marcros_string
->str
);
1878 mc_config_del_key (macros_config
, section_name
, skeyname
);
1881 edit_macro_sort_by_hotkey ();
1883 g_string_free (marcros_string
, TRUE
);
1884 mc_config_save_file (macros_config
, NULL
);
1885 mc_config_deinit (macros_config
);
1889 /* --------------------------------------------------------------------------------------------- */
1892 edit_repeat_macro_cmd (WEdit
* edit
)
1899 f
= input_dialog (_("Repeat last commands"), _("Repeat times:"), MC_HISTORY_EDIT_REPEAT
, NULL
);
1900 if (f
== NULL
|| *f
== '\0')
1906 count_repeat
= strtol (f
, &error
, 0);
1916 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
1917 edit
->force
|= REDRAW_PAGE
;
1919 for (j
= 0; j
< count_repeat
; j
++)
1920 for (i
= 0; i
< macro_index
; i
++)
1921 edit_execute_cmd (edit
, record_macro_buf
[i
].action
, record_macro_buf
[i
].ch
);
1922 edit_update_screen (edit
);
1926 /* --------------------------------------------------------------------------------------------- */
1927 /** return FALSE on error */
1930 edit_load_macro_cmd (WEdit
* edit
)
1932 mc_config_t
*macros_config
= NULL
;
1933 gchar
**profile_keys
, **keys
;
1934 gchar
**values
, **curr_values
;
1935 gsize len
, values_len
;
1936 const char *section_name
= "editor";
1937 gchar
*macros_fname
;
1942 macros_fname
= mc_config_get_full_path (MC_MACRO_FILE
);
1943 macros_config
= mc_config_init (macros_fname
);
1944 g_free (macros_fname
);
1946 if (macros_config
== NULL
)
1949 profile_keys
= keys
= mc_config_get_keys (macros_config
, section_name
, &len
);
1950 while (*profile_keys
!= NULL
)
1952 gboolean have_macro
;
1956 macros
= g_array_new (TRUE
, FALSE
, sizeof (macro_action_t
));
1958 curr_values
= values
= mc_config_get_string_list (macros_config
, section_name
,
1959 *profile_keys
, &values_len
);
1960 hotkey
= lookup_key (*profile_keys
, NULL
);
1963 while (*curr_values
!= NULL
&& *curr_values
[0] != '\0')
1965 char **macro_pair
= NULL
;
1967 macro_pair
= g_strsplit (*curr_values
, ":", 2);
1969 if (macro_pair
!= NULL
)
1971 macro_action_t m_act
;
1972 if (macro_pair
[0] == NULL
|| macro_pair
[0][0] == '\0')
1976 m_act
.action
= keybind_lookup_action (macro_pair
[0]);
1977 g_free (macro_pair
[0]);
1978 macro_pair
[0] = NULL
;
1980 if (macro_pair
[1] == NULL
|| macro_pair
[1][0] == '\0')
1984 m_act
.ch
= strtol (macro_pair
[1], NULL
, 0);
1985 g_free (macro_pair
[1]);
1986 macro_pair
[1] = NULL
;
1988 if (m_act
.action
!= 0)
1990 /* a shell command */
1991 if ((m_act
.action
/ CK_PipeBlock (0)) == 1)
1993 m_act
.action
= CK_PipeBlock (0) + (m_act
.ch
> 0 ? m_act
.ch
: 0);
1996 g_array_append_val (macros
, m_act
);
1999 g_strfreev (macro_pair
);
2006 macro
.hotkey
= hotkey
;
2007 macro
.macro
= macros
;
2008 g_array_append_val (macros_list
, macro
);
2011 g_strfreev (values
);
2014 mc_config_deinit (macros_config
);
2015 edit_macro_sort_by_hotkey ();
2019 /* }}} Macro stuff end here */
2021 /* --------------------------------------------------------------------------------------------- */
2022 /** returns 1 on success */
2025 edit_save_confirm_cmd (WEdit
* edit
)
2029 if (edit
->filename_vpath
== NULL
)
2030 return edit_save_as_cmd (edit
);
2032 if (!edit_check_newline (edit
))
2035 if (edit_confirm_save
)
2040 filename
= vfs_path_to_str (edit
->filename_vpath
);
2041 f
= g_strdup_printf (_("Confirm save file: \"%s\""), filename
);
2043 ok
= (edit_query_dialog2 (_("Save file"), f
, _("&Save"), _("&Cancel")) == 0);
2048 return edit_save_cmd (edit
);
2051 /* --------------------------------------------------------------------------------------------- */
2053 * Ask file to edit and load it.
2055 * @returns TRUE on success or cancel of ask.
2059 edit_load_cmd (Dlg_head
* h
)
2062 gboolean ret
= TRUE
; /* possible cancel */
2064 exp
= input_expand_dialog (_("Load"), _("Enter file name:"),
2065 MC_HISTORY_EDIT_LOAD
, INPUT_LAST_TEXT
);
2067 if (exp
!= NULL
&& *exp
!= '\0')
2069 vfs_path_t
*exp_vpath
;
2071 exp_vpath
= vfs_path_from_str (exp
);
2072 ret
= edit_load_file_from_filename (h
, exp_vpath
);
2073 vfs_path_free (exp_vpath
);
2081 /* --------------------------------------------------------------------------------------------- */
2083 * Load syntax file to edit.
2085 * @returns TRUE on success
2089 edit_load_syntax_file (Dlg_head
* h
)
2091 vfs_path_t
*extdir_vpath
;
2093 gboolean ret
= FALSE
;
2095 if (geteuid () == 0)
2096 dir
= query_dialog (_("Syntax file edit"),
2097 _("Which syntax file you want to edit?"), D_NORMAL
, 2,
2098 _("&User"), _("&System wide"));
2101 vfs_path_build_filename (mc_global
.sysconfig_dir
, "syntax", "Syntax", (char *) NULL
);
2102 if (!exist_file (vfs_path_get_last_path_str (extdir_vpath
)))
2104 vfs_path_free (extdir_vpath
);
2106 vfs_path_build_filename (mc_global
.share_data_dir
, "syntax", "Syntax", (char *) NULL
);
2111 vfs_path_t
*user_syntax_file_vpath
;
2113 user_syntax_file_vpath
= mc_config_get_full_vpath (EDIT_SYNTAX_FILE
);
2114 check_for_default (extdir_vpath
, user_syntax_file_vpath
);
2115 ret
= edit_load_file_from_filename (h
, user_syntax_file_vpath
);
2116 vfs_path_free (user_syntax_file_vpath
);
2119 ret
= edit_load_file_from_filename (h
, extdir_vpath
);
2121 vfs_path_free (extdir_vpath
);
2126 /* --------------------------------------------------------------------------------------------- */
2128 * Load menu file to edit.
2130 * @returns TRUE on success
2134 edit_load_menu_file (Dlg_head
* h
)
2136 vfs_path_t
*buffer_vpath
;
2137 vfs_path_t
*menufile_vpath
;
2141 dir
= query_dialog (_("Menu edit"),
2142 _("Which menu file do you want to edit?"), D_NORMAL
,
2143 geteuid () != 0 ? 2 : 3, _("&Local"), _("&User"), _("&System wide"));
2145 menufile_vpath
= vfs_path_build_filename (mc_global
.sysconfig_dir
, EDIT_GLOBAL_MENU
, NULL
);
2146 if (!exist_file (vfs_path_get_last_path_str (menufile_vpath
)))
2148 vfs_path_free (menufile_vpath
);
2149 menufile_vpath
= vfs_path_build_filename (mc_global
.share_data_dir
, EDIT_GLOBAL_MENU
, NULL
);
2155 buffer_vpath
= vfs_path_from_str (EDIT_LOCAL_MENU
);
2156 check_for_default (menufile_vpath
, buffer_vpath
);
2157 chmod (vfs_path_get_last_path_str (buffer_vpath
), 0600);
2161 buffer_vpath
= mc_config_get_full_vpath (EDIT_HOME_MENU
);
2162 check_for_default (menufile_vpath
, buffer_vpath
);
2166 buffer_vpath
= vfs_path_build_filename (mc_global
.sysconfig_dir
, EDIT_GLOBAL_MENU
, NULL
);
2167 if (!exist_file (vfs_path_get_last_path_str (buffer_vpath
)))
2169 vfs_path_free (buffer_vpath
);
2171 vfs_path_build_filename (mc_global
.share_data_dir
, EDIT_GLOBAL_MENU
, NULL
);
2176 vfs_path_free (menufile_vpath
);
2180 ret
= edit_load_file_from_filename (h
, buffer_vpath
);
2182 vfs_path_free (buffer_vpath
);
2183 vfs_path_free (menufile_vpath
);
2188 /* --------------------------------------------------------------------------------------------- */
2190 * Close window with opened file.
2192 * @returns TRUE if file was closed.
2196 edit_close_cmd (WEdit
* edit
)
2200 ret
= (edit
!= NULL
) && edit_ok_to_exit (edit
);
2204 Dlg_head
*h
= ((Widget
*) edit
)->owner
;
2206 if (edit
->locked
!= 0)
2207 unlock_file (edit
->filename_vpath
);
2211 if (edit_widget_is_editor ((Widget
*) h
->current
->data
))
2212 edit
= (WEdit
*) h
->current
->data
;
2215 edit
= find_editor (h
);
2217 dlg_set_top_widget (edit
);
2222 edit
->force
|= REDRAW_COMPLETELY
;
2227 /* --------------------------------------------------------------------------------------------- */
2229 if mark2 is -1 then marking is from mark1 to the cursor.
2230 Otherwise its between the markers. This handles this.
2231 Returns 1 if no text is marked.
2235 eval_marks (WEdit
* edit
, long *start_mark
, long *end_mark
)
2237 if (edit
->mark1
!= edit
->mark2
)
2239 long start_bol
, start_eol
;
2240 long end_bol
, end_eol
;
2245 if (edit
->end_mark_curs
< 0)
2246 end_mark_curs
= edit
->curs1
;
2248 end_mark_curs
= edit
->end_mark_curs
;
2250 if (edit
->mark2
>= 0)
2252 *start_mark
= min (edit
->mark1
, edit
->mark2
);
2253 *end_mark
= max (edit
->mark1
, edit
->mark2
);
2257 *start_mark
= min (edit
->mark1
, end_mark_curs
);
2258 *end_mark
= max (edit
->mark1
, end_mark_curs
);
2259 edit
->column2
= edit
->curs_col
+ edit
->over_col
;
2262 if (edit
->column_highlight
2263 && (((edit
->mark1
> end_mark_curs
) && (edit
->column1
< edit
->column2
))
2264 || ((edit
->mark1
< end_mark_curs
) && (edit
->column1
> edit
->column2
))))
2266 start_bol
= edit_bol (edit
, *start_mark
);
2267 start_eol
= edit_eol (edit
, start_bol
- 1) + 1;
2268 end_bol
= edit_bol (edit
, *end_mark
);
2269 end_eol
= edit_eol (edit
, *end_mark
);
2270 col1
= min (edit
->column1
, edit
->column2
);
2271 col2
= max (edit
->column1
, edit
->column2
);
2274 edit_move_forward3 (edit
, start_bol
, col2
, 0) - edit_move_forward3 (edit
, start_bol
,
2277 edit_move_forward3 (edit
, end_bol
, col2
, 0) - edit_move_forward3 (edit
, end_bol
,
2280 *start_mark
-= diff1
;
2282 *start_mark
= max (*start_mark
, start_eol
);
2283 *end_mark
= min (*end_mark
, end_eol
);
2289 *start_mark
= *end_mark
= 0;
2290 edit
->column2
= edit
->column1
= 0;
2295 /* --------------------------------------------------------------------------------------------- */
2298 edit_insert_over (WEdit
* edit
)
2302 for (i
= 0; i
< edit
->over_col
; i
++)
2304 edit_insert (edit
, ' ');
2309 /* --------------------------------------------------------------------------------------------- */
2312 edit_insert_column_of_text_from_file (WEdit
* edit
, int file
,
2313 long *start_pos
, long *end_pos
, int *col1
, int *col2
)
2317 int blocklen
= -1, width
= 0;
2318 unsigned char *data
;
2320 cursor
= edit
->curs1
;
2321 col
= edit_get_col (edit
);
2322 data
= g_malloc0 (TEMP_BUF_LEN
);
2324 while ((blocklen
= mc_read (file
, (char *) data
, TEMP_BUF_LEN
)) > 0)
2327 for (width
= 0; width
< blocklen
; width
++)
2329 if (data
[width
] == '\n')
2332 for (i
= 0; i
< blocklen
; i
++)
2334 if (data
[i
] == '\n')
2335 { /* fill in and move to next line */
2338 if (edit_get_byte (edit
, edit
->curs1
) != '\n')
2340 l
= width
- (edit_get_col (edit
) - col
);
2343 edit_insert (edit
, ' ');
2347 for (p
= edit
->curs1
;; p
++)
2349 if (p
== edit
->last_byte
)
2351 edit_cursor_move (edit
, edit
->last_byte
- edit
->curs1
);
2352 edit_insert_ahead (edit
, '\n');
2356 if (edit_get_byte (edit
, p
) == '\n')
2362 edit_cursor_move (edit
, edit_move_forward3 (edit
, p
, col
, 0) - edit
->curs1
);
2363 l
= col
- edit_get_col (edit
);
2364 while (l
>= space_width
)
2366 edit_insert (edit
, ' ');
2371 edit_insert (edit
, data
[i
]);
2375 *col2
= col
+ width
;
2376 *start_pos
= cursor
;
2377 *end_pos
= edit
->curs1
;
2378 edit_cursor_move (edit
, cursor
- edit
->curs1
);
2384 /* --------------------------------------------------------------------------------------------- */
2387 edit_block_copy_cmd (WEdit
* edit
)
2389 long start_mark
, end_mark
, current
= edit
->curs1
;
2394 unsigned char *copy_buf
;
2396 edit_update_curs_col (edit
);
2397 if (eval_marks (edit
, &start_mark
, &end_mark
))
2400 copy_buf
= edit_get_block (edit
, start_mark
, end_mark
, &size
);
2402 /* all that gets pushed are deletes hence little space is used on the stack */
2404 edit_push_markers (edit
);
2406 if (edit
->column_highlight
)
2408 col_delta
= abs (edit
->column2
- edit
->column1
);
2409 edit_insert_column_of_text (edit
, copy_buf
, size
, col_delta
, &mark1
, &mark2
, &c1
, &c2
);
2414 edit_insert_ahead (edit
, copy_buf
[size
]);
2418 edit_scroll_screen_over_cursor (edit
);
2420 if (edit
->column_highlight
)
2421 edit_set_markers (edit
, edit
->curs1
, mark2
, c1
, c2
);
2422 else if (start_mark
< current
&& end_mark
> current
)
2423 edit_set_markers (edit
, start_mark
, end_mark
+ end_mark
- start_mark
, 0, 0);
2425 edit
->force
|= REDRAW_PAGE
;
2429 /* --------------------------------------------------------------------------------------------- */
2432 edit_block_move_cmd (WEdit
* edit
)
2435 unsigned char *copy_buf
= NULL
;
2436 long start_mark
, end_mark
;
2439 if (eval_marks (edit
, &start_mark
, &end_mark
))
2442 line
= edit
->curs_line
;
2443 if (edit
->mark2
< 0)
2444 edit_mark_cmd (edit
, 0);
2445 edit_push_markers (edit
);
2447 if (edit
->column_highlight
)
2455 c1
= min (edit
->column1
, edit
->column2
);
2456 c2
= max (edit
->column1
, edit
->column2
);
2457 b_width
= (c2
- c1
);
2459 edit_update_curs_col (edit
);
2462 x2
= x
+ edit
->over_col
;
2464 /* do nothing when cursor inside first line of selected area */
2465 if ((edit_eol (edit
, edit
->curs1
) == edit_eol (edit
, start_mark
)) && (x2
> c1
&& x2
<= c2
))
2468 if (edit
->curs1
> start_mark
&& edit
->curs1
< edit_eol (edit
, end_mark
))
2472 else if (x
> c1
&& x
<= c2
)
2475 /* save current selection into buffer */
2476 copy_buf
= edit_get_block (edit
, start_mark
, end_mark
, &size
);
2478 /* remove current selection */
2479 edit_block_delete_cmd (edit
);
2481 edit
->over_col
= max (0, edit
->over_col
- b_width
);
2482 /* calculate the cursor pos after delete block */
2483 current
= edit_move_forward3 (edit
, edit_bol (edit
, edit
->curs1
), x
, 0);
2484 edit_cursor_move (edit
, current
- edit
->curs1
);
2485 edit_scroll_screen_over_cursor (edit
);
2487 /* add TWS if need before block insertion */
2488 if (option_cursor_beyond_eol
&& edit
->over_col
> 0)
2489 edit_insert_over (edit
);
2491 edit_insert_column_of_text (edit
, copy_buf
, size
, b_width
, &mark1
, &mark2
, &c1
, &c2
);
2492 edit_set_markers (edit
, mark1
, mark2
, c1
, c2
);
2498 current
= edit
->curs1
;
2499 copy_buf
= g_malloc0 (end_mark
- start_mark
);
2500 edit_cursor_move (edit
, start_mark
- edit
->curs1
);
2501 edit_scroll_screen_over_cursor (edit
);
2503 while (count
< end_mark
)
2505 copy_buf
[end_mark
- count
- 1] = edit_delete (edit
, 1);
2508 edit_scroll_screen_over_cursor (edit
);
2509 edit_cursor_move (edit
,
2510 current
- edit
->curs1
-
2511 (((current
- edit
->curs1
) > 0) ? end_mark
- start_mark
: 0));
2512 edit_scroll_screen_over_cursor (edit
);
2513 while (count
-- > start_mark
)
2514 edit_insert_ahead (edit
, copy_buf
[end_mark
- count
- 1]);
2515 edit_set_markers (edit
, edit
->curs1
, edit
->curs1
+ end_mark
- start_mark
, 0, 0);
2518 edit_scroll_screen_over_cursor (edit
);
2520 edit
->force
|= REDRAW_PAGE
;
2523 /* --------------------------------------------------------------------------------------------- */
2524 /** returns 1 if canceelled by user */
2527 edit_block_delete_cmd (WEdit
* edit
)
2529 long start_mark
, end_mark
;
2530 if (eval_marks (edit
, &start_mark
, &end_mark
))
2532 edit_delete_line (edit
);
2535 return edit_block_delete (edit
);
2538 /* --------------------------------------------------------------------------------------------- */
2539 /** call with edit = 0 before shutdown to close memory leaks */
2542 edit_replace_cmd (WEdit
* edit
, int again
)
2544 /* 1 = search string, 2 = replace with */
2545 static char *saved1
= NULL
; /* saved default[123] */
2546 static char *saved2
= NULL
;
2547 char *input1
= NULL
; /* user input from the dialog */
2548 char *input2
= NULL
;
2549 GString
*input2_str
= NULL
;
2552 long times_replaced
= 0;
2553 gboolean once_found
= FALSE
;
2557 g_free (saved1
), saved1
= NULL
;
2558 g_free (saved2
), saved2
= NULL
;
2562 edit
->force
|= REDRAW_COMPLETELY
;
2564 if (again
&& !saved1
&& !saved2
)
2569 input1
= g_strdup (saved1
? saved1
: "");
2570 input2
= g_strdup (saved2
? saved2
: "");
2574 char *tmp_inp1
, *tmp_inp2
;
2576 disp1
= edit_replace_cmd__conv_to_display (saved1
? saved1
: (char *) "");
2577 disp2
= edit_replace_cmd__conv_to_display (saved2
? saved2
: (char *) "");
2579 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
2581 editcmd_dialog_replace_show (edit
, disp1
, disp2
, &input1
, &input2
);
2586 if (input1
== NULL
|| *input1
== '\0')
2588 edit
->force
= REDRAW_COMPLETELY
;
2594 input1
= edit_replace_cmd__conv_to_input (input1
);
2595 input2
= edit_replace_cmd__conv_to_input (input2
);
2599 g_free (saved1
), saved1
= g_strdup (input1
);
2600 g_free (saved2
), saved2
= g_strdup (input2
);
2602 mc_search_free (edit
->search
);
2603 edit
->search
= NULL
;
2606 input2_str
= g_string_new (input2
);
2610 edit
->search
= mc_search_new (input1
, -1);
2611 if (edit
->search
== NULL
)
2613 edit
->search_start
= edit
->curs1
;
2616 edit
->search
->search_type
= edit_search_options
.type
;
2617 edit
->search
->is_all_charsets
= edit_search_options
.all_codepages
;
2618 edit
->search
->is_case_sensitive
= edit_search_options
.case_sens
;
2619 edit
->search
->whole_words
= edit_search_options
.whole_words
;
2620 edit
->search
->search_fn
= edit_search_cmd_callback
;
2621 edit
->search_line_type
= edit_get_search_line_type (edit
->search
);
2622 edit_search_fix_search_start_if_selection (edit
);
2625 if (edit
->found_len
&& edit
->search_start
== edit
->found_start
+ 1
2626 && edit_search_options
.backwards
)
2627 edit
->search_start
--;
2629 if (edit
->found_len
&& edit
->search_start
== edit
->found_start
- 1
2630 && !edit_search_options
.backwards
)
2631 edit
->search_start
++;
2637 if (!editcmd_find (edit
, &len
))
2639 if (!(edit
->search
->error
== MC_SEARCH_E_OK
||
2640 (once_found
&& edit
->search
->error
== MC_SEARCH_E_NOTFOUND
)))
2642 edit_error_dialog (_("Search"), edit
->search
->error_str
);
2648 edit
->search_start
= edit
->search
->normal_offset
;
2649 /*returns negative on not found or error in pattern */
2651 if ((edit
->search_start
>= 0) && (edit
->search_start
< edit
->last_byte
))
2656 edit
->found_start
= edit
->search_start
;
2657 i
= edit
->found_len
= len
;
2659 edit_cursor_move (edit
, edit
->search_start
- edit
->curs1
);
2660 edit_scroll_screen_over_cursor (edit
);
2662 if (edit
->replace_mode
== 0)
2667 l
= edit
->curs_row
- edit
->widget
.lines
/ 3;
2669 edit_scroll_downward (edit
, l
);
2671 edit_scroll_upward (edit
, -l
);
2673 edit_scroll_screen_over_cursor (edit
);
2674 edit
->force
|= REDRAW_PAGE
;
2675 edit_render_keypress (edit
);
2677 /*so that undo stops at each query */
2678 edit_push_key_press (edit
);
2679 /* and prompt 2/3 down */
2680 disp1
= edit_replace_cmd__conv_to_display (saved1
);
2681 disp2
= edit_replace_cmd__conv_to_display (saved2
);
2682 prompt
= editcmd_dialog_replace_prompt_show (edit
, disp1
, disp2
, -1, -1);
2686 if (prompt
== B_REPLACE_ALL
)
2687 edit
->replace_mode
= 1;
2688 else if (prompt
== B_SKIP_REPLACE
)
2690 if (edit_search_options
.backwards
)
2691 edit
->search_start
--;
2693 edit
->search_start
++;
2694 continue; /* loop */
2696 else if (prompt
== B_CANCEL
)
2698 edit
->replace_mode
= -1;
2703 repl_str
= mc_search_prepare_replace_str (edit
->search
, input2_str
);
2705 if (edit
->search
->error
!= MC_SEARCH_E_OK
)
2707 edit_error_dialog (_("Replace"), edit
->search
->error_str
);
2708 g_string_free (repl_str
, TRUE
);
2712 /* delete then insert new */
2713 for (i
= 0; i
< len
; i
++)
2714 edit_delete (edit
, 1);
2716 for (i
= 0; i
< repl_str
->len
; i
++)
2717 edit_insert (edit
, repl_str
->str
[i
]);
2719 edit
->found_len
= repl_str
->len
;
2720 g_string_free (repl_str
, TRUE
);
2723 /* so that we don't find the same string again */
2724 if (edit_search_options
.backwards
)
2726 edit
->search_start
--;
2730 edit
->search_start
+= edit
->found_len
+ (len
== 0 ? 1 : 0);
2732 if (edit
->search_start
>= edit
->last_byte
)
2736 edit_scroll_screen_over_cursor (edit
);
2740 /* try and find from right here for next search */
2741 edit
->search_start
= edit
->curs1
;
2742 edit_update_curs_col (edit
);
2744 edit
->force
|= REDRAW_PAGE
;
2745 edit_render_keypress (edit
);
2747 if (times_replaced
== 0)
2748 query_dialog (_("Replace"), _("Search string not found"), D_NORMAL
, 1, _("&OK"));
2752 while (edit
->replace_mode
>= 0);
2754 edit_scroll_screen_over_cursor (edit
);
2755 edit
->force
|= REDRAW_COMPLETELY
;
2756 edit_render_keypress (edit
);
2758 if ((edit
->replace_mode
== 1) && (times_replaced
!= 0))
2759 message (D_NORMAL
, _("Replace"), _("%ld replacements made"), times_replaced
);
2764 if (input2_str
!= NULL
)
2765 g_string_free (input2_str
, TRUE
);
2768 /* --------------------------------------------------------------------------------------------- */
2771 edit_search_cmd_callback (const void *user_data
, gsize char_offset
, int *current_char
)
2773 *current_char
= edit_get_byte ((WEdit
*) user_data
, (long) char_offset
);
2774 return MC_SEARCH_CB_OK
;
2777 /* --------------------------------------------------------------------------------------------- */
2780 edit_search_cmd (WEdit
* edit
, gboolean again
)
2788 else if (edit
->last_search_string
!= NULL
)
2789 edit_do_search (edit
);
2792 /* find last search string in history */
2795 history
= history_get (MC_HISTORY_SHARED_SEARCH
);
2796 if (history
!= NULL
&& history
->data
!= NULL
)
2798 edit
->last_search_string
= (char *) history
->data
;
2799 history
->data
= NULL
;
2800 history
= g_list_first (history
);
2801 g_list_foreach (history
, (GFunc
) g_free
, NULL
);
2802 g_list_free (history
);
2804 edit
->search
= mc_search_new (edit
->last_search_string
, -1);
2805 if (edit
->search
== NULL
)
2807 /* if not... then ask for an expression */
2808 g_free (edit
->last_search_string
);
2809 edit
->last_search_string
= NULL
;
2814 edit
->search
->search_type
= edit_search_options
.type
;
2815 edit
->search
->is_all_charsets
= edit_search_options
.all_codepages
;
2816 edit
->search
->is_case_sensitive
= edit_search_options
.case_sens
;
2817 edit
->search
->whole_words
= edit_search_options
.whole_words
;
2818 edit
->search
->search_fn
= edit_search_cmd_callback
;
2819 edit
->search_line_type
= edit_get_search_line_type (edit
->search
);
2820 edit_do_search (edit
);
2825 /* if not... then ask for an expression */
2826 g_free (edit
->last_search_string
);
2827 edit
->last_search_string
= NULL
;
2834 /* --------------------------------------------------------------------------------------------- */
2836 * Check if it's OK to close the file. If there are unsaved changes, ask user.
2838 * @returns TRUE if it's OK to exit, FALSE to continue editing.
2842 edit_ok_to_exit (WEdit
* edit
)
2844 char *fname
= (char *) N_("[NoName]");
2848 if (!edit
->modified
)
2851 if (edit
->filename_vpath
!= NULL
)
2852 fname
= vfs_path_to_str (edit
->filename_vpath
);
2855 fname
= g_strdup (_(fname
));
2858 fname
= g_strdup (fname
);
2861 if (!mc_global
.midnight_shutdown
)
2863 if (!edit_check_newline (edit
))
2871 msg
= g_strdup_printf (_("File %s was modified.\nSave before close?"), fname
);
2872 act
= edit_query_dialog3 (_("Close file"), msg
, _("&Yes"), _("&No"), _("&Cancel"));
2876 msg
= g_strdup_printf (_("Midnight Commander is being shut down.\nSave modified file %s?"),
2878 act
= edit_query_dialog2 (_("Quit"), msg
, _("&Yes"), _("&No"));
2891 edit_push_markers (edit
);
2892 edit_set_markers (edit
, 0, 0, 0, 0);
2893 if (!edit_save_cmd (edit
) || mc_global
.midnight_shutdown
)
2894 return mc_global
.midnight_shutdown
;
2898 case 2: /* Cancel quit */
2906 /* --------------------------------------------------------------------------------------------- */
2907 /** save block, returns 1 on success */
2910 edit_save_block (WEdit
* edit
, const char *filename
, long start
, long finish
)
2915 vpath
= vfs_path_from_str (filename
);
2916 file
= mc_open (vpath
, O_CREAT
| O_WRONLY
| O_TRUNC
,
2917 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
| O_BINARY
);
2918 vfs_path_free (vpath
);
2922 if (edit
->column_highlight
)
2926 r
= mc_write (file
, VERTICAL_MAGIC
, sizeof (VERTICAL_MAGIC
));
2929 unsigned char *block
, *p
;
2931 p
= block
= edit_get_block (edit
, start
, finish
, &len
);
2934 r
= mc_write (file
, p
, len
);
2948 len
= finish
- start
;
2949 buf
= g_malloc0 (TEMP_BUF_LEN
);
2950 while (start
!= finish
)
2952 end
= min (finish
, start
+ TEMP_BUF_LEN
);
2953 for (; i
< end
; i
++)
2954 buf
[i
- start
] = edit_get_byte (edit
, i
);
2955 len
-= mc_write (file
, (char *) buf
, end
- start
);
2966 /* --------------------------------------------------------------------------------------------- */
2969 edit_paste_from_history (WEdit
* edit
)
2972 edit_error_dialog (_("Error"), _("This function is not implemented"));
2975 /* --------------------------------------------------------------------------------------------- */
2978 edit_copy_to_X_buf_cmd (WEdit
* edit
)
2980 long start_mark
, end_mark
;
2981 if (eval_marks (edit
, &start_mark
, &end_mark
))
2983 if (!edit_save_block_to_clip_file (edit
, start_mark
, end_mark
))
2985 edit_error_dialog (_("Copy to clipboard"), get_sys_error (_("Unable to save to file")));
2988 /* try use external clipboard utility */
2989 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_file_to_ext_clip", NULL
);
2994 /* --------------------------------------------------------------------------------------------- */
2997 edit_cut_to_X_buf_cmd (WEdit
* edit
)
2999 long start_mark
, end_mark
;
3000 if (eval_marks (edit
, &start_mark
, &end_mark
))
3002 if (!edit_save_block_to_clip_file (edit
, start_mark
, end_mark
))
3004 edit_error_dialog (_("Cut to clipboard"), _("Unable to save to file"));
3007 /* try use external clipboard utility */
3008 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_file_to_ext_clip", NULL
);
3010 edit_block_delete_cmd (edit
);
3011 edit_mark_cmd (edit
, 1);
3015 /* --------------------------------------------------------------------------------------------- */
3018 edit_paste_from_X_buf_cmd (WEdit
* edit
)
3022 /* try use external clipboard utility */
3023 mc_event_raise (MCEVENT_GROUP_CORE
, "clipboard_file_from_ext_clip", NULL
);
3024 tmp
= mc_config_get_full_vpath (EDIT_CLIP_FILE
);
3025 edit_insert_file (edit
, tmp
);
3026 vfs_path_free (tmp
);
3030 /* --------------------------------------------------------------------------------------------- */
3032 * Ask user for the line and go to that line.
3033 * Negative numbers mean line from the end (i.e. -1 is the last line).
3037 edit_goto_cmd (WEdit
* edit
)
3040 static long line
= 0; /* line as typed, saved as default */
3045 g_snprintf (s
, sizeof (s
), "%ld", line
);
3046 f
= input_dialog (_("Goto line"), _("Enter line:"), MC_HISTORY_EDIT_GOTO_LINE
, line
? s
: "");
3056 l
= strtol (f
, &error
, 0);
3065 l
= edit
->total_lines
+ l
+ 2;
3066 edit_move_display (edit
, l
- edit
->widget
.lines
/ 2 - 1);
3067 edit_move_to_line (edit
, l
- 1);
3068 edit
->force
|= REDRAW_COMPLETELY
;
3073 /* --------------------------------------------------------------------------------------------- */
3074 /** Return 1 on success */
3077 edit_save_block_cmd (WEdit
* edit
)
3079 long start_mark
, end_mark
;
3082 if (eval_marks (edit
, &start_mark
, &end_mark
))
3085 tmp
= mc_config_get_full_path (EDIT_CLIP_FILE
);
3087 input_expand_dialog (_("Save block"), _("Enter file name:"),
3088 MC_HISTORY_EDIT_SAVE_BLOCK
, tmp
);
3090 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
3100 if (edit_save_block (edit
, exp
, start_mark
, end_mark
))
3103 edit
->force
|= REDRAW_COMPLETELY
;
3109 edit_error_dialog (_("Save block"), get_sys_error (_("Cannot save file")));
3113 edit
->force
|= REDRAW_COMPLETELY
;
3118 /* --------------------------------------------------------------------------------------------- */
3120 /** returns TRUE on success */
3122 edit_insert_file_cmd (WEdit
* edit
)
3126 gboolean ret
= FALSE
;
3128 tmp
= mc_config_get_full_path (EDIT_CLIP_FILE
);
3129 exp
= input_expand_dialog (_("Insert file"), _("Enter file name:"),
3130 MC_HISTORY_EDIT_INSERT_FILE
, tmp
);
3133 edit_push_undo_action (edit
, KEY_PRESS
+ edit
->start_display
);
3135 if (exp
!= NULL
&& *exp
!= '\0')
3137 vfs_path_t
*exp_vpath
;
3139 exp_vpath
= vfs_path_from_str (exp
);
3140 ret
= (edit_insert_file (edit
, exp_vpath
) >= 0);
3141 vfs_path_free (exp_vpath
);
3144 edit_error_dialog (_("Insert file"), get_sys_error (_("Cannot insert file")));
3149 edit
->force
|= REDRAW_COMPLETELY
;
3153 /* --------------------------------------------------------------------------------------------- */
3154 /** sorts a block, returns -1 on system fail, 1 on cancel and 0 on success */
3157 edit_sort_cmd (WEdit
* edit
)
3159 static char *old
= 0;
3160 char *exp
, *tmp
, *tmp_edit_block_name
, *tmp_edit_temp_name
;
3161 long start_mark
, end_mark
;
3164 if (eval_marks (edit
, &start_mark
, &end_mark
))
3166 edit_error_dialog (_("Sort block"), _("You must first highlight a block of text"));
3170 tmp
= mc_config_get_full_path (EDIT_BLOCK_FILE
);
3171 edit_save_block (edit
, tmp
, start_mark
, end_mark
);
3174 exp
= input_dialog (_("Run sort"),
3175 _("Enter sort options (see manpage) separated by whitespace:"),
3176 MC_HISTORY_EDIT_SORT
, (old
!= NULL
) ? old
: "");
3182 tmp_edit_block_name
= mc_config_get_full_path (EDIT_BLOCK_FILE
);
3183 tmp_edit_temp_name
= mc_config_get_full_path (EDIT_TEMP_FILE
);
3185 g_strconcat (" sort ", exp
, " ", tmp_edit_block_name
,
3186 " > ", tmp_edit_temp_name
, (char *) NULL
);
3187 g_free (tmp_edit_temp_name
);
3188 g_free (tmp_edit_block_name
);
3194 if (e
== -1 || e
== 127)
3196 edit_error_dialog (_("Sort"), get_sys_error (_("Cannot execute sort command")));
3201 sprintf (q
, "%d ", e
);
3202 tmp
= g_strdup_printf (_("Sort returned non-zero: %s"), q
);
3203 edit_error_dialog (_("Sort"), tmp
);
3209 edit
->force
|= REDRAW_COMPLETELY
;
3211 if (edit_block_delete_cmd (edit
))
3215 vfs_path_t
*tmp_vpath
;
3217 tmp_vpath
= mc_config_get_full_vpath (EDIT_TEMP_FILE
);
3218 edit_insert_file (edit
, tmp_vpath
);
3219 vfs_path_free (tmp_vpath
);
3224 /* --------------------------------------------------------------------------------------------- */
3226 * Ask user for a command, execute it and paste its output back to the
3231 edit_ext_cmd (WEdit
* edit
)
3233 char *exp
, *tmp
, *tmp_edit_temp_file
;
3237 input_dialog (_("Paste output of external command"),
3238 _("Enter shell command(s):"), MC_HISTORY_EDIT_PASTE_EXTCMD
, NULL
);
3243 tmp_edit_temp_file
= mc_config_get_full_path (EDIT_TEMP_FILE
);
3244 tmp
= g_strconcat (exp
, " > ", tmp_edit_temp_file
, (char *) NULL
);
3245 g_free (tmp_edit_temp_file
);
3252 edit_error_dialog (_("External command"), get_sys_error (_("Cannot execute command")));
3256 edit
->force
|= REDRAW_COMPLETELY
;
3259 vfs_path_t
*tmp_vpath
;
3261 tmp_vpath
= mc_config_get_full_vpath (EDIT_TEMP_FILE
);
3262 edit_insert_file (edit
, tmp_vpath
);
3263 vfs_path_free (tmp_vpath
);
3268 /* --------------------------------------------------------------------------------------------- */
3269 /** if block is 1, a block must be highlighted and the shell command
3270 processes it. If block is 0 the shell command is a straight system
3271 command, that just produces some output which is to be inserted */
3274 edit_block_process_cmd (WEdit
* edit
, int macro_number
)
3277 char *macros_fname
= NULL
;
3279 fname
= g_strdup_printf ("%s.%i.sh", MC_EXTMACRO_FILE
, macro_number
);
3280 macros_fname
= g_build_filename (mc_config_get_data_path (), fname
, (char *) NULL
);
3281 user_menu (edit
, macros_fname
, 0);
3283 g_free (macros_fname
);
3284 edit
->force
|= REDRAW_COMPLETELY
;
3287 /* --------------------------------------------------------------------------------------------- */
3290 edit_mail_dialog (WEdit
* edit
)
3293 char *tmail_subject
;
3296 static char *mail_cc_last
= 0;
3297 static char *mail_subject_last
= 0;
3298 static char *mail_to_last
= 0;
3300 QuickWidget quick_widgets
[] = {
3301 /* 0 */ QUICK_BUTTON (6, 10, 9, MAIL_DLG_HEIGHT
, N_("&Cancel"), B_CANCEL
, NULL
),
3302 /* 1 */ QUICK_BUTTON (2, 10, 9, MAIL_DLG_HEIGHT
, N_("&OK"), B_ENTER
, NULL
),
3303 /* 2 */ QUICK_INPUT (3, 50, 8, MAIL_DLG_HEIGHT
, "", 44, 0, "mail-dlg-input", &tmail_cc
),
3304 /* 3 */ QUICK_LABEL (3, 50, 7, MAIL_DLG_HEIGHT
, N_("Copies to")),
3305 /* 4 */ QUICK_INPUT (3, 50, 6, MAIL_DLG_HEIGHT
, "", 44, 0, "mail-dlg-input-2",
3307 /* 5 */ QUICK_LABEL (3, 50, 5, MAIL_DLG_HEIGHT
, N_("Subject")),
3308 /* 6 */ QUICK_INPUT (3, 50, 4, MAIL_DLG_HEIGHT
, "", 44, 0, "mail-dlg-input-3", &tmail_to
),
3309 /* 7 */ QUICK_LABEL (3, 50, 3, MAIL_DLG_HEIGHT
, N_("To")),
3310 /* 8 */ QUICK_LABEL (3, 50, 2, MAIL_DLG_HEIGHT
, N_("mail -s <subject> -c <cc> <to>")),
3314 QuickDialog Quick_input
= {
3315 50, MAIL_DLG_HEIGHT
, -1, -1, N_("Mail"),
3316 "[Input Line Keys]", quick_widgets
, NULL
, NULL
, FALSE
3319 quick_widgets
[2].u
.input
.text
= mail_cc_last
? mail_cc_last
: "";
3320 quick_widgets
[4].u
.input
.text
= mail_subject_last
? mail_subject_last
: "";
3321 quick_widgets
[6].u
.input
.text
= mail_to_last
? mail_to_last
: "";
3323 if (quick_dialog (&Quick_input
) != B_CANCEL
)
3325 g_free (mail_cc_last
);
3326 g_free (mail_subject_last
);
3327 g_free (mail_to_last
);
3328 mail_cc_last
= tmail_cc
;
3329 mail_subject_last
= tmail_subject
;
3330 mail_to_last
= tmail_to
;
3331 pipe_mail (edit
, mail_to_last
, mail_subject_last
, mail_cc_last
);
3336 /*******************/
3337 /* Word Completion */
3338 /*******************/
3340 /* --------------------------------------------------------------------------------------------- */
3342 * Complete current word using regular expression search
3343 * backwards beginning at the current cursor position.
3347 edit_complete_word_cmd (WEdit
* edit
)
3349 gsize i
, max_len
, word_len
= 0, num_compl
= 0;
3350 long word_start
= 0;
3351 unsigned char *bufpos
;
3353 struct selection
compl[MAX_WORD_COMPLETIONS
]; /* completions */
3355 /* search start of word to be completed */
3356 if (!edit_find_word_start (edit
, &word_start
, &word_len
))
3359 /* prepare match expression */
3360 bufpos
= &edit
->buffers1
[word_start
>> S_EDIT_BUF_SIZE
][word_start
& M_EDIT_BUF_SIZE
];
3362 /* match_expr = g_strdup_printf ("\\b%.*s[a-zA-Z_0-9]+", word_len, bufpos); */
3365 ("(^|\\s+|\\b)%.*s[^\\s\\.=\\+\\[\\]\\(\\)\\,\\;\\:\\\"\\'\\-\\?\\/\\|\\\\\\{\\}\\*\\&\\^\\%%\\$#@\\!]+",
3366 (int) word_len
, bufpos
);
3368 /* collect the possible completions */
3369 /* start search from begin to end of file */
3371 edit_collect_completions (edit
, word_start
, word_len
, match_expr
,
3372 (struct selection
*) &compl, &num_compl
);
3376 /* insert completed word if there is only one match */
3379 for (i
= word_len
; i
< compl[0].len
; i
++)
3380 edit_insert (edit
, *(compl[0].text
+ i
));
3382 /* more than one possible completion => ask the user */
3385 /* !!! usually only a beep is expected and when <ALT-TAB> is !!! */
3386 /* !!! pressed again the selection dialog pops up, but that !!! */
3387 /* !!! seems to require a further internal state !!! */
3390 /* let the user select the preferred completion */
3391 editcmd_dialog_completion_show (edit
, max_len
, word_len
,
3392 (struct selection
*) &compl, num_compl
);
3396 g_free (match_expr
);
3397 /* release memory before return */
3398 for (i
= 0; i
< num_compl
; i
++)
3399 g_free (compl[i
].text
);
3402 /* --------------------------------------------------------------------------------------------- */
3405 edit_select_codepage_cmd (WEdit
* edit
)
3408 if (do_select_codepage ())
3409 edit_set_codeset (edit
);
3411 edit
->force
= REDRAW_PAGE
;
3412 send_message ((Widget
*) edit
, WIDGET_DRAW
, 0);
3418 /* --------------------------------------------------------------------------------------------- */
3421 edit_insert_literal_cmd (WEdit
* edit
)
3423 int char_for_insertion
= editcmd_dialog_raw_key_query (_("Insert literal"),
3424 _("Press any key:"), 0);
3425 edit_execute_key_command (edit
, -1, ascii_alpha_to_cntrl (char_for_insertion
));
3428 /* --------------------------------------------------------------------------------------------- */
3431 edit_begin_end_macro_cmd (WEdit
* edit
)
3433 /* edit is a pointer to the widget */
3436 unsigned long command
= macro_index
< 0 ? CK_MacroStartRecord
: CK_MacroStopRecord
;
3437 edit_execute_key_command (edit
, command
, -1);
3441 /* --------------------------------------------------------------------------------------------- */
3444 edit_begin_end_repeat_cmd (WEdit
* edit
)
3446 /* edit is a pointer to the widget */
3449 unsigned long command
= macro_index
< 0 ? CK_RepeatStartRecord
: CK_RepeatStopRecord
;
3450 edit_execute_key_command (edit
, command
, -1);
3454 /* --------------------------------------------------------------------------------------------- */
3457 edit_load_forward_cmd (WEdit
* edit
)
3460 && edit_query_dialog2 (_("Warning"),
3461 _("Current text was modified without a file save.\n"
3462 "Continue discards these changes"), _("C&ontinue"),
3465 edit
->force
|= REDRAW_COMPLETELY
;
3469 if (edit_stack_iterator
+ 1 >= MAX_HISTORY_MOVETO
)
3472 if (edit_history_moveto
[edit_stack_iterator
+ 1].line
< 1)
3475 edit_stack_iterator
++;
3476 if (edit_history_moveto
[edit_stack_iterator
].filename_vpath
!= NULL
)
3477 return edit_reload_line (edit
, edit_history_moveto
[edit_stack_iterator
].filename_vpath
,
3478 edit_history_moveto
[edit_stack_iterator
].line
);
3483 /* --------------------------------------------------------------------------------------------- */
3486 edit_load_back_cmd (WEdit
* edit
)
3489 && edit_query_dialog2 (_("Warning"),
3490 _("Current text was modified without a file save.\n"
3491 "Continue discards these changes"), _("C&ontinue"),
3494 edit
->force
|= REDRAW_COMPLETELY
;
3498 if (edit_stack_iterator
< 0)
3501 edit_stack_iterator
--;
3502 if (edit_history_moveto
[edit_stack_iterator
].filename_vpath
!= NULL
)
3503 return edit_reload_line (edit
, edit_history_moveto
[edit_stack_iterator
].filename_vpath
,
3504 edit_history_moveto
[edit_stack_iterator
].line
);
3509 /* --------------------------------------------------------------------------------------------- */
3512 edit_get_match_keyword_cmd (WEdit
* edit
)
3514 gsize word_len
= 0, max_len
= 0;
3517 long word_start
= 0;
3518 unsigned char *bufpos
;
3522 char *tagfile
= NULL
;
3524 etags_hash_t def_hash
[MAX_DEFINITIONS
];
3526 for (i
= 0; i
< MAX_DEFINITIONS
; i
++)
3528 def_hash
[i
].filename
= NULL
;
3531 /* search start of word to be completed */
3532 if (!edit_find_word_start (edit
, &word_start
, &word_len
))
3535 /* prepare match expression */
3536 bufpos
= &edit
->buffers1
[word_start
>> S_EDIT_BUF_SIZE
][word_start
& M_EDIT_BUF_SIZE
];
3537 match_expr
= g_strdup_printf ("%.*s", (int) word_len
, bufpos
);
3539 ptr
= g_get_current_dir ();
3540 path
= g_strconcat (ptr
, G_DIR_SEPARATOR_S
, (char *) NULL
);
3543 /* Recursive search file 'TAGS' in parent dirs */
3546 ptr
= g_path_get_dirname (path
);
3550 tagfile
= mc_build_filename (path
, TAGS_NAME
, (char *) NULL
);
3551 if (exist_file (tagfile
))
3554 while (strcmp (path
, G_DIR_SEPARATOR_S
) != 0);
3559 etags_set_definition_hash (tagfile
, path
, match_expr
, (etags_hash_t
*) & def_hash
);
3564 max_len
= MAX_WIDTH_DEF_DIALOG
;
3568 editcmd_dialog_select_definition_show (edit
, match_expr
, max_len
, word_len
,
3569 (etags_hash_t
*) & def_hash
, num_def
);
3571 g_free (match_expr
);
3574 /* --------------------------------------------------------------------------------------------- */
3578 edit_suggest_current_word (WEdit
* edit
)
3582 long word_start
= 0;
3583 int retval
= B_SKIP_WORD
;
3586 /* search start of word to spell check */
3587 match_word
= edit_get_word_from_pos (edit
, edit
->curs1
, &word_start
, &word_len
, &cut_len
);
3590 if (mc_global
.source_codepage
>= 0 && (mc_global
.source_codepage
!= mc_global
.display_codepage
))
3594 tmp_word
= str_convert_to_display (match_word
);
3595 g_free (match_word
);
3596 match_word
= g_string_free (tmp_word
, FALSE
);
3599 if (!aspell_check (match_word
, (int) word_len
))
3604 suggest
= g_array_new (TRUE
, FALSE
, sizeof (char *));
3606 res
= aspell_suggest (suggest
, match_word
, (int) word_len
);
3609 char *new_word
= NULL
;
3611 edit
->found_start
= word_start
;
3612 edit
->found_len
= word_len
;
3613 edit
->force
|= REDRAW_PAGE
;
3614 edit_scroll_screen_over_cursor (edit
);
3615 edit_render_keypress (edit
);
3617 retval
= spell_dialog_spell_suggest_show (edit
, match_word
, &new_word
, suggest
);
3618 edit_cursor_move (edit
, word_len
- cut_len
);
3620 if (retval
== B_ENTER
&& new_word
!= NULL
)
3626 if (mc_global
.source_codepage
>= 0 &&
3627 (mc_global
.source_codepage
!= mc_global
.display_codepage
))
3631 tmp_word
= str_convert_to_input (new_word
);
3633 new_word
= g_string_free (tmp_word
, FALSE
);
3637 for (i
= 0; i
< word_len
; i
++)
3638 edit_backspace (edit
, 1);
3639 for (; *new_word
; new_word
++)
3640 edit_insert (edit
, *new_word
);
3643 else if (retval
== B_ADD_WORD
&& match_word
!= NULL
)
3644 aspell_add_to_dict (match_word
, (int) word_len
);
3647 g_array_free (suggest
, TRUE
);
3648 edit
->found_start
= 0;
3649 edit
->found_len
= 0;
3651 g_free (match_word
);
3655 /* --------------------------------------------------------------------------------------------- */
3658 edit_spellcheck_file (WEdit
* edit
)
3660 if (edit
->curs_line
> 0)
3662 edit_cursor_move (edit
, -edit
->curs1
);
3663 edit_move_to_prev_col (edit
, 0);
3664 edit_update_curs_row (edit
);
3671 c2
= edit_get_byte (edit
, edit
->curs1
);
3675 if (edit
->curs1
>= edit
->last_byte
)
3679 edit_cursor_move (edit
, 1);
3680 c2
= edit_get_byte (edit
, edit
->curs1
);
3682 while (is_break_char (c1
) || is_break_char (c2
));
3684 while (edit_suggest_current_word (edit
) != B_CANCEL
);
3687 /* --------------------------------------------------------------------------------------------- */
3690 edit_set_spell_lang (void)
3694 lang_list
= g_array_new (TRUE
, FALSE
, sizeof (char *));
3695 if (aspell_get_lang_list (lang_list
) != 0)
3699 lang
= spell_dialog_lang_list_show (lang_list
);
3701 (void) aspell_set_lang (lang
);
3703 aspell_array_clean (lang_list
);
3705 #endif /* HAVE_ASPELL */
3707 /* --------------------------------------------------------------------------------------------- */