115
;;*;; Access function for displaying help
117
123
(defun ess-display-help-on-object (object)
118
124
"Display documentation for OBJECT in another window.
119
125
If prefix arg is given, forces a query of the ESS process for the help
120
126
file. Otherwise just pops to an existing buffer if it exists.
121
Uses the variable `inferior-ess-help-command' for the actual help command."
122
(interactive (ess-find-help-file "Help on: "))
123
(let* ((hb-name (concat "*help["
124
ess-current-process-name
126
(old-hb-p (get-buffer hb-name))
127
(curr-win-mode major-mode)
128
(tbuffer (get-buffer-create hb-name))
129
(curr-help-command inferior-ess-help-command)
130
;;-- pass the buffer-local 'ess-help-sec-..' to the ess-help buffer:
131
(curr-help-sec-regex ess-help-sec-regex)
132
(curr-help-sec-keys-alist ess-help-sec-keys-alist)
133
(curr-help-syntax-table (syntax-table))
134
(alist ess-local-customize-alist))
137
(ess-setq-vars-local (eval alist))
138
(setq ess-help-sec-regex curr-help-sec-regex)
139
(setq ess-help-sec-keys-alist curr-help-sec-keys-alist)
140
;; see above, do same for inferior-ess-help-command... (i.e. remove
141
;; hack, restore old code :-).
143
(if (or (not old-hb-p)
145
(ess-help-bogus-buffer-p old-hb-p nil nil 'debug)
148
;; Ask the corresponding ESS process for the help file:
150
(if buffer-read-only (setq buffer-read-only nil))
151
(delete-region (point-min) (point-max))
153
(setq ess-local-process-name ess-current-process-name)
154
(ess-command (format curr-help-command object) tbuffer)
155
;; was inferior-ess-help-command
158
;; Stata is clean, so we get a big BARF from this.
159
(if (not (string= ess-language "STA"))
162
(goto-char (point-min))))
165
(let ((PM (point-min))
166
(nodocs (ess-help-bogus-buffer-p (current-buffer) nil 'give-match))
170
ess-help-kill-bogus-buffers)
172
(if (not (listp nodocs))
173
(setq nodocs (list PM (point-max))))
174
(ess-write-to-dribble-buffer
175
(format "(ess-help: error-buffer '%s' nodocs (%d %d)\n"
176
(buffer-name) (car nodocs) (cadr nodocs)))
177
;; Avoid using 'message here -- may be %'s in string
178
;;(princ (buffer-substring (car nodocs) (cadr nodocs)) t)
179
;; MM [3/2000]: why avoid? Yes, I *do* want message:
180
(message "%s" (buffer-substring (car nodocs) (cadr nodocs)))
181
;; ^^^ fixme : remove new lines from the above {and abbrev.}
183
(kill-buffer tbuffer))
187
;;dbg (ess-write-to-dribble-buffer
188
;;dbg (format "(ess-help '%s' before switch-to..\n" hb-name)
189
(let ((special-display-regexps
190
(if ess-help-own-frame '(".") nil))
191
(special-display-frame-alist ess-help-frame-alist)
192
(special-display-function
193
(if (eq ess-help-own-frame 'one)
195
special-display-function)))
196
(if (eq curr-win-mode 'ess-help-mode)
197
(if ess-help-own-frame
198
(pop-to-buffer tbuffer)
199
(switch-to-buffer tbuffer))
200
(ess-display-temp-buffer tbuffer)))
201
(if curr-help-syntax-table
202
(set-syntax-table curr-help-syntax-table))
203
(set-buffer-modified-p 'nil)
204
(toggle-read-only t))))))
127
Uses the variable `inferior-ess-help-command' for the actual help command.
128
Prompts for the object name based on the cursor location for all cases
129
except the S-Plus GUI. With S-Plus on Windows (both GUI and in an inferior
130
emacs buffer) the GUI help window is used."
132
(if (ess-ddeclient-p)
133
(list (read-string "Help on: "))
134
(ess-find-help-file "Help on: ")))
136
(if (or (ess-ddeclient-p)
137
(equal inferior-ess-help-filetype "chm"))
138
(if (ess-ddeclient-p)
139
(ess-display-help-on-object-ddeclient object) ;; ddeclient version
140
(ess-eval-linewise (concat "help(" object ")"))) ;; "chm" version
142
;; else: "normal", non-DDE behavior:
143
(let* ((hb-name (concat "*help["
144
ess-current-process-name
146
(old-hb-p (get-buffer hb-name))
147
(curr-win-mode major-mode)
148
(tbuffer (get-buffer-create hb-name))
149
(curr-help-command inferior-ess-help-command)
150
;;-- pass the buffer-local 'ess-help-sec-..' to the ess-help buffer:
151
(curr-help-sec-regex ess-help-sec-regex)
152
(curr-help-sec-keys-alist ess-help-sec-keys-alist)
153
(curr-help-syntax-table (syntax-table))
154
(curr-help-filetype inferior-ess-help-filetype)
155
(alist ess-local-customize-alist))
158
(ess-setq-vars-local (eval alist))
159
(setq ess-help-sec-regex curr-help-sec-regex)
160
(setq ess-help-sec-keys-alist curr-help-sec-keys-alist)
161
(setq inferior-ess-help-filetype curr-help-filetype)
162
;; see above, do same for inferior-ess-help-command... (i.e. remove
163
;; hack, restore old code :-).
165
(if (or (not old-hb-p)
167
(ess-help-bogus-buffer-p old-hb-p nil nil 'debug)
170
;; Ask the corresponding ESS process for the help file:
172
(if buffer-read-only (setq buffer-read-only nil))
173
(delete-region (point-min) (point-max))
175
(setq ess-local-process-name ess-current-process-name)
176
(ess-command (format curr-help-command object) tbuffer)
177
;; was inferior-ess-help-command
180
;; Stata is clean, so we get a big BARF from this.
181
(if (not (string= ess-language "STA"))
184
(goto-char (point-min))))
187
(let ((PM (point-min))
189
(ess-help-bogus-buffer-p (current-buffer) nil 'give-match )))
192
ess-help-kill-bogus-buffers)
194
(if (not (listp nodocs))
195
(setq nodocs (list PM (point-max))))
196
(ess-write-to-dribble-buffer
197
(format "(ess-help: error-buffer '%s' nodocs (%d %d)\n"
198
(buffer-name) (car nodocs) (cadr nodocs)))
199
;; Avoid using 'message here -- may be %'s in string
200
;;(princ (buffer-substring (car nodocs) (cadr nodocs)) t)
201
;; MM [3/2000]: why avoid? Yes, I *do* want message:
202
(message "%s" (buffer-substring (car nodocs) (cadr nodocs)))
203
;; ^^^ fixme : remove new lines from the above {and abbrev.}
205
(kill-buffer tbuffer))
207
;; else : show the help buffer.
209
;; Check if this buffer describes where help can be found in
210
;; various packages. (R only). This is a kind of bogus help
211
;; buffer, but it should not be killed immediately even if
212
;; ess-help-kill-bogus-buffers is t.
214
;; e.g. if within R, the user does:
216
;; > options("help.try.all.packages" = TRUE)
220
;; then a list of packages for where ?rlm is defined is
221
;; shown. (In this case, rlm is in package MASS). This
222
;; help buffer is then renamed *help[R](rlm in packages)* so
223
;; that after MASS is loaded, ?rlm will then show
226
(if (equal inferior-ess-program inferior-R-program-name)
227
;; this code should be used only for R processes.
229
(goto-char (point-min))
230
(if (looking-at "Help for topic")
233
(concat "*help[" ess-current-process-name
234
"](" object " in packages)*")))
235
;; if NEWBUF already exists, remove it.
236
(if (get-buffer newbuf)
237
(kill-buffer newbuf))
238
(rename-buffer newbuf)))))
240
;;dbg (ess-write-to-dribble-buffer
241
;;dbg (format "(ess-help '%s' before switch-to..\n" hb-name)
242
(let ((special-display-regexps
243
(if ess-help-own-frame '(".") nil))
244
(special-display-frame-alist ess-help-frame-alist)
245
(special-display-function
246
(if (eq ess-help-own-frame 'one)
248
special-display-function)))
249
(if (eq curr-win-mode 'ess-help-mode)
250
(if ess-help-own-frame
251
(pop-to-buffer tbuffer)
252
(switch-to-buffer tbuffer))
253
(ess-display-temp-buffer tbuffer)))
254
(if curr-help-syntax-table
255
(set-syntax-table curr-help-syntax-table))
256
(set-buffer-modified-p 'nil)
257
(toggle-read-only t)))))))
206
259
(defvar ess-help-frame nil
207
260
"Stores the frame used for displaying R help buffers.")