emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region
@ 2014-11-29 12:43 Oleh
  2014-11-29 13:33 ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Oleh @ 2014-11-29 12:43 UTC (permalink / raw)
  To: org mode

[-- Attachment #1: Type: text/plain, Size: 1526 bytes --]

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

[-- Attachment #2: 0001-org-src-allow-org-babel-edit-prep-.-to-mark-region.patch --]
[-- Type: text/x-patch, Size: 945 bytes --]

From 66f117d3bab3be682f136a74376ac8e5ca92876a Mon Sep 17 00:00:00 2001
From: Oleh Krehel <ohwoeowho@gmail.com>
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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-12-09 16:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-29 12:43 [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region Oleh
2014-11-29 13:33 ` Nicolas Goaziou
2014-11-29 13:47   ` Oleh
2014-11-29 14:15     ` Nicolas Goaziou
2014-11-29 14:34       ` Oleh
2014-12-07 23:37         ` Nicolas Goaziou
2014-12-09 11:03           ` Oleh
2014-12-09 16:12             ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).