emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Le Wang <l26wang@gmail.com>
To: Nicolas Goaziou <n.goaziou@gmail.com>
Cc: Orgmode Mailing List <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] org-edit-special too much space if starting with empty block
Date: Sun, 18 Nov 2012 13:49:18 +0800	[thread overview]
Message-ID: <CAM=K+ippN-uMWSJvAU6F6cCCuzqxkiYxoP_G9OtYAAZo2GJiZA@mail.gmail.com> (raw)
In-Reply-To: <87sj8jlj4b.fsf@gmail.com>

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

  reply	other threads:[~2012-11-18  5:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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='CAM=K+ippN-uMWSJvAU6F6cCCuzqxkiYxoP_G9OtYAAZo2GJiZA@mail.gmail.com' \
    --to=l26wang@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=n.goaziou@gmail.com \
    /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).