From: Andreas Gerler Date: Sun, 19 Mar 2017 13:12:17 +0000 (+0100) Subject: modified bba-copy-and-yank-org-src-block X-Git-Url: http://git.bundesbrandschatzamt.de/?a=commitdiff_plain;h=41e2ab53e32abc12a1fbaf050e277228605f1338;p=emacsconfig.git modified bba-copy-and-yank-org-src-block - if region marked copy only the BEGIN_SRC and END_SRC lines of previous src block. Useful if you have parameters in it. Signed-off-by: Andreas Gerler --- diff --git a/bba.org b/bba.org index 4ece8e53..b6309e7d 100644 --- a/bba.org +++ b/bba.org @@ -1026,20 +1026,48 @@ This is helpful in training sessions. #+BEGIN_SRC emacs-lisp :tangle yes (defun bba-copy-and-yank-org-src-block() - "copy last org src block and insert it at point." + "copy last org src block and insert it at point. + If region is active copy only the src begin and src end lines." (interactive) - (push-mark) - (re-search-backward "\#\\+BEGIN_SRC") - (set-mark-command nil) - (re-search-forward "\#\\+END_SRC") - (forward-line) - (beginning-of-line) - (kill-ring-save 1 1 1) - (set-mark-command '1) - (set-mark-command '1) - (insert (pop kill-ring)) - (re-search-backward "\#\\+BEGIN_SRC") - (forward-line) + (if (use-region-p) + (progn + (let (-p1 -p2 srclength) + (setq -p1 (region-beginning) -p2 (region-end)) + (setq mark-active nil) + (re-search-backward "\#\\+BEGIN_SRC") + (set-mark-command nil) + (forward-line) + (beginning-of-line) + (kill-ring-save 1 1 1) + (goto-char -p1) + (set-mark-command nil) + (insert (pop kill-ring)) + (setq srclength (- (region-end) (region-beginning))) + (setq mark-active nil) + (re-search-backward "\#\\+END_SRC") + (set-mark-command nil) + (forward-line) + (beginning-of-line) + (kill-ring-save 1 1 1) + (kill-append "\n" nil) + (goto-char (+ -p2 srclength)) + (insert (pop kill-ring)) + ) + ) + (progn + (push-mark) + (re-search-backward "\#\\+BEGIN_SRC") + (set-mark-command nil) + (re-search-forward "\#\\+END_SRC") + (forward-line) + (beginning-of-line) + (kill-ring-save 1 1 1) + (set-mark-command '1) + (set-mark-command '1) + (insert (pop kill-ring)) + (re-search-backward "\#\\+BEGIN_SRC") + (forward-line) + )) ) (defun bba-copy-org-src-block()