summaryrefslogtreecommitdiff
path: root/gdb/gdbtk/library/editor.tcl
blob: b569a31a430d93a6d4249f36596d1ac935c6cd80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
    }
  }
}