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

* Re: [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region
  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
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2014-11-29 13:33 UTC (permalink / raw)
  To: Oleh; +Cc: org mode

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

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

* Re: [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region
  2014-11-29 13:33 ` Nicolas Goaziou
@ 2014-11-29 13:47   ` Oleh
  2014-11-29 14:15     ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Oleh @ 2014-11-29 13:47 UTC (permalink / raw)
  To: Oleh, org mode

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

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

* Re: [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region
  2014-11-29 13:47   ` Oleh
@ 2014-11-29 14:15     ` Nicolas Goaziou
  2014-11-29 14:34       ` Oleh
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2014-11-29 14:15 UTC (permalink / raw)
  To: Oleh; +Cc: org mode

>> 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,

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

* Re: [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region
  2014-11-29 14:15     ` Nicolas Goaziou
@ 2014-11-29 14:34       ` Oleh
  2014-12-07 23:37         ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Oleh @ 2014-11-29 14:34 UTC (permalink / raw)
  To: org mode

>>> 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

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

* Re: [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region
  2014-11-29 14:34       ` Oleh
@ 2014-12-07 23:37         ` Nicolas Goaziou
  2014-12-09 11:03           ` Oleh
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2014-12-07 23:37 UTC (permalink / raw)
  To: Oleh; +Cc: org mode

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,

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

* Re: [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region
  2014-12-07 23:37         ` Nicolas Goaziou
@ 2014-12-09 11:03           ` Oleh
  2014-12-09 16:12             ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Oleh @ 2014-12-09 11:03 UTC (permalink / raw)
  To: org mode

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

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

* Re: [PATCH] org-src: allow `org-babel-edit-prep:.*' to mark region
  2014-12-09 11:03           ` Oleh
@ 2014-12-09 16:12             ` Nicolas Goaziou
  0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Goaziou @ 2014-12-09 16:12 UTC (permalink / raw)
  To: Oleh; +Cc: org mode

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,

^ permalink raw reply	[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).