Merge branch '3117_external_editor_line_number'

* 3117_external_editor_line_number:
  Update EN and RU manual pages.
  Launching external editor/viewer with F4/F3 w/o passing line number.
  Allow launch external editor/viewer w/o line number.
  Ticket #3117: Launching editor with CK_Edit shouldn't pass line number.
This commit is contained in:
Andrew Borodin 2014-01-14 14:25:34 +04:00
commit 7c7ed5ef0c
8 changed files with 52 additions and 51 deletions

View File

@ -4125,13 +4125,11 @@ and viewers. The Midnight Commander tries to search the
and then in the ~/.config/mc/ini file. The option name should be equal to the name and then in the ~/.config/mc/ini file. The option name should be equal to the name
(full pathname) of external editor or viewer. The option value can contain following (full pathname) of external editor or viewer. The option value can contain following
variables: variables:
.PP .TP
.I %filename .I %filename
.IP
The filename to edit/view. The filename to edit/view.
.PP .TP
.I %lineno .I %lineno
.IP
The start line in the opening file. The start line in the opening file.
.PP .PP
For example: For example:
@ -4142,6 +4140,17 @@ For example:
joe=%filename +%lineno joe=%filename +%lineno
more=%filename +%lineno more=%filename +%lineno
.fi .fi
.PP
Start line is passed to the external editor/viewer only if it is called from the
.\"LINK2"
Find file
.\"Find File"
results window.
.PP
If external editor/viewer is launched via F4/F3 keys, MC hopes that program
(at least "joe", but probably others too) has an own feature that by default
opens the file where it was last open. MC doesn't prevent external editor/viewer
to save and restore position in opened files.
.\"NODE "Terminal databases" .\"NODE "Terminal databases"
.SH "Terminal databases" .SH "Terminal databases"
The Midnight Commander provides a way to fix your system terminal The Midnight Commander provides a way to fix your system terminal

View File

@ -4512,11 +4512,9 @@ Midnight Commander позволяет задать некоторые парам
программы просмотра. Значение параметра может содержать следующие переменные: программы просмотра. Значение параметра может содержать следующие переменные:
.PP .PP
.I %filename .I %filename
.IP
Имя файла для редактирования или просмотра. Имя файла для редактирования или просмотра.
.PP .PP
.I %lineno .I %lineno
.IP
Номер начальной строки в открываемом файле. Номер начальной строки в открываемом файле.
.PP .PP
Пример: Пример:
@ -4527,6 +4525,18 @@ Midnight Commander позволяет задать некоторые парам
joe=%filename +%lineno joe=%filename +%lineno
more=%filename +%lineno more=%filename +%lineno
.fi .fi
.PP
Начальная строка передаётся в во внешнюю программу редактирования или просмотра
только в том случае, если она вызывается из окна результатов
.\"LINK2"
поиска файлов\&.
.\"Find File"
.PP
Если внешняя программа редактирования или просмотра запускается по клавишам F4 или F3,
MC надеется, что она имеет собственную функцию открытия файла в том же самом месте,
где он был закрыт в предыдущий раз. Такую функцию имеет, например, редактор "joe" и многие
другие. MC не препятствует внешней программе редактирования или просмотра самостоятельно
сохранять и восстановливать позиции в открываемых файлах.
.\"NODE "Terminal databases" .\"NODE "Terminal databases"
.SH "Базы терминалов" .SH "Базы терминалов"
Midnight Commander обеспечивает возможность внесения исправлений в Midnight Commander обеспечивает возможность внесения исправлений в

View File

@ -49,7 +49,7 @@
#endif #endif
#include "lib/event.h" /* mc_event_raise() */ #include "lib/event.h" /* mc_event_raise() */
#include "src/filemanager/cmd.h" /* do_edit_at_line(), view_other_cmd() */ #include "src/filemanager/cmd.h" /* edit_file_at_line(), view_other_cmd() */
#include "src/filemanager/panel.h" #include "src/filemanager/panel.h"
#include "src/filemanager/layout.h" /* Needed for get_current_index and get_other_panel */ #include "src/filemanager/layout.h" /* Needed for get_current_index and get_other_panel */
@ -2883,7 +2883,7 @@ dview_edit (WDiff * dview, diff_place_t ord)
vfs_path_t *tmp_vpath; vfs_path_t *tmp_vpath;
tmp_vpath = vfs_path_from_str (dview->file[ord]); tmp_vpath = vfs_path_from_str (dview->file[ord]);
do_edit_at_line (tmp_vpath, use_internal_edit, linenum); edit_file_at_line (tmp_vpath, use_internal_edit != 0, linenum);
vfs_path_free (tmp_vpath); vfs_path_free (tmp_vpath);
} }
h->modal = h_modal; h->modal = h_modal;

View File

@ -266,9 +266,13 @@ execute_get_external_cmd_opts_from_config (const char *command, const vfs_path_t
if (filename_vpath == NULL) if (filename_vpath == NULL)
return g_strdup (""); return g_strdup ("");
parameter = g_shell_quote (vfs_path_get_last_path_str (filename_vpath));
if (start_line <= 0)
return parameter;
str_from_config = execute_get_opts_from_cfg (command, "%filename"); str_from_config = execute_get_opts_from_cfg (command, "%filename");
parameter = g_shell_quote (vfs_path_get_last_path_str (filename_vpath));
return_str = str_replace_all (str_from_config, "%filename", parameter); return_str = str_replace_all (str_from_config, "%filename", parameter);
g_free (parameter); g_free (parameter);
g_free (str_from_config); g_free (str_from_config);
@ -615,6 +619,7 @@ execute_with_vfs_arg (const char *command, const vfs_path_t * filename_vpath)
* @param command editor/viewer to run * @param command editor/viewer to run
* @param filename_vpath path for edit/view * @param filename_vpath path for edit/view
* @param start_line cursor will be placed at the 'start_line' position after opening file * @param start_line cursor will be placed at the 'start_line' position after opening file
* if start_line is 0 or negative, no start line will be passed to editor/viewer
*/ */
void void

View File

@ -157,7 +157,7 @@ do_view_cmd (gboolean normal)
file_idx = current_panel->selected; file_idx = current_panel->selected;
filename_vpath = vfs_path_from_str (current_panel->dir.list[file_idx].fname); filename_vpath = vfs_path_from_str (current_panel->dir.list[file_idx].fname);
view_file (filename_vpath, normal, use_internal_view); view_file (filename_vpath, normal, use_internal_view != 0);
vfs_path_free (filename_vpath); vfs_path_free (filename_vpath);
} }
@ -169,17 +169,7 @@ do_view_cmd (gboolean normal)
static inline void static inline void
do_edit (const vfs_path_t * what_vpath) do_edit (const vfs_path_t * what_vpath)
{ {
long line = 0; edit_file_at_line (what_vpath, use_internal_edit != 0, 0);
if (!use_internal_edit)
{
long column;
off_t offset;
if (what_vpath != NULL && *(vfs_path_get_by_index (what_vpath, 0)->path) != '\0')
load_file_position (what_vpath, &line, &column, &offset, NULL);
}
do_edit_at_line (what_vpath, use_internal_edit, line);
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
@ -623,7 +613,8 @@ set_basic_panel_listing_to (int panel_index, int listing_mode)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
gboolean gboolean
view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal, long start_line) view_file_at_line (const vfs_path_t * filename_vpath, gboolean plain_view, gboolean internal,
long start_line)
{ {
gboolean ret = TRUE; gboolean ret = TRUE;
@ -661,7 +652,7 @@ view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int intern
{ {
char view_entry[BUF_TINY]; char view_entry[BUF_TINY];
if (start_line != 0) if (start_line > 0)
g_snprintf (view_entry, sizeof (view_entry), "View:%ld", start_line); g_snprintf (view_entry, sizeof (view_entry), "View:%ld", start_line);
else else
strcpy (view_entry, "View"); strcpy (view_entry, "View");
@ -703,20 +694,9 @@ view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int intern
*/ */
gboolean gboolean
view_file (const vfs_path_t * filename_vpath, int plain_view, int internal) view_file (const vfs_path_t * filename_vpath, gboolean plain_view, gboolean internal)
{ {
long line = 0; return view_file_at_line (filename_vpath, plain_view, internal, 0);
if (!internal)
{
long column;
off_t offset;
if (filename_vpath != NULL && *(vfs_path_get_by_index (filename_vpath, 0)->path) != '\0')
load_file_position (filename_vpath, &line, &column, &offset, NULL);
}
return view_file_at_line (filename_vpath, plain_view, internal, line);
} }
@ -742,12 +722,12 @@ view_file_cmd (void)
input_expand_dialog (_("View file"), _("Filename:"), input_expand_dialog (_("View file"), _("Filename:"),
MC_HISTORY_FM_VIEW_FILE, selection (current_panel)->fname, MC_HISTORY_FM_VIEW_FILE, selection (current_panel)->fname,
INPUT_COMPLETE_FILENAMES); INPUT_COMPLETE_FILENAMES);
if (!filename) if (filename == NULL)
return; return;
vpath = vfs_path_from_str (filename); vpath = vfs_path_from_str (filename);
g_free (filename); g_free (filename);
view_file (vpath, 0, use_internal_view); view_file (vpath, FALSE, use_internal_view != 0);
vfs_path_free (vpath); vfs_path_free (vpath);
} }
@ -789,7 +769,7 @@ view_filtered_cmd (void)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
void void
do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line) edit_file_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line)
{ {
#ifdef USE_INTERNAL_EDIT #ifdef USE_INTERNAL_EDIT
@ -809,9 +789,6 @@ do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_li
editor = get_default_editor (); editor = get_default_editor ();
} }
if (start_line < 1)
start_line = 1;
execute_external_editor_or_viewer (editor, what_vpath, start_line); execute_external_editor_or_viewer (editor, what_vpath, start_line);
} }
@ -849,7 +826,7 @@ edit_cmd_force_internal (void)
fname = vfs_path_from_str (selection (current_panel)->fname); fname = vfs_path_from_str (selection (current_panel)->fname);
if (regex_command (fname, "Edit") == 0) if (regex_command (fname, "Edit") == 0)
do_edit_at_line (fname, TRUE, 0); edit_file_at_line (fname, TRUE, 1);
vfs_path_free (fname); vfs_path_free (fname);
} }
#endif #endif

View File

@ -52,14 +52,14 @@ void help_cmd (void);
void smart_dirsize_cmd (void); void smart_dirsize_cmd (void);
void single_dirsize_cmd (void); void single_dirsize_cmd (void);
void dirsizes_cmd (void); void dirsizes_cmd (void);
gboolean view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal, gboolean view_file_at_line (const vfs_path_t * filename_vpath, gboolean plain_view,
long start_line); gboolean internal, long start_line);
gboolean view_file (const vfs_path_t * filename_vpath, int normal, int internal); gboolean view_file (const vfs_path_t * filename_vpath, gboolean normal, gboolean internal);
void view_cmd (void); void view_cmd (void);
void view_file_cmd (void); void view_file_cmd (void);
void view_raw_cmd (void); void view_raw_cmd (void);
void view_filtered_cmd (void); void view_filtered_cmd (void);
void do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line); void edit_file_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line);
void edit_cmd (void); void edit_cmd (void);
void edit_cmd_new (void); void edit_cmd_new (void);
#ifdef USE_INTERNAL_EDIT #ifdef USE_INTERNAL_EDIT

View File

@ -56,7 +56,7 @@
#include "src/history.h" /* MC_HISTORY_SHARED_SEARCH */ #include "src/history.h" /* MC_HISTORY_SHARED_SEARCH */
#include "dir.h" #include "dir.h"
#include "cmd.h" /* view_file_at_line */ #include "cmd.h" /* view_file_at_line() */
#include "midnight.h" /* current_panel */ #include "midnight.h" /* current_panel */
#include "boxes.h" #include "boxes.h"
#include "panelize.h" #include "panelize.h"
@ -1433,9 +1433,9 @@ find_do_view_edit (gboolean unparsed_view, gboolean edit, char *dir, char *file)
fullname_vpath = vfs_path_build_filename (dir, filename, (char *) NULL); fullname_vpath = vfs_path_build_filename (dir, filename, (char *) NULL);
if (edit) if (edit)
do_edit_at_line (fullname_vpath, use_internal_edit, line); edit_file_at_line (fullname_vpath, use_internal_edit != 0, line);
else else
view_file_at_line (fullname_vpath, unparsed_view ? 1 : 0, use_internal_view, line); view_file_at_line (fullname_vpath, unparsed_view, use_internal_view != 0, line);
vfs_path_free (fullname_vpath); vfs_path_free (fullname_vpath);
g_free (fullname); g_free (fullname);
} }

View File

@ -1000,7 +1000,7 @@ mc_maybe_editor_or_viewer (void)
if (mc_run_param0 != NULL && *(char *) mc_run_param0 != '\0') if (mc_run_param0 != NULL && *(char *) mc_run_param0 != '\0')
vpath = prepend_cwd_on_local ((char *) mc_run_param0); vpath = prepend_cwd_on_local ((char *) mc_run_param0);
ret = view_file (vpath, 0, 1); ret = view_file (vpath, FALSE, TRUE);
vfs_path_free (vpath); vfs_path_free (vpath);
break; break;
} }