Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open files in web browsers (e.g Firefox) within editors like vim or emacs?

How to open files in browsers (e.g Firefox) within editors like vim or emacs? Notepad++ open files in browsers by pressing Ctrl+Shift+Alt+X (Firefox). Is there a way to do this in gVim or Emacs?

like image 723
alexchenco Avatar asked Jan 10 '10 01:01

alexchenco


2 Answers

browse-url-of-file is an interactive compiled Lisp function in `browse-url.el'.

It is bound to <menu-bar> <HTML> <Load this Buffer in Browser>, C-c C-z v.

(browse-url-of-file &optional file)

Ask a WWW browser to display file.
Display the current buffer's file if file is nil or if called interactively. Turn the filename into a URL with function browse-url-file-url. Pass the URL to a browser using the browse-url function then run browse-url-of-file-hook.

like image 148
user144299 Avatar answered Sep 28 '22 19:09

user144299


In emacs I don't think this is built in, I may be wrong, but if not here is a function to do it:

(defun open-in-browser()   (interactive)   (let ((filename (buffer-file-name)))     (browse-url (concat "file://" filename)))) 
like image 37
justinhj Avatar answered Sep 28 '22 20:09

justinhj