]> code.delx.au - gnu-emacs/blobdiff - lisp/ehelp.el
*** empty log message ***
[gnu-emacs] / lisp / ehelp.el
index 48c6c5b169277ca653e81591c20da2d085771d2b..9755bf07b7c9baca5193a4a483392c9d3462c681 100644 (file)
@@ -20,8 +20,7 @@
 (provide 'ehelp) 
 
 (defvar electric-help-map ()
-  "Keymap defining commands available whilst scrolling
-through a buffer in electric-help-mode")
+  "Keymap defining commands available in `electric-help-mode'.")
 
 (put 'electric-help-undefined 'suppress-keymap t)
 (if electric-help-map
@@ -45,8 +44,8 @@ through a buffer in electric-help-mode")
     (setq electric-help-map map)))
    
 (defun electric-help-mode ()
-  "with-electric-help temporarily places its buffer in this mode
-\(On exit from with-electric-help, the buffer is put in default-major-mode)"
+  "`with-electric-help' temporarily places its buffer in this mode.
+\(On exit from `with-electric-help', the buffer is put in `default-major-mode'.)"
   (setq buffer-read-only t)
   (setq mode-name "Help")
   (setq major-mode 'help)
@@ -57,71 +56,59 @@ through a buffer in electric-help-mode")
   )
 
 (defun with-electric-help (thunk &optional buffer noerase)
-  "Arguments are THUNK &optional BUFFER NOERASE.
-BUFFER defaults to \"*Help*\"
-THUNK is a function of no arguments which is called to initialise
- the contents of BUFFER.  BUFFER will be erased before THUNK is called unless
- NOERASE is non-nil.  THUNK will be called with  standard-output  bound to
- the buffer specified by BUFFER
+  "Arguments are THUNK &optional BUFFER NOERASE.  BUFFER defaults to \"*Help*\"
+THUNK is a function of no arguments which is called to initialize
+the contents of BUFFER.  BUFFER will be erased before THUNK is called unless
+NOERASE is non-nil.  THUNK will be called with `standard-output' bound to
+the buffer specified by BUFFER
 
 After THUNK has been called, this function \"electrically\" pops up a window
 in which BUFFER is displayed and allows the user to scroll through that buffer
 in electric-help-mode.
-When the user exits (with electric-help-exit, or otherwise) the help
-buffer's window disappears (ie we use save-window-excursion)
-BUFFER is put into default-major-mode (or fundamental-mode) when we exit"
+When the user exits (with `electric-help-exit', or otherwise) the help
+buffer's window disappears (i.e., we use `save-window-excursion')
+BUFFER is put into `default-major-mode' (or `fundamental-mode') when we exit"
   (setq buffer (get-buffer-create (or buffer "*Help*")))
   (let ((one (one-window-p t))
-       (two nil))
-    (save-window-excursion
-      (save-excursion
-       (if one (goto-char (window-start (selected-window))))
-       (let ((pop-up-windows t))
-         (pop-to-buffer buffer))
-       (unwind-protect
-           (progn
-             (save-excursion
-               (set-buffer buffer)
-               (electric-help-mode)
-               (setq buffer-read-only nil)
-               (or noerase (erase-buffer)))
-             (let ((standard-output buffer))
-               (if (funcall thunk)
-                   ()
-                 (set-buffer buffer)
-                 (set-buffer-modified-p nil)
-                 (goto-char (point-min))
-                 (if one (shrink-window-if-larger-than-buffer (selected-window)))))
-             (set-buffer buffer)
-             (run-hooks 'electric-help-mode-hook)
-             (setq two (electric-help-command-loop))
-             (cond ((eq (car-safe two) 'retain)
-                    (setq two (vector (window-height (selected-window))
-                                      (window-start (selected-window))
-                                      (window-hscroll (selected-window))
-                                      (point))))
-                   (t (setq two nil))))
-                                 
-         (message "")
-         (set-buffer buffer)
-         (setq buffer-read-only nil)
-         (condition-case ()
-             (funcall (or default-major-mode 'fundamental-mode))
-           (error nil)))))
-    (if two
-       (let ((pop-up-windows t)
-             tem)
-         (pop-to-buffer buffer)
-         (setq tem (- (window-height (selected-window)) (elt two 0)))
-         (if (> tem 0) (shrink-window tem))
-         (set-window-start (selected-window) (elt two 1) t)
-         (set-window-hscroll (selected-window) (elt two 2))
-         (goto-char (elt two 3)))
-      ;;>> Perhaps this shouldn't be done.
-      ;; so that when we say "Press space to bury" we mean it
-      (replace-buffer-in-windows buffer)
-      ;; must do this outside of save-window-excursion
-      (bury-buffer buffer))))
+       (config (current-window-configuration))
+        (bury nil))
+    (unwind-protect
+         (save-excursion
+           (if one (goto-char (window-start (selected-window))))
+           (let ((pop-up-windows t))
+             (pop-to-buffer buffer))
+           (save-excursion
+             (set-buffer buffer)
+             (electric-help-mode)
+             (setq buffer-read-only nil)
+             (or noerase (erase-buffer)))
+           (let ((standard-output buffer))
+             (if (not (funcall thunk))
+                 (progn
+                   (set-buffer buffer)
+                   (set-buffer-modified-p nil)
+                   (goto-char (point-min))
+                   (if one (shrink-window-if-larger-than-buffer (selected-window))))))
+           (set-buffer buffer)
+           (run-hooks 'electric-help-mode-hook)
+           (if (eq (car-safe (electric-help-command-loop))
+                   'retain)
+               (setq config (current-window-configuration))
+               (setq bury t)))
+      (message "")
+      (set-buffer buffer)
+      (setq buffer-read-only nil)
+      (condition-case ()
+          (funcall (or default-major-mode 'fundamental-mode))
+        (error nil))
+      (set-window-configuration config)
+      (if bury
+          (progn
+            ;;>> Perhaps this shouldn't be done.
+            ;; so that when we say "Press space to bury" we mean it
+            (replace-buffer-in-windows buffer)
+            ;; must do this outside of save-window-excursion
+            (bury-buffer buffer))))))
 
 (defun electric-help-command-loop ()
   (catch 'exit
@@ -177,29 +164,13 @@ BUFFER is put into default-major-mode (or fundamental-mode) when we exit"
   (throw 'exit t))
 
 (defun electric-help-retain ()
-  "Exit electric-help, retaining the current window/buffer conifiguration.
+  "Exit `electric-help', retaining the current window/buffer configuration.
 \(The *Help* buffer will not be selected, but \\[switch-to-buffer-other-window] RET
 will select it.)"
   (interactive)
   (throw 'exit '(retain)))
 
 
-;(defun electric-help-undefined ()
-;  (interactive)
-;  (let* ((keys (this-command-keys))
-;       (n (length keys)))
-;    (if (or (= n 1)
-;          (and (= n 2)
-;               meta-flag
-;               (eq (aref keys 0) meta-prefix-char)))
-;      (setq unread-command-char last-input-char
-;            current-prefix-arg prefix-arg)
-;      ;;>>> I don't care.
-;      ;;>>> The emacs command-loop is too much pure pain to
-;      ;;>>> duplicate
-;      ))
-;  (throw 'exit t))
-
 (defun electric-help-undefined ()
   (interactive)
   (error "%s is undefined -- Press %s to exit"
@@ -315,7 +286,6 @@ will select it.)"
 ;(define-key help-map "a" 'electric-command-apropos)
 
 
-
 \f
 ;;;; ehelp-map
 
@@ -335,4 +305,3 @@ will select it.)"
     (fset 'ehelp-command map)))
 
 ;; Do (define-key global-map "\C-h" 'ehelp-command) if you want to win
-