Takafumi Arakaki  committed f0ed3b2

Add pydoc-info-current-symbol-functions

pydoc-info-python-symbol-at-point is extensible now.
Bonus: it works with python-mode.el now

  • Participants
  • Parent commits 151d877
  • Branches current-symbol-functions

Comments (0)

Files changed (1)

File pydoc-info.el

 ;;; Code:
+(eval-when-compile (require 'cl))
 (require 'info-look)
 which advises the function `info-insert-file-contents'."
   :group 'pydoc-info)
+(defcustom pydoc-info-current-symbol-functions
+  '(pydoc-info-current-symbol-python-el current-word)
+  "Functions to be called to fetch symbol at point.
+Each function is called with no argument and if it returns a
+string, that value is used.  If it returns nil, next function
+is tried.
+Default (fallback to `current-word' when not using python.el):
+   '(`pydoc-info-current-symbol-python-el' `current-word')."
+  :group 'pydoc-info)
 ;; Is there a better way to do this?
 (defadvice info-insert-file-contents (after
 (defun pydoc-info-python-symbol-at-point ()
   "Return the current Python symbol."
-  (require 'python)
-  (with-syntax-table python-dotty-syntax-table
-    (current-word)))
+  (loop for func in pydoc-info-current-symbol-functions
+        when (funcall func)
+        return it))
+(defun pydoc-info-current-symbol-python-el ()
+  "Return current symbol.  Requires python.el."
+  (when (featurep 'python)
+    (with-syntax-table python-dotty-syntax-table
+      (current-word))))
 (defun pydoc-info-lookup-transform-entry (item)
   "Transform a Python index entry to a help item."