Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browse-url fails #36

Closed
asok opened this issue Jan 27, 2014 · 13 comments
Closed

browse-url fails #36

asok opened this issue Jan 27, 2014 · 13 comments

Comments

@asok
Copy link

asok commented Jan 27, 2014

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
Copy link
Author

asok commented Jan 27, 2014

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
Copy link
Member

areina commented Jan 27, 2014

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
Copy link
Author

asok commented Jan 27, 2014

@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
Copy link
Member

kidd commented Jan 27, 2014

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
Copy link
Author

asok commented Jan 27, 2014

@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
Copy link
Member

kidd commented Jan 27, 2014

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
Copy link
Author

asok commented Jan 27, 2014

Thanks for the help.

@asok asok closed this as completed Jan 27, 2014
@jasonm23
Copy link

jasonm23 commented Jul 5, 2015

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

@jasonm23
Copy link

jasonm23 commented Jul 5, 2015

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
Copy link

jasonm23 commented Jul 7, 2015

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
Copy link

jasonm23 commented Jul 7, 2015

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
Copy link

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

osascript -e 'open location "file:///Somethingwithan.html#anchor" '

@markhuyong
Copy link

markhuyong commented Sep 22, 2016

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

  • set os default browser to chrome
  • add config to defun dotspacemacs/user-config ()
;;helm-dash
  (with-eval-after-load 'dash
    (setq helm-dash-browser-func 'browse-url-default-macosx-browser))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants