unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: master 6362f65474: Add new command `duplicate-line'
@ 2022-06-19  5:53 Pedro Andres Aranda Gutierrez
  0 siblings, 0 replies; 10+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2022-06-19  5:53 UTC (permalink / raw)
  To: emacs-devel

[-- 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 --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-06-19 17:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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
2022-06-19 17:10         ` [External] : " Drew Adams
2022-06-19  5:53 Pedro Andres Aranda Gutierrez

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).