aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2012-07-18 15:40:03 -0300
committerFabián Ezequiel Gallina2012-07-18 15:40:03 -0300
commitd583cbe6814dee8e976e00c2d71fa874a0310e36 (patch)
treed5f3cb5ada78ec8f9c6f05f7d636c8f27420587a
parent837131548b13935cc7a2cbb7114bfb0ee44eae76 (diff)
downloademacs-d583cbe6814dee8e976e00c2d71fa874a0310e36.tar.gz
emacs-d583cbe6814dee8e976e00c2d71fa874a0310e36.zip
* progmodes/python.el: Enhancements to eldoc support.
(python-info-current-symbol): New function. (python-eldoc-at-point): Use python-info-current-symbol. (python-info-current-defun): Fix cornercase on first defun scan. (python-eldoc--get-doc-at-point): Use python-info-current-symbol and signal error when no inferior python process is available.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/progmodes/python.el103
2 files changed, 63 insertions, 49 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e969bd800e8..9246d57ea79 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12012-07-18 Fabián Ezequiel Gallina <fgallina@cuca>
2
3 * progmodes/python.el: Enhancements to eldoc support.
4 (python-info-current-symbol): New function.
5 (python-eldoc-at-point): Use python-info-current-symbol.
6 (python-info-current-defun): Fix cornercase on first defun scan.
7 (python-eldoc--get-doc-at-point): Use python-info-current-symbol
8 and signal error when no inferior python process is available.
9
12012-07-18 Dmitry Gutov <dgutov@yandex.ru> 102012-07-18 Dmitry Gutov <dgutov@yandex.ru>
2 11
3 * vc/vc-git.el (vc-git-state): Don't call `vc-git-registered', 12 * vc/vc-git.el (vc-git-state): Don't call `vc-git-registered',
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 54486ba5a52..b5474732316 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -2487,46 +2487,19 @@ Runs COMMAND, a shell command, as if by `compile'. See
2487 2487
2488(defun python-eldoc--get-doc-at-point (&optional force-input force-process) 2488(defun python-eldoc--get-doc-at-point (&optional force-input force-process)
2489 "Internal implementation to get documentation at point. 2489 "Internal implementation to get documentation at point.
2490If not FORCE-INPUT is passed then what `current-word' returns 2490If not FORCE-INPUT is passed then what
2491will be used. If not FORCE-PROCESS is passed what 2491`python-info-current-symbol' returns will be used. If not
2492`python-shell-get-process' returns is used." 2492FORCE-PROCESS is passed what `python-shell-get-process' returns
2493is used."
2493 (let ((process (or force-process (python-shell-get-process)))) 2494 (let ((process (or force-process (python-shell-get-process))))
2494 (if (not process) 2495 (if (not process)
2495 "Eldoc needs an inferior Python process running." 2496 (error "Eldoc needs an inferior Python process running")
2496 (let* ((current-defun (python-info-current-defun)) 2497 (let ((input (or force-input
2497 (input (or force-input 2498 (python-info-current-symbol t))))
2498 (with-syntax-table python-dotty-syntax-table 2499 (and input
2499 (if (not current-defun) 2500 (python-shell-send-string-no-output
2500 (current-word) 2501 (format python-eldoc-string-code input)
2501 (concat current-defun "." (current-word)))))) 2502 process))))))
2502 (ppss (syntax-ppss))
2503 (help (when (and
2504 input
2505 (not (string= input (concat current-defun ".")))
2506 (not (or (python-info-ppss-context 'string ppss)
2507 (python-info-ppss-context 'comment ppss))))
2508 (when (string-match
2509 (concat
2510 (regexp-quote (concat current-defun "."))
2511 "self\\.") input)
2512 (with-temp-buffer
2513 (insert input)
2514 (goto-char (point-min))
2515 (forward-word)
2516 (forward-char)
2517 (delete-region
2518 (point-marker) (search-forward "self."))
2519 (setq input (buffer-substring
2520 (point-min) (point-max)))))
2521 (python-shell-send-string-no-output
2522 (format python-eldoc-string-code input) process))))
2523 (with-current-buffer (process-buffer process)
2524 (when comint-last-prompt-overlay
2525 (delete-region comint-last-input-end
2526 (overlay-start comint-last-prompt-overlay))))
2527 (when (and help
2528 (not (string= help "\n")))
2529 help)))))
2530 2503
2531(defun python-eldoc-function () 2504(defun python-eldoc-function ()
2532 "`eldoc-documentation-function' for Python. 2505 "`eldoc-documentation-function' for Python.
@@ -2539,17 +2512,16 @@ inferior python process is updated properly."
2539 "Get help on SYMBOL using `help'. 2512 "Get help on SYMBOL using `help'.
2540Interactively, prompt for symbol." 2513Interactively, prompt for symbol."
2541 (interactive 2514 (interactive
2542 (let ((symbol (with-syntax-table python-dotty-syntax-table 2515 (let ((symbol (python-info-current-symbol t))
2543 (current-word)))
2544 (enable-recursive-minibuffers t)) 2516 (enable-recursive-minibuffers t))
2545 (list (read-string (if symbol 2517 (list (read-string (if symbol
2546 (format "Describe symbol (default %s): " symbol) 2518 (format "Describe symbol (default %s): " symbol)
2547 "Describe symbol: ") 2519 "Describe symbol: ")
2548 nil nil symbol)))) 2520 nil nil symbol))))
2549 (let ((process (python-shell-get-process))) 2521 (message (python-eldoc--get-doc-at-point symbol)))
2550 (if (not process) 2522
2551 (message "Eldoc needs an inferior Python process running.") 2523(add-to-list 'debug-ignored-errors
2552 (message (python-eldoc--get-doc-at-point symbol process))))) 2524 "^Eldoc needs an inferior Python process running.")
2553 2525
2554 2526
2555;;; Misc helpers 2527;;; Misc helpers
@@ -2561,18 +2533,27 @@ This function is compatible to be used as
2561`add-log-current-defun-function' since it returns nil if point is 2533`add-log-current-defun-function' since it returns nil if point is
2562not inside a defun." 2534not inside a defun."
2563 (let ((names '()) 2535 (let ((names '())
2564 (min-indent) 2536 (starting-indentation)
2537 (starting-point)
2565 (first-run t)) 2538 (first-run t))
2566 (save-restriction 2539 (save-restriction
2567 (widen) 2540 (widen)
2568 (save-excursion 2541 (save-excursion
2542 (setq starting-point (point-marker))
2543 (setq starting-indentation (save-excursion
2544 (python-nav-beginning-of-statement)
2545 (current-indentation)))
2569 (end-of-line 1) 2546 (end-of-line 1)
2570 (setq min-indent (current-indentation))
2571 (while (python-beginning-of-defun-function 1) 2547 (while (python-beginning-of-defun-function 1)
2572 (when (or (< (current-indentation) min-indent) 2548 (when (or (< (current-indentation) starting-indentation)
2573 first-run) 2549 (and first-run
2550 (<
2551 starting-point
2552 (save-excursion
2553 (python-end-of-defun-function)
2554 (point-marker)))))
2574 (setq first-run nil) 2555 (setq first-run nil)
2575 (setq min-indent (current-indentation)) 2556 (setq starting-indentation (current-indentation))
2576 (looking-at python-nav-beginning-of-defun-regexp) 2557 (looking-at python-nav-beginning-of-defun-regexp)
2577 (setq names (cons 2558 (setq names (cons
2578 (if (not include-type) 2559 (if (not include-type)
@@ -2584,6 +2565,30 @@ not inside a defun."
2584 (when names 2565 (when names
2585 (mapconcat (lambda (string) string) names ".")))) 2566 (mapconcat (lambda (string) string) names "."))))
2586 2567
2568(defun python-info-current-symbol (&optional replace-self)
2569 "Return current symbol using dotty syntax.
2570With optional argument REPLACE-SELF convert \"self\" to current
2571parent defun name."
2572 (let ((name
2573 (and (not (python-info-ppss-comment-or-string-p))
2574 (with-syntax-table python-dotty-syntax-table
2575 (let ((sym (symbol-at-point)))
2576 (and sym
2577 (substring-no-properties (symbol-name sym))))))))
2578 (when name
2579 (if (not replace-self)
2580 name
2581 (let ((current-defun (python-info-current-defun)))
2582 (if (not current-defun)
2583 name
2584 (replace-regexp-in-string
2585 (python-rx line-start word-start "self" word-end ?.)
2586 (concat
2587 (mapconcat 'identity
2588 (butlast (split-string current-defun "\\."))
2589 ".") ".")
2590 name)))))))
2591
2587(defsubst python-info-beginning-of-block-statement-p () 2592(defsubst python-info-beginning-of-block-statement-p ()
2588 "Return non-nil if current statement opens a block." 2593 "Return non-nil if current statement opens a block."
2589 (save-excursion 2594 (save-excursion