1

In my Emacs config, I have set Firefox to be the browser to open URLs with,

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

Now, I have one org-mode file, in which I would like to open URLs with a different program (mpv, to be precise).

What I'm currently trying is a buffer-local variable, indicated by a mode line

# -*- browse-url-browser-function: 'browse-url-chromium -*-

at the top of my org file. However, whenever I click on an org-mode link pointing to a URL (or, just click on a URL, for that matter), I get an error

Debugger entered--Lisp error: (wrong-type-argument listp quote)
  browse-url("https://www.google.com/")
  (lambda (path) (browse-url (concat "https:" path)))("//www.google.com/")
  org-open-at-point()
  org-open-at-mouse((mouse-2 (#<window 1244 on testfile.org> 192 (163 . 95) 82295534 nil 192 (20 . 4) nil (3 . 9) (8 . 19))))
  funcall-interactively(org-open-at-mouse (mouse-2 (#<window 1244 on yoga.org> 192 (163 . 95) 82295534 nil 192 (20 . 4) nil (3 . 9) (8 . 19))))
  call-interactively(org-open-at-mouse nil nil)
  command-execute(org-open-at-mouse)

I would appreciate any pointer towards how I can resolve this.

2

Error is caused by this quote:

# -*- browse-url-browser-function: 'browse-url-chromium -*-
___________________________________|

It shouldn't be there.

Open video path in MPV on *nix OS's

Add this line to the init file(.emacs), or evaluate in Scratch buffer

(org-add-link-type "mpv" (lambda (path) (browse-url-xdg-open path)))

browse-url-xdg-open uses xdg-open program that exists on all *nix desktops("X Desktop Group"). It check file extension to decide which program on desktop should open that path.

Custom link in org mode:

[[mpv:/somepath_to_a_file/some_filename.extension]]

mpv: prefix, or any other defined by org-add-link-type
Actually it would open any file according to MIME type known to xdg-open. It would be MPV video player for a video file if it's configured as a default player on a desktop.

  • 2
    You can have Emacs create this line for you if not sure of the syntax. Try: M-x add-file-local-variable-prop-line, which will prompt you for the variable and the value to set. – glucas Jan 12 at 19:25
0

Like you, I could not figure out how to directly assign a function to a file variable using mode lines. What I ended up having to do was define a function that set the local variables that I wanted, and use a Local Variables: section at the end of the file to call the function.

  (defun set-mpv-local-variables ()
    "Set local variables for using mpv"
    (set (make-local-variable 'browse-url-browser-function) 'browse-url-chromium))

Then at the bottom of your org document add:

# Local Variables:
# eval: (set-mpv-local-variables)
# End:

https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html

If you only want to set one variable, just inlining the set expression may be enough, but if you need to set more than one local variable, I'd split it out into a separate function as I did here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.