Comment 6 for bug 328803

Revision history for this message
Liujin (liujin) wrote :

Unable to see errebepe's patch, but here's my attempt
following IPython's implemention. It's like other
completions in Emacs:
- No completion: ring bell and display in echo area "Can't
find completion for 'foo'"
- Sole completion: complete
- Multiple completion: open a window with mouse-clickable
entries

[pycomplete.py]
--- pycomplete.py.old Wed Jan 11 21:07:19 2006
+++ pycomplete.py Sun Feb 26 23:49:19 2006
@@ -74,12 +74,21 @@

 def pycomplete(s, imports=None):
     completions = get_all_completions(s, imports)
+ if len(completions) == 0:
+ return None
+
     dots = s.split(".")
- return os.path.commonprefix([k[len(dots[-1]):] for k
in completions])
+ prefix = os.path.commonprefix([k for k in completions])
+ if len(completions)==1 or len(prefix)>len(dots[-1]):
+ return [prefix[len(dots[-1]):]]
+
+ return completions

[pycomplete.el]
--- pycomplete.el.old Sat Dec 3 00:30:11 2005
+++ pycomplete.el Sun Feb 26 23:51:16 2006
@@ -10,9 +10,21 @@

 (defun py-complete ()
   (interactive)
- (let ((pymacs-forget-mutability t))
- (insert (pycomplete-pycomplete (py-symbol-near-point)
- (py-find-global-
imports)))))
+ (let* ((pymacs-forget-mutability t)
+ (symbol (py-symbol-near-point))
+ (completions
+ (pycomplete-pycomplete symbol
+ (py-find-global-
imports))))
+ (cond ((null completions) ; no matching
symbol
+ (message "Can't find completion for \"%s\""
symbol)
+ (ding))
+ ((null (cdr completions)) ; sole completion
+ (insert (car completions)))
+ (t
+ (message "Making completion list...")
+ (with-output-to-temp-buffer "*Python
Completions*"
+ (display-completion-list completions))
+ (message "Making completion list...%
s" "done")))))

 (defun py-find-global-imports ()
   (save-excursion