-
Notifications
You must be signed in to change notification settings - Fork 31
Save and load file positions
David-Apps edited this page Dec 10, 2022
·
20 revisions
You can use these functions to save and load your position in files. This can make it easier to return to where you were in a file after taking a break.
The `s` function writes the file name and the current line number on a pair of lines in a new buffer.
You can save this pair of lines to use later with the `l` or `lall` functions.
You can use the `^` command to return to the file in the previous buffer.
The `l` function reads a pair of lines, opening the file whose file name appears on the first line in the pair and moving to the line number that is on the second line in the pair.
The `sall` function writes pairs of lines for the current file in each session to a single buffer.
You can save these pairs to use later with the `l` or `lall` functions.
The `lall` function reads each pair of lines in the buffer, opening each file and moving to its line number.
The `sfp` and `lfp` functions show how you can use these functions.
The `sfp` function writes a pair of lines for each session to a file.
The `lfp` function opens this file and loads the files it contains.
You can pass a partial file name to either of these functions so that you can save and load sets of file positions.
# Write the current file name and line number.
# usage <s
function+s {
db0
H-
ebvar+
!true
ebvar-
enew
r !echo "$EB_BASE"; echo $EB_LN
bw
}
# Open a file at a line number.
# usage <l
# This function uses session 999.
function+l {
db0
H-
sw+
.g/^\d+$/fX
if(?) {
/^\d+$/fX
}
.w999
-X
bw
g
1X
e999
r !seq $(((EB_DOT - 1) / 1000000))
.g/^0$/fd
if(?) {
2X
while(*) {
eret
+1000000X
eret
$d
2X
}
}
r !seq $((((EB_DOT - 1) % 1000000) / 1000))
.g/^0$/fd
if(?) {
2X
while(*) {
eret
+1000X
eret
$d
2X
}
}
0r !seq $(((EB_DOT - 1) % 1000))
.g/^0$/fd
if(?) {
$-1,$d
while(*) {
eret
+X
eret
d
}
}
bw
eret
q999
}
# Write the file name and current line number of each session.
# usage: <sall
# This function uses session 999.
function+sall {
db0
while(*) {
e-
}
while(*) {
enew
^
e+
}
while(*) {
<s
w+999
if(?) {
w999
}
^
e-
}
enew
r999
e999
bw
eret
q999
bw
}
# Open each file at its line number.
# usage: <lall
function+lall {
db0
$X
<l
while(*) {
M0
;d
<l
}
q
}
# Save file positions.
# usage: <sfp [<partial file name>]
function+sfp {
db0
<sall
w ~/file_positions_~0.txt
while(*) {
q
}
}
# Load file positions.
# usage: <lfp [<partial file name>]
function+lfp {
db0
e ~/file_positions_~0.txt
<lall
}