Permalink
Browse files

Duplicate sexp as per http://inclojurewetrust.blogspot.de/2013/01/dup…

  • Loading branch information...
1 parent 1b70e3a commit 54c0fe123b5dbae1dc5435a594c09cffcc39b3b3 @bodil committed Jan 26, 2013
Showing with 26 additions and 0 deletions.
  1. +26 −0 bodil-paredit.el
View
@@ -23,4 +23,30 @@
'(define-key paredit-mode-map (kbd "M-)")
'paredit-wrap-round-from-behind))
+;; Duplicate sexp
+(defun paredit-duplicate-after-point
+ ()
+ "Duplicates the content of the line that is after the point."
+ (interactive)
+ ;; skips to the next sexp
+ (while (looking-at " ")
+ (forward-char))
+ (set-mark-command nil)
+ ;; while we find sexps we move forward on the line
+ (while (and (<= (point) (car (bounds-of-thing-at-point 'sexp)))
+ (not (= (point) (line-end-position))))
+ (forward-sexp)
+ (while (looking-at " ")
+ (forward-char)))
+ (kill-ring-save (mark) (point))
+ ;; go to the next line and copy the sexprs we encountered
+ (paredit-newline)
+ (set-mark-command nil)
+ (yank)
+ (exchange-point-and-mark))
+
+(eval-after-load "paredit"
+ '(define-key paredit-mode-map (kbd "C-c C-d")
+ 'paredit-duplicate-after-point))
+
(provide 'bodil-paredit)

0 comments on commit 54c0fe1

Please sign in to comment.