Save current line in editor and persistent blocks patch



2) This patch allow to save current line in editor and restore it on next 
editing. Persistent blocks also may be useful if Shift+arrows using for block 
selection.
diff -Naur mc/edit/edit_key_translator.c mc-4.5.54-m8/edit/edit_key_translator.c
--- mc/edit/edit_key_translator.c	Wed Jun  6 02:04:39 2001
+++ mc-4.5.54-m8/edit/edit_key_translator.c	Sat Jun 16 21:14:43 2001
@@ -287,6 +287,20 @@
 	char_for_insertion = conv_input [x_key];
 #endif
 	goto fin;
+    }
+
+/* persistent blocks - mAX */
+    if (!option_persist_blocks) {
+	/* Remove selected block if DEL key pressed - mAX */
+	if (x_key == KEY_DC && (edit->mark1 != edit->mark2)) {
+	    command = CK_Remove;
+	    goto fin;
+	}
+	/* Remove selection if other key pressed - mAX */
+	if (edit->highlight)
+	    edit_mark_cmd (edit, 0);
+	edit_mark_cmd (edit, 1);
+	edit->highlight = 0;
     }
 
 /* other commands */
diff -Naur mc/gtkedit/edit.h mc-new/gtkedit/edit.h
--- mc/gtkedit/edit.h	Sat Jun 16 02:43:21 2001
+++ mc-new/gtkedit/edit.h	Mon Jul  2 15:13:37 2001
@@ -706,6 +706,8 @@
 int option_backspace_through_tabs = 0;
 int option_fake_half_tabs = 1;
 int option_save_mode = 0;
+int option_edit_save_line = 1;	/* default - save position - mAX */
+int option_persist_blocks = 1;	/* default - persistent blocks - mAX */
 int option_backup_ext_int = -1;
 int option_find_bracket = 1;
 int option_max_undo = 32768;
@@ -754,6 +756,8 @@
 extern int option_backspace_through_tabs;
 extern int option_fake_half_tabs;
 extern int option_save_mode;
+extern int option_edit_save_line;	/* added by mAX */
+extern int option_persist_blocks;	/* added by mAX */
 extern int option_backup_ext_int;
 extern int option_find_bracket;
 extern int option_max_undo;
diff -Naur mc/gtkedit/editoptions.c mc-new/gtkedit/editoptions.c
--- mc/gtkedit/editoptions.c	Sat Apr  7 00:48:11 2001
+++ mc-new/gtkedit/editoptions.c	Mon Jul  2 15:11:48 2001
@@ -56,6 +56,8 @@
     int toption_fill_tabs_with_spaces = option_fill_tabs_with_spaces;
     int tedit_confirm_save = edit_confirm_save;
     int tedit_syntax_highlighting = option_syntax_highlighting;
+    int tedit_edit_save_line = option_edit_save_line;	/* added by mAX */
+    int tedit_persist_blocks = option_persist_blocks;	/* added by mAX */
     int toption_return_does_auto_indent = option_return_does_auto_indent;
     int toption_backspace_through_tabs = option_backspace_through_tabs;
     int toption_fake_half_tabs = option_fake_half_tabs;
@@ -80,7 +82,10 @@
 /*5 */
 	{quick_input, OPT_DLG_W / 2 + 24, OPT_DLG_W, OPT_DLG_H - 5, OPT_DLG_H, "", OPT_DLG_W / 2 - 4 - 24, 0,
 	 0, 0, "i"},
-/*6 */
+/*6 */	/* save editor line option - mAX */
+	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H, N_("save file &Position"), 0, 0,
+	 0, 0, NULL},
+/*7 */
 #if !defined(MIDNIGHT) || defined(HAVE_SYNTAXH)
 #define OA 1
 	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, N_("synta&X highlighting"), 8, 0,
@@ -88,31 +93,34 @@
 #else
 #define OA 0
 #endif
-/*7 */
+/*8 */
 	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 8, OPT_DLG_H, N_("confir&M before saving"), 6, 0,
 	 0, 0, NULL},
-/*8 */
+/*9 */
 	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 9, OPT_DLG_H, N_("fill tabs with &Spaces"), 0, 0,
 	 0, 0, NULL},
-/*9 */
+/*10 */
 	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 10, OPT_DLG_H, N_("&Return does autoindent"), 0, 0,
 	 0, 0, NULL},
-/*10 */
+/*11 */
 	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, N_("&Backspace through tabs"), 0, 0,
 	 0, 0, NULL},
-/*11 */
+/*12 */
 	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H, N_("&Fake half tabs"), 0, 0,
 	 0, 0, NULL},
-/*12 */
+/*13 */	/* persistent blocks option - mAX */
+	{quick_checkbox, OPT_DLG_W / 2 + 1, OPT_DLG_W, OPT_DLG_H - 13, OPT_DLG_H, N_("Persistent b&locks"), 0, 0,
+	 0, 0, NULL},
+/*14 */
 	{quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 6, OPT_DLG_H, "", 3, 0,
 	 0, wrap_str, "wrapm"},
-/*13 */
+/*15 */
 	{quick_label, 4, OPT_DLG_W, OPT_DLG_H - 7, OPT_DLG_H, N_("Wrap mode"), 0, 0,
 	 0, 0, NULL},
-/*14 */
+/*16 */
 	{quick_radio, 5, OPT_DLG_W, OPT_DLG_H - 11, OPT_DLG_H, "", 2, 0,
        0, key_emu_str, "keyemu"},
-/*15 */
+/*17 */
 	{quick_label, 4, OPT_DLG_W, OPT_DLG_H - 12, OPT_DLG_H, N_("Key emulation"), 0, 0,
 	 0, 0, NULL},
 	{0}};
@@ -132,12 +140,14 @@
     quick_widgets[3].str_result = &p;
     quick_widgets[5].text = tab_spacing;
     quick_widgets[5].str_result = &q;
-    quick_widgets[5 + OA].result = &tedit_syntax_highlighting;
-    quick_widgets[6 + OA].result = &tedit_confirm_save;
-    quick_widgets[7 + OA].result = &toption_fill_tabs_with_spaces;
-    quick_widgets[8 + OA].result = &toption_return_does_auto_indent;
-    quick_widgets[9 + OA].result = &toption_backspace_through_tabs;
-    quick_widgets[10 + OA].result = &toption_fake_half_tabs;
+    quick_widgets[5 + OA].result = &tedit_edit_save_line;	/* added by mAX */
+    quick_widgets[6 + OA].result = &tedit_syntax_highlighting;
+    quick_widgets[7 + OA].result = &tedit_confirm_save;
+    quick_widgets[8 + OA].result = &toption_fill_tabs_with_spaces;
+    quick_widgets[9 + OA].result = &toption_return_does_auto_indent;
+    quick_widgets[10 + OA].result = &toption_backspace_through_tabs;
+    quick_widgets[11 + OA].result = &toption_fake_half_tabs;
+    quick_widgets[12 + OA].result = &tedit_persist_blocks;	/* added by mAX */
 
     if (option_auto_para_formatting)
 	wrap_mode = 1;
@@ -146,11 +156,11 @@
     else
 	wrap_mode = 0;
 
-    quick_widgets[11 + OA].result = &wrap_mode;
-    quick_widgets[11 + OA].value = wrap_mode;
+    quick_widgets[13 + OA].result = &wrap_mode;
+    quick_widgets[13 + OA].value = wrap_mode;
 
-    quick_widgets[13 + OA].result = &tedit_key_emulation;
-    quick_widgets[13 + OA].value = tedit_key_emulation;
+    quick_widgets[15 + OA].result = &tedit_key_emulation;
+    quick_widgets[15 + OA].value = tedit_key_emulation;
 
     {
 	QuickDialog Quick_options =
@@ -171,17 +181,19 @@
 		option_tab_spacing += option_tab_spacing & 1;
 		free (q);
 	    }
-	    option_syntax_highlighting = *quick_widgets[5 + OA].result;
-	    edit_confirm_save = *quick_widgets[6 + OA].result;
-	    option_fill_tabs_with_spaces = *quick_widgets[7 + OA].result;
-	    option_return_does_auto_indent = *quick_widgets[8 + OA].result;
-	    option_backspace_through_tabs = *quick_widgets[9 + OA].result;
-	    option_fake_half_tabs = *quick_widgets[10 + OA].result;
+	    option_edit_save_line = *quick_widgets[5 + OA].result;	/* added by mAX */
+	    option_syntax_highlighting = *quick_widgets[6 + OA].result;
+	    edit_confirm_save = *quick_widgets[7 + OA].result;
+	    option_fill_tabs_with_spaces = *quick_widgets[8 + OA].result;
+	    option_return_does_auto_indent = *quick_widgets[9 + OA].result;
+	    option_backspace_through_tabs = *quick_widgets[10 + OA].result;
+	    option_fake_half_tabs = *quick_widgets[11 + OA].result;
+	    option_persist_blocks = *quick_widgets[12 + OA].result;	/* added by mAX */
 
-	    if (*quick_widgets[11 + OA].result == 1) {
+	    if (*quick_widgets[13 + OA].result == 1) {
 		option_auto_para_formatting = 1;
 		option_typewriter_wrap = 0;
-	    } else if (*quick_widgets[11 + OA].result == 2) {
+	    } else if (*quick_widgets[13 + OA].result == 2) {
 		option_auto_para_formatting = 0;
 		option_typewriter_wrap = 1;
 	    } else {
@@ -189,7 +201,7 @@
 		option_typewriter_wrap = 0;
 	    }
 
-	    edit_key_emulation = *quick_widgets[13 + OA].result;
+	    edit_key_emulation = *quick_widgets[15 + OA].result;
 
 	    return;
 	} else {
diff -Naur mc/gtkedit/editwidget.c mc-new/gtkedit/editwidget.c
--- mc/gtkedit/editwidget.c	Sat Jun 16 01:06:11 2001
+++ mc-new/gtkedit/editwidget.c	Mon Jul  2 15:09:06 2001
@@ -996,12 +996,82 @@
 
 extern Menu EditMenuBar[5];
 
+/* save position routines start - mAX */
+/* file where stored positions */
+#define MC_EDITPOS ".mc/EditPos"
+/* temporary file */
+#define MC_EDITPOS_TMP ".mc/EditPos.tmp"
+/* maximum entries in MC_EDITPOS */
+#define MC_MAX_EDITPOS_ENTRIES 1024
+
+/*
+    input:  full editing file name
+    return: stored line or 1 if undefined  
+*/
+int edit_get_saved_line(const char *filename) {
+    char *fn;
+    FILE *f;
+    char buf [MC_MAXPATHLEN + 20];
+    int i = 1, len = strlen (filename);
+
+    if ((fn = concat_dir_and_file (home_dir, MC_EDITPOS)) == NULL)
+	return 1;
+    f = fopen (fn, "r");
+    g_free(fn);
+    if (!f) return 1;
+    while (fgets (buf, sizeof (buf), f))
+	if ((strncmp (buf, filename, len) == 0) && (buf[len] == ' ' || buf[len] == '\t')){
+	    i = atoi(&buf[len+1]);
+	    break;
+	}
+    fclose (f);
+    return i;
+}
+
+/*
+    store filename and position in MC_EDITPOS
+*/
+void edit_save_curs_line(const char *filename, const int line) {
+    char *tmp, *fn;
+    FILE *f, *t;
+    char buf [MC_MAXPATHLEN + 20];
+    int i=1;
+
+    if ((tmp = concat_dir_and_file (home_dir, MC_EDITPOS_TMP)) == NULL)
+	return;
+    if ((fn = concat_dir_and_file (home_dir, MC_EDITPOS)) == NULL) {
+	g_free(tmp);
+	return;
+    }
+
+    t = fopen (tmp, "w");
+    if (t) {
+	fprintf (t, "%s %i\n", filename, line);
+	f = fopen (fn, "r");
+	if (f) {
+	    while (fgets (buf, sizeof (buf), f)) {
+		if (strncmp (buf, filename, strlen (filename)) == 0) continue;
+		fprintf (t, "%s", buf);
+		if (++i>MC_MAX_EDITPOS_ENTRIES) break;
+	    }
+	    fclose (f);
+	}
+    }
+    fclose (t);
+    rename (tmp, fn);
+    g_free(tmp);
+    g_free(fn);
+}
+/* save position routines end - mAX */
+
 int edit (const char *_file, int line)
 {
     static int made_directory = 0;
     int framed = 0;
     int midnight_colors[4];
     char *text = 0;
+    char *fullfilename;		/* full editing file name - mAX */
+    char dir [MC_MAXPATHLEN];	/* current work dir - mAX */
 
     if (option_backup_ext_int != -1) {
 	option_backup_ext = malloc (sizeof (int) + 1);
@@ -1060,11 +1130,21 @@
 	add_widget (edit_dlg, edit_menubar);
 
     add_widget (edit_dlg, edit_bar);
-    edit_move_display (wedit, line - 1);
+/* restore current line - mAX */
+    mc_get_current_wd (dir, MC_MAXPATHLEN);
+    fullfilename = concat_dir_and_file (dir, _file);
+    if ((line==1) && option_edit_save_line)
+	    line = edit_get_saved_line(fullfilename);
+
+    edit_move_display (wedit, line - 13);
     edit_move_to_line (wedit, line - 1);
 
     run_dlg (edit_dlg);
 
+/* store current line - mAX */
+    if (option_edit_save_line)
+	edit_save_curs_line(fullfilename, wedit->curs_line+1);
+
     if (!framed)
 	edit_done_menu ();	/* editmenu.c */
 
diff -Naur mc/src/main.h mc-new/src/main.h
--- mc/src/main.h	Wed Jun 27 16:29:16 2001
+++ mc-new/src/main.h	Mon Jul  2 15:25:52 2001
@@ -55,6 +55,8 @@
 extern int option_backspace_through_tabs;
 extern int option_fake_half_tabs;
 extern int option_save_mode;
+extern int option_edit_save_line;	/* save position - mAX */
+extern int option_persist_blocks;	/* persistent clock - mAX */
 extern int option_backup_ext_int;
 extern int option_auto_para_formatting;
 extern int option_typewriter_wrap;
diff -Naur mc/src/setup.c mc-new/src/setup.c
--- mc/src/setup.c	Wed Jun 27 16:29:19 2001
+++ mc-new/src/setup.c	Mon Jul  2 15:20:02 2001
@@ -260,6 +260,8 @@
     { "editor_option_typewriter_wrap", &option_typewriter_wrap },
     { "editor_edit_confirm_save", &edit_confirm_save },
     { "editor_syntax_highlighting", &option_syntax_highlighting },
+    { "editor_edit_save_line", &option_edit_save_line },	/* save editing file position - mAX */
+    { "editor_persist_blocks", &option_persist_blocks },	/* persistent blocks in editor - mAX */
 #endif
 
 #ifdef HAVE_GNOME


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]