comparison lisp/progmodes/python.el @ 106482:806e9f7990d8

* minibuffer.el (completion-at-point-functions): New var. (completion-at-point): New command. * indent.el (indent-for-tab-command): Handle the new `complete' behavior. * progmodes/python.el (python-mode-map): Use completion-at-point. (python-completion-at-point): Rename from python-partial-symbol and adjust for use in completion-at-point-functions. (python-mode): Setup completion-at-point for Python completion. * emacs-lisp/lisp.el (lisp-completion-at-point): New function extracted from lisp-complete-symbol. (lisp-complete-symbol): Use it. * emacs-lisp/lisp-mode.el (emacs-lisp-mode): Use define-derived-mode, setup completion-at-point for Elisp completion. (emacs-lisp-mode-map, lisp-interaction-mode-map): Use completion-at-point. * ielm.el (ielm-map): Use completion-at-point. (inferior-emacs-lisp-mode): Setup completion-at-point for Elisp completion. * progmodes/sym-comp.el: Move to... * obsolete/sym-comp.el: Move from progmodes.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 07 Dec 2009 20:06:26 +0000
parents 26baacb565b0
children 427e81917607
comparison
equal deleted inserted replaced
106481:665bd5e777e1 106482:806e9f7990d8
266 (define-key map "\C-c\M-r" 'python-send-region-and-go) 266 (define-key map "\C-c\M-r" 'python-send-region-and-go)
267 (define-key map "\C-c\C-c" 'python-send-buffer) 267 (define-key map "\C-c\C-c" 'python-send-buffer)
268 (define-key map "\C-c\C-z" 'python-switch-to-python) 268 (define-key map "\C-c\C-z" 'python-switch-to-python)
269 (define-key map "\C-c\C-m" 'python-load-file) 269 (define-key map "\C-c\C-m" 'python-load-file)
270 (define-key map "\C-c\C-l" 'python-load-file) ; a la cmuscheme 270 (define-key map "\C-c\C-l" 'python-load-file) ; a la cmuscheme
271 (substitute-key-definition 'complete-symbol 'symbol-complete 271 (substitute-key-definition 'complete-symbol 'completion-at-point
272 map global-map) 272 map global-map)
273 (define-key map "\C-c\C-i" 'python-find-imports) 273 (define-key map "\C-c\C-i" 'python-find-imports)
274 (define-key map "\C-c\C-t" 'python-expand-template) 274 (define-key map "\C-c\C-t" 'python-expand-template)
275 (easy-menu-define python-menu map "Python Mode menu" 275 (easy-menu-define python-menu map "Python Mode menu"
276 `("Python" 276 `("Python"
317 ["Check file" python-check :help "Run pychecker"] 317 ["Check file" python-check :help "Run pychecker"]
318 ["Debugger" pdb :help "Run pdb under GUD"] 318 ["Debugger" pdb :help "Run pdb under GUD"]
319 "-" 319 "-"
320 ["Help on symbol" python-describe-symbol 320 ["Help on symbol" python-describe-symbol
321 :help "Use pydoc on symbol at point"] 321 :help "Use pydoc on symbol at point"]
322 ["Complete symbol" symbol-complete 322 ["Complete symbol" completion-at-point
323 :help "Complete (qualified) symbol before point"] 323 :help "Complete (qualified) symbol before point"]
324 ["Find function" python-find-function 324 ["Find function" python-find-function
325 :help "Try to find source definition of function at point"] 325 :help "Try to find source definition of function at point"]
326 ["Update imports" python-find-imports 326 ["Update imports" python-find-imports
327 :help "Update list of top-level imports for completion"])) 327 :help "Update list of top-level imports for completion"]))
2157 (sort 2157 (sort
2158 ;; We can get duplicates from the above -- don't know why. 2158 ;; We can get duplicates from the above -- don't know why.
2159 (delete-dups completions) 2159 (delete-dups completions)
2160 #'string<)))) 2160 #'string<))))
2161 2161
2162 (defun python-partial-symbol () 2162 (defun python-completion-at-point ()
2163 "Return the partial symbol before point (for completion)."
2164 (let ((end (point)) 2163 (let ((end (point))
2165 (start (save-excursion 2164 (start (save-excursion
2166 (and (re-search-backward 2165 (and (re-search-backward
2167 (rx (or buffer-start (regexp "[^[:alnum:]._]")) 2166 (rx (or buffer-start (regexp "[^[:alnum:]._]"))
2168 (group (1+ (regexp "[[:alnum:]._]"))) point) 2167 (group (1+ (regexp "[[:alnum:]._]"))) point)
2169 nil t) 2168 nil t)
2170 (match-beginning 1))))) 2169 (match-beginning 1)))))
2171 (if start (buffer-substring-no-properties start end)))) 2170 (when start
2171 (list start end
2172 (completion-table-dynamic 'python-symbol-completions)))))
2172 2173
2173 ;;;; FFAP support 2174 ;;;; FFAP support
2174 2175
2175 (defun python-module-path (module) 2176 (defun python-module-path (module)
2176 "Function for `ffap-alist' to return path to MODULE." 2177 "Function for `ffap-alist' to return path to MODULE."
2469 (set (make-local-variable 'eldoc-documentation-function) 2470 (set (make-local-variable 'eldoc-documentation-function)
2470 #'python-eldoc-function) 2471 #'python-eldoc-function)
2471 (add-hook 'eldoc-mode-hook 2472 (add-hook 'eldoc-mode-hook
2472 (lambda () (run-python nil t)) ; need it running 2473 (lambda () (run-python nil t)) ; need it running
2473 nil t) 2474 nil t)
2474 (set (make-local-variable 'symbol-completion-symbol-function) 2475 (add-hook 'completion-at-point-functions
2475 'python-partial-symbol) 2476 'python-completion-at-point nil 'local)
2476 (set (make-local-variable 'symbol-completion-completions-function)
2477 'python-symbol-completions)
2478 ;; Fixme: should be in hideshow. This seems to be of limited use 2477 ;; Fixme: should be in hideshow. This seems to be of limited use
2479 ;; since it isn't (can't be) indentation-based. Also hide-level 2478 ;; since it isn't (can't be) indentation-based. Also hide-level
2480 ;; doesn't seem to work properly. 2479 ;; doesn't seem to work properly.
2481 (add-to-list 'hs-special-modes-alist 2480 (add-to-list 'hs-special-modes-alist
2482 `(python-mode "^\\s-*\\(?:def\\|class\\)\\>" nil "#" 2481 `(python-mode "^\\s-*\\(?:def\\|class\\)\\>" nil "#"
2486 nil)) 2485 nil))
2487 (set (make-local-variable 'skeleton-further-elements) 2486 (set (make-local-variable 'skeleton-further-elements)
2488 '((< '(backward-delete-char-untabify (min python-indent 2487 '((< '(backward-delete-char-untabify (min python-indent
2489 (current-column)))) 2488 (current-column))))
2490 (^ '(- (1+ (current-indentation)))))) 2489 (^ '(- (1+ (current-indentation))))))
2491 ;; Let's not mess with hippie-expand. Symbol-completion should rather be
2492 ;; bound to another key, since it has different performance requirements.
2493 ;; (if (featurep 'hippie-exp)
2494 ;; (set (make-local-variable 'hippie-expand-try-functions-list)
2495 ;; (cons 'symbol-completion-try-complete
2496 ;; hippie-expand-try-functions-list)))
2497 ;; Python defines TABs as being 8-char wide. 2490 ;; Python defines TABs as being 8-char wide.
2498 (set (make-local-variable 'tab-width) 8) 2491 (set (make-local-variable 'tab-width) 8)
2499 (unless font-lock-mode (font-lock-mode 1)) 2492 (unless font-lock-mode (font-lock-mode 1))
2500 (when python-guess-indent (python-guess-indent)) 2493 (when python-guess-indent (python-guess-indent))
2501 ;; Let's make it harder for the user to shoot himself in the foot. 2494 ;; Let's make it harder for the user to shoot himself in the foot.