Proposed improvement for pycomplete

Bug #328803 reported by Hugoh-users
4
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

Bug Description

Hi.

I really like the idea of pycomplete a lot.

However, it only completes simple cases: "sys.cl"
becomes "sys.clock" once completed.

What would be interesting would be to get a list of
completions for "sys.".

I believe that what needs to be changed is the following:
- have pycomplete.py return a list of all possibilities
- in py-complete() in pycomplete.el, use the output of
pycomplete.py to call try-completion; if it works, use
it, if not and there are several possibilities, display
all the possibilities given by all-completions and
allow to chose between them.

The former is trivial (patch attached).

I tried to do the latter, but my lack of knowledge in
elisp put a rapid stop to it, so in case somebody knows
elisp and is interested by this (I think it would be a
cool feature), I thought I'd record the idea here.

Regards,

Hugo

[http://sourceforge.net/tracker/index.php?func=detail&aid=1180180&group_id=86916&atid=581349]

Revision history for this message
Hugoh-users (hugoh-users) wrote :
Revision history for this message
Errebepe (errebepe) wrote :

I've implemented these suggestions and put the resulting
files at http://isnomore.net/prog/pycomplete/ . Please take
a look and let me know what you (all) think.

Revision history for this message
Hugoh-users (hugoh-users) wrote :

It seems to do exactly what I was after! Except maybe for
the completion prompt, as maybe it could just give a list of
possibilities in a separate buffer without requiring the use
of the mini-buffer, but that's a detail.

Thanks a lot.

Revision history for this message
Errebepe (errebepe) wrote :

I used minibuffer because it seems to be the way Emacs
usually handles these things. It's also a close analogy with
the way Eclipse does it.

Anyway, I've been thinking about code-completion for a
while, and it seems the best way to do it would be to parse
the code and act according to context. Apparently, the
Semantic package
(http://cedet.sourceforge.net/semantic.shtml) does this.
Now, if I can get it to work...

Revision history for this message
Errebepe (errebepe) wrote :

I just managed to use Semantic with ECB
(http://ecb.sourceforge.net/). Installed both, fired up ECB
(M-x ecb-activate). From then on, on a source file, I type
M-Tab and it completes (using the same "interface" my patch
provides, which I found cool, BTW). I've spotted what is
apparently a bug (when importing a module from a file I
created on the current directory), but otherwise it seems to
work!

Revision history for this message
Errebepe (errebepe) wrote :

Ahn... Sorry, false alarm. I was still using my code
completion code and hadn't realized it. No wonder it was so
similar ;)

Haven't had much luck using Semantic yet, though I still
think it's the best approach.

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

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
Changed in python-mode:
status: New → In Progress
Changed in python-mode:
milestone: none → 6.2
Changed in python-mode:
status: In Progress → Fix Committed
Revision history for this message
Jeff S (jeffspencerd) wrote :

Where was this fix commited? This still doesn't function properly for me.

Changed in python-mode:
status: Fix Committed → Fix Released
status: Fix Released → New
Changed in python-mode:
status: New → Fix Committed
Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.