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

Pedro Andres Aranda Gutierrez <[email protected]> Fri, 31 Jul 2026 11:04:07 +0200
Newsgroups gmane.emacs.devel
Message-ID <CAO48Bk-C4d08GPs9B+p2HsRd39L9NKiU7-oxfRam1-g0Gh8efA@mail.gmail.com>
Just before leaving, I've pushed a new version on my codeberg.

Functions: two just to make the keybindings easier, one which all the meat
in it.

When I return, we can discuss whether it merits to be in Emacs or it would
stir up controversy.

Nice summer, /PA

On Fri, 31 Jul 2026 at 06:55, Pedro Andres Aranda Gutierrez <
[email protected]> wrote:

> 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 ;-)
> 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
>>
>
>
> --
> Fragen sind nicht da, um beantwortet zu werden,
> Fragen sind da um gestellt zu werden
> Georg Kreisler
>
> "Sagen's Paradeiser" (ORF: Als Radiohören gefährlich war) => write BE!
> Year 2 of the New Koprocracy
>
> *IA: onomatopeya del rebuznar*
>
> This was produced by a human (implied virtues and weaknesses acknowledged)
> Don't feed your ArtStup (SKA AI) with this. It won't make YOU smarter...
>


-- 
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

"Sagen's Paradeiser" (ORF: Als Radiohören gefährlich war) => write BE!
Year 2 of the New Koprocracy

*IA: onomatopeya del rebuznar*

This was produced by a human (implied virtues and weaknesses acknowledged)
Don't feed your ArtStup (SKA AI) with this. It won't make YOU smarter...