[-- 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
Hello,
Oleh <ohwoeowho@gmail.com> writes:
> 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
I don't understand what your use-case is. Note that `org-edit-special'
already preserves region.
Regards,
--
Nicolas Goaziou
Hi Nicolas,
> I don't understand what your use-case is. Note that `org-edit-special'
> already preserves region.
That's good, but not what I need. I want to go from an unmarked region
in an org file with markup
to a marked region without markup in the *Org Src* buffer.
I've defined a custom `org-babel-edit-prep:elisp' that does this, but
it's not allowed to mark region in this function. A patch to
`org-edit-src-code' is required for this.
Just to sum it up: I want a custom `org-babel-edit-prep:elisp' to be
able to mark region, even if it wasn't marked before.
regards,
Oleh
>> I don't understand what your use-case is. Note that `org-edit-special' >> already preserves region. > > That's good, but not what I need. I want to go from an unmarked region > in an org file with markup > to a marked region without markup in the *Org Src* buffer. That still doesn't explain why you need it. > I've defined a custom `org-babel-edit-prep:elisp' that does this, but > it's not allowed to mark region in this function. Why? > Just to sum it up: I want a custom `org-babel-edit-prep:elisp' to be > able to mark region, even if it wasn't marked before. Your markup is very personal. I still don't see the need to turn it into a general mechanism. Isn't an advice enough? Regards,
>>> I don't understand what your use-case is. Note that `org-edit-special' >>> already preserves region. >> >> That's good, but not what I need. I want to go from an unmarked region >> in an org file with markup >> to a marked region without markup in the *Org Src* buffer. > > That still doesn't explain why you need it. To automate things. I'm writing a function reference for a package here: https://raw.githubusercontent.com/abo-abo/lispy/gh-pages/index.org. Here's the link in case you don't want to compile the org-file: http://abo-abo.github.io/lispy/. Some of the source blocks in this document feature a marked region that I export marked to HTML. Most source blocks are step-by-step examples that assume a certain point and region state in order to work. And it's nice to automatically set the region state in order to text out an example. > >> I've defined a custom `org-babel-edit-prep:elisp' that does this, but >> it's not allowed to mark region in this function. > > Why? Well, I can call `set-mark' in this function, but it won't work unless the function that calls it binds `deactivate-mark' to nil. > >> Just to sum it up: I want a custom `org-babel-edit-prep:elisp' to be >> able to mark region, even if it wasn't marked before. > > Your markup is very personal. I still don't see the need to turn it into > a general mechanism. Well, I'm not trying to push my markup or anything, I just want my custom `org-babel-edit-prep:elisp' to be able to mark the region. Currently I'm not given that option. > Isn't an advice enough? I don't know how this would work. `org-babel-edit-prep:elisp' is already the exit point of `org-edit-src-code' and it's not allowed to mark the region. regards, Oleh
Oleh <ohwoeowho@gmail.com> writes:
> Well, I'm not trying to push my markup or anything, I just want my
> custom `org-babel-edit-prep:elisp' to be able to mark the region.
> Currently I'm not given that option.
Understood.
Would you mind providing a patch with format-patch, and reference the
current thread in the commit message?
Regards,
Hi Nicolas, >> Well, I'm not trying to push my markup or anything, I just want my >> custom `org-babel-edit-prep:elisp' to be able to mark the region. >> Currently I'm not given that option. > > Understood. > > Would you mind providing a patch with format-patch, and reference the > current thread in the commit message? I can just push it through if you don't mind. I have push access. Is this OK as reference: http://article.gmane.org/gmane.emacs.orgmode/93053 ? regards, Oleh
Oleh <ohwoeowho@gmail.com> writes: >> Would you mind providing a patch with format-patch, and reference the >> current thread in the commit message? > > I can just push it through if you don't mind. I have push access. Sure, go ahead. Thank you. > Is this OK as reference: > http://article.gmane.org/gmane.emacs.orgmode/93053 ? It is. Regards,