From b2c5eb674ffc0831fb10184ebfb928ffd28ca19d Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Fri, 17 Mar 2017 14:10:52 +0100 Subject: [PATCH] added xah-copy-line-or-region borrowed from http://ergoemacs.org/emacs/emacs_copy_cut_current_line.html Signed-off-by: Andreas Gerler --- bba.org | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/bba.org b/bba.org index f116b4f5..8cb4726c 100644 --- 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 -- 2.47.3