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