diff options
| author | Fabián Ezequiel Gallina | 2012-05-17 00:02:59 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-05-17 00:02:59 -0300 |
| commit | 046428d32838bd413a44d221d929627949fb949a (patch) | |
| tree | 34b2d6b4507f2c51020ec48424936463d8e95f36 | |
| parent | 1066882c6ddb30f786d665c5db305897f20f7119 (diff) | |
| download | emacs-046428d32838bd413a44d221d929627949fb949a.tar.gz emacs-046428d32838bd413a44d221d929627949fb949a.zip | |
Added ffap support
| -rw-r--r-- | lisp/progmodes/python.el | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 735f25dfa54..83d58360551 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -88,8 +88,6 @@ | |||
| 88 | 88 | ||
| 89 | ;; (Perhaps) python-check | 89 | ;; (Perhaps) python-check |
| 90 | 90 | ||
| 91 | ;; (Perhaps) ffap support | ||
| 92 | |||
| 93 | ;; (Perhaps) some skeletons (I never use them because of yasnippet) | 91 | ;; (Perhaps) some skeletons (I never use them because of yasnippet) |
| 94 | 92 | ||
| 95 | ;;; Code: | 93 | ;;; Code: |
| @@ -1431,6 +1429,62 @@ Optional argument JUSTIFY defines if the paragraph should be justified." | |||
| 1431 | (t t)))) | 1429 | (t t)))) |
| 1432 | 1430 | ||
| 1433 | 1431 | ||
| 1432 | ;;; FFAP | ||
| 1433 | |||
| 1434 | (defvar python-ffap-setup-code | ||
| 1435 | "def __FFAP_get_module_path(module): | ||
| 1436 | try: | ||
| 1437 | import os | ||
| 1438 | path = __import__(module).__file__ | ||
| 1439 | if path[-4:] == '.pyc' and os.path.exists(path[0:-1]): | ||
| 1440 | path = path[:-1] | ||
| 1441 | return path | ||
| 1442 | except: | ||
| 1443 | return ''" | ||
| 1444 | "Python code to get a module path.") | ||
| 1445 | |||
| 1446 | (defvar python-ffap-string-code | ||
| 1447 | "__FFAP_get_module_path('''%s''')\n" | ||
| 1448 | "Python code used to get a string with the path of a module.") | ||
| 1449 | |||
| 1450 | (defun python-ffap-setup () | ||
| 1451 | "Send `python-ffap-setup-code' to inferior Python process. | ||
| 1452 | It is specially designed to be added to the | ||
| 1453 | `inferior-python-mode-hook'." | ||
| 1454 | (when python-ffap-setup-code | ||
| 1455 | (let ((temp-file (make-temp-file "py"))) | ||
| 1456 | (with-temp-file temp-file | ||
| 1457 | (insert python-ffap-setup-code) | ||
| 1458 | (delete-trailing-whitespace) | ||
| 1459 | (goto-char (point-min))) | ||
| 1460 | (python-shell-send-file temp-file (get-buffer-process (current-buffer))) | ||
| 1461 | (message (format "FFAP setup code sent."))))) | ||
| 1462 | |||
| 1463 | (defun python-ffap-module-path (module) | ||
| 1464 | "Function for `ffap-alist' to return path for MODULE." | ||
| 1465 | (let ((process (or | ||
| 1466 | (and (eq major-mode 'inferior-python-mode) | ||
| 1467 | (get-buffer-process (current-buffer))) | ||
| 1468 | (python-shell-get-process)))) | ||
| 1469 | (if (not process) | ||
| 1470 | nil | ||
| 1471 | (let ((module-file | ||
| 1472 | (python-shell-send-and-clear-output | ||
| 1473 | (format python-ffap-string-code module) process))) | ||
| 1474 | (when module-file | ||
| 1475 | (ffap-locate-file | ||
| 1476 | (substring-no-properties module-file 1 -1) | ||
| 1477 | nil nil)))))) | ||
| 1478 | |||
| 1479 | (eval-after-load "ffap" | ||
| 1480 | '(progn | ||
| 1481 | (push '(python-mode . python-ffap-module-path) ffap-alist) | ||
| 1482 | (push '(inferior-python-mode . python-ffap-module-path) ffap-alist))) | ||
| 1483 | |||
| 1484 | (add-hook 'inferior-python-mode-hook | ||
| 1485 | #'python-ffap-setup) | ||
| 1486 | |||
| 1487 | |||
| 1434 | ;;; Eldoc | 1488 | ;;; Eldoc |
| 1435 | 1489 | ||
| 1436 | (defvar python-eldoc-setup-code | 1490 | (defvar python-eldoc-setup-code |
| @@ -1463,7 +1517,7 @@ It is specially designed to be added to the | |||
| 1463 | (delete-trailing-whitespace) | 1517 | (delete-trailing-whitespace) |
| 1464 | (goto-char (point-min))) | 1518 | (goto-char (point-min))) |
| 1465 | (python-shell-send-file temp-file (get-buffer-process (current-buffer))) | 1519 | (python-shell-send-file temp-file (get-buffer-process (current-buffer))) |
| 1466 | (message (format "Completion setup code sent."))))) | 1520 | (message (format "Eldoc setup code sent."))))) |
| 1467 | 1521 | ||
| 1468 | (defun python-eldoc-function () | 1522 | (defun python-eldoc-function () |
| 1469 | "`eldoc-documentation-function' for Python. | 1523 | "`eldoc-documentation-function' for Python. |