From: Fabián Ezequiel Gallina Date: Thu, 17 May 2012 03:02:59 +0000 (-0300) Subject: Added ffap support X-Git-Tag: emacs-24.2.90~1199^2~611 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=046428d32838bd413a44d221d929627949fb949a;p=emacs.git Added ffap support --- 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 @@ ;; (Perhaps) python-check -;; (Perhaps) ffap support - ;; (Perhaps) some skeletons (I never use them because of yasnippet) ;;; Code: @@ -1430,6 +1428,62 @@ Optional argument JUSTIFY defines if the paragraph should be justified." (goto-char (line-end-position)))) t) (t t)))) + +;;; FFAP + +(defvar python-ffap-setup-code + "def __FFAP_get_module_path(module): + try: + import os + path = __import__(module).__file__ + if path[-4:] == '.pyc' and os.path.exists(path[0:-1]): + path = path[:-1] + return path + except: + return ''" + "Python code to get a module path.") + +(defvar python-ffap-string-code + "__FFAP_get_module_path('''%s''')\n" + "Python code used to get a string with the path of a module.") + +(defun python-ffap-setup () + "Send `python-ffap-setup-code' to inferior Python process. +It is specially designed to be added to the +`inferior-python-mode-hook'." + (when python-ffap-setup-code + (let ((temp-file (make-temp-file "py"))) + (with-temp-file temp-file + (insert python-ffap-setup-code) + (delete-trailing-whitespace) + (goto-char (point-min))) + (python-shell-send-file temp-file (get-buffer-process (current-buffer))) + (message (format "FFAP setup code sent."))))) + +(defun python-ffap-module-path (module) + "Function for `ffap-alist' to return path for MODULE." + (let ((process (or + (and (eq major-mode 'inferior-python-mode) + (get-buffer-process (current-buffer))) + (python-shell-get-process)))) + (if (not process) + nil + (let ((module-file + (python-shell-send-and-clear-output + (format python-ffap-string-code module) process))) + (when module-file + (ffap-locate-file + (substring-no-properties module-file 1 -1) + nil nil)))))) + +(eval-after-load "ffap" + '(progn + (push '(python-mode . python-ffap-module-path) ffap-alist) + (push '(inferior-python-mode . python-ffap-module-path) ffap-alist))) + +(add-hook 'inferior-python-mode-hook + #'python-ffap-setup) + ;;; Eldoc @@ -1463,7 +1517,7 @@ It is specially designed to be added to the (delete-trailing-whitespace) (goto-char (point-min))) (python-shell-send-file temp-file (get-buffer-process (current-buffer))) - (message (format "Completion setup code sent."))))) + (message (format "Eldoc setup code sent."))))) (defun python-eldoc-function () "`eldoc-documentation-function' for Python.