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:
Anthony Cowley 2015-08-17 15:36:21 -04:00
parent 78c5cea161
commit b4bb930037
2 changed files with 25 additions and 4 deletions

View File

@ -10,6 +10,17 @@
(require 'ghc-comp) (require 'ghc-comp)
(require 'ghc-info) (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: ;;; Code:
(defun ghc-browse-document (&optional haskell-org) (defun ghc-browse-document (&optional haskell-org)
@ -43,9 +54,18 @@
(defconst ghc-doc-hackage-format (defconst ghc-doc-hackage-format
"http://hackage.haskell.org/packages/archive/%s/%s/doc/html/%s.html") "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) (defun ghc-display-document (pkg-ver-path mod haskell-org &optional symbol)
(let* ((mod- (ghc-replace-character mod ?. ?-)) (let* ((pkg (ghc-pkg-ver-path-get-pkg pkg-ver-path))
(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)) (ver (ghc-pkg-ver-path-get-ver pkg-ver-path))
(path (ghc-pkg-ver-path-get-path pkg-ver-path)) (path (ghc-pkg-ver-path-get-path pkg-ver-path))
(pkg-with-ver (format "%s-%s" pkg ver)) (pkg-with-ver (format "%s-%s" pkg ver))
@ -54,8 +74,7 @@
(file (format "%s/%s.html" path mod-)) (file (format "%s/%s.html" path mod-))
(url0 (if (or haskell-org (not (file-exists-p file))) remote local)) (url0 (if (or haskell-org (not (file-exists-p file))) remote local))
(url (if symbol (ghc-add-anchor url0 symbol) url0))) (url (if symbol (ghc-add-anchor url0 symbol) url0)))
;; Mac's "open" removes the anchor from "file://", sigh. (funcall ghc-doc-browser-function url)))
(browse-url url)))
(defun ghc-add-anchor (url symbol) (defun ghc-add-anchor (url symbol)
(let ((case-fold-search nil)) (let ((case-fold-search nil))

View File

@ -30,6 +30,8 @@
(defconst ghc-version "5.3.0.0") (defconst ghc-version "5.3.0.0")
(defgroup ghc-mod '() "ghc-mod customization")
;; (eval-when-compile ;; (eval-when-compile
;; (require 'haskell-mode)) ;; (require 'haskell-mode))