9fans / plan9port

Plan 9 from User Space
https://9fans.github.io/plan9port/
Other
1.63k stars 322 forks source link

setting addr to dot(.) does not work #41

Open cleahcim opened 9 years ago

cleahcim commented 9 years ago

Expected behavior: Be able to write an addr that includes dot to the addr file and be able to read xdata to get the selection.

#example
echo -n .,$ | 9p write acme/$winid/addr
9p read acme/$winid/xdata

Actual behavior: The results are random, most of the time xdata is empty. Sometimes it holds the expected results, other times it is a random selection.

Button three respects the dot (.) symbol when part of an address. For example:

/path/to/my/file:.,$

if the file is open then it will select from the beginning of dot to the end of the file.

According to the docs addr should respect it as well.

It could be useful to quickly get a byte offset set addr to 0,. and read xdata and count the bytes. I know there are other ways to do this. Just mentioning a use case.

jxy commented 4 years ago

you need to hold addr open.

addr=<>{9p rdwr acme/$winid/addr} {
    9 read $addr(1)>/dev/null
    echo 'addr=dot'|9p write acme/$winid/ctl
    echo . >$addr(2)
    9 read $addr(1)
    9p read acme/$winid/xdata
}
aeggenberger commented 3 years ago

I think the docs could be more clear about this. What's the downside of making add persistent across multiple opens? Could changes to the data in the meantime invalidate the addr?

callemo commented 10 months ago

This helped me to reposition the cursor after running a code formatter. Not using rc(1) but sh(1), managed to get the cursor address with:

cur="$(perl -e '
    open $pipe, "|-", "9p rdwr acme/$ARGV[0]/addr >/dev/null" || die $!;
    system("echo addr=dot | 9p write acme/$ARGV[0]/ctl && 9p read acme/$ARGV[0]/addr");
    close $pipe || die $!;' -- "$winid" | awk '{ printf "#%d", $1 }')"