help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I decode an NROFF file for viewing?


From: Kevin Ryde
Subject: Re: How do I decode an NROFF file for viewing?
Date: Wed, 23 Jul 2008 11:01:29 +1000
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.2 (gnu/linux)

Alan Mackenzie <address@hidden> writes:
>
> I have an Nroff file, mount.8, loaded into Emacs.  How do I do part
> (ii) of the above, and get it nicely displayed?

I use a bit as simple as a "man -l filename" for files:

(defun my-man-preview ()
  (interactive)
  (my-save-current-buffer-maybe)
  (setq Man-notify-method 'pushy)
  (man (concat "-l " (buffer-file-name))))

(defun my-save-current-buffer-maybe ()
  "Use `save-some-buffers' to save the current buffer, if it's modified."
  (interactive)
  (let ((my-save-current-buffer-maybe--target (current-buffer)))
    (save-some-buffers nil
                       (lambda ()
                         (equal my-save-current-buffer-maybe--target
                                (current-buffer))))))


I had a similar bit with woman (below) in the past, trying to get it to
preserve the window position in a re-preview (might be slightly broken),
but I think I ended up preferring plain man plus
(setq Man-switches "-Tlatin1").

My perl-pod-preview.el has some hairier stuff preserving the window
position and working from a buffer (from pod2man in its case) instead of
a file.  The guts of it is a call-process-region with "man -Tlatin1 -l -"
then Man-fontify-manpage and Man-mode.


(defun my-man-preview-woman ()
  (interactive)
  (my-save-current-buffer-maybe)
  (my-woman-find-or-revert (buffer-file-name)))

(defun my-woman-find-or-revert (filename)
  (let ((bufname
         (concat "*WoMan "
                 (file-name-extension filename)
                 " "
                 (file-name-sans-extension (file-name-nondirectory filename))
                 "*")))
    (if (get-buffer bufname)
        (progn
          (switch-to-buffer bufname)
          (let* ((point-column (current-column))
                 (point-line   (progn
                                 (beginning-of-line)
                                 (1+ (count-lines (point-min) (point)))))
                 (start-line   (count-lines (point-min) (window-start))))
            (kill-buffer (current-buffer))
            (woman-find-file filename)
            (goto-line start-line)
            (set-window-start (selected-window) (point))
            (goto-line point-line)
            (move-to-column point-column)))
      (woman-find-file filename))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]