Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

Your bug report will be posted to the Org mailing list.
When org-edit-src-code is called with org-window-setup equal to
'split-window-below or 'split-window-right it will keep splitting the
window if the mouse is clicked on the src block in the org buffer.
This patch tries to address that

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 9134d5b5d..c7e201687 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -786,6 +786,13 @@ Raise an error when current buffer is not a source editing buffer."
   (unless (org-src-edit-buffer-p) (error "Not in a source buffer"))
+(defun org-src-select-window-for-buffer (buffer split-fun)
+  "Tries to select an existing window for buffer or splits the window."
+  (select-window
+   (or
+    (display-buffer-reuse-window buffer '())
+    (funcall split-fun))))
 (defun org-src-switch-to-buffer (buffer context)
   (pcase org-src-window-setup
     (`current-window (pop-to-buffer-same-window buffer))
@@ -794,12 +801,12 @@ Raise an error when current buffer is not a source editing buffer."
      (if (eq context 'exit)
-       (select-window (split-window-vertically)))
+       (org-src-select-window-for-buffer buffer #'split-window-vertically))
      (pop-to-buffer-same-window buffer))
      (if (eq context 'exit)
-       (select-window (split-window-horizontally)))
+       (org-src-select-window-for-buffer buffer #'split-window-horizontally))
      (pop-to-buffer-same-window buffer))
      (pcase context

Emacs  : GNU Emacs 26.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
 of 2019-07-17
Package: Org mode version 9.2.5 (release_9.2.5-504-g3c24be @ 

current state:
 org-src-mode-hook '(org-src-babel-configure-edit-buffer 
 org-link-shell-confirm-function 'yes-or-no-p
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
 org-reveal-start-hook '(org-decrypt-entry)
 org-mode-hook '(#[0 "\301\211\207" [imenu-create-index-function 
org-imenu-get-tree] 2] #[0 "\300\301\302\303\304$\207" [add-hook 
change-major-mode-hook org-show-all append local] 5]
                 #[0 "\300\301\302\303\304$\207" [add-hook 
change-major-mode-hook org-babel-show-result-all append local] 5] 
org-babel-result-hide-spec org-babel-hide-all-hashes
 org-archive-hook '(org-attach-archive-delete-maybe)
 org-confirm-elisp-link-function 'yes-or-no-p
 org-agenda-before-write-hook '(org-agenda-add-entry-text)
 org-metaup-hook '(org-babel-load-in-session-maybe)
 org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 "\n\n(fn 
 org-babel-pre-tangle-hook '(save-buffer)
 org-tab-first-hook '(org-babel-hide-result-toggle-maybe 
 org-babel-load-languages '((emacs-lisp . t) (C) (python . t) (shell . t) 
(plantuml . t))
 org-src-preserve-indentation t
 org-occur-hook '(org-first-headline-recenter)
 org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-show-empty-lines 
 org-speed-command-hook '(org-speed-command-activate 
 org-babel-tangle-lang-exts '(("D" . "d") ("C++" . "cpp") ("abc" . "abc") 
("asymptote" . "asy") ("awk" . "awk") ("clojure" . "clj") ("fortran" . "F90") 
("groovy" . "groovy")
                              ("haskell" . "hs") ("io" . "io") ("java" . 
"java") ("latex" . "tex") ("LilyPond" . "ly") ("lisp" . "lisp") ("lua" . "lua") 
("maxima" . "max") ("ocaml" . "ml")
                              ("perl" . "pl") ("picolisp" . "l") ("processing" 
. "pde") ("ruby" . "rb") ("sed" . "sed") ("vala" . "vala") ("python" . "py") 
("emacs-lisp" . "el")
                              ("elisp" . "el"))
 org-confirm-shell-link-function 'yes-or-no-p
 org-link-parameters '(("attachment" :follow org-attach-open-link :export 
org-attach-export-link :complete org-attach-complete-link) ("id" :follow 
                       ("eww" :follow eww :store org-eww-store-link) ("rmail" 
:follow org-rmail-open :store org-rmail-store-link) ("mhe" :follow org-mhe-open 
:store org-mhe-store-link)
                       ("irc" :follow org-irc-visit :store org-irc-store-link 
:export org-irc-export) ("info" :follow org-info-open :export org-info-export 
:store org-info-store-link)
                       ("gnus" :follow org-gnus-open :store 
org-gnus-store-link) ("docview" :follow org-docview-open :export 
org-docview-export :store org-docview-store-link)
                       ("bibtex" :follow org-bibtex-open :store 
                       ("bbdb" :follow org-bbdb-open :export org-bbdb-export 
:complete org-bbdb-complete-link :store org-bbdb-store-link) ("w3m" :store 
org-w3m-store-link) ("file+sys")
                       ("file+emacs") ("shell" :follow org-link--open-shell) 
("news" :follow #[257 "\301\300\302Q!\207" ["news" browse-url ":"] 5 "\n\n(fn 
                       ("mailto" :follow #[257 "\301\300\302Q!\207" ["mailto" 
browse-url ":"] 5 "\n\n(fn URL)"])
                       ("https" :follow #[257 "\301\300\302Q!\207" ["https" 
browse-url ":"] 5 "\n\n(fn URL)"])
                       ("http" :follow #[257 "\301\300\302Q!\207" ["http" 
browse-url ":"] 5 "\n\n(fn URL)"])
                       ("ftp" :follow #[257 "\301\300\302Q!\207" ["ftp" 
browse-url ":"] 5 "\n\n(fn URL)"]) ("help" :follow org-link--open-elisp) 
("file" :complete org-link-complete-file)
                       ("elisp" :follow org-link--open-elisp) ("doi" :follow 
 org-link-elisp-confirm-function 'yes-or-no-p
 org-attach-id-to-path-function 'org-attach-id-folder-format
 org-src-window-setup 'split-window-below
 org-confirm-babel-evaluate nil

Reply via email to