From 378f9937f10466aab340f81206193c11346cf9c2 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 22 Aug 2007 18:52:59 +0000 Subject: [PATCH] (browse-url-emacs): New function. --- etc/NEWS | 2 ++ lisp/ChangeLog | 6 +++++- lisp/net/browse-url.el | 25 ++++++++++++++++++------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 63591f40e61..e93c9128991 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -41,6 +41,8 @@ below. Emacs tries to warn you about these through `bad-packages-alist'. * Changes in Emacs 22.2 +** `browse-url-emacs' loads a URL into an Emacs buffer. Handy for *.el URLs. + ** `bad-packages-alist' will warn about external packages that are known to cause problems in this version of Emacs. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 593a390b91a..a3a70d624cf 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2007-08-22 Johan Bockg,Ae(Brd + + * net/browse-url.el (browse-url-emacs): New function. + 2007-08-22 Stefan Monnier * emacs-lisp/bytecomp.el (byte-compile-from-buffer): Display a big fat @@ -938,7 +942,7 @@ * lpr.el (lpr-page-header-switches): Move %s to separate element for correct quoting. Doc fix. -2007-06-13 Johan Bockg,Ae(Brd (tiny change) +2007-06-13 Johan Bockg,Ae(Brd * term/xterm.el (terminal-init-xterm): Escape parens in character constants. diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index 208e1fc178a..55d8d6609e0 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -669,8 +669,7 @@ interactively. Turn the filename into a URL with function (error "Current buffer has no file")) (let ((buf (get-file-buffer file))) (if buf - (save-excursion - (set-buffer buf) + (with-current-buffer buf (cond ((not (buffer-modified-p))) (browse-url-save-file (save-buffer)) (t (message "%s modified since last save" file)))))) @@ -1170,6 +1169,20 @@ used instead of `browse-url-new-window-flag'." browse-url-epiphany-program (append browse-url-epiphany-startup-arguments (list url)))))) +;;;###autoload +(defun browse-url-emacs (url &optional new-window) + "Ask Emacs to load URL into a buffer and show it in another window." + (interactive (browse-url-interactive-arg "URL: ")) + (require 'url-handlers) + (let ((file-name-handler-alist + (cons (cons url-handler-regexp 'url-file-handler) + file-name-handler-alist))) + ;; Ignore `new-window': with all other browsers the URL is always shown + ;; in another window than the current Emacs one since it's shown in + ;; another application's window. + ;; (if new-window (find-file-other-window url) (find-file url)) + (find-file-other-window url))) + ;;;###autoload (defun browse-url-gnome-moz (url &optional new-window) "Ask Mozilla/Netscape to load URL via the GNOME program `gnome-moz-remote'. @@ -1257,8 +1270,7 @@ Default to the URL around or before point. Runs the program in the variable `browse-url-grail'." (interactive (browse-url-interactive-arg "Grail URL: ")) (message "Sending URL to Grail...") - (save-excursion - (set-buffer (get-buffer-create " *Shell Command Output*")) + (with-current-buffer (get-buffer-create " *Shell Command Output*") (erase-buffer) ;; don't worry about this failing. (if (browse-url-maybe-new-window new-window) @@ -1428,8 +1440,7 @@ used instead of `browse-url-new-window-flag'." Default to the URL around or before point." (interactive (browse-url-interactive-arg "MMM URL: ")) (message "Sending URL to MMM...") - (save-excursion - (set-buffer (get-buffer-create " *Shell Command Output*")) + (with-current-buffer (get-buffer-create " *Shell Command Output*") (erase-buffer) ;; mmm_remote just SEGVs if the file isn't there... (if (or (file-exists-p (expand-file-name "~/.mmm_remote")) @@ -1507,5 +1518,5 @@ Default to the URL around or before point." (provide 'browse-url) -;;; arch-tag: d2079573-5c06-4097-9598-f550fba19430 +;; arch-tag: d2079573-5c06-4097-9598-f550fba19430 ;;; browse-url.el ends here -- 2.39.5