coteditor / cot

Command-line helper tool for CotEditor
https://coteditor.com/cot
Apache License 2.0
55 stars 11 forks source link

Please add a cot option to place cursor after last character in file #8

Closed drq883 closed 5 years ago

drq883 commented 5 years ago

Environment

Short Description

I have an automated process that pops up a cotedit window every hour and prompts me for input. It would be nice for an option to be added, maybe --endoffile that would place the cursor on the very last character. I used to use wc -l on the file, add 1 to that value and add options --line <count> --column 99, but that stopped working. Most of the time now, it puts the cursor on the very first byte.

Steps to Reproduce the Issue

It's not an issue, just a request

Expected Result

Running cot --endoffile <filename> would edit the file and position cursor after last byte.

1024jp commented 5 years ago

Oh sorry, this must be a side effect that I changed the internal character counting algorithm for scripting and cot command. I forgot to write the change in the release notes.

By the way, current --line option accepts also a negative number, and it means counting lines from the end. In addition, I changed the character location counting from 0-based to 1-based in the next version (cf. #826). Therefore, I need anyway change also the current behavior of cot command for --column option. So, in the next version, I will make cot --line -1 --column -1 <filename> put the cursor at the end of the document. This may better than introducing a new option, such as --endoffile ;-)

(And it seems I also need to write documentation about this negative character/line number rule.)

drq883 commented 5 years ago

Thanks.

I've modified my code to use --line -1 and it works perfectly.

I look forward to --column -1 working and until then I'm figuring the column with:

$column = int(`tail -1 $file | tr -d '\n'|wc -c`);