sábado, 12 de noviembre de 2011

change emacs url-browser

When you click an url in emacs, it'll open a browser with that url. That's fine.

Problems arise when you have multiple browsers and they fight to be your preferred one. In a coworker's box, it tries to open konqueror (WTF?!).

One way to fix the issue is changing browse-url-browser-function.


(setq browse-url-browser-function 'browse-url-generic
browse-url-generic-program "chromium-browser")


Not only that, but the nice thing would be that emacs reused a browser if you have one opened (firefox or chrome) and opened a new one (chrome) otherwise.

I've been messing a bit with proced.el to find out how to list external processes programmatically, but had no luck. If I find out how, I 'll modify this post with new info.

If you have related info, please, comment :)

Thanks to Davazp that pointed me to list-system-processes function, I just wrote the code to use an already opened browser to open a given url.

(defun is-proc-opened (procname)
(let ((procs (list-system-processes)))
(remove-if-not (lambda (proc)
(search procname
(name-of-proccess proc)))
procs)))
(defun name-of-process (proc)
(cdr (car (process-attributes proc))))
(defun browse-url-open-browser (url &rest new-window)
(setq browse-url-generic-program (open-browser))
(apply 'browse-url-generic url new-window))
(defun open-browser ()
"define the priorities of browsers"
(if (is-proc-opened "chromium")
"chromium-browser"
(if (is-proc-opened "firefox")
"firefox"
"chromium-browser")))
(setq browse-url-browser-function 'browse-url-open-browser)
view raw open-browser.el hosted with ❤ by GitHub


A good quickreference to look for function signature differences between elisp, scheme and cl is here. It helps quite a lot

1 comentario:

David dijo...

I think you are looking for LIST-PROCESSES. It is described in the Elisp manual. Also, you have LIST-SYSTEM-PROCESSES if you want to list all system processes.

I hope this helps!