Skip to content

Save and load file positions

David-Apps edited this page Mar 23, 2023 · 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 commands to open the current file, go to the current line number, and add the labels that you have set. The sall function uses the s function for the file in each session to write commands to open each file. The sfp function uses the sall function, saves the commands to a file, and quits.

The lfp function runs the commands in a file that you saved with the sfp function.

# Write the line number of a label.
# usage: <getlabel <label>
# Function s uses this function.
function+getlabel {
up
'~0X
if(*) {
ebvar+
!true
ebvar-
down
r !if [ -n "$EB_FILE" ]; then echo ${EB_LN}k~0; fi
} else {
down
}
}

# Write commands to restore the file position.
# usage <s
function+s {
db0
H-
ebvar+
!true
ebvar-
enew
r !if [ -n "$EB_FILE" ]; then if [ "$EB_FILE" = "$EB_BASE" ]; then echo e "$EB_FILE"; else echo b "$EB_BASE"; fi; echo ${EB_LN}X; fi
bw
<getlabel a
<getlabel b
<getlabel c
<getlabel d
<getlabel e
<getlabel f
<getlabel g
<getlabel h
<getlabel i
<getlabel j
<getlabel k
<getlabel l
<getlabel m
<getlabel n
<getlabel o
<getlabel p
<getlabel q
<getlabel r
<getlabel s
<getlabel t
<getlabel u
<getlabel v
<getlabel w
<getlabel x
<getlabel y
<getlabel z
r !if [ -n "$EB_FILE" ]; then echo M0; fi
}

# Write commands to restore the file position of each session.
# usage: <sall
# This function uses session 999.
function+sall {
db0
while(*) {
e-
}
while(*) {
enew
^
e+
}
while(*) {
<s
.X
if(*) {
w999@0
if(?) {
w999
}
}
^
e-
}
enew
r999
if(*) {
e999
bw
eret
q999
}
bw
e+
while(*) {
q
while(*) {
e-
}
e+
}
}

# Save commands to restore the file positions.
# usage: <sfp [<partial file name>]
function+sfp {
db0
<sall
w ~/file_positions_~0.txt
q
}

# Load file positions.
# usage: <lfp [<partial file name>]
# This function uses session 999.
function+lfp {
db0
e999
e ~/data/other/file_positions_~0.txt
eret
<999
q999
.X
if(?) {
q
}
}