mirror of
https://github.com/larstvei/dot-emacs.git
synced 2024-11-26 07:28:31 +00:00
Updated duplicate-thing to optionally comment out original thing.
This commit is contained in:
parent
746dbec267
commit
0f3ce6d6fd
10
init.el
10
init.el
@ -635,16 +635,18 @@ the buffer is buried."
|
|||||||
;; To duplicate either selected text or a line we define this interactive
|
;; To duplicate either selected text or a line we define this interactive
|
||||||
;; function.
|
;; function.
|
||||||
|
|
||||||
(defun duplicate-thing ()
|
(defun duplicate-thing (comment)
|
||||||
"Duplicates the current line, or the region if active."
|
"Duplicates the current line, or the region if active. If an argument is
|
||||||
(interactive)
|
given, the duplicated region will be commented out."
|
||||||
|
(interactive "P")
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let ((start (if (region-active-p) (region-beginning) (point-at-bol)))
|
(let ((start (if (region-active-p) (region-beginning) (point-at-bol)))
|
||||||
(end (if (region-active-p) (region-end) (point-at-eol))))
|
(end (if (region-active-p) (region-end) (point-at-eol))))
|
||||||
(goto-char end)
|
(goto-char end)
|
||||||
(unless (region-active-p)
|
(unless (region-active-p)
|
||||||
(newline))
|
(newline))
|
||||||
(insert (buffer-substring start end)))))
|
(insert (buffer-substring start end))
|
||||||
|
(when comment (comment-region start end)))))
|
||||||
|
|
||||||
;; To tidy up a buffer we define this function borrowed from [[https://github.com/simenheg][simenheg]].
|
;; To tidy up a buffer we define this function borrowed from [[https://github.com/simenheg][simenheg]].
|
||||||
|
|
||||||
|
10
init.org
10
init.org
@ -812,16 +812,18 @@
|
|||||||
function.
|
function.
|
||||||
|
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(defun duplicate-thing ()
|
(defun duplicate-thing (comment)
|
||||||
"Duplicates the current line, or the region if active."
|
"Duplicates the current line, or the region if active. If an argument is
|
||||||
(interactive)
|
given, the duplicated region will be commented out."
|
||||||
|
(interactive "P")
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let ((start (if (region-active-p) (region-beginning) (point-at-bol)))
|
(let ((start (if (region-active-p) (region-beginning) (point-at-bol)))
|
||||||
(end (if (region-active-p) (region-end) (point-at-eol))))
|
(end (if (region-active-p) (region-end) (point-at-eol))))
|
||||||
(goto-char end)
|
(goto-char end)
|
||||||
(unless (region-active-p)
|
(unless (region-active-p)
|
||||||
(newline))
|
(newline))
|
||||||
(insert (buffer-substring start end)))))
|
(insert (buffer-substring start end))
|
||||||
|
(when comment (comment-region start end)))))
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
To tidy up a buffer we define this function borrowed from [[https://github.com/simenheg][simenheg]].
|
To tidy up a buffer we define this function borrowed from [[https://github.com/simenheg][simenheg]].
|
||||||
|
Loading…
Reference in New Issue
Block a user