Skip to content

Save and load file positions

David-Apps edited this page Nov 18, 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.

The rf function refreshes the buffer, restores the labels that you had created, and returns to the line number that you were on.

# 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 '_ ]; 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 '_ ]; then if [ '_ = "$EB_BASE" ]; then echo e '_; 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 '_ ]; 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 sessions 998 and 999.
function+lfp {
db0
e999
e ~/file_positions_~0.txt
if(*) {
eret
e998
eret
.X
if(?) {
q
}
e998
if(?) {
}
<999
q999
eret
q998
} else {
h
eret
q999
}
}

# Refresh the file and return to the current line number.
# usage: <rf
function+rf {
db0
H-
sw+
e/temporary buffer for function rf to use
if(*) {
eret
ebvar-
!echo temporary buffer already exists
} else {
ebvar+
!true
ebvar-
enew
f temporary buffer for function rf to use
bw
r !echo $EB_LN
<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
bw
M0
rf
<+/temporary buffer for function rf to use
q/temporary buffer for function rf to use
}
}