Search code examples
emacselisp

How to modify browser in markdown mode?


I use emacs and markdown-mode to write markdown file.
When I press C-c C-c p to call a browser to preview my markdown file, it runs the following code.

(defun markdown-preview (&optional output-buffer-name)
  "Run `markdown-command' on the current buffer and view output in browser.
When OUTPUT-BUFFER-NAME is given, insert the output in the buffer with
that name."
  (interactive)
  (browse-url-of-buffer (markdown-standalone markdown-output-buffer-name)))

It will call my default system browser Firefox. But I want to call Chrome to preview my markdown file, and I don't want to modify my default system browser.
How to modify the code to call Chrome?


Solution

  • You can set up advice to temporarily override the value of browse-url-browser-function when markdown-preview is invoked.

    (defadvice markdown-preview (around markdown-preview-in-chromium activate compile)
       (let ((browse-url-browser-function #'browse-url-chromium))                    
         ad-do-it))
    

    As noted by @jpkotta in the comments, you can configure Emacs to use Chrome instead of Chromium with (setq browse-url-chromium-program "google-chrome") (or whatever your chrome binary is named).