Improved documentation browsing on OS X.
Opening a tab in Safari using AppleScript preserves URL anchors. The use of this function may be toggled with a new customization option.
This commit is contained in:
parent
78c5cea161
commit
b4bb930037
@ -10,6 +10,17 @@
|
||||
(require 'ghc-comp)
|
||||
(require 'ghc-info)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;;;
|
||||
;;; Customize Variables
|
||||
;;;
|
||||
|
||||
(defcustom ghc-doc-browser-function #'browse-url
|
||||
"Function used to browse documentation."
|
||||
:type '(radio (function-item browse-url)
|
||||
(function-item ghc-browse-url-safari))
|
||||
:group 'ghc-mod)
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defun ghc-browse-document (&optional haskell-org)
|
||||
@ -43,9 +54,18 @@
|
||||
(defconst ghc-doc-hackage-format
|
||||
"http://hackage.haskell.org/packages/archive/%s/%s/doc/html/%s.html")
|
||||
|
||||
(defun ghc-browse-url-safari (uri &rest args)
|
||||
"Open a URI in Safari using AppleScript. This preserves anchors."
|
||||
(let ((script (format "
|
||||
tell application \"Safari\"
|
||||
open location \"%s\"
|
||||
activate
|
||||
end tell" uri)))
|
||||
(do-applescript script)))
|
||||
|
||||
(defun ghc-display-document (pkg-ver-path mod haskell-org &optional symbol)
|
||||
(let* ((mod- (ghc-replace-character mod ?. ?-))
|
||||
(pkg (ghc-pkg-ver-path-get-pkg pkg-ver-path))
|
||||
(let* ((pkg (ghc-pkg-ver-path-get-pkg pkg-ver-path))
|
||||
(mod- (ghc-replace-character mod ?. ?-))
|
||||
(ver (ghc-pkg-ver-path-get-ver pkg-ver-path))
|
||||
(path (ghc-pkg-ver-path-get-path pkg-ver-path))
|
||||
(pkg-with-ver (format "%s-%s" pkg ver))
|
||||
@ -54,8 +74,7 @@
|
||||
(file (format "%s/%s.html" path mod-))
|
||||
(url0 (if (or haskell-org (not (file-exists-p file))) remote local))
|
||||
(url (if symbol (ghc-add-anchor url0 symbol) url0)))
|
||||
;; Mac's "open" removes the anchor from "file://", sigh.
|
||||
(browse-url url)))
|
||||
(funcall ghc-doc-browser-function url)))
|
||||
|
||||
(defun ghc-add-anchor (url symbol)
|
||||
(let ((case-fold-search nil))
|
||||
|
@ -30,6 +30,8 @@
|
||||
|
||||
(defconst ghc-version "5.3.0.0")
|
||||
|
||||
(defgroup ghc-mod '() "ghc-mod customization")
|
||||
|
||||
;; (eval-when-compile
|
||||
;; (require 'haskell-mode))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user