0

Suppose, we have a link [[https://www.google.com/][Google]]. When I put the cursor at the link and run org-open-at-point, instead of opening https://www.google.com/ in browser it downloads the page to /var/tmp and opens the file in browser: file:///var/tmp/kdecache-user/krun/20635_0_. All the css and js are broken of course.

Can I make it open the direct link in browser? Or maybe, it's not Emacs, but KDE.

11
  • What's the "it" that downloads the page to /var/tmp?
    – NickD
    Apr 9 at 18:49
  • What happens if you say ESC ESC : (browse-url "https://www.google.com/") RET?
    – NickD
    Apr 9 at 18:56
  • @NickD "it" is the html page of google. It is downloaded into a file and then opened in Firefox.
    – user4035
    Apr 9 at 19:22
  • @NickD When I execute the command, I get the same thing: it is downloaded into a file and the file is opened in Firefox.
    – user4035
    Apr 9 at 19:23
  • @NickD Does it work correctly on your system?
    – user4035
    Apr 9 at 19:24
1

[This answer is meant as a tutorial introduction to how one would debug problems like the OP's, so it is more detailed than the "answer" which is just the setting of browse-url-browser-function below. But I have always found answers of the sort "Do this - problem solved" unsatisfactory: I like to understand what's going on. YMMV, in which case skip the long-winded explanations.]

org-open-at-point calls org-link-open which uses the variable org-link-parameters to look up the :follow property for the type of the link. In this case the type is https and the :follow property turns out to be an anonymous function that is set when the file ol.el[c] (l.1349 in my version of the file) is loaded:

...
;;;; "http", "https", "mailto", "ftp", and "news" link types
(dolist (scheme '("ftp" "http" "https" "mailto" "news"))
  (org-link-set-parameters scheme
               :follow
               (lambda (url arg)
                 (browse-url (concat scheme ":" url) arg))))
...

The upshot is that this anonymous (lambda) function calls browse-url. It is unlikely that the problem as described is caused by any of the above, so we concentrate on browse-url.

Reading the doc string of browse-url (C-h f browse-url) uncovers the fact that it calls the function that is specified as the value of the variable browse-url-browser-function. After prodding the OP with a question, we find out that the OP's setting of that variable was browse-url-default-browser. Unfortunately for debugging purposes (remote debugging purposes, no less), that function pokes around all over the place until it finds something that it can use and then calls that something. So at that point, it was more expedient to suggest that the OP bypass that and set the browse-url-browser-function variable directly to the function corresponding to the desired browser:

(setq browse-url-browser-function #'browse-url-firefox)

Setting that in the init file did the trick for the OP. Other "direct to external browser" function available include browse-url-chrome and browse-url-mozilla.

The only remaining mystery is why the default browser function did what the OP described. From the description, it seems that the culprit is browse-url-kde. I have no way to test that, but a KDE user can confirm (or refute) that claim by evaluating the following (e.g. in the *scratch* buffer - paste the expression and type C-j after the closing paren):

(browse-url-kde "https://www.google.com")

If that does what the OP describes, it's arguably a bug in the browse-url-kde function and should probably be reported (M-x report-emacs-bug).

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .