;;; 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 Free Software Foundation, Inc.
+;; 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
;; Maintainer: FSF
;; Keywords: wp
(define-key map "\n" 'nroff-electric-newline)
(define-key map "\en" 'nroff-forward-text-line)
(define-key map "\ep" 'nroff-backward-text-line)
+ (define-key map "\C-c\C-c" 'nroff-view)
(define-key map [menu-bar nroff-mode] (cons "Nroff" menu-map))
(define-key menu-map [nn]
'(menu-item "Newline" nroff-electric-newline
nroff-electric-mode
:help "Auto insert closing requests if necessary"
:button (:toggle . nroff-electric-mode)))
+ (define-key menu-map [npm]
+ '(menu-item "Preview as man page" nroff-view
+ :help "Run man on this file."))
map)
"Major mode keymap for `nroff-mode'.")
(concat "[.']\\|" paragraph-start))
(set (make-local-variable 'paragraph-separate)
(concat "[.']\\|" paragraph-separate))
+ ;; Don't auto-fill directive lines starting . or ' since they normally
+ ;; have to be one line. But do auto-fill comments .\" .\# and '''.
+ ;; Comment directives (those starting . or ') are [.'][ \t]*\\[#"]
+ ;; or ''', and this regexp is everything except those. So [.']
+ ;; followed by not backslash and not ' or followed by backslash but
+ ;; then not # or "
+ (set (make-local-variable 'auto-fill-inhibit-regexp)
+ "[.'][ \t]*\\([^ \t\\']\\|\\\\[^#\"]\\)")
;; comment syntax added by mit-erl!gildea 18 Apr 86
(set (make-local-variable 'comment-start) "\\\" ")
(set (make-local-variable 'comment-start-skip) "\\\\[\"#][ \t]*")
:lighter " Electric"
(or (derived-mode-p 'nroff-mode) (error "Must be in nroff mode")))
+(declare-function Man-getpage-in-background "man" (topic))
+
+(defun nroff-view ()
+ "Run man on this file."
+ (interactive)
+ (require 'man)
+ (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")
(define-obsolete-function-alias 'forward-text-line 'nroff-forward-text-line "22.1")