Stealing focus: emacs, and PIL, in Windows

D

damonwischik

I'm using GNU Emacs 21.3.1 with python-mode 1.0alpha under Windows XP.
Whenever I execute a command in an edit window (with
py-execute-region), the output window steals the focus. How can I stop
this happening?

I don't know any lisp, but I hacked together this routine so that that
when I press ctrl+return the entire current block is executed.

(defun py-execute-paragraph (vis)
"Send the current paragraph to Python
Don't know what vis does."
(interactive "P")
(save-excursion
(forward-paragraph)
(let ((end (point)))
(backward-paragraph)
(py-execute-region (point) end ))))
(global-set-key [(ctrl return)] 'py-execute-paragraph)

It seems to me (though I could well be wrong) that the focus stays in
the edit window during the execution of this command (thanks to
save-excursion); but the focus shifts to the command window whenever
there is output, in this case a new prompt ">>>", in the routine
py-comint-output-filter-function. I commented out the command
(pop-to-buffer (current-buffer))
and now the command window no longer steals focus. But I don't know if
this has any other side effects, or it there's a better way to prevent
focus being stolen.

Damon.
 
G

Graham Fawcett

I'm using GNU Emacs 21.3.1 with python-mode 1.0alpha under Windows XP.
Whenever I execute a command in an edit window (with
py-execute-region), the output window steals the focus. How can I stop
this happening? [snip]
I commented out the command
(pop-to-buffer (current-buffer))
and now the command window no longer steals focus. But I don't know if
this has any other side effects, or it there's a better way to prevent
focus being stolen.

For someone who says he doesn't know Lisp, you seem to be doing just
fine. :)

Not sure if there would be side-effects. Note that py-execute-string,
py-execute-buffer, py-execute-def-or-class all use py-execute-region.
Their behaviour may be altered by your change. But it would be easy to
test.

If you did encounter a problematic side-effect, you could define your
own "py-execute-region-custom" as a copy of py-execute-region but with
the (pop-to-buffer) call removed. Then use

(require 'python-mode) ;; if you're putting this in .emacs
(define-key py-mode-map "\C-c|" 'py-execute-region-custom)

to redefine the keyboard mapping. (The (require 'python-mode) call
ensures that the py-mode-map variable has been initialized.) You could
provide an alternate mapping for your new function, of course.

If you put the custom function and your define-key call both in your
..emacs file, then you can easily port it to other machines (perh.
easier than maintaining a patch for python-mode).

Graham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top