From unknown Thu Aug 14 12:23:30 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#5390 <5390@debbugs.gnu.org> To: bug#5390 <5390@debbugs.gnu.org> Subject: Status: changes in python.el to support IPython Reply-To: bug#5390 <5390@debbugs.gnu.org> Date: Thu, 14 Aug 2025 19:23:30 +0000 retitle 5390 changes in python.el to support IPython reassign 5390 emacs submitter 5390 Fabian Ezequiel Gallina severity 5390 wishlist tag 5390 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 15 12:43:18 2010 Received: (at quiet) by debbugs.gnu.org; 15 Jan 2010 17:43:18 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NVqCZ-0006Ze-Ij for submit@debbugs.gnu.org; Fri, 15 Jan 2010 12:43:18 -0500 Received: from fencepost.gnu.org ([140.186.70.10]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NVqCY-0006ZT-2N for quiet@debbugs.gnu.org; Fri, 15 Jan 2010 12:43:14 -0500 Received: from rgm by fencepost.gnu.org with local (Exim 4.69) (envelope-from ) id 1NVqCT-00056Z-Ic for quiet@debbugs.gnu.org; Fri, 15 Jan 2010 12:43:09 -0500 From: Fabian Ezequiel Gallina To: quiet@debbugs.gnu.org Subject: changes in python.el to support IPython Date: Mon, 28 Dec 2009 02:05:36 -0300 Lines: 172 X-From-Line: emacs-devel-bounces+rgm=gnu.org@gnu.org Mon Dec 28 00:06:33 2009 Received: from mail.gnu.org ([199.232.76.166]:54262 helo=mx10.gnu.org) by fencepost.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NP7oD-0002fd-Kr for rgm@gnu.org; Mon, 28 Dec 2009 00:06:25 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NP7oB-0003oy-7a for rgm@gnu.org; Mon, 28 Dec 2009 00:06:20 -0500 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on monty-python X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00, DNS_FROM_RFC_POST,UNPARSEABLE_RELAY autolearn=no version=3.1.0 Received: from lists.gnu.org ([199.232.76.165]:38002) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NP7oA-0003ou-S0 for rgm@gnu.org; Mon, 28 Dec 2009 00:06:18 -0500 Received: from localhost ([127.0.0.1]:39602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NP7oA-0006zS-QK for rgm@gnu.org; Mon, 28 Dec 2009 00:06:18 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NP7nY-0006xW-7r for emacs-devel@gnu.org; Mon, 28 Dec 2009 00:05:40 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NP7nX-0006wm-Lj for emacs-devel@gnu.org; Mon, 28 Dec 2009 00:05:39 -0500 Received: from [199.232.76.173] (port=35403 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NP7nX-0006wb-8V for emacs-devel@gnu.org; Mon, 28 Dec 2009 00:05:39 -0500 Received: from fg-out-1718.google.com ([72.14.220.158]:42374) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NP7nW-0003kx-M7 for emacs-devel@gnu.org; Mon, 28 Dec 2009 00:05:39 -0500 Received: by fg-out-1718.google.com with SMTP id e21so1143976fga.12 for ; Sun, 27 Dec 2009 21:05:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=xw76GSBC1X6RxzVK8S6MRLmL/owuKmpmiMhVKzDxvYE=; b=Di43nbCtCxJfH7xP17YJSTkUHe3o4rmdkTus5XDMIoP347OCScvQWSCkwPYf3ED6uz 5IjKEEXWIxylUrZ+Y0X5VcCmpWXXN9F1U5RJUzOBOKlwkGTtnLdXh4rpPRLLv9PZWGdZ OcyaRcRNF1FO3o1TMn6UaRDs6xRoKqwVeMn04= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=ut7Yi3SU/stnfNO+HqQ3xdqNz8Qd94cgKSe/I92zWbv0cr1Vv0/NpsmVelIGqzeAT+ eDeL8Hg4M2/WH/bYfwFEK5t8D/Rzf3wD9P+taRpegTi0+Xec/NcouAqBSr0zoIcWIJ4M aQTrUdyNIyBHBPuNzRIdgw3NlSIX1zwMwH2cE= Received: by 10.86.88.20 with SMTP id l20mr803970fgb.14.1261976736187; Sun, 27 Dec 2009 21:05:36 -0800 (PST) X-Debbugs-No-Ack: yes X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Message-ID: <4caawf9scy.fsf@fencepost.gnu.org> User-Agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -4.6 (----) X-Debbugs-Envelope-To: quiet X-BeenThere: debbugs-submit@debbugs.gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.3 (-----) --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Package: emacs,python Severity: wishlist Tags: patch [ resent from http://lists.gnu.org/archive/html/emacs-devel/2009-12/msg00817.html ] Hi everybody, I made several changes to python.el to support the IPython console. I always preferred the standard Emacs version of python.el to this one https://launchpad.net/python-mode but the IPython support was always making me use the other. Also, I really think that python's menu item "Start interpreter" should execute `run-python' instead of `python-shell', mainly because all the items below use that interpreter to work. With that said I really don't understand why `python-shell' could be useful at all, my guess is that it could be set as a defalias to `run-python'. Regards, --=20 Fabi=E1n E. Gallina http://www.from-the-cloud.com --=-=-= Content-Type: text/plain; name=python.el.diff Content-Disposition: attachment; filename=python.el.diff diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 104ea26..bcef353 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -298,7 +298,7 @@ Used for syntactic keywords. N is the match number (1, 2 or 3)." :filter (lambda (&rest junk) (abbrev-table-menu python-mode-abbrev-table))) "-" - ["Start interpreter" python-shell + ["Start interpreter" run-python :help "Run `inferior' Python in separate buffer"] ["Import/reload file" python-load-file :help "Load into inferior Python session"] @@ -571,10 +571,21 @@ having to restart the program." "Queue of Python temp files awaiting execution. Currently-active file is at the head of the list.") +(defcustom python-shell-input-prompt-1-regexp "^>>> " + "*A regular expression to match the input prompt of the shell." + :type 'string + :group 'python) + +(defcustom python-shell-input-prompt-2-regexp "^[.][.][.] " + "*A regular expression to match the input prompt of the shell after the + first line of input." + :type 'string + :group 'python) + (defvar python-pdbtrack-is-tracking-p nil) (defconst python-pdbtrack-stack-entry-regexp - "^> \\(.*\\)(\\([0-9]+\\))\\([?a-zA-Z0-9_]+\\)()" + "^> \\(.*\\)(\\([0-9]+\\))\\([?a-zA-Z0-9_<>]+\\)()" "Regular expression pdbtrack uses to find a stack trace entry.") (defconst python-pdbtrack-input-prompt "\n[(<]*[Pp]db[>)]+ " @@ -1303,13 +1314,22 @@ See `python-check-command' for the default." ;;;; Inferior mode stuff (following cmuscheme). -;; Fixme: Make sure we can work with IPython. - (defcustom python-python-command "python" "Shell command to run Python interpreter. Any arguments can't contain whitespace. -Note that IPython may not work properly; it must at least be used -with the `-cl' flag, i.e. use `ipython -cl'." + +Note that IPython may not work properly; you must especify the +correct `python-shell-input-prompt-1-regexp' and +`python-shell-input-prompt-2-regexp' regular expressions so the +prompt is identified correctly. + +Normally you would set them as follows in your .emacs: + +\(setq python-shell-input-prompt-1-regexp \"^In \\[[0-9]+\\]: *\" + python-shell-input-prompt-2-regexp \"^ [.][.][.]+: *\") + +Alternatively you could just add the `-cl' flag to the command so +prompts remain the same as the standard python console." :group 'python :type 'string) @@ -1411,12 +1431,17 @@ For running multiple processes in multiple buffers, see `run-python' and :group 'python (setq mode-line-process '(":%s")) (set (make-local-variable 'comint-input-filter) 'python-input-filter) - (add-hook 'comint-preoutput-filter-functions #'python-preoutput-filter - nil t) + (add-hook 'comint-preoutput-filter-functions #'python-preoutput-filter + nil t) ;; Still required by `comint-redirect-send-command', for instance ;; (and we need to match things like `>>> ... >>> '): - (set (make-local-variable 'comint-prompt-regexp) - (rx line-start (1+ (and (or (repeat 3 (any ">.")) "(Pdb)") " ")))) + ;; (set (make-local-variable 'comint-prompt-regexp) + ;; (rx line-start (1+ (and (or (repeat 3 (any ">.")) "(Pdb)") " ")))) + (make-local-variable 'comint-prompt-regexp) + (setq comint-prompt-regexp (format "%s\\|%s\\|%s" + python-shell-input-prompt-1-regexp + python-shell-input-prompt-2-regexp + "^([Pp]db) ")) (set (make-local-variable 'compilation-error-regexp-alist) python-compilation-regexp-alist) (compilation-shell-minor-mode 1)) @@ -1513,11 +1538,10 @@ Don't save anything for STR matching `inferior-python-filter-regexp'." cmd))) (unless (shell-command-to-string cmd) (error "Can't run Python command `%s'" cmd)) - (let* ((res (shell-command-to-string (concat cmd " --version")))) - (string-match "Python \\([0-9]\\)\\.\\([0-9]\\)" res) - (unless (and (equal "2" (match-string 1 res)) - (match-beginning 2) - (>= (string-to-number (match-string 2 res)) 2)) + (let* ((res (shell-command-to-string + (concat cmd + " -c \"from sys import version_info; print version_info >= (2, 2) and version_info < (3, 0)\"")))) + (unless (string-match "True" res) (error "Only Python versions >= 2.2 and < 3.0 supported"))) (setq python-version-checked t))) @@ -1558,8 +1582,12 @@ buffer for a list of commands.)" (if path (concat path path-separator)) data-directory) process-environment)) - ;; Suppress use of pager for help output: - (process-connection-type nil)) + ;; If we set process-connection-type to nil for some + ;; reason the IPython console will not work at all. + ;; My guess is that it redirects stdout and stderr in + ;; special ways the standard python console doesn't + ;; -- fg + (process-connection-type t)) (apply 'make-comint-in-buffer "Python" (generate-new-buffer "*Python*") (car cmdlist) nil (cdr cmdlist))) @@ -1615,7 +1643,12 @@ buffer for a list of commands.)" ;; non-ASCII. (interactive "r") (let* ((f (make-temp-file "py")) - (command (format "emacs.eexecfile(%S)" f)) + (command + ;; Unfortunately IPython puts the FakeModule module into + ;; __main__ so emacs.eexecfile becomes useless. + (if (string-match "^ipython" python-command) + (format "execfile %S" f) + (format "emacs.eexecfile(%S)" f))) (orig-start (copy-marker start))) (when (save-excursion (goto-char start) @@ -1815,7 +1848,10 @@ If there isn't, it's probably not appropriate to send input to return Eldoc information etc. If PROC is non-nil, check the buffer for that process." (with-current-buffer (process-buffer (or proc (python-proc))) (save-excursion - (save-match-data (re-search-backward ">>> \\=" nil t))))) + (save-match-data (re-search-backward + (format "%s *\\=" + python-shell-input-prompt-1-regexp) + nil t))))) ;; Fixme: Is there anything reasonable we can do with random methods? ;; (Currently only works with functions.) @@ -2531,9 +2567,7 @@ Runs `jython-mode-hook' after `python-mode-hook'." "Watch output for Python prompt and exec next file waiting in queue. This function is appropriate for `comint-output-filter-functions'." ;; TBD: this should probably use split-string - (when (and (or (string-equal string ">>> ") - (and (>= (length string) 5) - (string-equal (substring string -5) "\n>>> "))) + (when (and (string-match python-shell-input-prompt-1-regexp string) python-file-queue) (condition-case nil (delete-file (car python-file-queue)) @@ -2745,6 +2779,7 @@ comint believe the user typed this string so that (funcall (process-filter proc) proc msg)) (set-buffer curbuf)) (process-send-string proc cmd))) + ;;;###autoload (defun python-shell (&optional argprompt) "Start an interactive Python interpreter in another window. @@ -2803,7 +2838,10 @@ filter." (make-local-variable 'comint-prompt-regexp) (set-process-sentinel (get-buffer-process (current-buffer)) 'python-sentinel) - (setq comint-prompt-regexp "^>>> \\|^[.][.][.] \\|^(pdb) ") + (setq comint-prompt-regexp (format "%s\\|%s\\|%s" + python-shell-input-prompt-1-regexp + python-shell-input-prompt-2-regexp + "^([Pp]db) ")) (add-hook 'comint-output-filter-functions 'python-comint-output-filter-function nil t) ;; pdbtrack --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 24 16:23:42 2010 Received: (at 5390) by debbugs.gnu.org; 24 Aug 2010 20:23:42 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oo022-0006wm-HP for submit@debbugs.gnu.org; Tue, 24 Aug 2010 16:23:42 -0400 Received: from pantheon-po44.its.yale.edu ([130.132.50.78]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oo01z-0006wg-MY for 5390@debbugs.gnu.org; Tue, 24 Aug 2010 16:23:40 -0400 Received: from furry (dhcp128036014154.central.yale.edu [128.36.14.154]) (authenticated bits=0) by pantheon-po44.its.yale.edu (8.12.11.20060308/8.12.11) with ESMTP id o7OKP0FS015929 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 24 Aug 2010 16:25:00 -0400 Received: by furry (Postfix, from userid 1000) id 86D41C013; Tue, 24 Aug 2010 16:25:00 -0400 (EDT) From: Chong Yidong To: Fabian Ezequiel Gallina Subject: Re: changes in python.el to support IPython Date: Tue, 24 Aug 2010 16:25:00 -0400 Message-ID: <87y6bvahcz.fsf@stupidchicken.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-YaleITSMailFilter: Version 1.2c (attachment(s) not renamed) X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: 5390 Cc: 5390@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) > I made several changes to python.el to support the IPython console. I did some reworking of your patch, and have committed it to the trunk repository. Thanks for your contribution. > Also, I really think that python's menu item "Start interpreter" > should execute `run-python' instead of `python-shell', mainly because > all the items below use that interpreter to work. With that said I > really don't understand why `python-shell' could be useful at all, my > guess is that it could be set as a defalias to `run-python'. I'm not sure what is the correct thing here, so I left it alone. If you would like to discuss this, please start a thread on emacs-devel and we can sort it out there. Thanks. From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 24 16:23:53 2010 Received: (at control) by debbugs.gnu.org; 24 Aug 2010 20:23:53 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oo02D-0006wz-C3 for submit@debbugs.gnu.org; Tue, 24 Aug 2010 16:23:53 -0400 Received: from pantheon-po41.its.yale.edu ([130.132.50.98]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oo02A-0006ws-Uw for control@debbugs.gnu.org; Tue, 24 Aug 2010 16:23:51 -0400 Received: from furry (dhcp128036014154.central.yale.edu [128.36.14.154]) (authenticated bits=0) by pantheon-po41.its.yale.edu (8.12.11.20060308/8.12.11) with ESMTP id o7OKPBCc016444 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Tue, 24 Aug 2010 16:25:12 -0400 Received: by furry (Postfix, from userid 1000) id E42D0C013; Tue, 24 Aug 2010 16:25:11 -0400 (EDT) From: Chong Yidong To: control@debbugs.gnu.org Subject: close 5390 Date: Tue, 24 Aug 2010 16:25:11 -0400 Message-ID: <87vd6zahco.fsf@stupidchicken.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-YaleITSMailFilter: Version 1.2c (attachment(s) not renamed) X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) close 5390 thanks From unknown Thu Aug 14 12:23:30 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 22 Sep 2010 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator