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

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