Emacs: Harden web browser detection

master
Pierre Neidhardt 2017-09-11 18:29:35 +01:00
parent af41a6c939
commit de00aa53b2
2 changed files with 19 additions and 5 deletions

View File

@ -87,16 +87,17 @@ If there is none, fire it up."
(interactive)
(if (and (eq major-mode 'exwm-mode)
(string-match
(format " - %s$" (regexp-quote (file-name-nondirectory browse-url-generic-program)))
(buffer-name (current-buffer))))
;; Only match against the end as some window names are hard to predict, e.g. "Mozilla Firefox".
(format "%s$" (regexp-quote (file-name-nondirectory browse-url-generic-program)))
(downcase (buffer-name (current-buffer)))))
(start-process-shell-command browse-url-generic-program nil browse-url-generic-program)
(let ((last (buffer-list)))
(while (and last
(not (with-current-buffer (car last)
(and (eq major-mode 'exwm-mode)
(string-match
(format " - %s$" (regexp-quote (file-name-nondirectory browse-url-generic-program)))
(buffer-name (current-buffer)))))))
(format "%s$" (regexp-quote (file-name-nondirectory browse-url-generic-program)))
(downcase (buffer-name (current-buffer))))))))
(setq last (cdr last)))
(if last
(switch-to-buffer (car last))

View File

@ -163,7 +163,20 @@
(if (executable-find "xdg-open") 'browse-url-xdg-open 'browse-url-generic))
;;; If xdg-open is not found, set Emacs URL browser to the environment browser,
;;; or w3m if BROWSER is not set.
(setq browse-url-generic-program (or (executable-find (or (getenv "BROWSER") "")) (executable-find "w3m")))
;;; TODO: Upstream should be smart at this, e.g. allow using xdg without a DE. Report.
(setq browse-url-generic-program (or
(executable-find (or (getenv "BROWSER") ""))
(when (executable-find "xdg-mime")
(let ((desktop-browser (call-process-to-string "xdg-mime" "query" "default" "text/html")))
(substring desktop-browser 0 (string-match "\\.desktop" desktop-browser))))
(executable-find browse-url-mozilla-program)
(executable-find browse-url-firefox-program)
(executable-find browse-url-chromium-program)
(executable-find browse-url-kde-program)
(executable-find browse-url-conkeror-program)
(executable-find browse-url-chrome-program)))
;;; Default ispell dictionary. If not set, Emacs uses the current locale.
(setq ispell-dictionary "english")