9

I want to open a.html in a browser from emacs (v. 24.5.1, using -Q [updated after comment]).

M-x shell-command
xdg-open a.html

works as expected, but

M-x eshell
$ xdg-open a.html

does not seem to do anything. There is no error message. This problem also occurs when exporting and directly opening html files from org-mode.

  • This seems to work in my config. Does it not work for you in `emacs -Q`? – PythonNut Jan 07 '16 at 17:53
  • I've updated the question -- I was already using `emacs -q -Q` – Jannis Teunissen Jan 07 '16 at 17:58
  • 1
    @JannisTeunissen Unless I am mistaken, `-Q` includes the `-q` option, so `-q -Q` will be the same as `-Q` – elethan Jan 07 '16 at 18:41
  • Also, this does not answer the question as to why `xdg-open` does not work in `eshell`, but you can use the command `browse-url-of-file` called from a buffer visiting `a.html` to open that file in your default browser. – elethan Jan 07 '16 at 18:44
  • 2
    Try setting `process-connection-type` to `nil` (you can just type `(setq process-connection-type nil)` at the eshell prompt). (By the way, while this works on my machine, I don't understand why it works.) – Omar Jan 07 '16 at 23:01
  • Thanks, after setting `(setq process-connection-type nil)` it works as expected! If you submit your comment as an answer I can accept it :) – Jannis Teunissen Jan 07 '16 at 23:30
  • checkout https://askubuntu.com/questions/646631/emacs-doesnot-work-with-xdg-open - setting this variable might break some functionality, I had to debug for hours until I found it broke `ripgrep` integration for me! – xeruf Feb 24 '21 at 10:56

2 Answers2

4

Set process-connection-type to nil. To be honest I don't understand why xdg-open doesn't work when that variable has the value t and I also can't remember how I learned that changing the value let me use xdg-open from Emacs. (If someone knows, I'd love to hear about it.)

Omar
  • 4,732
  • 1
  • 17
  • 32
1

Using setsid -w $shell_cmd is better, because of (setq process-connection-type nil) causing some problems like sudo: no tty present and no askpass program specified when using M-& sudo $shell_cmd.

REF

Big Shield
  • 183
  • 6
  • I face this problem when opening links to external files in org-mode (links of type `file+sys`) Could you elaborate on what do you mean by "using `setsid -w ...`"? how/where do I use that? Also, I don't want to just open 1.pdf (as seen in the link you post), but any file. – onlycparra Feb 14 '22 at 21:28