]> code.delx.au - dotemacs/commitdiff
smarter yank
authorJames Bunton <jamesbunton@delx.net.au>
Wed, 27 Jul 2016 15:25:34 +0000 (01:25 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Wed, 27 Jul 2016 15:26:47 +0000 (01:26 +1000)
lisp/my-defuns.el
lisp/my-keys.el

index 2232e79e2cab6c1e482642c56911a0c58354c97a..1e1a6303e23764ea80c64608d3ed79b39f5a3490 100644 (file)
   (beginning-of-line)
   (kill-line arg)
   (indent-for-tab-command))
+
+(defun my/yank (arg)
+  "If the text to be yanked has a newline then move to beginning of line before yanking. Otherwise same as normal `yank'."
+  (interactive "*P")
+  (advice-add 'insert-for-yank :around #'my/yank/advice)
+  (unwind-protect
+      (yank arg)
+    (advice-remove 'insert-for-yank #'my/yank/advice)))
+
+(defun my/yank/advice (original-function string)
+  (if (string-match-p "\n" string)
+      (beginning-of-line))
+  (funcall original-function string))
index 5fbef901e625bc7b95c6271c8ecdc0e98b689ad2..29c9f1e2c2ec4882e94c6cc6837e4923e60d14ff 100644 (file)
@@ -51,6 +51,7 @@
 (global-set-key (kbd "C-c m") 'mc/mark-more-like-this-extended)
 
 ;; Killing and deleting
+(global-set-key (kbd "C-y") 'my/yank)
 (global-set-key (kbd "M-y") 'counsel-yank-pop)
 (global-set-key (kbd "M-z") 'zap-up-to-char)
 (global-set-key (kbd "C-c k") 'kill-whole-line)