summaryrefslogtreecommitdiff
path: root/lisp/ehelp.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/ehelp.el')
-rw-r--r--lisp/ehelp.el133
1 files changed, 82 insertions, 51 deletions
diff --git a/lisp/ehelp.el b/lisp/ehelp.el
index 9755bf07b7c..48c6c5b1692 100644
--- a/lisp/ehelp.el
+++ b/lisp/ehelp.el
@@ -20,7 +20,8 @@
(provide 'ehelp)
(defvar electric-help-map ()
- "Keymap defining commands available in `electric-help-mode'.")
+ "Keymap defining commands available whilst scrolling
+through a buffer in electric-help-mode")
(put 'electric-help-undefined 'suppress-keymap t)
(if electric-help-map
@@ -44,8 +45,8 @@
(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)
@@ -56,59 +57,71 @@
)
(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 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
+ "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
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 (i.e., 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 (ie 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))
- (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))))))
+ (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))))
(defun electric-help-command-loop ()
(catch 'exit
@@ -164,13 +177,29 @@ 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 configuration.
+ "Exit electric-help, retaining the current window/buffer conifiguration.
\(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"
@@ -286,6 +315,7 @@ will select it.)"
;(define-key help-map "a" 'electric-command-apropos)
+
;;;; ehelp-map
@@ -305,3 +335,4 @@ will select it.)"
(fset 'ehelp-command map)))
;; Do (define-key global-map "\C-h" 'ehelp-command) if you want to win
+