]> git.bundesbrandschatzamt.de Git - emacsconfig.git/commitdiff
added xah-copy-line-or-region
authorAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Fri, 17 Mar 2017 13:10:52 +0000 (14:10 +0100)
committerAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Fri, 17 Mar 2017 13:10:52 +0000 (14:10 +0100)
borrowed from http://ergoemacs.org/emacs/emacs_copy_cut_current_line.html

Signed-off-by: Andreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
bba.org

diff --git a/bba.org b/bba.org
index f116b4f5047d41489f027c3d51031cbd61c61c42..8cb4726c50d5562d639fb02e8cc4166373046b21 100644 (file)
--- a/bba.org
+++ b/bba.org
@@ -2753,6 +2753,46 @@ Thanks to [[http://ergoemacs.org/emacs/emacs_keybinding_design_beginning-of-line
 
 #+END_SRC
 
+* [[http://ergoemacs.org/emacs/emacs_copy_cut_current_line.html][xah-copy-line-or-region]]
+[2017-03-17 Fri 14:07]
+
+#+BEGIN_SRC emacs-lisp :tangle yes
+  (defun xah-copy-line-or-region ()
+    "Copy current line, or text selection.
+  When called repeatedly, append copy subsequent lines.
+  When `universal-argument' is called first, copy whole buffer (respects `narrow-to-region').
+
+  URL `http://ergoemacs.org/emacs/emacs_copy_cut_current_line.html'
+  Version 2016-06-18"
+    (interactive)
+    (let (-p1 -p2)
+      (if current-prefix-arg
+          (setq -p1 (point-min) -p2 (point-max))
+       (if (use-region-p)
+            (setq -p1 (region-beginning) -p2 (region-end))
+          (setq -p1 (line-beginning-position) -p2 (line-end-position))))
+      (if (eq last-command this-command)
+          (progn
+            (progn ; hack. exit if there's no more next line
+              (end-of-line)
+              (forward-char)
+              (backward-char))
+            ;; (push-mark (point) "NOMSG" "ACTIVATE")
+            (kill-append "\n" nil)
+            (kill-append (buffer-substring-no-properties (line-beginning-position) (line-end-position)) nil)
+            (message "Line copy appended"))
+       (progn
+          (kill-ring-save -p1 -p2)
+          (if current-prefix-arg
+              (message "Buffer text copied")
+            (message "Text copied"))))
+      (end-of-line)
+      (forward-char)
+      ))
+
+  (define-key global-map (kbd "M-w") 'xah-copy-line-or-region)
+#+END_SRC
+
 * copy buffer file name to kill ring
 
 Sometimes you need the filename of your current buffer on the command