~handrake/python-mode/devel-0.1

275 by montanaro
This almost certainly needs work, but if you add
1
;;; Complete symbols at point using Pymacs.
2
338 by montanaro
add README file, author info for pycomplete
3
;; Copyright (C) 2007  Skip Montanaro
4
5
;; Author:     Skip Montanaro
6
;; Maintainer: skip@pobox.com
7
;; Created:    Oct 2004
8
;; Keywords:   python pymacs emacs
9
10
;; This software is provided as-is, without express or implied warranty.
11
;; Permission to use, copy, modify, distribute or sell this software,
12
;; without fee, for any purpose and by any individual or organization, is
13
;; hereby granted, provided that the above copyright notice and this
14
;; paragraph appear in all copies.
15
16
;; Along with pycomplete.py this file allows programmers to complete Python
17
;; symbols within the current buffer.  See pycomplete.py for the Python side
18
;; of things and a short description of what to expect.
275 by montanaro
This almost certainly needs work, but if you add
19
20
(require 'pymacs)
21
(require 'python-mode)
22
23
(pymacs-load "pycomplete")
24
25
(defun py-complete ()
26
  (interactive)
27
  (let ((pymacs-forget-mutability t)) 
28
    (insert (pycomplete-pycomplete (py-symbol-near-point)
29
				   (py-find-global-imports)))))
30
31
(defun py-find-global-imports ()
32
  (save-excursion
33
    (let (first-class-or-def imports)
34
      (goto-char (point-min))
35
      (setq first-class-or-def
36
	    (re-search-forward "^ *\\(def\\|class\\) " nil t))
37
      (goto-char (point-min))
38
      (setq imports nil)
39
      (while (re-search-forward
40
	      "^\\(import \\|from \\([A-Za-z_][A-Za-z_0-9]*\\) import \\).*"
41
	      nil t)
42
	(setq imports (append imports
43
			      (list (buffer-substring
44
				     (match-beginning 0)
45
				     (match-end 0))))))
46
      imports)))
47
48
(define-key py-mode-map "\M-\C-i"  'py-complete)
49
50
(provide 'pycomplete)