From: "Андрей Парамонов" <cmr.pent@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: fx@gnu.org, 7329@debbugs.gnu.org
Subject: bug#7329: [Patch] Enable completion in inferior-python-mode
Date: Fri, 19 Nov 2010 23:33:37 +0300 [thread overview]
Message-ID: <AANLkTikw8O36yV=zo8nwre-Pu444uOc3qJ7bM5-6LsvV@mail.gmail.com> (raw)
In-Reply-To: <jwvipzwdrgk.fsf-monnier+emacs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 254 bytes --]
Updated version of the patch attached. It does the following:
1) Enables completion in inferior Python mode.
2) Enables describe-symbol in inferior Python mode.
3) Checks for interpreter more intelligently.
Also it works with 23.2.
Andrey Paramonov
[-- Attachment #2: inferior-python-completion.patch --]
[-- Type: text/x-diff, Size: 5139 bytes --]
--- /home/pent/python.el.orig 2010-11-12 21:55:47.000000000 +0300
+++ /home/pent/python.el 2010-11-19 23:20:14.000000000 +0300
@@ -1365,13 +1365,9 @@
;; This will inherit from comint-mode-map.
(define-key map "\C-c\C-l" 'python-load-file)
(define-key map "\C-c\C-v" 'python-check)
- ;; Note that we _can_ still use these commands which send to the
- ;; Python process even at the prompt iff we have a normal prompt,
- ;; i.e. '>>> ' and not '... '. See the comment before
- ;; python-send-region. Fixme: uncomment these if we address that.
-
- ;; (define-key map [(meta ?\t)] 'python-complete-symbol)
- ;; (define-key map "\C-c\C-f" 'python-describe-symbol)
+ (substitute-key-definition 'complete-symbol 'completion-at-point
+ map global-map)
+ (define-key map "\C-c\C-f" 'python-describe-symbol)
map))
(defvar inferior-python-mode-syntax-table
@@ -1412,6 +1408,8 @@
(set (make-local-variable 'comint-input-filter) 'python-input-filter)
(add-hook 'comint-preoutput-filter-functions #'python-preoutput-filter
nil t)
+ (add-hook 'completion-at-point-functions
+ 'python-completion-at-point nil 'local)
;; Still required by `comint-redirect-send-command', for instance
;; (and we need to match things like `>>> ... >>> '):
(set (make-local-variable 'comint-prompt-regexp)
@@ -1771,50 +1769,51 @@
(format "Describe symbol (default %s): " symbol)
"Describe symbol: ")
nil nil symbol))))
- (if (equal symbol "") (error "No symbol"))
- ;; Ensure we have a suitable help buffer.
- ;; Fixme: Maybe process `Related help topics' a la help xrefs and
- ;; allow C-c C-f in help buffer.
- (let ((temp-buffer-show-hook ; avoid xref stuff
- (lambda ()
- (toggle-read-only 1)
- (setq view-return-to-alist
- (list (cons (selected-window) help-return-method))))))
- (with-output-to-temp-buffer (help-buffer)
- (with-current-buffer standard-output
- ;; Fixme: Is this actually useful?
- (help-setup-xref (list 'python-describe-symbol symbol)
- (called-interactively-p 'interactive))
- (set (make-local-variable 'comint-redirect-subvert-readonly) t)
- (help-print-return-message))))
- (comint-redirect-send-command-to-process (format "emacs.ehelp(%S, %s)"
- symbol python-imports)
- "*Help*" (python-proc) nil nil))
-
-(add-to-list 'debug-ignored-errors "^No symbol")
+ (when (python-check-comint-prompt)
+ (if (equal symbol "") (error "No symbol"))
+ ;; Ensure we have a suitable help buffer.
+ ;; Fixme: Maybe process `Related help topics' a la help xrefs and
+ ;; allow C-c C-f in help buffer.
+ (let ((temp-buffer-show-hook ; avoid xref stuff
+ (lambda ()
+ (toggle-read-only 1)
+ (setq view-return-to-alist
+ (list (cons (selected-window) help-return-method))))))
+ (with-output-to-temp-buffer (help-buffer)
+ (with-current-buffer standard-output
+ ;; Fixme: Is this actually useful?
+ (help-setup-xref (list 'python-describe-symbol symbol)
+ (called-interactively-p 'interactive))
+ (set (make-local-variable 'comint-redirect-subvert-readonly) t)
+ (help-print-return-message))))
+ (comint-redirect-send-command-to-process
+ (format "emacs.ehelp(%S, %s)" symbol python-imports)
+ "*Help*" (python-proc) nil nil))
+ (add-to-list 'debug-ignored-errors "^No symbol"))
(defun python-send-receive (string)
"Send STRING to inferior Python (if any) and return result.
The result is what follows `_emacs_out' in the output.
This is a no-op if `python-check-comint-prompt' returns nil."
- (python-send-string string)
- (let ((proc (python-proc)))
- (with-current-buffer (process-buffer proc)
- (when (python-check-comint-prompt proc)
- (set (make-local-variable 'python-preoutput-result) nil)
- (while (progn
- (accept-process-output proc 5)
- (null python-preoutput-result)))
- (prog1 python-preoutput-result
- (kill-local-variable 'python-preoutput-result))))))
+ (when (python-check-comint-prompt)
+ (python-send-string string)
+ (with-current-buffer (process-buffer (python-proc))
+ (set (make-local-variable 'python-preoutput-result) nil)
+ (while (progn
+ (accept-process-output (python-proc) 5)
+ (null python-preoutput-result)))
+ (prog1 python-preoutput-result
+ (kill-local-variable 'python-preoutput-result)))))
(defun python-check-comint-prompt (&optional proc)
"Return non-nil if and only if there's a normal prompt in the inferior buffer.
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)))))
+ (let ((process (or proc (python-proc))))
+ (with-current-buffer (process-buffer process)
+ (save-excursion
+ (goto-char (process-mark process))
+ (save-match-data (re-search-backward "^>>> \\=" nil t))))))
;; Fixme: Is there anything reasonable we can do with random methods?
;; (Currently only works with functions.)
next prev parent reply other threads:[~2010-11-19 20:33 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87iq0dhwwd.fsf@neo.paramonovs>
2010-11-04 17:11 ` bug#7329: Fwd: 23.2; inferior-python-mode: completion does not work Андрей Парамонов
2010-11-12 20:08 ` bug#7329: [Patch] Enable completion in inferior-python-mode Андрей Парамонов
2010-11-12 21:35 ` Stefan Monnier
2010-11-16 8:41 ` Андрей Парамонов
2010-11-16 8:43 ` Андрей Парамонов
2010-11-17 13:14 ` Stefan Monnier
2010-11-19 20:33 ` Андрей Парамонов [this message]
2010-11-28 16:14 ` Dave Love
2012-04-11 11:31 ` Lars Magne Ingebrigtsen
2012-04-11 11:47 ` Андрей Парамонов
2012-04-11 11:59 ` Lars Magne Ingebrigtsen
2012-04-11 12:08 ` Андрей Парамонов
2012-04-11 11:47 ` Leo
2012-04-11 16:26 ` Glenn Morris
2012-07-28 14:23 ` bug#7329: Fwd: 23.2; inferior-python-mode: completion does not work Chong Yidong
2012-07-28 15:10 ` Андрей Парамонов
2012-07-28 15:14 ` Chong Yidong
2012-07-28 15:35 ` Андрей Парамонов
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='AANLkTikw8O36yV=zo8nwre-Pu444uOc3qJ7bM5-6LsvV@mail.gmail.com' \
--to=cmr.pent@gmail.com \
--cc=7329@debbugs.gnu.org \
--cc=fx@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.