-
Notifications
You must be signed in to change notification settings - Fork 31
Save and load file positions
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 run
function runs a set of commands by adding a temporary function containing those commands to your configuration file, running the temporary function, and deleting the temporary function.
The lfp
function uses the run
function to run 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
}
# Run commands.
# usage: <run [<session>]
# This function uses a temporary function called tempfn.
function+run {
db0
H-
sw+
bw
enew
nostack e -c
s/$/\nfunction+tempfn {/f
r~0
if(?) {
r ~0
if(?) {
a
~0
.
.g/^$/fX
if(*) {
d
# There is no argument, so use session 999 to copy from the previous buffer in this session.
bw
up
w999
down
r999
e999
bw
eret
q999
} else {
d
}
}
}
s/$/\n}/f
w
config
^
<tempfn
bw
enew
nostack e -c
?^function\+tempfn {?f,d
w
config
^
}
# Load file positions.
# usage: <lfp [<partial file name>]
function+lfp {
db0
enew
<run ~/file_positions_~0.txt
.X
if(?) {
^
.X
if(?) {
q
}
}
}