10

I want to use Emacs as an enhanced way to view the source of a page (say http://example.com). Is there some easy way to download the page directly from Emacs, maybe even through C-x C-f?

I remember doing this somehow in the past (maybe thanks to TRAMP?), but not how, and I can't reproduce it any more.

Tikhon Jelvis
  • 6,152
  • 2
  • 27
  • 40
  • You mean something more clever than just wget and then viewing that right? Perhaps w3m in emacs gives some kind of option? – c-o-d Sep 25 '14 at 18:04
  • @EdgarAroutiounian: Not necessarily more clever so much as more integrated. For some reason, I think there's a more immediate way to do it. – Tikhon Jelvis Sep 25 '14 at 18:08

2 Answers2

8

Here's a really quick and dirty solution:

(defun my-view-source (url)
  (interactive "MURL: ")
  (switch-to-buffer (url-retrieve url (lambda (_)))))

url-retrieve is built-in to Emacs; there are also alternatives such as request.el.

shosti
  • 5,048
  • 26
  • 33
5

The w3 mode can do this with the w3-source-document-at-point command which by default is bound to s.

You could also use M-! and invoke curl.

b4hand
  • 1,995
  • 1
  • 19
  • 31