Disclaimer: I'm using Emacs Prelude, but I don't think this is a problem of that specific distribution.

Some time ago I discovered that pressing M-S-up or C-S-up with no selection just swaps the line above the current one and current one. The point stays on lower line and doesn't follow the moved line. It was not the case earlier, although I can't tell what broke it (maybe some update). The both sequences are bound to move-text-up.

move-text-down still works properly - moving unselected line and point both down.

I didn't modify my move-text.el... Toggling transient-mark-mode doesn't help either. I use move-text-20140307.1644 and GNU Emacs 24.4.1 which I built from sources myself.

How can I debug and fix the problem?..


Here is a solution:

(defun move-text-internal (arg)
   ((and mark-active transient-mark-mode)
    (let ((column (current-column))
          (pos (< (point) (mark)))
          (text (delete-and-extract-region (point) (mark))))
      (forward-line arg)
      (move-to-column column t)
      (set-mark (point))
      (insert text)
      (and pos (exchange-point-and-mark))
      (setq deactivate-mark nil)))
    (let ((column (current-column)))
      (when (or (> arg 0) (not (bobp)))
        (when (or (< arg 0) (not (eobp)))
          (transpose-lines arg)
          ;; Account for changes to transpose-lines in Emacs 24.3
          (when (and (eval-when-compile
                       (not (version-list-<
                             (version-to-list emacs-version)
                             '(24 3 50 0))))
                     (< arg 0))
            (forward-line -1)))
        (forward-line -1))
      (move-to-column column t)))))

The variable pos keeps track of where the point was to restore it. Another tricky behaviour (yet to solve) is when moving up the last line of a buffer...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.