Emacs mode for man pages

emacsmanroff

I'm translating man pages, and have run in to a few problems with Emacs.

  1. How do you specify language? (With man, it looks like this man -Lsv shutdown for the Swedish "sv" subdirectory, if available.)

  2. In the Emacs man mode, you can use N or P to jump forward or backward according to headers (in roff, they look like this: .SH). But, this doesn't work if the header includes one (or more) of the three special Swedish characters: Å, Ä, and Ö. It doesn't matter if I escape them (like this \(:A). (But they are correctly displayed.)

  3. To view a work in project, I use for example M-x man RET ./ls.1 (that is, the absolute path). This is great, because it is the same man mode as for viewing "real" manpages (those in /usr/share/man). Only, when I do some changes in the document, how do I refresh the manpage? revert-buffer says the buffer is not associated with a file (not true, but OK, I get it); M-x load-file RET seems to have lost track of the file; … Ideas?

By the way, translating is a lot of fun!

EDIT: (see the first comment)
Table

Best Answer

How to update the man page in man page mode while editing the roff source:

;;;; MAN / man
(defvar *curr-man* "~/mansv/ls.1")

(defun edman ()
  "edit the current work-in-progress man page"
  (interactive)
  (find-file *curr-man*) )

(defun upman () ; edit: better version of this function below
  "update the current work-in-progress man page"
  (interactive)
  (buffer-menu)
  (revert-buffer)
  (with-temp-buffer
    (progn
      (insert-buffer-substring "*Buffer List*")
      (beginning-of-buffer)
        (let ((man-buffer (format "*Man %s*" *curr-man*)))
          (if (word-search-forward man-buffer (point-max) t) ; t = nil on fail
            (kill-buffer man-buffer) ))
      (man *curr-man*)
      (edman)
      (kill-buffer "*Buffer List*") )))

EDIT

This version of upman is hopefully more stable. Note the introducton of a new global.

(defun upman ()
  "update the current work-in-progress man page"
  (interactive)
  (if (get-buffer *curr-man-file*) (save-buffer))
  (let ((man-buffer (format "*Man %s*" *curr-man*)))
    (if (get-buffer man-buffer) (kill-buffer man-buffer))
    (man *curr-man*)
    (edman) ))
Related Question