From: Oleh <ohwoeowho@gmail.com>
To: org mode <emacs-orgmode@gnu.org>
Subject: [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region
Date: Sat, 29 Nov 2014 13:43:14 +0100 [thread overview]
Message-ID: <CAA01p3r6qTFjFH8+Gi=-teAAqsUhu9_spqJdY91R8E8sgLbEng@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2014-11-29 12:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-29 12:43 Oleh [this message]
2014-11-29 13:33 ` [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAA01p3r6qTFjFH8+Gi=-teAAqsUhu9_spqJdY91R8E8sgLbEng@mail.gmail.com' \
--to=ohwoeowho@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).