From 562441deb6a1a2794dd0d1ae8bb564aaedefe222 Mon Sep 17 00:00:00 2001 From: Daniel Schoepe Date: Wed, 27 Oct 2010 20:55:31 +0200 Subject: [PATCH 1/3] Don't discard version number in ghc-resolve-package and match last (i.e. newest) rather than first listed package. --- elisp/ghc-doc.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/elisp/ghc-doc.el b/elisp/ghc-doc.el index e90a5a3..ca7d6ac 100644 --- a/elisp/ghc-doc.el +++ b/elisp/ghc-doc.el @@ -22,8 +22,8 @@ (with-temp-buffer (call-process "ghc-pkg" nil t nil "find-module" "--simple-output" mod) (goto-char (point-min)) - (when (looking-at "^\\([^ ]+\\)-[0-9]") - (match-string-no-properties 1)))) + (when (re-search-forward "[^ ]+-[0-9]*\\(\\.[0-9]*\\)*$") + (match-string-no-properties 0)))) (defun ghc-resolve-document-path (pkg) (with-temp-buffer @@ -70,4 +70,4 @@ (if (looking-at "^\\(import\\|module\\) +\\(qualified +\\)?\\([^ (\n]+\\)") (match-string-no-properties 3)))) -(provide 'ghc-doc) \ No newline at end of file +(provide 'ghc-doc) From 3017ea063e8d9a36365917be3c7c71b4202458cc Mon Sep 17 00:00:00 2001 From: Daniel Schoepe Date: Wed, 27 Oct 2010 21:03:28 +0200 Subject: [PATCH 2/3] Minor correction in ghc-resolve-package --- elisp/ghc-doc.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/elisp/ghc-doc.el b/elisp/ghc-doc.el index ca7d6ac..d4f972e 100644 --- a/elisp/ghc-doc.el +++ b/elisp/ghc-doc.el @@ -22,7 +22,7 @@ (with-temp-buffer (call-process "ghc-pkg" nil t nil "find-module" "--simple-output" mod) (goto-char (point-min)) - (when (re-search-forward "[^ ]+-[0-9]*\\(\\.[0-9]*\\)*$") + (when (re-search-forward "[^ ]+-[0-9]*\\(\\.[0-9]+\\)*$") (match-string-no-properties 0)))) (defun ghc-resolve-document-path (pkg) From aaf72e536b4d7949d01204231c8c7f4279e69e9e Mon Sep 17 00:00:00 2001 From: Daniel Schoepe Date: Wed, 27 Oct 2010 21:45:15 +0200 Subject: [PATCH 3/3] Fix breakage caused by previous commit --- elisp/ghc-doc.el | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/elisp/ghc-doc.el b/elisp/ghc-doc.el index d4f972e..e0464c3 100644 --- a/elisp/ghc-doc.el +++ b/elisp/ghc-doc.el @@ -22,8 +22,9 @@ (with-temp-buffer (call-process "ghc-pkg" nil t nil "find-module" "--simple-output" mod) (goto-char (point-min)) - (when (re-search-forward "[^ ]+-[0-9]*\\(\\.[0-9]+\\)*$") - (match-string-no-properties 0)))) + (when (re-search-forward "\\([^ ]+\\)-\\([0-9]*\\(\\.[0-9]+\\)*\\)$") + (cons (match-string-no-properties 1) + (match-string-no-properties 2))))) (defun ghc-resolve-document-path (pkg) (with-temp-buffer @@ -36,17 +37,23 @@ (defconst ghc-doc-local-format "file://%s/%s.html") (defconst ghc-doc-hackage-format - "http://hackage.haskell.org/packages/archive/%s/latest/doc/html/%s.html") + "http://hackage.haskell.org/packages/archive/%s/%s/doc/html/%s.html") (defun ghc-display-document (pkg mod haskell-org) (when (and pkg mod) (let* ((mod- (ghc-replace-character mod ?. ?-)) - (url (if haskell-org - (format ghc-doc-hackage-format pkg mod-) - (format ghc-doc-local-format - (ghc-resolve-document-path pkg) mod-)))) + (url (if haskell-org + (format ghc-doc-hackage-format (car pkg) (cdr pkg) mod-) + (let* ((pkg-with-ver (format "%s-%s" (car pkg) (cdr pkg))) + (path (ghc-resolve-document-path pkg-with-ver))) + (if (file-exists-p (format "%s/%s.html" path mod-)) + (format ghc-doc-local-format path mod-) + ;; fall back to online version if local file + ;; doesn't exist: + (format ghc-doc-hackage-format (car pkg) (cdr pkg) mod-)))))) (browse-url url)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar ghc-input-map nil)