eaburns / T

T is a work-in-progress text editor inspired by the Acme editor from Plan9.
MIT License
8 stars 1 forks source link

edit: set dot if command is empty #22

Closed ktye closed 5 years ago

ktye commented 5 years ago

From the sam manual:

Sam is most commonly run connected to a bitmap display and mouse for interactive editing. 
The only difference in the command language between regular,
mouse-driven sam and sam -d is that if an address is provided without a command,
sam -d will print the text referenced by the address, 
but regular sam will highlight it on the screen — in fact, dot is always highlighted

Should edit.Edit return a Diff that updates the dot if no command is given? Currently it returns the error "no command".

eaburns commented 5 years ago

This was done on purpose. The edit package is stateless, so there is no dot to set.

However, the ui package isn't stateless, and we will want to set dot when the user gives an Edit command with only an address. We can get to that when we implement Edit.

In general, sam and the sam manual are useful references, but I don't consider it to be the specification for how T should behave. There are some points where I choose to deviate from sam on purpose. This is one such place.

eaburns commented 5 years ago

For the record, the way to handle this is that edit.Edit should return a named error type in the case of "no command":

// NoCommandError is returned when there was no command to execute.
type NoCommandError struct {
  // At contains the evaluation of the address preceding the missing command.
  // An empty address is dot, so an empty edit results in a NoCommandError
  // At set to the value of dot.
  At [2]int64
}

Then the caller, who is the one responsible for maintaining state, can set their dot.

eaburns commented 5 years ago

The title is a bit off, because we won't be setting dot, but just returning a valid dot. But this should be open (especially since there is a fix for it coming).