Commits

Jon Waltman  committed 8e124d6

Update regexps due to changes in how Sphinx formats indexes

  • Participants
  • Parent commits f2f0796

Comments (0)

Files changed (2)

 
 If you want to build the Python documentation yourself, follow these steps:
 
-#. Download and install the latest version of Sphinx (virtualenv may be useful)::
+#. Download and install the development version of Sphinx (virtualenv
+   may be useful)::
 
-      hg clone https://bitbucket.org/birkenfeld/sphinx
-      cd sphinx
+      hg clone https://bitbucket.org/jonwaltman/sphinx-info
+      cd sphinx-info
       sudo python setup.py install
 
 #. Install some libraries::
 #. Modify the configuration file ``conf.py``::
 
       cd Python-2.7.1/Doc
-      cat >> conf.py <<'EOF'
+      cat >> conf.py
 
       texinfo_documents = [
           ('contents', 'python', 'Python Documentation', _stdauthor,
-           "Python", "The Python Documentation", "Software Development"),
+           'Python', 'The Python Documentation', 'Software Development'),
       ]
-      EOF
+
 
 #. Generate the Texinfo::
 

File pydoc-info.el

  :mode 'python-mode
  :parse-rule 'pydoc-info-python-symbol-at-point
  :doc-spec
- '(("(python)Index" pydoc-info-lookup-transform-entry)))
+ '(("(python)Python Module Index" pydoc-info-lookup-transform-entry)
+   ("(python)Index" pydoc-info-lookup-transform-entry)))
 
 (defun pydoc-info-python-symbol-at-point ()
   (with-syntax-table python-dotty-syntax-table
 
 (defun pydoc-info-lookup-transform-entry (item)
   "Transform a Python index entry to a help item."
-  (cond
-   ;; keyword; foo --> foo
-   ;; statement; foo --> foo
-   ((string-match "\\`\\(keyword\\|statement\\);? \\([[:alnum:]_]+\\)" item)
-    (replace-regexp-in-string " " "." (match-string 2 item)))
+  (let* ((py-re "\\([[:alnum:]_.]+\\)(?)?"))
+    (cond
+     ;; keyword; foo --> foo
+     ;; statement; foo --> foo
+     ((string-match (concat "\\`\\(keyword\\|statement\\);? " py-re) item)
+      (replace-regexp-in-string " " "." (match-string 2 item)))
 
-   ;; foo [built-in ...] --> foo
-   ((string-match "\\`\\([[:alnum:]_ ]+\\) \\[built-in .+\\]" item)
-    (replace-regexp-in-string " " "." (match-string 1 item)))
+     ;; foo (built-in ...) --> foo
+     ((string-match (concat "\\`" py-re " (built-in .+)") item)
+      (replace-regexp-in-string " " "." (match-string 1 item)))
 
-   ;; foo bar [module] --> foo.bar
-   ((string-match "\\`\\([[:alnum:]_ ]+\\) \\[module\\]" item)
-    (replace-regexp-in-string " " "." (match-string 1 item)))
+     ;; foo.bar (module) --> foo.bar
+     ((string-match (concat "\\`" py-re " (module)") item)
+      (replace-regexp-in-string " " "." (match-string 1 item)))
 
-   ;; baz [in module foo bar] --> foo.bar.baz
-   ((string-match "\\`\\([[:alnum:]_ ]+\\) \\[in module \\(.+\\)\\]" item)
-    (replace-regexp-in-string " " "." (concat (match-string 2 item) " "
-                                              (match-string 1 item))))
-   ;; Bar [class in foo bar] --> foo.bar.Bar
-   ((string-match "\\`\\([[:alnum:]_ ]+\\) \\[class in \\(.+\\)\\]" item)
-    (replace-regexp-in-string " " "." (concat (match-string 2 item) " "
-                                              (match-string 1 item))))
-   ;; bar [foo Foo method] --> foo.Foo.bar
-   ((string-match
-     "\\`\\([[:alnum:]_ ]+\\) \\[\\(.+\\) \\(method\\|attribute\\)\\]" item)
-    (replace-regexp-in-string " " "." (concat (match-string 2 item) " "
-                                              (match-string 1 item))))
-   (t
-    item)))
+     ;; baz (in module foo.bar) --> foo.bar.baz
+     ((string-match (concat "\\`" py-re " (in module \\(.+\\))") item)
+      (replace-regexp-in-string " " "." (concat (match-string 2 item) " "
+                                                (match-string 1 item))))
+     ;; Bar (class in foo.bar) --> foo.bar.Bar
+     ((string-match (concat "\\`" py-re " (class in \\(.+\\))") item)
+      (replace-regexp-in-string " " "." (concat (match-string 2 item) " "
+                                                (match-string 1 item))))
+     ;; bar (foo.Foo method) --> foo.Foo.bar
+     ((string-match
+       (concat "\\`" py-re " (\\(.+\\) \\(method\\|attribute\\))") item)
+      (replace-regexp-in-string " " "." (concat (match-string 2 item) " "
+                                                (match-string 1 item))))
+     (t
+      item))))
 
 (provide 'pydoc-info)
 ;;; pydoc-info.el ends here