Mercurial > emacs
comparison lisp/ehelp.el @ 107764:1734936f6133
* ehelp.el (electric-help-orig-major-mode): New buffer-local variable.
(electric-help-mode): Set it to original major-mode. Doc fix.
(with-electric-help): Use `electric-help-orig-major-mode' instead
of (default-value 'major-mode). Doc fix.
http://lists.gnu.org/archive/html/emacs-devel/2010-04/msg00069.html
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Sat, 03 Apr 2010 02:01:22 +0300 |
parents | 1d1d5d9bd884 |
children | 417b1e4d63cd |
comparison
equal
deleted
inserted
replaced
107751:e130bb78db87 | 107764:1734936f6133 |
---|---|
92 (define-key map "\ex" 'electric-help-execute-extended) | 92 (define-key map "\ex" 'electric-help-execute-extended) |
93 (define-key map "\C-x" 'electric-help-ctrl-x-prefix) | 93 (define-key map "\C-x" 'electric-help-ctrl-x-prefix) |
94 map) | 94 map) |
95 "Keymap defining commands available in `electric-help-mode'.") | 95 "Keymap defining commands available in `electric-help-mode'.") |
96 | 96 |
97 (defvar electric-help-orig-major-mode nil) | |
98 (make-variable-buffer-local 'electric-help-orig-major-mode) | |
99 | |
97 (defun electric-help-mode () | 100 (defun electric-help-mode () |
98 "`with-electric-help' temporarily places its buffer in this mode. | 101 "`with-electric-help' temporarily places its buffer in this mode. |
99 \(On exit from `with-electric-help', the buffer is put in default `major-mode'.)" | 102 \(On exit from `with-electric-help', the original `major-mode' is restored.)" |
100 (setq buffer-read-only t) | 103 (setq buffer-read-only t) |
104 (setq electric-help-orig-major-mode major-mode) | |
101 (setq mode-name "Help") | 105 (setq mode-name "Help") |
102 (setq major-mode 'help) | 106 (setq major-mode 'help) |
103 (setq mode-line-buffer-identification '(" Help: %b")) | 107 (setq mode-line-buffer-identification '(" Help: %b")) |
104 (use-local-map electric-help-map) | 108 (use-local-map electric-help-map) |
105 (add-hook 'mouse-leave-buffer-hook 'electric-help-retain) | 109 (add-hook 'mouse-leave-buffer-hook 'electric-help-retain) |
129 shrink the window to fit if `electric-help-shrink-window' is non-nil. | 133 shrink the window to fit if `electric-help-shrink-window' is non-nil. |
130 If THUNK returns non-nil, we don't do those things. | 134 If THUNK returns non-nil, we don't do those things. |
131 | 135 |
132 When the user exits (with `electric-help-exit', or otherwise), the help | 136 When the user exits (with `electric-help-exit', or otherwise), the help |
133 buffer's window disappears (i.e., we use `save-window-excursion'), and | 137 buffer's window disappears (i.e., we use `save-window-excursion'), and |
134 BUFFER is put into default `major-mode' (or `fundamental-mode')." | 138 BUFFER is put back into its original major mode." |
135 (setq buffer (get-buffer-create (or buffer "*Help*"))) | 139 (setq buffer (get-buffer-create (or buffer "*Help*"))) |
136 (let ((one (one-window-p t)) | 140 (let ((one (one-window-p t)) |
137 (config (current-window-configuration)) | 141 (config (current-window-configuration)) |
138 (bury nil) | 142 (bury nil) |
139 (electric-help-form-to-execute nil)) | 143 (electric-help-form-to-execute nil)) |
168 (remove-hook 'mouse-leave-buffer-hook 'electric-help-retain))) | 172 (remove-hook 'mouse-leave-buffer-hook 'electric-help-retain))) |
169 (message "") | 173 (message "") |
170 (set-buffer buffer) | 174 (set-buffer buffer) |
171 (setq buffer-read-only nil) | 175 (setq buffer-read-only nil) |
172 | 176 |
177 ;; Restore the original major mode saved by `electric-help-mode'. | |
173 ;; We should really get a usable *Help* buffer when retaining | 178 ;; We should really get a usable *Help* buffer when retaining |
174 ;; the electric one with `r'. The problem is that a simple | 179 ;; the electric one with `r'. The problem is that a simple |
175 ;; call to help-mode won't cut it; at least RET is bound wrong | 180 ;; call to `help-mode' won't cut it; e.g. RET is bound wrong |
176 ;; afterwards. It's also not clear that `help-mode' is always | 181 ;; afterwards (`View-scroll-line-forward' instead of `help-follow'). |
177 ;; the right thing, maybe we should add an optional parameter. | 182 ;; That's because Help mode should be set with `with-help-window' |
183 ;; instead of the direct call to `help-mode'. But at least | |
184 ;; RET works correctly on links after using `help-mode'. | |
185 ;; This is satisfactory enough. | |
178 (condition-case () | 186 (condition-case () |
179 (funcall (or (default-value 'major-mode) 'fundamental-mode)) | 187 (funcall (or electric-help-orig-major-mode 'fundamental-mode)) |
180 (error nil)) | 188 (error nil)) |
181 | 189 |
182 (set-window-configuration config) | 190 (set-window-configuration config) |
183 (when bury | 191 (when bury |
184 ;;>> Perhaps this shouldn't be done, | 192 ;;>> Perhaps this shouldn't be done, |