emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-edit-special too much space if starting with empty block
@ 2012-11-05 14:31 Le Wang
  2012-11-08 12:33 ` Le Wang
  2012-11-09  0:23 ` Nicolas Goaziou
  0 siblings, 2 replies; 14+ messages in thread
From: Le Wang @ 2012-11-05 14:31 UTC (permalink / raw)
  To: Orgmode Mailing List

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

Some tests:

Case 1:

Start with emacs -Q

I insert

"
#+begin_src javascript
#+end_src
"

with point before "#+end_src", I press " C-c ' " to start editing the source

I enter "foobar" into the source buffer and immediately exit with " C-c ' "

Case 2:

restart with

"
#+begin_src javascript

#+end_src
"

I've included a patch that fixes both issues.

-- 
Le

[-- Attachment #2: org-src.el.3.diff --]
[-- Type: application/octet-stream, Size: 1412 bytes --]

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 75db1d7..064bf19 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -215,11 +215,19 @@ buffer."
     (setq org-edit-src-saved-temp-window-config (current-window-configuration)))
   (let* ((mark (and (org-region-active-p) (mark)))
 	 (case-fold-search t)
-	 (info (org-edit-src-find-region-and-lang))
+	 (info (let* ((first-pass (org-edit-src-find-region-and-lang))
+		      (first-pass-beg (nth 0 first-pass))
+		      (first-pass-end (nth 1 first-pass)))
+		 (if (< first-pass-end first-pass-beg)
+		     (progn
+		       (goto-char first-pass-beg)
+		       (insert "\n")
+		       (org-edit-src-find-region-and-lang))
+		   first-pass)))
 	 (full-info (org-babel-get-src-block-info 'light))
 	 (org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive
 	 (beg (make-marker))
-	 (end (make-marker))
+	 (end (copy-marker nil t))
 	 (allow-write-back-p (null code))
 	 block-nindent total-nindent ovl lang lang-f single lfmt buffer msg
 	 begline markline markcol line col transmitted-variables)
@@ -692,7 +700,8 @@ with \",*\", \",#+\", \",,*\" and \",,#+\"."
       (delete-region beg (max beg (1- end)))
       (unless (string-match "\\`[ \t]*\\'" code)
 	(insert code)
-	(delete-char 1))
+	(unless (= (point) end)
+	  (delete-char 1)))
       (goto-char beg)
       (if single (just-one-space)))
     (if (memq t (mapcar (lambda (overlay)

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-11-05 14:31 [PATCH] org-edit-special too much space if starting with empty block Le Wang
@ 2012-11-08 12:33 ` Le Wang
  2012-11-09  0:23 ` Nicolas Goaziou
  1 sibling, 0 replies; 14+ messages in thread
From: Le Wang @ 2012-11-08 12:33 UTC (permalink / raw)
  To: Orgmode Mailing List

Can someone take a look at these test cases and if this patch or some
other fixes is appropriate?

I use org-mode to take lots of notes of source code and this is annoying.

On Mon, Nov 5, 2012 at 10:31 PM, Le Wang <l26wang@gmail.com> wrote:
> Some tests:
>
> Case 1:
>
> Start with emacs -Q
>
> I insert
>
> "
> #+begin_src javascript
> #+end_src
> "
>
> with point before "#+end_src", I press " C-c ' " to start editing the source
>
> I enter "foobar" into the source buffer and immediately exit with " C-c ' "
>
> Case 2:
>
> restart with
>
> "
> #+begin_src javascript
>
> #+end_src
> "
>
> I've included a patch that fixes both issues.
>
> --
> Le



-- 
Le

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-11-05 14:31 [PATCH] org-edit-special too much space if starting with empty block Le Wang
  2012-11-08 12:33 ` Le Wang
@ 2012-11-09  0:23 ` Nicolas Goaziou
  2012-11-18  5:49   ` Le Wang
  1 sibling, 1 reply; 14+ messages in thread
From: Nicolas Goaziou @ 2012-11-09  0:23 UTC (permalink / raw)
  To: Le Wang; +Cc: Orgmode Mailing List

Hello,

Le Wang <l26wang@gmail.com> writes:

> Some tests:
>
> Case 1:
>
> Start with emacs -Q
>
> I insert
>
> "
> #+begin_src javascript
> #+end_src
> "
>
> with point before "#+end_src", I press " C-c ' " to start editing the source
>
> I enter "foobar" into the source buffer and immediately exit with " C-c ' "
>
> Case 2:
>
> restart with
>
> "
> #+begin_src javascript
>
> #+end_src
> "
>
> I've included a patch that fixes both issues.

Thank you for your patch.

Would you mind adding comments in the function in order to explain the
need for two pass. Also, you may want to reverse the if test in order to
get rid of the progn.

Finally, could you provide the patch as "git format-patch" and add
a changelog entry to it?


Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-11-09  0:23 ` Nicolas Goaziou
@ 2012-11-18  5:49   ` Le Wang
  2012-11-23 14:54     ` Le Wang
  0 siblings, 1 reply; 14+ messages in thread
From: Le Wang @ 2012-11-18  5:49 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Orgmode Mailing List

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

On Fri, Nov 9, 2012 at 8:23 AM, Nicolas Goaziou <n.goaziou@gmail.com> wrote:
> Thank you for your patch.
>
> Would you mind adding comments in the function in order to explain the
> need for two pass. Also, you may want to reverse the if test in order to
> get rid of the progn.

I've refactored and added comments.

> Finally, could you provide the patch as "git format-patch" and add
> a changelog entry to it?

The patch is now in the requested format.  If the commit message and
inlined comments still aren't enough to explain the changes, please
let me know.

Thanks!


-- 
Le

[-- Attachment #2: org-src.el.patch --]
[-- Type: application/octet-stream, Size: 2054 bytes --]

From ec36f46a1ac57e99e34db29cf71379d91a8d6b9b Mon Sep 17 00:00:00 2001
From: Le Wang <le.wang@agworld.com.au>
Date: Sun, 18 Nov 2012 13:39:51 +0800
Subject: [PATCH] fix org-edit-src-code for empty blocks and block with just
 an empty line

- use marker with insertion type 't to track end and remove hack requiring
  delete from `beg' to `(1- end)'
---
 lisp/org-src.el | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 75db1d7..4bd85a6 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -215,11 +215,23 @@ buffer."
     (setq org-edit-src-saved-temp-window-config (current-window-configuration)))
   (let* ((mark (and (org-region-active-p) (mark)))
 	 (case-fold-search t)
-	 (info (org-edit-src-find-region-and-lang))
+	 (info
+	  ;; if the src region consistes of no lines, we insert a
+	  ;; blank line.
+	  (let* ((temp (org-edit-src-find-region-and-lang))
+		 (beg (nth 0 temp))
+		 (end (nth 1 temp)))
+	    (if (< end beg)
+		(progn (goto-char beg)
+		       (insert "\n")
+		       (org-edit-src-find-region-and-lang))
+	      temp)))
 	 (full-info (org-babel-get-src-block-info 'light))
 	 (org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive
 	 (beg (make-marker))
-	 (end (make-marker))
+	 ;; move marker with inserted text for case when src block is
+	 ;; just one empty line, i.e. beg == end
+	 (end (copy-marker nil t))
 	 (allow-write-back-p (null code))
 	 block-nindent total-nindent ovl lang lang-f single lfmt buffer msg
 	 begline markline markcol line col transmitted-variables)
@@ -689,10 +701,9 @@ with \",*\", \",#+\", \",,*\" and \",,#+\"."
       (kill-buffer buffer))
     (goto-char beg)
     (when allow-write-back-p
-      (delete-region beg (max beg (1- end)))
+      (delete-region beg (max beg end))
       (unless (string-match "\\`[ \t]*\\'" code)
-	(insert code)
-	(delete-char 1))
+	(insert code))
       (goto-char beg)
       (if single (just-one-space)))
     (if (memq t (mapcar (lambda (overlay)
-- 
1.7.11.4

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-11-18  5:49   ` Le Wang
@ 2012-11-23 14:54     ` Le Wang
  2012-11-30 13:23       ` Nicolas Goaziou
  0 siblings, 1 reply; 14+ messages in thread
From: Le Wang @ 2012-11-23 14:54 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Orgmode Mailing List

Has anyone had a chance to check this out?  Others have run into this problem.

On Sun, Nov 18, 2012 at 1:49 PM, Le Wang <l26wang@gmail.com> wrote:
> On Fri, Nov 9, 2012 at 8:23 AM, Nicolas Goaziou <n.goaziou@gmail.com> wrote:
>> Thank you for your patch.
>>
>> Would you mind adding comments in the function in order to explain the
>> need for two pass. Also, you may want to reverse the if test in order to
>> get rid of the progn.
>
> I've refactored and added comments.
>
>> Finally, could you provide the patch as "git format-patch" and add
>> a changelog entry to it?
>
> The patch is now in the requested format.  If the commit message and
> inlined comments still aren't enough to explain the changes, please
> let me know.
>
> Thanks!
>
>
> --
> Le



-- 
Le

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-11-23 14:54     ` Le Wang
@ 2012-11-30 13:23       ` Nicolas Goaziou
  2012-12-13 14:05         ` Le Wang
  0 siblings, 1 reply; 14+ messages in thread
From: Nicolas Goaziou @ 2012-11-30 13:23 UTC (permalink / raw)
  To: Le Wang; +Cc: Orgmode Mailing List

Le Wang <l26wang@gmail.com> writes:

> Has anyone had a chance to check this out?  Others have run into this
> problem.

I've pushed your changes. Thank you.

Btw, have you signed the FSF papers for larger patches?


Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-11-30 13:23       ` Nicolas Goaziou
@ 2012-12-13 14:05         ` Le Wang
  2012-12-13 14:05           ` Nicolas Goaziou
  0 siblings, 1 reply; 14+ messages in thread
From: Le Wang @ 2012-12-13 14:05 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Orgmode Mailing List

On Fri, Nov 30, 2012 at 9:23 PM, Nicolas Goaziou <n.goaziou@gmail.com> wrote:
> I've pushed your changes. Thank you.
>
> Btw, have you signed the FSF papers for larger patches?


Thanks Nicolas.  I have signed assignment papers for Emacs.


-- 
Le

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-12-13 14:05         ` Le Wang
@ 2012-12-13 14:05           ` Nicolas Goaziou
  2012-12-13 15:15             ` Bastien
  0 siblings, 1 reply; 14+ messages in thread
From: Nicolas Goaziou @ 2012-12-13 14:05 UTC (permalink / raw)
  To: Le Wang; +Cc: Orgmode Mailing List

Le Wang <l26wang@gmail.com> writes:

> Thanks Nicolas.  I have signed assignment papers for Emacs.

Great. I have added you to the list of contributors, in Worg.


Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-12-13 14:05           ` Nicolas Goaziou
@ 2012-12-13 15:15             ` Bastien
  2012-12-13 15:53               ` Le Wang
  0 siblings, 1 reply; 14+ messages in thread
From: Bastien @ 2012-12-13 15:15 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Orgmode Mailing List, Le Wang

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Le Wang <l26wang@gmail.com> writes:
>
>> Thanks Nicolas.  I have signed assignment papers for Emacs.
>
> Great. I have added you to the list of contributors, in Worg.

Note: I did not received confirmation from the FSF yet.  
Le, did you receive it?   To be on the safe side, I try
to add people on this list only with the FSF copyright
clerk confirm the author status.  Just double-checking.

-- 
 Bastien

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-12-13 15:15             ` Bastien
@ 2012-12-13 15:53               ` Le Wang
  2012-12-13 16:00                 ` Bastien
  2012-12-13 18:09                 ` Achim Gratz
  0 siblings, 2 replies; 14+ messages in thread
From: Le Wang @ 2012-12-13 15:53 UTC (permalink / raw)
  To: Bastien; +Cc: Orgmode Mailing List, Nicolas Goaziou

On Thu, Dec 13, 2012 at 11:15 PM, Bastien <bzg@altern.org> wrote:
> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>
>> Le Wang <l26wang@gmail.com> writes:
>>
>>> Thanks Nicolas.  I have signed assignment papers for Emacs.
>>
>> Great. I have added you to the list of contributors, in Worg.
>
> Note: I did not received confirmation from the FSF yet.
> Le, did you receive it?   To be on the safe side, I try
> to add people on this list only with the FSF copyright
> clerk confirm the author status.  Just double-checking.

I'm not sure how to check, but I signed it and sent it back a while
ago and got a confirmation e-mail from Donald on Aug 9.  AFAIK
everything is sorted.


-- 
Le

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-12-13 15:53               ` Le Wang
@ 2012-12-13 16:00                 ` Bastien
  2012-12-13 18:09                 ` Achim Gratz
  1 sibling, 0 replies; 14+ messages in thread
From: Bastien @ 2012-12-13 16:00 UTC (permalink / raw)
  To: Le Wang; +Cc: Nicolas Goaziou, Orgmode Mailing List

Le Wang <l26wang@gmail.com> writes:

> I'm not sure how to check, but I signed it and sent it back a while
> ago and got a confirmation e-mail from Donald on Aug 9.  AFAIK
> everything is sorted.

Okay, thanks for confirming!

-- 
 Bastien

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-12-13 15:53               ` Le Wang
  2012-12-13 16:00                 ` Bastien
@ 2012-12-13 18:09                 ` Achim Gratz
  2012-12-13 21:53                   ` Le Wang
  1 sibling, 1 reply; 14+ messages in thread
From: Achim Gratz @ 2012-12-13 18:09 UTC (permalink / raw)
  To: emacs-orgmode

Le Wang writes:
> I'm not sure how to check, but I signed it and sent it back a while
> ago and got a confirmation e-mail from Donald on Aug 9.  AFAIK
> everything is sorted.

Did you just get a confirmation of receipt or a confirmation of the
papers having been signed and accepted?  If the latter, that email
should have had a scan of those papers added as a PDF attachment.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptations for KORG EX-800 and Poly-800MkII V0.9:
http://Synth.Stromeko.net/Downloads.html#KorgSDada

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-12-13 18:09                 ` Achim Gratz
@ 2012-12-13 21:53                   ` Le Wang
  2012-12-13 22:20                     ` Bastien
  0 siblings, 1 reply; 14+ messages in thread
From: Le Wang @ 2012-12-13 21:53 UTC (permalink / raw)
  To: Achim Gratz; +Cc: emacs-orgmode

On Fri, Dec 14, 2012 at 2:09 AM, Achim Gratz <Stromeko@nexgo.de> wrote:
> Le Wang writes:
>> I'm not sure how to check, but I signed it and sent it back a while
>> ago and got a confirmation e-mail from Donald on Aug 9.  AFAIK
>> everything is sorted.
>
> Did you just get a confirmation of receipt or a confirmation of the
> papers having been signed and accepted?  If the latter, that email
> should have had a scan of those papers added as a PDF attachment.

I have a signed and accepted PDF.  Do you want me to do something with it?


-- 
Le

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

* Re: [PATCH] org-edit-special too much space if starting with empty block
  2012-12-13 21:53                   ` Le Wang
@ 2012-12-13 22:20                     ` Bastien
  0 siblings, 0 replies; 14+ messages in thread
From: Bastien @ 2012-12-13 22:20 UTC (permalink / raw)
  To: Le Wang; +Cc: Achim Gratz, emacs-orgmode

Le Wang <l26wang@gmail.com> writes:

> I have a signed and accepted PDF.  Do you want me to do something
> with it?

Nope, it is fine.  Thanks Le!

-- 
 Bastien

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

end of thread, other threads:[~2012-12-13 22:20 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-05 14:31 [PATCH] org-edit-special too much space if starting with empty block Le Wang
2012-11-08 12:33 ` Le Wang
2012-11-09  0:23 ` Nicolas Goaziou
2012-11-18  5:49   ` Le Wang
2012-11-23 14:54     ` Le Wang
2012-11-30 13:23       ` Nicolas Goaziou
2012-12-13 14:05         ` Le Wang
2012-12-13 14:05           ` Nicolas Goaziou
2012-12-13 15:15             ` Bastien
2012-12-13 15:53               ` Le Wang
2012-12-13 16:00                 ` Bastien
2012-12-13 18:09                 ` Achim Gratz
2012-12-13 21:53                   ` Le Wang
2012-12-13 22:20                     ` Bastien

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