Re: move-lines.el: a lazy programmer's package to move lines around

Philip Kaludercic <[email protected]> Fri, 31 Jul 2026 18:51:01 +0000
Newsgroups gmane.emacs.devel
Message-ID <[email protected]>
Pedro Andres Aranda Gutierrez <[email protected]> writes:

> Hi Philip
>
> Thanks for the time you took to analyse this.
> I keep the functions apart because of the corner cases ;-) and
> because I use it to introduce people into intermediate Lisp
> programming.
>
> Of course it is tempting to have this added to Emacs itself.
> My main concern are potential collisions with ways of working other
> people may have developed over the years ;-)

What exactly is your concern here?  Having a command that can move
around text in an interactive setting is useful in general, but also not
something that we expect to be upgraded and extended extensively, so
having it stable and complete in core sounds like a good idea to me, as
opposed to a third-party package where the user has to first install it
and then (especially nowadays) be concerned about security risks when
upgrading.  In case you haven't seen it, I'd recommend taking a look at
https://elpa.gnu.org/contributing.html, especially the list of "soft
criteria".

> I will sleep over it starting tomorrow during my "Internet-free cure".
>
> Best, /PA
>
> On Thu, 30 Jul 2026 at 22:02, Philip Kaludercic <[email protected]> wrote:
>
>> Pedro Andres Aranda Gutierrez <[email protected]> writes:
>>
>> > Hi,
>> > I've been using this for some time now as an alternative to the move-text
>> > package and was thinking about the possibility of releasing it in elpa:
>> >
>> > https://codeberg.org/paaguti/move-lines
>>
>> I am not sure if the complexity of the package really warrants a
>> package, it is essentially just a single function that you can trim down
>> to something like
>>
>> --8<---------------cut here---------------start------------->8---
>> ;;;###autoload
>> (defun move-lines-down (arg start end)
>>   "Move region or line ARG times down.
>> Use the current line when nothing is selected.  Move full lines
>> regardless of the position of the mark and the point."
>>   (interactive
>>    (list (prefix-numeric-value current-prefix-arg)
>>          (or (use-region-beginning) (pos-bol))
>>          (or (use-region-end) (pos-eol))))
>>   (let ((start (save-excursion (goto-char start) (pos-bol)))
>>         (end (save-excursion (goto-char end) (pos-bol (if (bolp) 1 2))))
>>         (deactivate-mark nil))
>>     (goto-char (if (> arg 0) end start))
>>     (unless (= (forward-line arg) 0)
>>       (user-error "Cannot move %d lines" arg))
>>     (when (use-region-p)
>>       (set-mark (point)))
>>     (insert (delete-and-extract-region start end))))
>> --8<---------------cut here---------------end--------------->8---
>>
>> IIUC.  This is just a rough rewrite, there are likely some edge-cases
>> missing but I think something like this would be better added to Emacs
>> itself instead of as a micro-package.  But if you insist, I think we can
>> clean up the code a bit (`move-lines-down' and `move-lines-up' are
>> almost duplicates) and we could add the package to ELPA.
>>
>> >
>> > Comments highly appretiated.
>> > Best, /PA
>>