PageRenderTime 35ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/_emacs.d/site-lisp/packages/epy/eepy-doc.el

http://bamanzi-misc.googlecode.com/
Emacs Lisp | 144 lines | 95 code | 12 blank | 37 comment | 1 complexity | ecc0c86e4ceef009943ed1ebf9c54691 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-4.0
  1. ;; query python document
  2. ;; This file is part of EEPY (Enhanced Emacs for Python)
  3. ;;
  4. ;;** `info-lookup-symbol'
  5. ;; With python 2.6's switching to sphinx as documentation tool, the texinfo
  6. ;; document no longer provided with python official releases.
  7. ;;
  8. ;; You can generate texinfo documents following these info:
  9. ;; http://stackoverflow.com/questions/1054903/how-do-you-get-python-documentation-in-texinfo-info-format
  10. ;; http://bitbucket.org/jonwaltman/sphinx-info
  11. ;; http://bitbucket.org/jonwaltman/rst2texinfo/src
  12. ;;
  13. ;; But if you're lazy, you can force to use python-2.5's info file
  14. ;; http://packages.debian.org/squeeze/python2.5-doc
  15. (defvar eepy-python-info-force-version "2.5"
  16. "Force using python X.x's texinfo documents.)
  17. ;;stolen from Dave Love's python.el
  18. (defun python-init-info-look ()
  19. "Set up info-look for Python.
  20. Tries to take account of versioned Python Info files, e.g. Debian's
  21. python2.5-ref.info.gz.
  22. Used with `eval-after-load'."
  23. (let* ((py-version (let ((s
  24. (shell-command-to-string (concat python-command " -V"))))
  25. (string-match "^Python \\([0-9]+\\.[0-9]+\\>\\)" s)
  26. (match-string 1 s)))
  27. (version (or eepy-python-info-foce-version py-version))
  28. ;; Whether info files have a Python version suffix, e.g. in Debian.
  29. (versioned
  30. (with-temp-buffer
  31. (Info-mode)
  32. ;; First look for Info files corresponding to the version
  33. ;; of the interpreter we're running.
  34. (condition-case ()
  35. ;; Don't use `info' because it would pop-up a *info* buffer.
  36. (progn
  37. (Info-goto-node (format "(python%s-lib)Miscellaneous Index"
  38. version))
  39. t)
  40. (error
  41. ;; Otherwise see if we actually have an un-versioned one.
  42. (condition-case ()
  43. (progn
  44. (Info-goto-node
  45. (format "(python-lib)Miscellaneous Index" version))
  46. nil)
  47. (error
  48. ;; Otherwise look for any versioned Info file.
  49. (condition-case ()
  50. (let (found)
  51. (dolist (dir (or Info-directory-list
  52. Info-default-directory-list))
  53. (unless found
  54. (let ((file (car (file-expand-wildcards
  55. (expand-file-name "python*-lib*"
  56. dir)))))
  57. (if (and file
  58. (string-match
  59. "\\<python\\([0-9]+\\.[0-9]+\\>\\)-"
  60. file))
  61. (setq version (match-string 1 file)
  62. found t)))))
  63. found)
  64. (error)))))))))
  65. (info-lookup-maybe-add-help
  66. :mode 'python-mode
  67. :regexp "[[:alnum:]_]+"
  68. :doc-spec
  69. ;; Fixme: Can this reasonably be made specific to indices with
  70. ;; different rules? Is the order of indices optimal?
  71. ;; (Miscellaneous in -ref first prefers lookup of keywords, for
  72. ;; instance.)
  73. (if versioned
  74. ;; The empty prefix just gets us highlighted terms.
  75. `((,(concat "(python" version "-ref)Miscellaneous Index"))
  76. (,(concat "(python" version "-ref)Module Index"))
  77. (,(concat "(python" version "-ref)Function-Method-Variable Index"))
  78. (,(concat "(python" version "-ref)Class-Exception-Object Index"))
  79. (,(concat "(python" version "-lib)Module Index"))
  80. (,(concat "(python" version "-lib)Class-Exception-Object Index"))
  81. (,(concat "(python" version "-lib)Function-Method-Variable Index"))
  82. (,(concat "(python" version "-lib)Miscellaneous Index")))
  83. '(("(python-ref)Miscellaneous Index")
  84. ("(python-ref)Module Index")
  85. ("(python-ref)Function-Method-Variable Index")
  86. ("(python-ref)Class-Exception-Object Index")
  87. ("(python-lib)Module Index")
  88. ("(python-lib)Class-Exception-Object Index")
  89. ("(python-lib)Function-Method-Variable Index")
  90. ("(python-lib)Miscellaneous Index"))))))
  91. (eval-after-load "info-look" '(python-init-info-look))
  92. ;;** CHM (only available on Windows)
  93. (defcustom eepy-chm-file-path "python.chm"
  94. :group 'eepy
  95. :type 'filename
  96. "Path to pythonXXx.chm")
  97. ;;You need to install `keyhh' utility
  98. ;; http://www.keyworks.net/keyhh.htm
  99. ;;KeyHH -MyHelp -#klink "ActiveX Control Wizard" htmlhelp.chm
  100. (defun chm-keyword-lookup (typeid help-file symbol)
  101. "lookup a keyword in a CHM file and display it"
  102. (interactive)
  103. (start-process "CHM keyword lookup" nil
  104. "keyhh.exe"
  105. (concat "-" typeid) "-#klink"
  106. (format "'%s'" symbol)
  107. help-file ))
  108. (defun eepy-get-keyword-help (symbol)
  109. (interactive
  110. (list (read-string "Help on symbol(CHM): "
  111. (or (thing-at-point 'symbol) ""))))
  112. (chm-keyword-lookup "EEPY" eepy-chm-file-path symbol))
  113. ;;** pylookup
  114. ;;TODO: http://taesoo.org/Opensource/Pylookup
  115. ;;** haddoc
  116. ;;haddoc: Browse HTML Python Documentation From Emacs
  117. ;;TODO: http://furius.ca/haddoc/
  118. ;;** pydoc
  119. ;;stolen from http://stackoverflow.com/questions/1054903/how-do-you-get-python-documentation-in-texinfo-info-format
  120. (defun pydoc (&optional arg)
  121. (interactive)
  122. (when (not (stringp arg))
  123. (setq arg (thing-at-point 'word)))
  124. (setq cmd (concat "pydoc " arg))
  125. (ad-activate-regexp "auto-compile-yes-or-no-p-always-yes")
  126. (shell-command cmd)
  127. (setq pydoc-buf (get-buffer "*Shell Command Output*"))
  128. (switch-to-buffer-other-window pydoc-buf)
  129. (python-mode)
  130. (ad-deactivate-regexp "auto-compile-yes-or-no-p-always-yes")
  131. )
  132. (provide 'eepy-doc)