Merge from emacs-23
[bpt/emacs.git] / lisp / textmodes / nroff-mode.el
index 14b0b10..420472f 100644 (file)
@@ -1,7 +1,7 @@
 ;;; nroff-mode.el --- GNU Emacs major mode for editing nroff source
 
 ;; Copyright (C) 1985, 1986, 1994, 1995, 1997, 2001, 2002, 2003,
-;;   2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;;   2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: wp
@@ -311,10 +311,16 @@ turns it on if arg is positive, otherwise off."
   "Run man on this file."
   (interactive)
   (require 'man)
-  (let* ((file (buffer-file-name)))
-    (if file
-       (Man-getpage-in-background file)
-      (error "No associated file for the current buffer"))))
+  (let* ((file (buffer-file-name))
+        (viewbuf (get-buffer (concat "*Man " file "*"))))
+    (unless file
+      (error "Buffer is not associated with any file"))
+    (and (buffer-modified-p)
+        (y-or-n-p (format "Save buffer %s first? " (buffer-name)))
+        (save-buffer))
+    (if viewbuf
+       (kill-buffer viewbuf))
+    (Man-getpage-in-background file)))
 
 ;; Old names that were not namespace clean.
 (define-obsolete-function-alias 'count-text-lines 'nroff-count-text-lines "22.1")