python buffer window on top when using python3

Bug #1579309 reported by vkoch@lbl.gov on 2016-05-07
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mode.el
Medium
Andreas Roehler

Bug Description

When using python3 as either the py-shell-name or as shebang (#! /usr/env python3) after pressing C-c C-c the python shell window pops up on top of my python file instead of below, which happens if I user "python" for the py-shell name (or shebang). This is annoying and re-aranging the buffers does not help, since the next C-c C-c messes it up again.
Interestingly it also happens if I set python2 in py-shell-nam (or shebang). So it seems it has to do with the number at the end. Same behavior if I replace python -> python. Number at the end messes things up.
This happened on a mac with OS X 10.11.4 in either aquamacs (emacs 24.4.25) or on emacs proper version 24.4.
Thanks for you help
Volker

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)

On 07.05.2016 08:30, <email address hidden> wrote:
> Public bug reported:
>
> When using python3 as either the py-shell-name or as shebang (#! /usr/env python3) after pressing C-c C-c the python shell window pops up on top of my python file instead of below, which happens if I user "python" for the py-shell name (or shebang). This is annoying and re-aranging the buffers does not help, since the next C-c C-c messes it up again.
> Interestingly it also happens if I set python2 in py-shell-nam (or shebang). So it seems it has to do with the number at the end. Same behavior if I replace python -> python. Number at the end messes things up.
> This happened on a mac with OS X 10.11.4 in either aquamacs (emacs 24.4.25) or on emacs proper version 24.4.
> Thanks for you help
> Volker
>
> ** Affects: python-mode
> Importance: Undecided
> Status: New
>

Can't reproduce with current trunk - see attachment. Might try some
recipes though when given.

Changed in python-mode:
status: New → Incomplete
vkoch@lbl.gov (vkoch) wrote :

Well, I just downloaded the latest version form the giit repository. No change. II attach some screen shots which show what I mean. I get the same result if I set py-shell-name to python3. Could it be an emacs issue. I see that you are using version 25.0 whole I have 24.4. Or could it be related to OS X vs LINUX?
As You can see from the attachment, if I use the shebang with python 3 things are upside down. Actually the same is happens if I use !#/usr/bin/env python2.
It only works correctly for !#/usr/bin/env python
So the problem is related with the number at the end. Same its true if I got from change python to ipython....
I have more screenshots but don't know how to attach more than one
Thanks
Volker

On 16.05.2016 21:45, <email address hidden> wrote:
> Well, I just downloaded the latest version form the giit repository. No change. II attach some screen shots which show what I mean. I get the same result if I set py-shell-name to python3. Could it be an emacs issue. I see that you are using version 25.0 whole I have 24.4.

Maybe, window.el was heavily developed last month.

> Or could it be related to OS X vs LINUX?
> As You can see from the attachment, if I use the shebang with python 3 things are upside down. Actually the same is happens if I use !#/usr/bin/env python2.

Hmm, whatever I try, output appears below. See from python2 attached.

> It only works correctly for !#/usr/bin/env python
> So the problem is related with the number at the end. Same its true if I got from change python to ipython....
> I have more screenshots but don't know how to attach more than one
> Thanks
> Volker
>

The whole splitting is dispatched by py--shell-manage-windows. Maybe run
this from edebug and look where it goes wrong?

Andreas Roehler (a-roehler) wrote :

On 17.05.2016 08:18, Andreas Roehler wrote:
> Maybe, window.el was heavily developed last month.

Please read month in plural, resp. last years.

vkoch@lbl.gov (vkoch) wrote :

I just upgraded to emacs 25.09, no change. Still the same problem.

When it comes to inspecting the py--shell-manage-windows I am a bit at a loss. It complains about lack of arguments. I am not a lisp expert. It seems it needs at least two arguments

(defun py--shell-manage-windows (output-buffer windows-config &optional exception-buffer)

output-buffer and windows-config

Can you provide me with a sample call to get going. If use
(py--shell-manage-wiindows py-buffer-name py-window-config) and walk through with step by step win edebug I see now real issues. When I get to

    ((and
       (eq py-split-window-on-execute 'just-two)
       (not py-switch-buffers-on-execute-p))
      (switch-to-buffer py-exception-buffer)
      (delete-other-windows)
      (unless
   (member (get-buffer-window output-buffer)(window-list))
 (py--manage-windows-split py-exception-buffer output-buffer))
      ;; Fixme: otherwise new window appears above

it opens a window above, exactly the problem what I have. But I am not sure is this is related...I see the "Fixme:" statement. This happens with both the latest git version and the version I installed from melpa

Anything I can do?

Thanks
Volker

Andreas Roehler (a-roehler) wrote :

On 17.05.2016 23:56, <email address hidden> wrote:
> I just upgraded to emacs 25.09, no change. Still the same problem.

You could call M-x edebug-defun RET when in source.
Than normally call your commands. Debugger will jump in.

However, without some elisp, this won't tell you much.

Will keep that bug in eye and work with it, as soon I have an example
which triggers it.

Download full text (3.9 KiB)

Thanks for the help to get started with edebug:
So I played around with this and identified the area where things go wrong as indicated by the comment below in the code snippet of py—shell-manage-windows

     ((and
       (eq py-split-window-on-execute 'just-two)
       (not py-switch-buffers-on-execute-p))
      (switch-to-buffer py-exception-buffer)
      (delete-other-windows)
      (unless
   (member (get-buffer-window output-buffer)(window-list))
 (py--manage-windows-split py-exception-buffer output-buffer)) ###### POINT 1
      ;; Fixme: otherwise new window appears above
      (save-excursion
 (other-window 1)
      ;;(pop-to-buffer output-buffer) ##### for whatever reason pop-to-buffer behaves differently for buffer name *Python* and *Python3*
 (switch-to-buffer output-buffer) #### using instead switch to buffer does the trick (so far ….)
 (goto-char (point-max))
 (other-window 1)))
      ((and
       py-split-window-on-execute
       (not py-switch-buffers-on-execute-p))
      ;; https://bugs.launchpad.net/python-mode/+bug/1478122
      ;; > If the shell is visible in any of the windows it should re-use that window
      ;; > I did double check and py-keep-window-configuration is nil and py-split-window-on-execute is t.

So what happens is the following
1) I start with one window with the python code
2) After completing ### POINT 1 (py--manage-windows-split py-exception-buffer output-buffer))
    I have tow windows BOTH containing the python code and the focus is on the TOP window
3) (other-window 1) changes focus to the BOTTOM window
4) (pop-to-buffer output-buffer) now put the out-buffer in the TOP window for buffer name *Python3* and in the BOTTOM window for buffer name *Python*
I can actually reproduce this somewhat erratic behavior if I do this directly from the window containing the python source code.

Not sure if this is a full fix but so far it its working for me. Probably there iris a deep reason to use (pop-to-buffer) instead of (switch-to-buffer) but this is certainly beyond my lisp skills

Thanks
Volker

> On May 17, 2016, at 11:06 PM, Andreas Roehler <email address hidden> wrote:
>
> On 17.05.2016 23:56, <email address hidden> wrote:
>> I just upgraded to emacs 25.09, no change. Still the same problem.
>
> You could call M-x edebug-defun RET when in source.
> Than normally call your commands. Debugger will jump in.
>
> However, without some elisp, this won't tell you much.
>
> Will keep that bug in eye and work with it, as soon I have an example
> which triggers it.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1579309
>
> Title:
> python buffer window on top when using python3
>
> Status in python-mode.el:
> Incomplete
>
> Bug description:
> When using python3 as either the py-shell-name or as shebang (#! /usr/env python3) after pressing C-c C-c the python shell window pops up on top of my python file instead of below, which happens if I user "python" for the py-shell name (or shebang). This is annoying and re-aranging the buffers does not help, since the next C-c C-c messes it up again.
> Int...

Read more...

vkoch@lbl.gov (vkoch) wrote :

On more thing: For completeness and to rule out any Mac related problems I just tried in my Debian8 virtual machine. Same problems there.
Volker

> On May 17, 2016, at 11:06 PM, Andreas Roehler <email address hidden> wrote:
>
> On 17.05.2016 23:56, <email address hidden> wrote:
>> I just upgraded to emacs 25.09, no change. Still the same problem.
>
> You could call M-x edebug-defun RET when in source.
> Than normally call your commands. Debugger will jump in.
>
> However, without some elisp, this won't tell you much.
>
> Will keep that bug in eye and work with it, as soon I have an example
> which triggers it.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1579309
>
> Title:
> python buffer window on top when using python3
>
> Status in python-mode.el:
> Incomplete
>
> Bug description:
> When using python3 as either the py-shell-name or as shebang (#! /usr/env python3) after pressing C-c C-c the python shell window pops up on top of my python file instead of below, which happens if I user "python" for the py-shell name (or shebang). This is annoying and re-aranging the buffers does not help, since the next C-c C-c messes it up again.
> Interestingly it also happens if I set python2 in py-shell-nam (or shebang). So it seems it has to do with the number at the end. Same behavior if I replace python -> python. Number at the end messes things up.
> This happened on a mac with OS X 10.11.4 in either aquamacs (emacs 24.4.25) or on emacs proper version 24.4.
> Thanks for you help
> Volker
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/python-mode/+bug/1579309/+subscriptions

-------------------------------------------------------------
Nuclear Science Division, MS70R0319
Lawrence Berkeley National Laboratory
Berkeley, CA 94720-8169, USA
Tel:+1-510-486-5323 Fax: +1-510-486-4794
-------------------------------------------------------------

Changed in python-mode:
status: Incomplete → In Progress
importance: Undecided → Medium
milestone: none → 6.2.3
Andreas Roehler (a-roehler) wrote :

Thanks, used your change.

Changed in python-mode:
status: In Progress → Fix Committed
vkoch@lbl.gov (vkoch) wrote :

Hi,
I just upgraded the python-mode and the problem is back...
So I went back to the old version...
Not sure if I find time to help debugging in the next several weeks
Cheers
Volker

Changed in python-mode:
milestone: 6.2.3 → 6.2.4
status: Fix Committed → New
Andreas Roehler (a-roehler) wrote :

See the bug from emacs -Q only, not with my setting, strange.

Changed in python-mode:
status: New → Confirmed
Andreas Roehler (a-roehler) wrote :

Works for me also from emacs -Q meanwhile. Please re-open if not doen.

Changed in python-mode:
status: Confirmed → Fix Committed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers