wyuenho / move-dup

Emacs minor mode for Eclipse-like moving and duplications of lines or selections with convenient key bindings.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue moving empty lines

Ergus opened this issue · comments

Hi:

I have been using move-dup as a replacement for move-text. But there is an issue when I try to move empty lines, because they are not recognized and are not moved. Commands like md-move-lines-down only moves non empty lines.

Comparing the codes the main difference sems to be that move-text uses transpose-lines for lines like:

(defun move-text-line-up ()
  "Move the current line up."
  (interactive)
    (if (move-text--at-last-line-p)
        (let ((target-point))
          (kill-whole-line)
          (forward-line -1)
          (beginning-of-line)
          (setq target-point (point))
          (yank)
          (unless (looking-at "\n")
            (newline))
          (goto-char target-point))
      (let ((col (current-column)))
        (progn (transpose-lines 1)
               (forward-line -2)
               (move-to-column col)))))

(defun move-text-line-down ()
  "Move the current line down."
  (interactive)
  (unless (or
           (move-text--at-last-line-p)
           (and
            (move-text--last-line-is-just-newline)
            (move-text--at-penultimate-line-p)))
    (let ((col (current-column)))
      (forward-line 1)
      (transpose-lines 1)
      (forward-line -1)
      (move-to-column col))))

Thanks for the report. Can you show me a reproduction so I can understand the problem a little better?

Suppose we have this

aaa
X
bbb
ccc

where X is the cursor.

If you try md-move-lines-down/up there. then nothing happens because in empty lines the end of line is the same than the beginning so the region is empty. I proposed a solution in #14 that works perfectly for me.