abo-abo / avy

Jump to things in Emacs tree-style
1.72k stars 110 forks source link

A space is left behind on an empty line after teleporting #229

Open duianto opened 6 years ago

duianto commented 6 years ago

A space is left behind on an empty line after teleporting.

Steps to reproduce

  1. Start Emacs
  2. Type:
    one
    two
    three
  3. Place the cursor on the o in one
  4. M-x avy-goto-line
  5. Press t (teleport action) and s (the second line)

Observed

twoone

three

there's a space character on the second line, It's easier to see with M-x whitespace-mode.

Expected

No space character on the second line.

Possible cause

(just-one-space) is called in the avy-action-kill-stay function: https://github.com/abo-abo/avy/blob/6459f7f12aef1e71ff5e265b1edb414fd81123e6/avy.el#L682

Possible solution:

(just-one-space) should probably be excluded, when the teleported line becomes empty.

Maybe something like this:

(unless (and (bolp) (eolp))
      (just-one-space))

Additional notes:

Teleport first and last word

When the first or last word of a line is teleported, then a space is left behind. For example with this sample text:

one two three
four five six
  1. With the cursor on o in one
  2. M-x avy-goto-word-1
  3. Press: t to target all words starting with t
  4. Press: t to start the teleport action
  5. Press: s to target the word three
  6. This results in:
threeone two 
four five six

with a space after two. (the space was not inserted by the (just-one-space) command, it remained after the word three was killed, then the just-one-space command ran, but nothing changed, since there already was a single space).

Teleporting the first word on the second line: Continuing from the result in the example above

  1. With the cursor on t in three
  2. M-x avy-goto-word-1
  3. Press f to target words starting with f
  4. Press t to start the teleport action
  5. Press a to target the word four
  6. This results in:
    fourthreeone two 
    five six

    with a space before five.

Maybe the leading and trailing spaces also should be removed?

System info

Windows 10 Version 1709 (OS Build 16299.125) GNU Emacs 25.3.1 (x86_64-w64-mingw32) of 2017-09-26 and GNU Emacs 26.0.50 (build 4, x86_64-w64-mingw32) of 2017-08-07 Avy Version 0.4.0