Skip to content

Save and load file positions

David-Apps edited this page Mar 24, 2024 · 18 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.

Before quitting, the sfp function saves commands to a file to open the current files, return to the current line numbers, and set the current labels.

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

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

# Write the line number of a label of the previous buffer on the stack.
# usage: <getlabel <label>
# Functions rf and sfp use this function.
function+getlabel {
up
'~0X
if(*) {
ebvar+
!true
ebvar-
down
r !if [ -n '_ ]; then echo ${EB_LN}k~0; fi
} else {
down
}
}

# Write the line number of a label of the next session.
# usage: <getlabeln <label>
# Function sfp uses this function.
function+getlabeln {
e+
'~0X
if(*) {
ebvar+
!true
ebvar-
eret
r !if [ -n '_ ]; then echo ${EB_LN}k~0; fi
} else {
eret
}
}

# Save commands to restore the file positions.
# usage: <sfp [<partial file name>]
function+sfp {
db0
while(*) {
e-
}
while(*) {
enew
^
e+
}
while(*) {
e-
}
H-
ebvar+
!true
ebvar-
etmp
r !if [ -n '_ ]; then if [ '_ = "$EB_BASE" ]; then echo e '_; else echo b "$EB_BASE"; fi; echo ${EB_LN}X; fi
<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
s/$/\nM0/f
e+
while(*) {
ebvar+
!true
ebvar-
eret
r !if [ -n '_ ]; then if [ '_ = "$EB_BASE" ]; then echo e '_; else echo b "$EB_BASE"; fi; echo ${EB_LN}X; fi
<getlabeln a
<getlabeln b
<getlabeln c
<getlabeln d
<getlabeln e
<getlabeln f
<getlabeln g
<getlabeln h
<getlabeln i
<getlabeln j
<getlabeln k
<getlabeln l
<getlabeln m
<getlabeln n
<getlabeln o
<getlabeln p
<getlabeln q
<getlabeln r
<getlabeln s
<getlabeln t
<getlabeln u
<getlabeln v
<getlabeln w
<getlabeln x
<getlabeln y
<getlabeln z
s/$/\nM0/f
eret
q
while(*) {
e-
}
e+
}
w ~/file_positions_~0.txt
q
}

# Load file positions.
# usage: <lfp [<partial file name>]
function+lfp {
db0
e ~/file_positions_~0.txt
etmp
<+1
^^
.X
if(?) {
up
if(*) {
down
} else {
q
}
}
}

# Refresh the file and return to the current line number.
# usage: <rf
function+rf {
db0
H-
ebvar+
!true
ebvar-
enew
r !echo ${EB_LN}X
<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
up
rf
<*-1
down
^
}