Hello,
Is it ok to apply the attached patch? I don't want to break anything.
I want to be able to denote my source blocks like so:
- *~* is the mark,
- *|* is the point
#+begin_src elisp
(~a b c| d e f g h i j k l m n o p q r s t u v w x y z)
#+end_src
- `org-edit-special' will automatically transform this markup into an
actual active region
- `org-edit-src-exit' will automatically transform an active region into markup
If anyone is interested, the implementation looks like this:
#+begin_src elisp
(defun org-src-denote-region (&optional context)
(when (and (memq major-mode '(emacs-lisp-mode))
(region-active-p))
(let ((pt (point))
(mk (mark)))
(deactivate-mark)
(insert "|")
(goto-char (if (> pt mk) mk (1+ mk)))
(insert "~"))))
(advice-add 'org-edit-src-exit :before #'org-src-denote-region)
(defun org-babel-edit-prep:elisp (info)
(when (string-match "[~|][^~|]+[|~]" (cadr info))
(let (mk pt deactivate-mark)
(goto-char (point-min))
(re-search-forward "[|~]")
(if (looking-back "~")
(progn
(backward-delete-char 1)
(setq mk (point))
(re-search-forward "|")
(backward-delete-char 1)
(set-mark mk))
(backward-delete-char 1)
(setq pt (point))
(re-search-forward "~")
(backward-delete-char 1)
(set-mark (point))
(goto-char pt)))))
#+end_src
The only thing left to do is to patch `org-edit-src-code'.
regards,
Oleh
From 66f117d3bab3be682f136a74376ac8e5ca92876a Mon Sep 17 00:00:00 2001
From: Oleh Krehel <[email protected]>
Date: Sat, 29 Nov 2014 13:20:41 +0100
Subject: [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region
* lisp/org-src.el (org-edit-src-code): Let `deactivate-mark' nil.
---
lisp/org-src.el | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 6bc2171..af5336d 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -710,7 +710,8 @@ name of the sub-editing buffer."
"example"))
(lang-f (and (eq type 'src-block) (org-src--get-lang-mode lang)))
(babel-info (and (eq type 'src-block)
- (org-babel-get-src-block-info 'light))))
+ (org-babel-get-src-block-info 'light)))
+ deactivate-mark)
(when (and (eq type 'src-block) (not (functionp lang-f)))
(error "No such language mode: %s" lang-f))
(org-src--edit-element
--
1.8.4