unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Pedro Andres Aranda Gutierrez <paaguti@gmail.com>
To: emacs-devel <emacs-devel@gnu.org>
Subject: Re: master 6362f65474: Add new command `duplicate-line'
Date: Sun, 19 Jun 2022 07:53:39 +0200	[thread overview]
Message-ID: <CAO48Bk8Y3mU3oECxu5S-qxhAuP4QNj4V39TVQUAKsgQqTG35GQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1189 bytes --]

Hi

I'm lagging behind the list... I recently saw the new duplicate-line
function and I feel I have an alternative, which also takes the region into
account:

;;
;; Duplicate region
;;
(defun duplicate-region-after (beg end add-cr)
  "Insert a newline and duplicate after selection"
    (let ((dupstr (buffer-substring-no-properties beg end)))
      (goto-char end)
      (when add-cr (insert "\n"))
      (insert dupstr)))

(defun duplicate-line-or-region (arg)
  "Duplicate the region or the line when nothing is selected"
  (interactive "p")
  (save-excursion
    (let ((b (if mark-active (region-beginning)
           (line-beginning-position)))
        (e (if mark-active (region-end)
           (line-end-position)))
        _ign)
      (dotimes (_ign arg)
        (duplicate-region-after b e (not mark-active)))
      )))

When and if I have CPU cycles I'd like to expand this to take a rectangular
region into account.

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

Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet

[-- Attachment #2: Type: text/html, Size: 2124 bytes --]

             reply	other threads:[~2022-06-19  5:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-19  5:53 Pedro Andres Aranda Gutierrez [this message]
     [not found] <165548727183.24473.6170306052807994962@vcs2.savannah.gnu.org>
     [not found] ` <20220617173432.17B6FC00BAF@vcs2.savannah.gnu.org>
2022-06-17 17:44   ` master 6362f65474: Add new command `duplicate-line' Visuwesh
2022-06-17 17:47     ` Lars Ingebrigtsen
2022-06-18 16:30     ` Ergus
2022-06-18 16:52       ` Eli Zaretskii
2022-06-18 22:22         ` Ergus
2022-06-19  5:55           ` Eli Zaretskii
2022-06-19 11:55           ` Andreas Schwab
2022-06-19 11:06       ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAO48Bk8Y3mU3oECxu5S-qxhAuP4QNj4V39TVQUAKsgQqTG35GQ@mail.gmail.com \
    --to=paaguti@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).