dash-docs-el / helm-dash

Browse Dash docsets inside emacs
511 stars 59 forks source link

`browse-url` fails #36

Closed asok closed 10 years ago

asok commented 10 years ago

I'm using Emacs 24.3.1 on Macos. It seems that url browsing does not work. When I try:

(browse-url "file:///Users/asok/.docsets/Ruby on Rails.docset/Contents/Resources/Documents/api.rubyonrails.org/v3.2.16/classes/AbstractController/Callbacks/ClassMethods.html#method-i-append_before_filter")

In the *Messages* I see:

#<process open file:///Users/asok/.docsets/Ruby on Rails.docset/Contents/Resources/Documents/api.rubyonrails.org/v3.2.16/classes/AbstractController/Callbacks/ClassMethods.html#method-i-append_before_filter>

And no browser's window is opened. Though when I strip the #target part of the url:

(browse-url "file:///Users/asok/.docsets/Ruby on Rails.docset/Contents/Resources/Documents/api.rubyonrails.org/v3.2.16/classes/AbstractController/Callbacks/ClassMethods.html")

The browser window is opened with the html file.

It might be the bug mentioned here (under the section named: "Bug" in browse-url-default-windows-browser).

Maybe it's worth mentioning that in the README.

asok commented 10 years ago

I've dig more into it. In my setup browse-url will use browse-url-default-macosx-browser function to open the url. And this is resorting to the system's open command which fails when url holds the #target suffix.

As wikiemacs suggests the solution is to open the url in the browser directly (omitting the call to open).

areina commented 10 years ago

Hi @asok , thanks for the info.

Then, I guess that you could solve it changing the value of browse-url-browser-function, no?

If that works well for you, we could add this info in the README.

asok commented 10 years ago

@areina I have a hard time solving this actually. I've tried to run google chrome with this:

(defun browse-url-open-chrome-browser (url &optional new-window)
  (interactive (browse-url-interactive-arg "URL: "))
  (start-process url nil "open" (concat " -a /Applications/Google Chrome.app --args " url)))

(setq browse-url-browser-function 'browse-url-open-chrome-browser)

But to no avail.

For now, I've settled to use w3m. It works with such setup:

(setq browse-url-browser-function 'browse-url-w3)
kidd commented 10 years ago

Hey @asok ! thanks for trying and reporting!

you can try browse-url-chrome, creating the function by copypasta-ing browse-url-chromium.

something like:

(setq browse-url-chrome-program "google-chrome")

(defun browse-url-chrome (url &optional _new-window)
  (interactive (browse-url-interactive-arg "URL: "))
  (setq url (browse-url-encode-url url))
  (let* ((process-environment (browse-url-process-environment)))
    (apply 'start-process
       (concat "google-chrome " url) nil
       browse-url-chrome-program
       (append
        browse-url-chromium-arguments
        (list url)))))

This is not using 'open' but directly running the google-chrome app. in linux it works fine :/

asok commented 10 years ago

@kidd thanks a lot. The only issue is that on osx google-chrome executable is not present. It has got its own launcher in the /Applications/Google Chrome.app/ which does not open the file when passed as an argument. This what happens on my machine:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome  file:///Users/asok/.bashrc                                                           20 ↵
[58734:1799:0127/205051:ERROR:process_singleton_mac.cc(103)] Unable to obtain profile lock.

Sadly I can't find anything helpful on google. Am I really the only one having this issue?

kidd commented 10 years ago

No clue if you're the only one with this issue... :/ for the moment, you'll have to stay with w3 (or eww, which will be bundled with emacs 24.4, and works quite well) until we find out wtf is osx doing, and how to solve it.. :/

Cheers!

asok commented 10 years ago

Thanks for the help.

jasonm23 commented 9 years ago

Another way would be to host via a little local webserver and allow helm-dash to have a different base url from file:///

jasonm23 commented 9 years ago

I'm now using this method

(defun helm-dash-start-localhost-server ()
  "Start a localhost server on port 5000 via a ruby sub process, and serve dash docsets."
  (start-process "dash-docset-localhost-server" "*dash-docset-localhost-server*"
                 "ruby" "-run" "-e" "httpd" helm-dash-docsets-path "-p5000"))

(defun helm-dash-browse-localhost-url (url)
  "Convert file:///URL to http://localhost:5000/ for use with dash local server"
  (let* ((docsets (concat "file://" helm-dash-docsets-path))
         (localurl (replace-regexp-in-string (regexp-quote docsets) "http://localhost:5000" url nil 'literal)))
    (unless (processp 'dash-docset-localhost-server)
      (helm-dash-start-localhost-server))
    (message "%s" localurl)
    (browse-url localurl)))

(setq helm-dash-browser-func 'helm-dash-browse-localhost-url)

note: a couple of edits.

jasonm23 commented 9 years ago

Also just tried to open a URL in Google chrome OSX with

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome "file:///Users/jason/index.html#jump"

Seems to work, so I'm trying shell-command / start-process

jasonm23 commented 9 years ago

This worked.

(shell-command "/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome \"file:///Users/jason/index.html#jump\"")

Safari needs an osascript solution...

Personally I like the localhost server solution, as it doesn't require a specific browser.

jasonm23 commented 9 years ago

http://apple.stackexchange.com/a/197284/1267

osascript -e 'open location "file:///Somethingwithan.html#anchor" '
markhuyong commented 8 years ago

refer to ANN: Helm-dash, the documentation browser for emacs : emacs , for mac ox El Captan, spacemacs:

;;helm-dash
  (with-eval-after-load 'dash
    (setq helm-dash-browser-func 'browse-url-default-macosx-browser))