From 4fd1aa963a1e850f5cd0fb93914bb973838f1df9 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Wed, 10 Mar 2010 16:51:42 +0900 Subject: [PATCH] C-uM-C-d browse hackage. --- elisp/ghc-doc.el | 19 ++++++++++++------- elisp/ghc-func.el | 7 ++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/elisp/ghc-doc.el b/elisp/ghc-doc.el index 5af31ab..756df61 100644 --- a/elisp/ghc-doc.el +++ b/elisp/ghc-doc.el @@ -11,12 +11,12 @@ ;;; Code: -(defun ghc-browse-document () - (interactive) +(defun ghc-browse-document (&optional haskell-org) + (interactive "P") (let* ((mod0 (ghc-extract-module)) (mod (ghc-read-module-name mod0)) (pkg (ghc-resolve-package-name mod))) - (ghc-display-document pkg mod))) + (ghc-display-document pkg mod haskell-org))) (defun ghc-resolve-package-name (mod) (with-temp-buffer @@ -32,11 +32,17 @@ (when (looking-at "^haddock-html: \\([^ \n]+\\)$") (match-string-no-properties 1)))) -(defun ghc-display-document (pkg mod) +(defvar ghc-doc-local-format "file://%s/%s.html") +(defvar ghc-doc-hackage-format + "http://hackage.haskell.org/packages/archive/%s/latest/doc/html/%s.html") + +(defun ghc-display-document (pkg mod haskell-org) (when (and pkg mod) (let* ((mod- (ghc-replace-character mod ?. ?-)) - (path (ghc-resolve-document-path pkg)) - (url (format "file://%s/%s.html" path mod-))) + (url (if haskell-org + (format ghc-doc-hackage-format pkg mod-) + (format ghc-doc-local-format + (ghc-resolve-document-path pkg) mod-)))) (browse-url url)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -50,5 +56,4 @@ (make-sparse-keymap))) (define-key ghc-input-map "\t" 'ghc-complete)) - (provide 'ghc-doc) \ No newline at end of file diff --git a/elisp/ghc-func.el b/elisp/ghc-func.el index aa2aebc..59b4634 100644 --- a/elisp/ghc-func.el +++ b/elisp/ghc-func.el @@ -10,9 +10,10 @@ (defun ghc-replace-character (string from to) "Replace characters equal to FROM to TO in STRING." - (dotimes (cnt (length string) string) - (if (char-equal (aref string cnt) from) - (aset string cnt to)))) + (let ((ret (copy-sequence string))) + (dotimes (cnt (length ret) ret) + (if (char-equal (aref ret cnt) from) + (aset ret cnt to))))) (defun ghc-which (cmd) (catch 'loop