sachac / subed

subed is a subtitle editor for Emacs
177 stars 16 forks source link

Fancy overwrite-mode when point is on a timestamp #2

Open rndusr opened 5 years ago

rndusr commented 5 years ago

It would be convenient if a timestamp could be edited by just typing the new digits without removing the old ones, i.e. what overwrite-mode (bound to Insert by default) does.

Point could also automatically skip over colons and the comma in a timestamp so that you can move point to the beginning of "00:00:00,000", type "123456789" and it would result in "12:34:56,789".

Essentially, it should be impossible to make the timestamp invalid while in subed-mode, and it should be very quick to navigate to and within timestamps and changing them.

Implementation

Text properties or overlays should make this possible, but I have no idea how exactly.

Maybe a function in modification_hooks? For overlays, these are called both before and after a buffer change. But that seems quite complicated.

There is already subed-point-motion-hook, which could be used to determine if point is on a timestamp and enable or disable overlay-mode accordingly.

Maybe it's possible to use the cursor-intangible property to implement the skipping of ":" and ","?

Is it a good idea to apply properties when loading a file or does that take too many resources? Would it be possible to add/remove properties as they come into view?

Or should there be a special mode for editing the timestamps of the current subtitle that can be enabled with a key? For example, M-RET moves point to the beginning of the start time and creates an overlay. If point is already on the start time, M-RET moves point to the stop time. If point is already on the stop time, move back to the text or original position.

mbork commented 3 years ago

You could define commands to enter digits with overwriting/skipping non-digits, define a keymap with them and use the keymap property on the timestamps.