Skip to content

Commit

Permalink
Derive Man and WoMan modes from special-mode
Browse files Browse the repository at this point in the history
* lisp/man.el (Man-mode-map): Set parent to map composed from both
button-buffer-map and special-mode-map.  Remove redundant bindings.
Fix menu to refer to the quit-window command.
(Man-mode): Derive from special-mode.  Fix docstring.  Remove redundant
buffer-read-only binding.
(Man-quit): Remove.
* lisp/woman.el (woman-really-find-file): Use setq-local.
(woman-mode-map): Refer to woman-mode in docstring.
(woman-mode): Derive from special-mode.  Document woman-mode-map in
docstring.  Use setq-local where possible; imenu-generic-expression is
already buffer-local.
(woman-negative-vertical-space): Replace unused binding with _.
  • Loading branch information
holomorph committed Oct 13, 2016
1 parent 8ee9522 commit 506a97a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 35 deletions.
26 changes: 6 additions & 20 deletions lisp/man.el
Original file line number Diff line number Diff line change
Expand Up @@ -432,29 +432,23 @@ Otherwise, the value is whatever the function
(defvar Man-mode-map
(let ((map (make-sparse-keymap)))
(suppress-keymap map)
(set-keymap-parent map button-buffer-map)
(set-keymap-parent map
(make-composed-keymap button-buffer-map special-mode-map))

(define-key map [?\S-\ ] 'scroll-down-command)
(define-key map " " 'scroll-up-command)
(define-key map "\177" 'scroll-down-command)
(define-key map "n" 'Man-next-section)
(define-key map "p" 'Man-previous-section)
(define-key map "\en" 'Man-next-manpage)
(define-key map "\ep" 'Man-previous-manpage)
(define-key map ">" 'end-of-buffer)
(define-key map "<" 'beginning-of-buffer)
(define-key map "." 'beginning-of-buffer)
(define-key map "r" 'Man-follow-manual-reference)
(define-key map "g" 'Man-goto-section)
(define-key map "s" 'Man-goto-see-also-section)
(define-key map "k" 'Man-kill)
(define-key map "q" 'Man-quit)
(define-key map "u" 'Man-update-manpage)
(define-key map "m" 'man)
;; Not all the man references get buttons currently. The text in the
;; manual page can contain references to other man pages
(define-key map "\r" 'man-follow)
(define-key map "?" 'describe-mode)

(easy-menu-define nil map
"`Man-mode' menu."
Expand All @@ -476,7 +470,7 @@ Otherwise, the value is whatever the function
"--"
["Man..." man t]
["Kill Buffer" Man-kill t]
["Quit" Man-quit t]))
["Quit" quit-window t]))
map)
"Keymap for Man mode.")

Expand Down Expand Up @@ -1474,9 +1468,7 @@ manpage command."

(defvar bookmark-make-record-function)

(put 'Man-mode 'mode-class 'special)

(define-derived-mode Man-mode fundamental-mode "Man"
(define-derived-mode Man-mode special-mode "Man"
"A mode for browsing Un*x manual pages.
The following man commands are available in the buffer. Try
Expand All @@ -1490,7 +1482,7 @@ The following man commands are available in the buffer. Try
\\[Man-previous-section] Jump to previous manpage section.
\\[Man-goto-section] Go to a manpage section.
\\[Man-goto-see-also-section] Jumps to the SEE ALSO manpage section.
\\[Man-quit] Deletes the manpage window, bury its buffer.
\\[quit-window] Deletes the manpage window, bury its buffer.
\\[Man-kill] Deletes the manpage window, kill its buffer.
\\[describe-mode] Prints this help text.
Expand All @@ -1517,8 +1509,7 @@ The following key bindings are currently in effect in the buffer:
mode-line-buffer-identification
(list (default-value 'mode-line-buffer-identification)
" {" 'Man-page-mode-string "}")
truncate-lines t
buffer-read-only t)
truncate-lines t)
(buffer-disable-undo)
(auto-fill-mode -1)
(setq imenu-generic-expression (list (list nil Man-heading-regexp 0)))
Expand Down Expand Up @@ -1794,11 +1785,6 @@ Specify which REFERENCE to use; default is based on word at point."
(interactive)
(quit-window t))

(defun Man-quit ()
"Bury the buffer containing the manpage."
(interactive)
(quit-window))

(defun Man-goto-page (page &optional noerror)
"Go to the manual page on page PAGE."
(interactive
Expand Down
25 changes: 10 additions & 15 deletions lisp/woman.el
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ Do not call directly!"
(woman-insert-file-contents filename compressed)
;; Set buffer's default directory to that of the file.
(setq default-directory (file-name-directory filename))
(set (make-local-variable 'backup-inhibited) t)
(setq-local backup-inhibited t)
(set-visited-file-name "")
(woman-process-buffer)))

Expand Down Expand Up @@ -1780,7 +1780,7 @@ Leave point at end of new text. Return length of inserted text."
(define-key map [remap man] 'woman)
(define-key map [remap man-follow] 'woman-follow)
map)
"Keymap for woman mode.")
"Keymap for `woman-mode'.")

(defun woman-follow (topic)
"Get a Un*x manual page of the item under point and put it in a buffer."
Expand Down Expand Up @@ -1872,15 +1872,15 @@ Argument EVENT is the invoking mouse event."
(woman-reformat-last-file))

(defvar bookmark-make-record-function)
(put 'woman-mode 'mode-class 'special)

(defun woman-mode ()
(define-derived-mode woman-mode special-mode "WoMan"
"Turn on (most of) Man mode to browse a buffer formatted by WoMan.
WoMan is an ELisp emulation of much of the functionality of the Emacs
`man' command running the standard UN*X man and ?roff programs.
WoMan author: F.J.Wright@Maths.QMW.ac.uk
WoMan version: see `woman-version'.
See `Man-mode' for additional details."
See `Man-mode' for additional details.
\\{woman-mode-map}"
(let ((Man-build-page-list (symbol-function 'Man-build-page-list))
(Man-strip-page-headers (symbol-function 'Man-strip-page-headers))
(Man-unindent (symbol-function 'Man-unindent))
Expand All @@ -1905,23 +1905,18 @@ See `Man-mode' for additional details."
(kill-local-variable 'mode-line-buffer-identification)
(use-local-map woman-mode-map)
;; Imenu support:
(set (make-local-variable 'imenu-generic-expression)
;; `make-local-variable' in case imenu not yet loaded!
woman-imenu-generic-expression)
(set (make-local-variable 'imenu-space-replacement) " ")
(setq imenu-generic-expression woman-imenu-generic-expression)
(setq-local imenu-space-replacement " ")
;; Bookmark support.
(set (make-local-variable 'bookmark-make-record-function)
'woman-bookmark-make-record)
(setq-local bookmark-make-record-function 'woman-bookmark-make-record)
;; For reformat ...
;; necessary when reformatting a file in its old buffer:
(setq imenu--last-menubar-index-alist nil)
;; necessary to avoid re-installing the same imenu:
(setq woman-imenu-done nil)
(if woman-imenu (woman-imenu))
(let ((inhibit-read-only t))
(Man-highlight-references 'WoMan-xref-man-page))
(set-buffer-modified-p nil)
(run-mode-hooks 'woman-mode-hook))
(Man-highlight-references 'WoMan-xref-man-page)))

(defun woman-imenu (&optional redraw)
"Add a \"Contents\" menu to the menubar.
Expand Down Expand Up @@ -3884,7 +3879,7 @@ Leave 1 blank line. Format paragraphs upto TO."
((eq c ?\t) ; skip
(if (eq (following-char) ?\t)
(forward-char) ; both tabs, just skip
(dotimes (i woman-tab-width)
(dotimes (_ woman-tab-width)
(if (eolp)
(insert ?\s) ; extend line
(forward-char)) ; skip
Expand Down

0 comments on commit 506a97a

Please sign in to comment.