unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Patch to optionally show Python process buffer after C-c C-c
@ 2012-06-17 13:03 Deniz Dogan
  2012-06-17 19:13 ` Glenn Morris
  0 siblings, 1 reply; 10+ messages in thread
From: Deniz Dogan @ 2012-06-17 13:03 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 199 bytes --]

I got tired of repeatedly switching to the Python process buffer after 
using C-c C-c in python-mode, so here is a patch which gives users the 
option to do that automatically.

Any comments?

Deniz

[-- Attachment #2: python-patch.diff --]
[-- Type: text/plain, Size: 1295 bytes --]

=== modified file 'lisp/progmodes/python.el'
--- lisp/progmodes/python.el	2012-06-06 13:05:11 +0000
+++ lisp/progmodes/python.el	2012-06-17 13:00:00 +0000
@@ -541,6 +541,15 @@
   :group 'python
   :version "24.1")

+(defcustom python-show-process-buffer-on-send nil
+  "Whether or not to show the Python process buffer after sending
+a region to the Python process."
+  :type '(choice (const :tag "No" nil)
+                 (const :tag "In current window" current)
+		 (const :tag "In another window" other))
+  :group 'python
+  :version "24.1")
+
 (defvar python-pdbtrack-is-tracking-p nil)

 (defconst python-pdbtrack-stack-entry-regexp
@@ -1628,7 +1637,11 @@
       ;; Tell compile.el to redirect error locations in file `f' to
       ;; positions past marker `orig-start'.  It has to be done *after*
       ;; `python-send-command''s call to `compilation-forget-errors'.
-      (compilation-fake-loc orig-start f))))
+      (compilation-fake-loc orig-start f)
+      (cond ((eq python-show-process-buffer-on-send 'other)
+             (switch-to-buffer-other-window (current-buffer)))
+            ((eq python-show-process-buffer-on-send 'current)
+             (switch-to-buffer (current-buffer)))))))

 (defun python-send-string (string)
   "Evaluate STRING in inferior Python process."

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch to optionally show Python process buffer after C-c C-c
  2012-06-17 13:03 Patch to optionally show Python process buffer after C-c C-c Deniz Dogan
@ 2012-06-17 19:13 ` Glenn Morris
  2012-06-17 20:31   ` Deniz Dogan
  0 siblings, 1 reply; 10+ messages in thread
From: Glenn Morris @ 2012-06-17 19:13 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: emacs-devel

Deniz Dogan wrote:

> I got tired of repeatedly switching to the Python process buffer after
> using C-c C-c in python-mode, so here is a patch which gives users the
> option to do that automatically.
>
> Any comments?

Your patch seems to be against the 24.1 version of python.el. I'm afraid
the trunk version is very different, so you will have to rework your
patch (it might not even be necessary any more).



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch to optionally show Python process buffer after C-c C-c
  2012-06-17 19:13 ` Glenn Morris
@ 2012-06-17 20:31   ` Deniz Dogan
  2012-06-18 17:56     ` Glenn Morris
  0 siblings, 1 reply; 10+ messages in thread
From: Deniz Dogan @ 2012-06-17 20:31 UTC (permalink / raw)
  To: Glenn Morris; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 540 bytes --]

On 2012-06-17 21:13,, Glenn Morris wrote:
> Deniz Dogan wrote:
>
>> I got tired of repeatedly switching to the Python process buffer after
>> using C-c C-c in python-mode, so here is a patch which gives users the
>> option to do that automatically.
>>
>> Any comments?
>
> Your patch seems to be against the 24.1 version of python.el. I'm afraid
> the trunk version is very different, so you will have to rework your
> patch (it might not even be necessary any more).
>

Sorry about that.  Here is a refined patch from the current trunk.



[-- Attachment #2: new-python-patch.diff --]
[-- Type: text/plain, Size: 1367 bytes --]

=== modified file 'lisp/progmodes/python.el'
--- lisp/progmodes/python.el	2012-06-17 08:53:31 +0000
+++ lisp/progmodes/python.el	2012-06-17 20:30:39 +0000
@@ -1328,6 +1328,15 @@
   :type '(alist string)
   :group 'python)

+(defcustom python-show-process-buffer-on-send nil
+  "Whether or not to show the Python process buffer after sending
+a region to the Python process."
+  :type '(choice (const :tag "No" nil)
+                 (const :tag "In current window" current)
+		 (const :tag "In another window" other))
+  :group 'python
+  :version "24.1")
+
 (defun python-shell-get-process-name (dedicated)
   "Calculate the appropriate process name for inferior Python process.
 If DEDICATED is t and the variable `buffer-file-name' is non-nil
@@ -1592,7 +1601,11 @@
       (comint-send-string process string)
       (when (or (not (string-match "\n$" string))
                 (string-match "\n[ \t].*\n?$" string))
-        (comint-send-string process "\n")))))
+        (comint-send-string process "\n")))
+    (cond ((eq python-show-process-buffer-on-send 'other)
+           (switch-to-buffer-other-window (current-buffer)))
+          ((eq python-show-process-buffer-on-send 'current)
+           (switch-to-buffer (current-buffer))))))

 (defun python-shell-send-string-no-output (string &optional process msg)
   "Send STRING to PROCESS and inhibit output.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch to optionally show Python process buffer after C-c C-c
  2012-06-17 20:31   ` Deniz Dogan
@ 2012-06-18 17:56     ` Glenn Morris
  2012-06-18 18:03       ` Deniz Dogan
  0 siblings, 1 reply; 10+ messages in thread
From: Glenn Morris @ 2012-06-18 17:56 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: emacs-devel

Deniz Dogan wrote:

> +(defcustom python-show-process-buffer-on-send nil
> +  "Whether or not to show the Python process buffer after sending
> +a region to the Python process."

The first line of a doc string should be a complete sentence.

> +  :version "24.1")

24.2



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch to optionally show Python process buffer after C-c C-c
  2012-06-18 17:56     ` Glenn Morris
@ 2012-06-18 18:03       ` Deniz Dogan
  2012-06-18 18:20         ` Glenn Morris
  0 siblings, 1 reply; 10+ messages in thread
From: Deniz Dogan @ 2012-06-18 18:03 UTC (permalink / raw)
  To: Glenn Morris; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 365 bytes --]

On 2012-06-18 19:56,, Glenn Morris wrote:
> Deniz Dogan wrote:
>
>> +(defcustom python-show-process-buffer-on-send nil
>> +  "Whether or not to show the Python process buffer after sending
>> +a region to the Python process."
>
> The first line of a doc string should be a complete sentence.
>
>> +  :version "24.1")
>
> 24.2
>

Attached the changes you requested.

[-- Attachment #2: new-python-patch-2.diff --]
[-- Type: text/plain, Size: 1454 bytes --]

=== modified file 'lisp/progmodes/python.el'
--- lisp/progmodes/python.el	2012-06-17 08:53:31 +0000
+++ lisp/progmodes/python.el	2012-06-18 18:03:07 +0000
@@ -1328,6 +1328,16 @@
   :type '(alist string)
   :group 'python)

+(defcustom python-show-process-buffer-on-send nil
+  "If non-nil, show the process buffer after sending.
+If the value is `current', show the process buffer in the current
+window.  If the value is `other', display it in another window."
+  :type '(choice (const :tag "No" nil)
+                 (const :tag "In current window" current)
+		 (const :tag "In another window" other))
+  :group 'python
+  :version "24.2")
+
 (defun python-shell-get-process-name (dedicated)
   "Calculate the appropriate process name for inferior Python process.
 If DEDICATED is t and the variable `buffer-file-name' is non-nil
@@ -1592,7 +1602,11 @@
       (comint-send-string process string)
       (when (or (not (string-match "\n$" string))
                 (string-match "\n[ \t].*\n?$" string))
-        (comint-send-string process "\n")))))
+        (comint-send-string process "\n")))
+    (cond ((eq python-show-process-buffer-on-send 'other)
+           (switch-to-buffer-other-window (current-buffer)))
+          ((eq python-show-process-buffer-on-send 'current)
+           (switch-to-buffer (current-buffer))))))

 (defun python-shell-send-string-no-output (string &optional process msg)
   "Send STRING to PROCESS and inhibit output.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch to optionally show Python process buffer after C-c C-c
  2012-06-18 18:03       ` Deniz Dogan
@ 2012-06-18 18:20         ` Glenn Morris
       [not found]           ` <CABq4mQtPF8Sns2Pf0U8pw+oaJ9pnxser7-oiaCng8J3kTxHyiA@mail.gmail.com>
  0 siblings, 1 reply; 10+ messages in thread
From: Glenn Morris @ 2012-06-18 18:20 UTC (permalink / raw)
  To: Deniz Dogan; +Cc: fabian, emacs-devel


I tested it with M-x python-shell-send-string and it has no effect.
Use process-buffer to get the actual buffer to switch to?
The command python-shell-switch-to-shell does this.
So maybe just add an option to call that at the end of
python-shell-send-string?

In line with current python name space, the option should probably be
called python-shell-something.

I don't use python much, so I'll cc the mode's author.

Context is here:

http://lists.gnu.org/archive/html/emacs-devel/2012-06/msg00272.html



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch to optionally show Python process buffer after C-c C-c
       [not found]           ` <CABq4mQtPF8Sns2Pf0U8pw+oaJ9pnxser7-oiaCng8J3kTxHyiA@mail.gmail.com>
@ 2012-06-18 21:32             ` Glenn Morris
  2012-06-18 23:41               ` Glenn Morris
  0 siblings, 1 reply; 10+ messages in thread
From: Glenn Morris @ 2012-06-18 21:32 UTC (permalink / raw)
  To: Emacs developers; +Cc: Fabian Ezequiel Gallina


Looks like the following reply was sent just to me, so I am resending
this to emacs-devel:

Fabian Ezequiel Gallina wrote (on Mon, 18 Jun 2012 at 16:12 -0300):

> 2012/6/18 Glenn Morris <rgm@gnu.org>:
> >
> > I tested it with M-x python-shell-send-string and it has no effect.
> > Use process-buffer to get the actual buffer to switch to?
> > The command python-shell-switch-to-shell does this.
> > So maybe just add an option to call that at the end of
> > python-shell-send-string?
> >
> > In line with current python name space, the option should probably be
> > called python-shell-something.
> >
> > I don't use python much, so I'll cc the mode's author.
> >
> > Context is here:
> >
> > http://lists.gnu.org/archive/html/emacs-devel/2012-06/msg00272.html
> >
> Hi all,
> 
> I just saw the patch and I have to say I don't see much of a need to
> add that particular code. User is always at just one binding of having
> the shell shown via C-c C-z. Even if this is a customizable behavior
> users will have to deal with the shell showing even if they just sent
> the current buffer for the sake of having enhanced completion with an
> updated context.
> 
> For the OP if he really wants this implemented here's a rough approach
> you can add to your .emacs:
> 
> (defun python-shell-send-buffer-and-switch ()
>   (interactive)
>   (python-shell-send-buffer)
>   (python-shell-switch-to-shell))
> 
> Also if you want something more general that would work with any of
> the python-shell-send-* functions, I would rather work on the
> python-shell-send-string function itself and add the check for the
> customization variable just there. For your use-case you might just
> def-advice it and add the defcustom check at the end and the
> python-shell-switch-to-shell.
> 
> Regards,
> Fabián E. Gallina



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch to optionally show Python process buffer after C-c C-c
  2012-06-18 21:32             ` Glenn Morris
@ 2012-06-18 23:41               ` Glenn Morris
  2012-06-19  2:13                 ` Glenn Morris
  0 siblings, 1 reply; 10+ messages in thread
From: Glenn Morris @ 2012-06-18 23:41 UTC (permalink / raw)
  To: Emacs developers; +Cc: Fabian Ezequiel Gallina


PS this was previously requested:

http://debbugs.gnu.org/8607



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch to optionally show Python process buffer after C-c C-c
  2012-06-18 23:41               ` Glenn Morris
@ 2012-06-19  2:13                 ` Glenn Morris
  2012-06-19  7:44                   ` Glenn Morris
  0 siblings, 1 reply; 10+ messages in thread
From: Glenn Morris @ 2012-06-19  2:13 UTC (permalink / raw)
  To: Fabian Ezequiel Gallina; +Cc: Emacs developers


PPS You might like to look at the other Emacs python bug reports:

http://debbugs.gnu.org/cgi/pkgreport.cgi?include=subject%3Apython;package=emacs

to see if you have fixed (or want to fix) any of them.
Send replies to ###@debbugs.gnu.org.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Patch to optionally show Python process buffer after C-c C-c
  2012-06-19  2:13                 ` Glenn Morris
@ 2012-06-19  7:44                   ` Glenn Morris
  0 siblings, 0 replies; 10+ messages in thread
From: Glenn Morris @ 2012-06-19  7:44 UTC (permalink / raw)
  To: Fabian Ezequiel Gallina; +Cc: Emacs developers


PPPS Are the etc/emacs*.py files used for anything now, or can they be
removed? (data-directory no longer seems to be added to PYTHONPATH.)



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-06-19  7:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-17 13:03 Patch to optionally show Python process buffer after C-c C-c Deniz Dogan
2012-06-17 19:13 ` Glenn Morris
2012-06-17 20:31   ` Deniz Dogan
2012-06-18 17:56     ` Glenn Morris
2012-06-18 18:03       ` Deniz Dogan
2012-06-18 18:20         ` Glenn Morris
     [not found]           ` <CABq4mQtPF8Sns2Pf0U8pw+oaJ9pnxser7-oiaCng8J3kTxHyiA@mail.gmail.com>
2012-06-18 21:32             ` Glenn Morris
2012-06-18 23:41               ` Glenn Morris
2012-06-19  2:13                 ` Glenn Morris
2012-06-19  7:44                   ` Glenn Morris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).