... | ... |
@@ -23,8 +23,12 @@ wm geometry . 128x42 |
23 | 23 |
|
24 | 24 |
option add *font "-*-*-*-*-*-*-20-*-*-*-*-*-*-*" |
25 | 25 |
|
26 |
+button .b0 -text copysel -command { |
|
27 |
+ selection handle -selection CLIPBOARD . selectionrequest |
|
28 |
+ selection own -selection CLIPBOARD . } -font "-*-*-*-*-*-*-12-*-*-*-*-*-*-*" |
|
29 |
+pack .b0 -side left -fill both -expand false |
|
26 | 30 |
button .b -text Exit -command exit |
27 |
-pack .b -side top -fill both -expand true |
|
31 |
+pack .b -side left -fill both -expand true |
|
28 | 32 |
|
29 | 33 |
set curselection "" |
30 | 34 |
|
... | ... |
@@ -30,6 +30,7 @@ set curselection "" |
30 | 30 |
|
31 | 31 |
set lastseconds 0 |
32 | 32 |
set nstolen 0 |
33 |
+set lastfile "" |
|
33 | 34 |
|
34 | 35 |
proc selectionlost {} { |
35 | 36 |
global curselection |
... | ... |
@@ -47,9 +48,11 @@ proc selectionlost {} { |
47 | 48 |
set nstolen 0 |
48 | 49 |
} |
49 | 50 |
# process the selection |
50 |
- set curselection [selection get -selection PRIMARY] |
|
51 |
- puts $curselection |
|
52 |
- checkselection $curselection |
|
51 |
+ catch { |
|
52 |
+ set curselection [selection get -selection PRIMARY] |
|
53 |
+ puts $curselection |
|
54 |
+ checkselection $curselection |
|
55 |
+ } |
|
53 | 56 |
selection own -selection PRIMARY -command selectionlost "." |
54 | 57 |
} |
55 | 58 |
|
... | ... |
@@ -59,12 +62,10 @@ proc selectionrequest { offset maxchars } { |
59 | 62 |
} |
60 | 63 |
|
61 | 64 |
proc checkselection { curselection } { |
62 |
- global env |
|
65 |
+ global env lastfile |
|
63 | 66 |
set socketsdir /tmp/.re_$env(USER) |
64 |
- set filenames [list] |
|
65 |
- catch { |
|
66 |
- set filenames [glob -tails -directory $socketsdir ) *] |
|
67 |
- } |
|
67 |
+ set filenames [glob -tails -directory $socketsdir ) *] |
|
68 |
+ # search for occurrences of <filename>:<line>[:<col>] |
|
68 | 69 |
foreach f $filenames { |
69 | 70 |
set index -1 |
70 | 71 |
set flen [string length $f] |
... | ... |
@@ -82,9 +83,14 @@ proc checkselection { curselection } { |
82 | 83 |
} |
83 | 84 |
set newpos [string range $curselection $startindex $index-1] |
84 | 85 |
remotecontrol $socketsdir $f "goto $newpos" |
86 |
+ set lastfile $f |
|
85 | 87 |
} |
86 | 88 |
} |
87 | 89 |
} |
90 |
+ # if it is just <line>, set last used file to that line (useful for gdb) |
|
91 |
+ if { [string length $lastfile]>0 && [string is ascii $curselection] && [string is digit $curselection] } { |
|
92 |
+ remotecontrol $socketsdir $lastfile "goto $curselection" |
|
93 |
+ } |
|
88 | 94 |
} |
89 | 95 |
|
90 | 96 |
proc remotecontrol { socketsdir filename command } { |
... | ... |
@@ -61,7 +61,10 @@ proc selectionrequest { offset maxchars } { |
61 | 61 |
proc checkselection { curselection } { |
62 | 62 |
global env |
63 | 63 |
set socketsdir /tmp/.re_$env(USER) |
64 |
- set filenames [glob -tails -directory $socketsdir ) *] |
|
64 |
+ set filenames [list] |
|
65 |
+ catch { |
|
66 |
+ set filenames [glob -tails -directory $socketsdir ) *] |
|
67 |
+ } |
|
65 | 68 |
foreach f $filenames { |
66 | 69 |
set index -1 |
67 | 70 |
set flen [string length $f] |
... | ... |
@@ -28,8 +28,25 @@ pack .b -side top -fill both -expand true |
28 | 28 |
|
29 | 29 |
set curselection "" |
30 | 30 |
|
31 |
+set lastseconds 0 |
|
32 |
+set nstolen 0 |
|
33 |
+ |
|
31 | 34 |
proc selectionlost {} { |
32 | 35 |
global curselection |
36 |
+ global lastseconds nstolen |
|
37 |
+ # check if there is another instance fighting for the selection |
|
38 |
+ set newseconds [clock seconds] |
|
39 |
+ if { $newseconds == $lastseconds } { |
|
40 |
+ incr nstolen |
|
41 |
+ if { $nstolen>10 } { |
|
42 |
+ puts "There seems to be another instance running, exiting" |
|
43 |
+ exit 0 |
|
44 |
+ } |
|
45 |
+ } else { |
|
46 |
+ set lastseconds $newseconds |
|
47 |
+ set nstolen 0 |
|
48 |
+ } |
|
49 |
+ # process the selection |
|
33 | 50 |
set curselection [selection get -selection PRIMARY] |
34 | 51 |
puts $curselection |
35 | 52 |
checkselection $curselection |
1 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,81 @@ |
1 |
+#!/usr/bin/tclsh |
|
2 |
+# |
|
3 |
+# rehelper |
|
4 |
+# |
|
5 |
+# Monitors the primary selection for occurrences of filename:lineno . |
|
6 |
+# When found, sends to the corresponding recenteditor instance the lineno. |
|
7 |
+# |
|
8 |
+# Dependencies: |
|
9 |
+# socat |
|
10 |
+# |
|
11 |
+# Documentation: |
|
12 |
+# https://wiki.tcl-lang.org/page/Primary+Transfer+vs.+the+Clipboard |
|
13 |
+# https://wiki.tcl-lang.org/page/Unix+Domain+Sockets |
|
14 |
+# |
|
15 |
+# Author: Dario Rodriguez antartica@whereismybit.com |
|
16 |
+# (c) 2024 Dario Rodriguez |
|
17 |
+# This program is in the public domain |
|
18 |
+ |
|
19 |
+package require Tk |
|
20 |
+ |
|
21 |
+wm title . rehelper |
|
22 |
+wm geometry . 128x42 |
|
23 |
+ |
|
24 |
+option add *font "-*-*-*-*-*-*-20-*-*-*-*-*-*-*" |
|
25 |
+ |
|
26 |
+button .b -text Exit -command exit |
|
27 |
+pack .b -side top -fill both -expand true |
|
28 |
+ |
|
29 |
+set curselection "" |
|
30 |
+ |
|
31 |
+proc selectionlost {} { |
|
32 |
+ global curselection |
|
33 |
+ set curselection [selection get -selection PRIMARY] |
|
34 |
+ puts $curselection |
|
35 |
+ checkselection $curselection |
|
36 |
+ selection own -selection PRIMARY -command selectionlost "." |
|
37 |
+} |
|
38 |
+ |
|
39 |
+proc selectionrequest { offset maxchars } { |
|
40 |
+ global curselection |
|
41 |
+ return $curselection |
|
42 |
+} |
|
43 |
+ |
|
44 |
+proc checkselection { curselection } { |
|
45 |
+ global env |
|
46 |
+ set socketsdir /tmp/.re_$env(USER) |
|
47 |
+ set filenames [glob -tails -directory $socketsdir ) *] |
|
48 |
+ foreach f $filenames { |
|
49 |
+ set index -1 |
|
50 |
+ set flen [string length $f] |
|
51 |
+ while { [set index [string first $f $curselection [expr $index + 1]]]!=-1 } { |
|
52 |
+ if { [string compare [string index $curselection [expr $index+$flen]] ":"]==0 |
|
53 |
+ && ( $index==0 || [string is alnum [string index $curselection [expr $index-1]]]==0 ) |
|
54 |
+ && [string compare [string index $curselection [expr $index+$flen+1]] ""]!=0 |
|
55 |
+ && [string is digit [string index $curselection [expr $index+$flen+1]]]==1} { |
|
56 |
+ set index [expr $index+$flen+1] |
|
57 |
+ set startindex $index |
|
58 |
+ while { [string compare [string index $curselection $index] ""]!=0 |
|
59 |
+ && ( [string is digit [string index $curselection $index]]==1 |
|
60 |
+ || [string compare [string index $curselection $index] ":"]==0 ) } { |
|
61 |
+ incr index |
|
62 |
+ } |
|
63 |
+ set newpos [string range $curselection $startindex $index-1] |
|
64 |
+ remotecontrol $socketsdir $f "goto $newpos" |
|
65 |
+ } |
|
66 |
+ } |
|
67 |
+ } |
|
68 |
+} |
|
69 |
+ |
|
70 |
+proc remotecontrol { socketsdir filename command } { |
|
71 |
+ puts "filename:$socketsdir/$filename command:\"$command\"" |
|
72 |
+ catch { |
|
73 |
+ set f [open "|socat - UNIX-CONNECT:$socketsdir/$filename" r+] |
|
74 |
+ puts -nonewline $f "$command\n" |
|
75 |
+ close $f |
|
76 |
+ } |
|
77 |
+} |
|
78 |
+ |
|
79 |
+selection handle -selection PRIMARY "." selectionrequest |
|
80 |
+selection own -selection PRIMARY -command selectionlost "." |
|
81 |
+ |