This is the mail archive of the
insight@sources.redhat.com
mailing list for the Insight project.
Patch: external editor changes
- To: Insight List <insight at sourceware dot cygnus dot com>
- Subject: Patch: external editor changes
- From: Tom Tromey <tromey at redhat dot com>
- Date: 02 Oct 2001 13:35:24 -0600
- Reply-To: tromey at redhat dot com
I've always found it strange that you can only use the `external
editor' feature if you pass insight all sorts of obscure command-line
options.
For that matter, I've always found those command-line options obscure
and in some ways a bad idea (e.g. they don't really need short
options) -- but it is too late to fix this.
This patch fixes the external editor code so that anybody can set a
command to run to bring up the file in an editor. I set mine to
`emacsclient --no-wait +%d %s'. The old command-line options are
still recognized, and if the global `external_editor_command' is set,
it will be used in preference to the user's editor choice. That way,
Source Navigator will continue to work with Insight.
I added a new file where the editor code is centralized.
Ok to commit?
Do I need separate approval for the main.c change?
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* main.c (enable_external_editor): Don't declare.
(captured_main): Don't set enable_external_editor.
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.12
diff -u -r1.12 main.c
--- main.c 2001/07/14 18:59:07 1.12
+++ main.c 2001/10/02 19:15:37
@@ -81,7 +81,6 @@
/* These two are used to set the external editor commands when gdb is farming
out files to be edited by another program. */
-extern int enable_external_editor;
extern char *external_editor_command;
/* Call command_loop. If it happens to return, pass that through as a
@@ -341,23 +340,10 @@
break;
}
case 'y':
- {
- /*
- * This enables the edit/button in the main window, even
- * when IDE_ENABLED is set to false. In this case you must
- * use --tclcommand to specify a tcl/script to be called,
- * Tcl/Variable to store the edit/command is:
- * external_editor
- */
- enable_external_editor = 1;
- break;
- }
+ /* Backwards compatibility only. */
+ break;
case 'w':
{
- /*
- * if editor command is enabled, both flags are set
- */
- enable_external_editor = 1;
external_editor_command = xstrdup (optarg);
break;
}
Index: gdbtk/ChangeLog
from Tom Tromey <tromey@redhat.com>
* library/tclIndex: Updated.
* library/prefs.tcl (pref_set_defaults): Define gdb/editor
preference.
* library/srcpref.itb (SrcPref::constructor): Save gdb/editor
preference.
(SrcPref::build_win): Added external editor control.
* library/srctextwin.itb (SrcTextWin::do_source_popup): Always
enable external editor.
* library/srcwin.itb (SrcWin::edit): Use Editor::edit.
* library/editor.tcl: New file.
* generic/gdbtk.c (enable_external_editor): Removed.
(external_editor_command): Default to NULL.
(gdbtk_init): Don't set enable_external_editor. Free external
editor command when finished with it.
Index: gdbtk/generic/gdbtk.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/generic/gdbtk.c,v
retrieving revision 1.22
diff -u -r1.22 gdbtk.c
--- gdbtk/generic/gdbtk.c 2001/09/19 18:10:37 1.22
+++ gdbtk/generic/gdbtk.c 2001/10/02 19:15:39
@@ -83,16 +83,11 @@
}
/*
- * These two variables control the interaction with an external editor.
- * If enable_external_editor is set at startup, BEFORE Gdbtk_Init is run
- * then the Tcl variable of the same name will be set, and a command will
- * called external_editor_command will be invoked to call out to the
- * external editor. We give a dummy version here to warn if it is not set.
+ * This variable controls the interaction with an external editor.
*/
-int enable_external_editor = 0;
-char *external_editor_command = "tk_dialog .warn-external \\\n\
-\"No command is specified.\nUse --tclcommand <tcl/file> or --external-editor <cmd> to specify a new command\" 0 Ok";
+char *external_editor_command = NULL;
+
extern int Tktable_Init (Tcl_Interp * interp);
static void gdbtk_init (char *);
@@ -585,13 +580,16 @@
"Send a command directly into tk.");
/*
- * Set the variables for external editor:
+ * Set the variable for external editor:
*/
- Tcl_SetVar (gdbtk_interp, "enable_external_editor",
- enable_external_editor ? "1" : "0", 0);
- Tcl_SetVar (gdbtk_interp, "external_editor_command",
- external_editor_command, 0);
+ if (external_editor_command != NULL)
+ {
+ Tcl_SetVar (gdbtk_interp, "external_editor_command",
+ external_editor_command, 0);
+ xfree (external_editor_command);
+ external_editor_command = NULL;
+ }
/* close old output and send new to GDBTK */
ui_file_delete (gdb_stdout);
Index: gdbtk/library/editor.tcl
===================================================================
RCS file: editor.tcl
diff -N editor.tcl
--- /dev/null Tue May 5 13:32:27 1998
+++ gdbtk/library/editor.tcl Tue Oct 2 12:15:39 2001
@@ -0,0 +1,47 @@
+# Editor
+# Copyright 2001 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) as published by
+# the Free Software Foundation; either version 2 of the License, or (at
+# your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# ----------------------------------------------------------------------
+# Implements a set of editor commands
+# ----------------------------------------------------------------------
+
+namespace eval Editor {
+ namespace export edit
+
+ proc edit {loc_info} {
+ global external_editor_command
+
+ if {[info exists external_editor_command]} {
+ if {[catch {uplevel \#0 "$external_editor_command edit $loc_info"} \
+ err]} {
+ tk_dialog .warn-sn "Edit" $err error 0 Ok
+ }
+ return
+ }
+
+ lassign $loc_info baseName fnName fileName lineNum addr pc
+
+ set newCmd [pref get gdb/editor]
+ if {! [string compare $newCmd ""]} {
+ tk_dialog .warn "Edit" "No editor command specified" error 0 Ok
+ }
+
+ # Replace %s with file name and %d with line number.
+ regsub -all -- %s $newCmd $fileName newCmd
+ regsub -all -- %d $newCmd $lineNum newCmd
+
+ if {[catch "exec $newCmd &" err]} {
+ tk_dialog .warn "Edit" $err error 0 Ok
+ }
+ }
+}
Index: gdbtk/library/prefs.tcl
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/prefs.tcl,v
retrieving revision 1.13
diff -u -r1.13 prefs.tcl
--- gdbtk/library/prefs.tcl 2001/09/27 14:47:45 1.13
+++ gdbtk/library/prefs.tcl 2001/10/02 19:15:40
@@ -409,6 +409,9 @@
pref define gdb/mem/ascii_char .
pref define gdb/mem/bytes_per_row 16
pref define gdb/mem/color green
+
+ # External editor.
+ pref define gdb/editor ""
}
# This traces the global/fixed font and forces src-font to
Index: gdbtk/library/srcpref.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/srcpref.itb,v
retrieving revision 1.2
diff -u -r1.2 srcpref.itb
--- gdbtk/library/srcpref.itb 2001/08/28 23:04:59 1.2
+++ gdbtk/library/srcpref.itb 2001/10/02 19:15:40
@@ -34,6 +34,7 @@
set saved(gdb/src/source2_fg) [pref get gdb/src/source2_fg]
set saved(gdb/src/tab_size) [pref get gdb/src/tab_size]
set saved(gdb/mode) [pref get gdb/mode]
+ set saved(gdb/editor) [pref get gdb/editor]
}
# ------------------------------------------------------------------
@@ -170,6 +171,13 @@
set current_disassembly_flavor ""
}
+ # External editor.
+ frame $f.exted
+ label $f.exted.l -text "External Editor: "
+ entry $f.exted.e -width 40 -textvariable [pref varname gdb/editor]
+ pack $f.exted.l -side left
+ pack $f.exted.e -side left -padx 4
+
pack $f.colors -fill both -expand 1
pack $f.rmv -fill both -expand yes
pack $f.x -fill x -expand yes
@@ -177,6 +185,8 @@
if {$have_disassembly_flavor} {
pack $f.dis -side top -fill x -padx 4
}
+
+ pack $f.exted -side top -fill x -padx 4
button $itk_interior.f.b.ok -text OK -width 7 -underline 0 -command [code $this _save]
button $itk_interior.f.b.apply -text Apply -width 7 -underline 0 -command [code $this _apply]
Index: gdbtk/library/srctextwin.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/srctextwin.itb,v
retrieving revision 1.27
diff -u -r1.27 srctextwin.itb
--- gdbtk/library/srctextwin.itb 2001/08/20 17:55:32 1.27
+++ gdbtk/library/srctextwin.itb 2001/10/02 19:15:42
@@ -2138,10 +2138,8 @@
$popups(source) add command -label "Open Another Source Window" \
-command {ManagedWin::open SrcWin -force}
- if {[info exists ::enable_external_editor] && $::enable_external_editor} {
- $popups(source) add command -label "Open Source in external editor" \
- -command [list $parent edit]
- }
+ $popups(source) add command -label "Open Source in external editor" \
+ -command [list $parent edit]
tk_popup $popups(source) $X $Y
}
Index: gdbtk/library/srcwin.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/srcwin.itb,v
retrieving revision 1.16
diff -u -r1.16 srcwin.itb
--- gdbtk/library/srcwin.itb 2001/08/24 00:11:06 1.16
+++ gdbtk/library/srcwin.itb 2001/10/02 19:15:43
@@ -684,26 +684,20 @@
# PUBLIC METHOD: edit - invoke external editor
# ------------------------------------------------------------------
body SrcWin::edit {} {
- global enable_external_editor external_editor_command
+ global external_editor_command
# If external editor is enabled, pass the file to the specified command
-
+
if {$current(filename) == ""} {
tk_dialog .warn {Edit} {No file is loaded in the source window.} error 0 Ok
return
}
-
+
if {[catch {$twin report_source_location} loc_info]} {
tk_dialog .warn "Edit" "No source file selected" error 0 Ok
return
}
-
-
- if {[info exists enable_external_editor] && $enable_external_editor} {
- if {[catch {uplevel \#0 "$external_editor_command edit $loc_info"} ]} {
- tk_dialog .warn-sn "Edit" $err error 0 Ok
- }
- return
- }
+
+ Editor::edit $loc_info
}
# ------------------------------------------------------------------
Index: gdbtk/library/tclIndex
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/tclIndex,v
retrieving revision 1.19
diff -u -r1.19 tclIndex
--- gdbtk/library/tclIndex 2001/08/16 18:55:50 1.19
+++ gdbtk/library/tclIndex 2001/10/02 19:15:43
@@ -602,3 +602,4 @@
set auto_index(::TargetSelection::target_trace) [list source [file join $dir targetselection.itb]]
set auto_index(::TargetSelection::valid_target) [list source [file join $dir targetselection.itb]]
set auto_index(::TargetSelection::native_debugging) [list source [file join $dir targetselection.itb]]
+set auto_index(::Editor::edit) [list source [file join $dir editor.tcl]]