Declaration fixes.
[emacs.git] / lisp / progmodes / idlw-help.el
blob7202d95c8dbbb9560d4b1db0521ab687ec852298
1 ;;; idlw-help.el --- HTML Help code for IDLWAVE
3 ;; Copyright (C) 2000-2011 Free Software Foundation, Inc.
4 ;;
5 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
6 ;; Carsten Dominik <dominik@science.uva.nl>
7 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
8 ;; Version: 6.1.22
9 ;; Package: idlwave
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;; Commentary:
28 ;; The help link information for IDLWAVE's online help feature for
29 ;; system routines is extracted automatically from the IDL
30 ;; documentation, and is available, along with general routine
31 ;; information, in the file idlw-rinfo.el. The HTML help file
32 ;; themselves are not distributable with Emacs, but are available,
33 ;; along with new versions of IDLWAVE, documentation, and more
34 ;; information, at:
36 ;; http://idlwave.org
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
42 ;;; Code:
43 (defvar idlwave-help-browse-url-available t
44 "Whether browse-url is available.")
46 (require 'browse-url)
48 (defgroup idlwave-online-help nil
49 "Online Help options for IDLWAVE mode."
50 :group 'idlwave)
52 (defcustom idlwave-html-help-pre-v6 nil
53 "Whether pre or post-v6.0 IDL help documents are being used."
54 :group 'idlwave-online-help
55 :type 'boolean)
57 (defvar idlwave-html-link-sep
58 (if idlwave-html-help-pre-v6 "#" "#wp"))
60 (defcustom idlwave-html-system-help-location "help/online_help/"
61 "The directory, relative to `idlwave-system-directory', where the IDL
62 HTML help files live, for IDL 6.2 and later. This location, if found,
63 is used in preference to the old `idlwave-html-help-location'."
64 :group 'idlwave-online-help
65 :type 'directory)
67 (defcustom idlwave-html-help-location
68 (if (memq system-type '(ms-dos windows-nt))
69 nil
70 "/usr/local/etc/")
71 "The directory where the idl_html_help/ dir lives. Obsolete for IDL
72 6.2 or later (see `idlwave-html-system-help-location')."
73 :group 'idlwave-online-help
74 :type 'directory)
76 (defvar idlwave-help-use-hh nil
77 "Obsolete variable.")
79 (defcustom idlwave-help-use-assistant t
80 "Whether to use the IDL Assistant as the help browser."
81 :group 'idlwave-online-help
82 :type 'boolean)
84 (defcustom idlwave-help-browser-function browse-url-browser-function
85 "Function to use to display HTML help.
86 Defaults to `browse-url-browser-function', which see."
87 :group 'idlwave-online-help
88 :type 'function)
90 (defcustom idlwave-help-browser-generic-program browse-url-generic-program
91 "Program to run if using `browse-url-generic-program'."
92 :group 'idlwave-online-help
93 :type 'string)
95 (defvar browse-url-generic-args)
97 (defcustom idlwave-help-browser-generic-args
98 (if (boundp 'browse-url-generic-args)
99 browse-url-generic-args "")
100 "Program args to use if using `browse-url-generic-program'."
101 :group 'idlwave-online-help
102 :type 'string)
104 (defcustom idlwave-help-browser-is-local nil
105 "Whether the browser will display locally in an Emacs window.
106 Several browsers run and/or display inside Emacs windows, but most are
107 external programs. If the browser name contains \"-w3\", it is
108 assumed to be local to Emacs. For other local browsers, this variable
109 must be explicitly set non-nil in order for the variable
110 `idlwave-help-use-dedicated-frame' to function."
111 :group 'idlwave-online-help
112 :type 'boolean)
114 (defvar idlwave-help-directory ""
115 "Obsolete variable. See `idlwave-html-help-location'.")
117 (defcustom idlwave-help-use-dedicated-frame t
118 "*Non-nil means, use a separate frame for Online Help if possible."
119 :group 'idlwave-online-help
120 :type 'boolean)
122 (defcustom idlwave-help-frame-parameters
123 '((height . 32) (unsplittable . t))
124 "The frame parameters for the special Online Help frame.
125 See also `idlwave-help-use-dedicated-frame'.
126 If you do not set the frame width here, the value specified in
127 `idlw-help.el' will be used."
128 :group 'idlwave-online-help
129 :type '(repeat
130 (cons symbol sexp)))
132 (defcustom idlwave-max-popup-menu-items 20
133 "Maximum number of items per pane in popup menus.
134 Currently only used for class selection during completion help."
135 :group 'idlwave-online-help
136 :type 'integer)
138 (defcustom idlwave-extra-help-function 'idlwave-help-with-source
139 "The function to call for online help if the normal help fails.
140 Online help works only for system routines which are described in the
141 IDL manuals. A function may be specified to access help from other sources.
143 The function must accept four arguments: NAME, TYPE, CLASS, KEYWORD.
144 The Help buffer is current when this function is called, and the help
145 text should be loaded into this buffer. If help is found, the
146 function should return the buffer position which should be used as
147 `window-start' in the help window. Also, the variable
148 `idlwave-help-mode-line-indicator' should be set to a useful string,
149 which will be displayed in the mode line of the help window. If
150 should also set the variable `idlwave-help-min-frame-width' to a
151 positive integer. IDLWAVE will ensure that the help frame is at least
152 that many columns wide. Failure to find help should be indicated by
153 throwing an error.
155 When this variable is non-nil, IDLWAVE will allow the mouse-3 help click
156 for every routine and keyword, even though the item may not be highlighted
157 in blue (indicating the availability of system documentation).
159 The default value for this function is `idlwave-help-with-source' which
160 loads the routine source file into the help buffer. If you try to write
161 a different function which accesses a special help file or so, it is
162 probably a good idea to still call this function as a fallback."
163 :group 'idlwave-online-help
164 :type 'symbol)
166 (defcustom idlwave-help-fontify-source-code nil
167 "*Non-nil means, fontify source code displayed as help like normal code."
168 :group 'idlwave-online-help
169 :type 'boolean)
171 (defcustom idlwave-help-source-try-header t
172 "*Non-nil means, try to find help in routine header when displaying source.
173 Routines which are not documented in the system manual use their source as
174 help text. When this variable is non-nil, we try to find a description of
175 the help item in the first routine doclib header above the routine definition.
176 If the variable is nil, or if we cannot find/parse the header, the routine
177 definition is displayed instead."
178 :group 'idlwave-online-help
179 :type 'boolean)
182 (defcustom idlwave-help-doclib-name "name"
183 "*A regexp for the heading word to search for in doclib headers
184 which specifies the `name' section. Can be used for localization
185 support."
186 :group 'idlwave-online-help
187 :type 'string)
189 (defcustom idlwave-help-doclib-keyword "KEYWORD"
190 "*A regexp for the heading word to search for in doclib headers
191 which specifies the `keywords' section. Can be used for localization
192 support."
193 :group 'idlwave-online-help
194 :type 'string)
196 (defface idlwave-help-link
197 '((t :inherit link))
198 "Face for highlighting links into IDLWAVE online help."
199 :group 'idlwave-online-help)
201 (defvar idlwave-help-activate-links-aggressively nil
202 "Obsolete variable.")
204 (defvar idlwave-completion-help-info)
206 (defvar idlwave-help-frame nil
207 "The frame for display of IDL online help.")
208 (defvar idlwave-help-frame-width 102
209 "The default width of the help frame.")
211 (defvar idlwave-html-help-is-available nil
212 "Is the system online help text available?")
214 (defvar idlwave-help-mode-line-indicator ""
215 "Used for the special mode line in the `idlwave-help-mode'.")
217 (defvar idlwave-help-window-configuration nil)
218 (defvar idlwave-help-special-topic-words nil) ; defined by get_rinfo
220 ;; Define the key bindings for the Help application
222 (defvar idlwave-help-mode-map
223 (let ((map (make-sparse-keymap)))
224 (define-key map "q" 'idlwave-help-quit)
225 (define-key map "w" 'widen)
226 (define-key map "\C-m" (lambda (arg)
227 (interactive "p")
228 (scroll-up arg)))
229 (define-key map " " 'scroll-up)
230 (define-key map [delete] 'scroll-down)
231 (define-key map "h" 'idlwave-help-find-header)
232 (define-key map "H" 'idlwave-help-find-first-header)
233 (define-key map "." 'idlwave-help-toggle-header-match-and-def)
234 (define-key map "F" 'idlwave-help-fontify)
235 (define-key map "\M-?" 'idlwave-help-return-to-calling-frame)
236 (define-key map "x" 'idlwave-help-return-to-calling-frame)
237 map)
238 "The keymap used in `idlwave-help-mode'.")
240 ;; Define the menu for the Help application
242 (easy-menu-define
243 idlwave-help-menu idlwave-help-mode-map
244 "Menu for Help IDLWAVE system"
245 '("IDLHelp"
246 ["Definition <-> Help Text" idlwave-help-toggle-header-match-and-def t]
247 ["Find DocLib Header" idlwave-help-find-header t]
248 ["Find First DocLib Header" idlwave-help-find-first-header t]
249 ["Fontify help buffer" idlwave-help-fontify t]
250 "--"
251 ["Quit" idlwave-help-quit t]))
253 (defvar idlwave-help-def-pos)
254 (defvar idlwave-help-args)
255 (defvar idlwave-help-in-header)
256 (declare-function idlwave-prepare-structure-tag-completion "idlw-complete-structtag")
257 (declare-function idlwave-all-method-classes "idlwave")
258 (declare-function idlwave-all-method-keyword-classes "idlwave")
259 (declare-function idlwave-beginning-of-statement "idlwave")
260 (declare-function idlwave-best-rinfo-assoc "idlwave")
261 (declare-function idlwave-class-found-in "idlwave")
262 (declare-function idlwave-class-or-superclass-with-tag "idlwave")
263 (declare-function idlwave-completing-read "idlwave")
264 (declare-function idlwave-current-routine "idlwave")
265 (declare-function idlwave-downcase-safe "idlwave")
266 (declare-function idlwave-entry-find-keyword "idlwave")
267 (declare-function idlwave-expand-keyword "idlwave")
268 (declare-function idlwave-find-class-definition "idlwave")
269 (declare-function idlwave-find-inherited-class "idlwave")
270 (declare-function idlwave-find-struct-tag "idlwave")
271 (declare-function idlwave-get-buffer-visiting "idlwave")
272 (declare-function idlwave-in-quote "idlwave")
273 (declare-function idlwave-make-full-name "idlwave")
274 (declare-function idlwave-members-only "idlwave")
275 (declare-function idlwave-popup-select "idlwave")
276 (declare-function idlwave-routine-source-file "idlwave")
277 (declare-function idlwave-routines "idlwave")
278 (declare-function idlwave-sintern-class "idlwave")
279 (declare-function idlwave-sintern-keyword "idlwave")
280 (declare-function idlwave-sintern-method "idlwave")
281 (declare-function idlwave-sintern-routine-or-method "idlwave")
282 (declare-function idlwave-sintern-sysvar "idlwave" t t);idlwave-new-sintern-type
283 (declare-function idlwave-sintern-sysvartag "idlwave" t t)
284 (declare-function idlwave-substitute-link-target "idlwave")
285 (declare-function idlwave-sys-dir "idlwave")
286 (declare-function idlwave-this-word "idlwave")
287 (declare-function idlwave-what-module-find-class "idlwave")
288 (declare-function idlwave-where "idlwave")
290 (define-derived-mode idlwave-help-mode special-mode "IDLWAVE Help"
291 "Major mode for displaying IDL Help.
293 This is a VIEW mode for the ASCII version of IDL Help files,
294 with some extras. Its main purpose is speed - so don't
295 expect a fully hyper-linked help.
297 Scrolling: SPC DEL RET
298 Text Searches: Inside Topic: Use Emacs search functions
299 Exit: [q]uit or mouse button 3 will kill the frame
301 When the hep text is a source file, the following commands are available
303 Fontification: [F]ontify the buffer like source code
304 Jump: [h] to function doclib header
305 [H] to file doclib header
306 [.] back and forth between header and definition
308 Here are all keybindings.
309 \\{idlwave-help-mode-map}"
310 (buffer-disable-undo)
311 (easy-menu-add idlwave-help-menu idlwave-help-mode-map)
312 (setq truncate-lines t)
313 (setq case-fold-search t)
314 (setq mode-line-format
315 (list ""
316 'mode-line-modified
317 'mode-line-buffer-identification
318 ": " 'idlwave-help-mode-line-indicator
319 " -%-"))
320 (setq buffer-read-only t)
321 (set (make-local-variable 'idlwave-help-def-pos) nil)
322 (set (make-local-variable 'idlwave-help-args) nil)
323 (set (make-local-variable 'idlwave-help-in-header) nil))
325 (defun idlwave-html-help-location ()
326 "Return the help directory where HTML files are, or nil if that is unknown."
327 (let ((syshelp-dir (expand-file-name
328 idlwave-html-system-help-location (idlwave-sys-dir)))
329 (help-dir (or (and (stringp idlwave-html-help-location)
330 (> (length idlwave-html-help-location) 0)
331 idlwave-html-help-location)
332 (getenv "IDLWAVE_HELP_LOCATION"))))
333 (if (and syshelp-dir (file-directory-p syshelp-dir))
334 syshelp-dir
335 (if help-dir
336 (progn
337 (setq help-dir (expand-file-name "idl_html_help" help-dir))
338 (if (file-directory-p help-dir) help-dir))))))
340 (defvar idlwave-help-assistant-available nil)
342 (defun idlwave-help-check-locations ()
343 ;; Check help locations and assistant.
344 (let ((sys-dir (idlwave-sys-dir))
345 (help-loc (idlwave-html-help-location)))
346 (if (or (not (file-directory-p sys-dir))
347 (not help-loc)
348 (not (file-directory-p help-loc)))
349 (message
350 "HTML help location not found: try setting `idlwave-system-directory' and/or `idlwave-html-help-location'."))
351 ;; see if we have the assistant
352 (when (and idlwave-help-use-assistant
353 (not (eq (idlwave-help-assistant-available) t)))
354 (message "Cannot locate IDL Assistant, enabling default browser.")
355 (setq idlwave-help-use-assistant nil)
356 (unless idlwave-help-browse-url-available
357 (error "browse-url is not available; install it or IDL Assistant to use HTML help")))))
360 (defvar idlwave-current-obj_new-class)
361 (defvar idlwave-help-diagnostics)
362 (defvar idlwave-experimental)
363 (defvar idlwave-last-context-help-pos)
364 (defun idlwave-do-context-help (&optional arg)
365 "Wrapper around the call to `idlwave-do-context-help1'.
366 It collects and prints the diagnostics messages."
367 (let ((marker (list (current-buffer) (point)))
368 (idlwave-help-diagnostics nil))
369 ;; Check for frame switching. When the command is invoked twice
370 ;; at the same position, we try to switch to the help frame
371 ;; FIXME: Frame switching works only on XEmacs
372 (if (and idlwave-experimental
373 (equal last-command this-command)
374 (equal idlwave-last-context-help-pos marker))
375 (idlwave-help-select-help-frame)
376 ;; Do the real thing.
377 (setq idlwave-last-context-help-pos marker)
378 (idlwave-do-context-help1 arg)
379 (if idlwave-help-diagnostics
380 (message "%s" (mapconcat 'identity
381 (nreverse idlwave-help-diagnostics)
382 "; "))))))
384 (defvar idlwave-help-do-class-struct-tag nil)
385 (defvar idlwave-structtag-struct-location)
386 (defvar idlwave-help-do-struct-tag nil)
387 (defvar idlwave-system-variables-alist)
388 (defvar idlwave-executive-commands-alist)
389 (defvar idlwave-system-class-info)
390 (defun idlwave-do-context-help1 (&optional arg)
391 "The work-horse version of `idlwave-context-help', which see."
392 (save-excursion
393 (if (equal (char-after) ?/)
394 (forward-char 1)
395 (if (equal (char-before) ?=)
396 (backward-char 1)))
397 (let* ((idlwave-query-class nil)
398 (idlwave-force-class-query (equal arg '(4)))
399 (chars "a-zA-Z0-9_$.!")
400 (beg (save-excursion (skip-chars-backward chars) (point)))
401 (end (save-excursion (skip-chars-forward chars) (point)))
402 (this-word (buffer-substring-no-properties beg end))
403 (st-ass (assoc-string this-word
404 idlwave-help-special-topic-words t))
405 (classtag (and (string-match "self\\." this-word)
406 (< beg (- end 4))))
407 (structtag (and (fboundp 'idlwave-complete-structure-tag)
408 (string-match "\\`\\([^.]+\\)\\." this-word)
409 (< beg (- end 4))))
410 module keyword cw mod1 mod2 mod3)
411 (if (or arg
412 (and (not classtag)
413 (not structtag)
414 (not (member (string-to-char this-word) '(?! ?.)))))
415 ;; Need the module information
416 (progn
417 ;; MODULE is (name type class), for this or any inheriting class
418 (setq module (idlwave-what-module-find-class)
419 cw (nth 2 (idlwave-where))) ;what would we complete here?
420 ;; Correct for OBJ_NEW, we may need an INIT method instead.
421 (if (equal (idlwave-downcase-safe (car module)) "obj_new")
422 (let* ((bos (save-excursion (idlwave-beginning-of-statement)
423 (point)))
424 (str (buffer-substring bos (point))))
425 (if (string-match "OBJ_NEW([ \t]*['\"]\\([a-zA-Z][a-zA-Z0-9$_]+\\)['\"]" str)
426 (setq module (list "init" 'fun (match-string 1 str))
427 idlwave-current-obj_new-class (match-string 1 str))
428 )))))
429 (cond
430 (arg (setq mod1 module))
432 ;; A special topic -- only system help
433 ((and st-ass (not (memq cw '(function-keyword procedure-keyword))))
434 (setq mod1 (list (cdr st-ass))))
436 ;; A system variable -- only system help
437 ((string-match
438 "\\`!\\([a-zA-Z0-9_]+\\)\\(\.\\([A-Za-z0-9_]+\\)\\)?"
439 this-word)
440 (let* ((word (match-string-no-properties 1 this-word))
441 (entry (assq (idlwave-sintern-sysvar word)
442 idlwave-system-variables-alist))
443 (tag (match-string-no-properties 3 this-word))
444 (tag-target (if tag
445 (cdr
446 (assq (idlwave-sintern-sysvartag tag)
447 (cdr (assq 'tags entry))))))
448 (link (nth 1 (assq 'link entry))))
449 (if tag-target
450 (setq link (idlwave-substitute-link-target link
451 tag-target)))
452 (setq mod1 (list link))))
454 ;; An executive command -- only system help
455 ((string-match "^\\.\\([A-Z_]+\\)" this-word)
456 (let* ((word (match-string 1 this-word))
457 (link (cdr (assoc-string
458 word
459 idlwave-executive-commands-alist t))))
460 (setq mod1 (list link))))
462 ;; A class -- system OR in-text help (via class__define).
463 ((and (eq cw 'class)
464 (or (idlwave-in-quote) ; e.g. obj_new
465 (re-search-backward "\\<inherits[ \t]+[A-Za-z0-9_]*\\="
466 (max (point-min) (- (point) 40)) t)))
467 ;; Class completion inside string delimiters must be
468 ;; the class inside OBJ_NEW.
469 (let* ((entry (assq
470 (idlwave-sintern-class this-word)
471 idlwave-system-class-info))
472 (name (concat (downcase this-word) "__define"))
473 (link (nth 1 (assq 'link entry))))
474 (setq mod1 (list link name 'pro))))
476 ;; A class structure tag (self.BLAH) -- only in-text help available
477 (classtag
478 (let ((tag (substring this-word (match-end 0)))
479 class-with found-in)
480 (when (setq class-with
481 (idlwave-class-or-superclass-with-tag
482 (nth 2 (idlwave-current-routine))
483 tag))
484 (setq found-in (idlwave-class-found-in class-with))
485 (if (assq (idlwave-sintern-class class-with)
486 idlwave-system-class-info)
487 (error "No help available for system class tags"))
488 (setq idlwave-help-do-class-struct-tag t)
489 (setq mod1 (list nil
490 (if found-in
491 (cons (concat found-in "__define") class-with)
492 (concat class-with "__define"))
493 'pro
494 nil ; no class.... it's a procedure!
495 tag)))))
497 ;; A regular structure tag -- only in text, and if
498 ;; optional `complete-structtag' loaded.
499 (structtag
500 (let ((var (match-string 1 this-word))
501 (tag (substring this-word (match-end 0))))
502 ;; Check if we need to update the "current" structure
503 (idlwave-prepare-structure-tag-completion var)
504 (setq idlwave-help-do-struct-tag
505 idlwave-structtag-struct-location
506 mod1 (list nil nil nil nil tag))))
508 ;; A routine keyword -- in text or system help
509 ((and (memq cw '(function-keyword procedure-keyword))
510 (stringp this-word)
511 (string-match "\\S-" this-word)
512 (not (string-match "!" this-word)))
513 (cond ((or (= (char-before beg) ?/)
514 (save-excursion (goto-char end)
515 (looking-at "[ \t]*=")))
516 ;; Certainly a keyword. Check for abbreviation etc.
517 (setq keyword (idlwave-expand-keyword this-word module))
518 (cond
519 ((null keyword)
520 (idlwave-help-diagnostics
521 (format "%s does not accept `%s' kwd"
522 (idlwave-make-full-name (nth 2 module)
523 (car module))
524 (upcase this-word))
525 'ding))
526 ((consp keyword)
527 (idlwave-help-diagnostics
528 (format "%d matches for kwd abbrev `%s'"
529 (length keyword) this-word)
530 'ding)
531 ;; We continue anyway with the first match...
532 (setq keyword (car keyword))))
533 ;; Keyword, or just module
534 (setq mod1 (append (list t) module (list keyword)))
535 (setq mod2 (append (list t) module)))
536 ((equal (char-after end) ?\()
537 ;; A function - what-module will have caught this
538 (setq mod1 (append (list t) module)))
540 ;; undecided - try function, keyword, then enclosing mod.
541 ;; Check for keyword abbreviations, but do not report
542 ;; errors, because it might be something else.
543 ;; FIXME: is this a good way to handle this?
544 (setq keyword (idlwave-expand-keyword this-word module))
545 (if (consp keyword) (setq keyword (car keyword)))
546 (setq mod1 (append (list t) module (list keyword))
547 mod2 (list t this-word 'fun nil)
548 mod3 (append (list t) module)))))
550 ;; Everything else
552 (setq mod1 (append (list t) module))))
553 (if mod3
554 (condition-case nil
555 (apply 'idlwave-online-help mod1)
556 (error (condition-case nil
557 (apply 'idlwave-online-help mod2)
558 (error (apply 'idlwave-online-help mod3)))))
559 (if mod2
560 (condition-case nil
561 (apply 'idlwave-online-help mod1)
562 (error (apply 'idlwave-online-help mod2)))
563 (if mod1
564 (apply 'idlwave-online-help mod1)
565 (error "Don't know which item to show help for")))))))
567 (defun idlwave-do-mouse-completion-help (ev)
568 "Display online help on an item in the *Completions* buffer.
569 Needs additional info stored in global `idlwave-completion-help-info'."
570 (let* ((cw (selected-window))
571 (info idlwave-completion-help-info) ; global passed in
572 (what (nth 0 info))
573 (idlw-help-name (nth 1 info))
574 (type (nth 2 info))
575 (class (nth 3 info))
576 (need-class class)
577 (idlw-help-kwd (nth 4 info))
578 (sclasses (nth 5 info))
579 word idlw-help-link)
580 (mouse-set-point ev)
583 ;; See if we can also find help somewhere, e.g. for multiple classes
584 (setq word (idlwave-this-word))
585 (if (string= word "")
586 (error "No help item selected"))
587 (setq idlw-help-link (get-text-property 0 'link word))
588 (select-window cw)
589 (cond
590 ;; Routine name
591 ((memq what '(procedure function routine))
592 (setq idlw-help-name word)
593 (if (or (eq class t)
594 (and (stringp class) sclasses))
595 (let* ((classes (idlwave-all-method-classes
596 (idlwave-sintern-method idlw-help-name)
597 type)))
598 (setq idlw-help-link t) ; No specific link valid yet
599 (if sclasses
600 (setq classes (idlwave-members-only
601 classes (cons class sclasses))))
602 (setq class (idlwave-popup-select ev classes
603 "Select Class" 'sort))))
605 ;; XXX is this necessary, given all-method-classes?
606 (if (stringp class)
607 (setq class (idlwave-find-inherited-class
608 (idlwave-sintern-routine-or-method idlw-help-name class)
609 type (idlwave-sintern-class class)))))
611 ;; Keyword
612 ((eq what 'keyword)
613 (setq idlw-help-kwd word)
614 (if (or (eq class t)
615 (and (stringp class) sclasses))
616 (let ((classes (idlwave-all-method-keyword-classes
617 (idlwave-sintern-method idlw-help-name)
618 (idlwave-sintern-keyword idlw-help-kwd)
619 type)))
620 (setq idlw-help-link t) ; Link can't be correct yet
621 (if sclasses
622 (setq classes (idlwave-members-only
623 classes (cons class sclasses))))
624 (setq class (idlwave-popup-select ev classes
625 "Select Class" 'sort))
626 ;; XXX is this necessary, given all-method-keyword-classes?
627 (if (stringp class)
628 (setq class (idlwave-find-inherited-class
629 (idlwave-sintern-routine-or-method
630 idlw-help-name class)
631 type (idlwave-sintern-class class)))))
632 (if (string= (downcase idlw-help-name) "obj_new")
633 (setq class idlwave-current-obj_new-class
634 idlw-help-name "Init"))))
636 ;; Class name
637 ((eq what 'class)
638 (setq class word
639 word nil))
641 ;; A special named function to call which sets some of our variables
642 ((and (symbolp what)
643 (fboundp what))
644 (funcall what 'set word))
646 (t (error "Cannot help with this item")))
647 (if (and need-class (not class)
648 (not (and idlw-help-link (not (eq idlw-help-link t)))))
649 (error "Cannot help with this item"))
650 (idlwave-online-help idlw-help-link (or idlw-help-name word)
651 type class idlw-help-kwd)))
653 (defvar idlwave-highlight-help-links-in-completion)
654 (defvar idlwave-completion-help-links)
655 (defun idlwave-highlight-linked-completions ()
656 "Highlight all completions for which help is available and attach link.
657 Those words in `idlwave-completion-help-links' have links. The
658 `idlwave-help-link' face is used for this."
659 (if idlwave-highlight-help-links-in-completion
660 (with-current-buffer (get-buffer "*Completions*")
661 (save-excursion
662 (let* ((case-fold-search t)
663 (props (list 'face 'idlwave-help-link))
664 (info idlwave-completion-help-info) ; global passed in
665 (what (nth 0 info)) ; what was completed, or a func
666 (class (nth 3 info)) ; any class
667 word beg end doit)
668 (goto-char (point-min))
669 (re-search-forward "possible completions are:" nil t)
670 (while (re-search-forward "\\s-\\([A-Za-z0-9_.]+\\)\\(\\s-\\|\\'\\)"
671 nil t)
672 (setq beg (match-beginning 1) end (match-end 1)
673 word (match-string 1) doit nil)
674 ;; Call special completion function test
675 (if (and (symbolp what)
676 (fboundp what))
677 (setq doit (funcall what 'test word))
678 ;; Look for special link property passed in help-links
679 (if idlwave-completion-help-links
680 (setq doit (assoc-string
681 word idlwave-completion-help-links t))))
682 (when doit
683 (if (consp doit)
684 (setq props (append props `(link ,(cdr doit)))))
685 (let ((buffer-read-only nil))
686 (add-text-properties beg end props)))
687 (goto-char end)))))))
689 ;; Arrange for this function to be called after completion
690 (add-hook 'idlwave-completion-setup-hook
691 'idlwave-highlight-linked-completions)
693 (defvar idlwave-help-return-frame nil
694 "The frame to return to from the help frame.")
696 (defun idlwave-help-quit ()
697 "Exit IDLWAVE Help buffer. Kill the dedicated frame if any."
698 (interactive)
699 (cond ((and idlwave-help-use-dedicated-frame
700 (eq (selected-frame) idlwave-help-frame))
701 (if (and idlwave-experimental
702 (frame-live-p idlwave-help-return-frame))
703 ;; Try to select the return frame.
704 ;; This can crash on slow network connections, obviously when
705 ;; we kill the help frame before the return-frame is selected.
706 ;; To protect the workings, we wait for up to one second
707 ;; and check if the return-frame *is* now selected.
708 ;; This is marked "eperimental" since we are not sure when its OK.
709 (let ((maxtime 1.0) (time 0.) (step 0.1))
710 (select-frame idlwave-help-return-frame)
711 (while (and (sit-for step)
712 (not (eq (selected-frame)
713 idlwave-help-return-frame))
714 (< (setq time (+ time step)) maxtime)))))
715 (delete-frame idlwave-help-frame))
716 ((window-configuration-p idlwave-help-window-configuration)
717 (set-window-configuration idlwave-help-window-configuration)
718 (select-window (previous-window)))
719 (t (kill-buffer (idlwave-help-get-help-buffer)))))
722 (defvar default-toolbar-visible-p)
724 (defun idlwave-help-display-help-window (&optional pos-or-func)
725 "Display the help window.
726 Move window start to POS-OR-FUNC, if passed as a position, or call it
727 if passed as a function. See `idlwave-help-use-dedicated-frame'."
728 (let ((cw (selected-window))
729 (buf (idlwave-help-get-help-buffer)))
730 (if (and window-system idlwave-help-use-dedicated-frame)
731 (progn
732 (idlwave-help-show-help-frame)
733 (switch-to-buffer buf))
734 ;; Do it in this frame and save the window configuration
735 (if (not (get-buffer-window buf nil))
736 (setq idlwave-help-window-configuration
737 (current-window-configuration)))
738 (display-buffer buf nil (selected-frame))
739 (select-window (get-buffer-window buf)))
740 (raise-frame)
741 (if pos-or-func
742 (if (functionp pos-or-func)
743 (funcall pos-or-func)
744 (goto-char pos-or-func)
745 (recenter 0)))
746 (select-window cw)))
748 (defun idlwave-help-select-help-frame ()
749 "Select the help frame."
750 (if (and (frame-live-p idlwave-help-frame)
751 (not (eq (selected-frame) idlwave-help-frame)))
752 (progn
753 (setq idlwave-help-return-frame (selected-frame))
754 (select-frame idlwave-help-frame))))
756 (defun idlwave-help-return-to-calling-frame ()
757 "Select the frame from which the help frame was selected."
758 (interactive)
759 (if (and (frame-live-p idlwave-help-return-frame)
760 (not (eq (selected-frame) idlwave-help-return-frame)))
761 (select-frame idlwave-help-return-frame)))
763 (defun idlwave-online-help (link &optional name type class keyword)
764 "Display HTML or other special help on a certain topic.
765 Either loads an HTML link, if LINK is non-nil, or gets special-help on
766 the optional arguments, if any special help is defined. If LINK is
767 t, first look up the optional arguments in the routine info list to
768 see if a link is set for it. Try extra help functions if necessary."
769 ;; Lookup link
770 (if (eq link t)
771 (let ((entry (idlwave-best-rinfo-assoc name type class
772 (idlwave-routines) nil t)))
773 (if entry
774 (cond
775 ;; Try keyword link
776 ((and keyword
777 (setq link (cdr
778 (idlwave-entry-find-keyword entry keyword)))))
779 ;; Default, regular entry link
780 (t (setq link (idlwave-entry-has-help entry))))
781 (if (and
782 class
783 ;; Check for system class help
784 (setq entry (assq (idlwave-sintern-class class)
785 idlwave-system-class-info)
786 link (nth 1 (assq 'link entry))))
787 (message
788 (concat "No routine info for %s"
789 ", falling back on class help.")
790 (idlwave-make-full-name class name))))))
792 (cond
793 ;; An explicit link
794 ((stringp link)
795 (idlwave-help-html-link link))
797 ;; Any extra help
798 (idlwave-extra-help-function
799 (idlwave-help-get-special-help name type class keyword))
801 ;; Nothing worked
802 (t (idlwave-help-error name type class keyword))))
805 (defun idlwave-help-get-special-help (name type class keyword)
806 "Call the function given by `idlwave-extra-help-function'."
807 (let* ((cw (selected-window))
808 (help-pos (with-current-buffer (idlwave-help-get-help-buffer)
809 (let ((buffer-read-only nil))
810 (funcall idlwave-extra-help-function
811 name type class keyword)))))
812 (if help-pos
813 (idlwave-help-display-help-window help-pos)
814 (idlwave-help-error name type class keyword))
815 (select-window cw)))
817 (defun idlwave-help-html-link (link)
818 "Get HTML help on a given LINK."
819 (let ((browse-url-browser-function idlwave-help-browser-function)
820 (help-loc (idlwave-html-help-location))
821 (browse-url-generic-program idlwave-help-browser-generic-program)
822 ;(browse-url-generic-args idlwave-help-browser-generic-args)
823 full-link)
825 ;; Just a regular file name (+ anchor name)
826 (unless (and (stringp help-loc)
827 (file-directory-p help-loc))
828 (error "Invalid help location"))
829 (setq full-link (browse-url-file-url (expand-file-name link help-loc)))
831 ;; Select the browser
832 (cond
833 (idlwave-help-use-assistant
834 (idlwave-help-assistant-open-link link))
836 ((or idlwave-help-browser-is-local
837 (string-match "w3" (symbol-name idlwave-help-browser-function)))
838 (idlwave-help-display-help-window '(lambda () (browse-url full-link))))
840 (t (browse-url full-link)))))
842 ;; A special help routine for source-level syntax help in files.
843 (defvar idlwave-help-fontify-source-code)
844 (defvar idlwave-help-source-try-header)
845 (defvar idlwave-current-tags-buffer)
846 (defvar idlwave-current-tags-class)
847 (defun idlwave-help-with-source (name type class keyword)
848 "Provide help for routines not documented in the IDL manuals.
849 Works by loading the routine source file into the help buffer.
850 Depending on the value of `idlwave-help-source-try-header', it
851 attempts to show the routine definition or the header description.
852 If `idlwave-help-do-class-struct-tag' is non-nil, keyword is a tag
853 to show help on from the class definition structure.
854 If `idlwave-help-do-struct-tag' is non-nil, show help from the
855 matching structure tag definition.
857 This function can be used as `idlwave-extra-help-function'."
858 (let* ((class-struct-tag idlwave-help-do-class-struct-tag)
859 (struct-tag idlwave-help-do-struct-tag)
860 (case-fold-search t)
861 (real-class (if (consp name) (cdr name)))
862 (name (if (consp name) (car name) name))
863 (class-only (and (stringp class) (not (stringp name))))
864 file header-pos def-pos in-buf)
865 (if class-only ;Help with class? Using "Init" as source.
866 (setq name "Init"
867 type 'fun))
868 (if (not struct-tag)
869 (setq file
870 (idlwave-routine-source-file
871 (nth 3 (idlwave-best-rinfo-assoc
872 name (or type t) class (idlwave-routines))))))
873 (setq idlwave-help-def-pos nil
874 idlwave-help-args (list name type class keyword)
875 idlwave-help-in-header nil
876 idlwave-help-do-struct-tag nil
877 idlwave-help-do-class-struct-tag nil)
878 (if (or struct-tag (stringp file))
879 (progn
880 (setq in-buf ; structure-tag completion is always in current buffer
881 (if struct-tag
882 idlwave-current-tags-buffer
883 (idlwave-get-buffer-visiting file)))
884 ;; see if file is in a visited buffer, insert those contents
885 (if in-buf
886 (progn
887 (setq file (buffer-file-name in-buf))
888 (erase-buffer)
889 (insert-buffer-substring in-buf))
890 (if (file-exists-p file) ;; otherwise just load the file
891 (progn
892 (erase-buffer)
893 (insert-file-contents file nil nil nil 'replace))
894 (idlwave-help-error name type class keyword)))
895 (goto-char (point-min))
896 (if (and idlwave-help-fontify-source-code (not in-buf))
897 (idlwave-help-fontify)))
898 (idlwave-help-error name type class keyword))
899 (setq idlwave-help-mode-line-indicator file)
901 ;; Try to find a good place to display
902 (setq def-pos
903 ;; Find the class structure tag if that's what we're after
904 (cond
905 ;; Class structure tags: find the class or named structure
906 ;; definition
907 (class-struct-tag
908 (save-excursion
909 (setq class
910 (if (string-match "[a-zA-Z0-9]\\(__\\)" name)
911 (substring name 0 (match-beginning 1))
912 idlwave-current-tags-class))
913 (and
914 (idlwave-find-class-definition class nil real-class)
915 (idlwave-find-struct-tag keyword))))
917 ;; Generic structure tags: the structure definition
918 ;; location within the file has been recorded in
919 ;; `struct-tag'
920 (struct-tag
921 (save-excursion
922 (and
923 (integerp struct-tag)
924 (goto-char struct-tag)
925 (idlwave-find-struct-tag keyword))))
927 ;; Just find the routine definition
929 (if class-only (point-min)
930 (idlwave-help-find-routine-definition name type class keyword))))
931 idlwave-help-def-pos def-pos)
933 (if (and idlwave-help-source-try-header
934 (not (or struct-tag class-struct-tag)))
935 ;; Check if we can find the header
936 (save-excursion
937 (goto-char (or def-pos (point-max)))
938 (setq header-pos (idlwave-help-find-in-doc-header
939 name type class keyword 'exact)
940 idlwave-help-in-header header-pos)))
942 (if (or header-pos def-pos)
943 (progn
944 (if (boundp 'idlwave-help-min-frame-width)
945 (setq idlwave-help-min-frame-width 80))
946 (goto-char (or header-pos def-pos)))
947 (idlwave-help-error name type class keyword))
949 (point)))
952 (defun idlwave-help-find-routine-definition (name type class keyword)
953 "Find the definition of routine CLASS::NAME in current buffer.
954 Returns the point of match if successful, nil otherwise.
955 KEYWORD is ignored."
956 (save-excursion
957 (goto-char (point-max))
958 (if (re-search-backward
959 (concat "^[ \t]*"
960 (if (eq type 'pro) "pro"
961 (if (eq type 'fun) "function"
962 "\\(pro\\|function\\)"))
963 "[ \t]+"
964 (regexp-quote (downcase (idlwave-make-full-name class name)))
965 "[, \t\r\n]")
966 nil t)
967 (match-beginning 0)
968 nil)))
970 (defvar idlwave-doclib-start)
971 (defvar idlwave-doclib-end)
972 (defun idlwave-help-find-in-doc-header (name type class keyword
973 &optional exact)
974 "Find the requested help in the doc-header above point.
976 First checks if there is a doc-lib header which describes the correct
977 routine. Then tries to find the KEYWORDS section and the KEYWORD, if
978 given. Returns the point which should be window start of the help
979 window. If EXACT is non-nil, the full help position must be found -
980 down to the keyword requested. This setting is for context help, if
981 the exact spot is needed.
983 If EXACT is nil, the position of the header is returned if it
984 describes the correct routine - even if the keyword description cannot
985 be found. TYPE is ignored.
987 This function expects a more or less standard routine header. In
988 particlar it looks for the `NAME:' tag, either with a colon, or alone
989 on a line. Then `NAME:' must be followed by the routine name on the
990 same or the next line. When KEYWORD is non-nil, looks first for a
991 `KEYWORDS' section. It is amazing how inconsisten this is through
992 some IDL libraries I have seen. We settle for a line containing an
993 upper case \"KEYWORD\" string. If this line is not fould we search
994 for the keyword anyway to increase the hit-rate
996 When one of these sections exists we check for a line starting with any of
998 /KEYWORD KEYWORD- KEYWORD= KEYWORD
1000 with spaces allowed between the keyword and the following dash or equal sign.
1001 If there is a match, we assume it is the keyword description."
1002 (let* ((case-fold-search t)
1003 (rname (if (stringp class)
1004 (concat
1005 "\\("
1006 ;; Traditional name or class::name
1007 "\\("
1008 "\\(" (regexp-quote (downcase class)) "::\\)?"
1009 (regexp-quote (downcase name))
1010 "\\>\\)"
1011 (concat
1012 "\\|"
1013 ;; class__define or just class
1014 (regexp-quote (downcase class)) "\\(__define\\)?")
1015 "\\)")
1016 (regexp-quote (downcase name))))
1018 ;; NAME tag plus the routine name. The new version is from JD.
1019 (name-re (concat
1020 "\\(^;+\\*?[ \t]*"
1021 idlwave-help-doclib-name
1022 "\\([ \t]*:\\|[ \t]*$\\)[ \t]*\\(\n;+[ \t]*\\)*"
1023 rname
1024 "\\|"
1025 "^;+[ \t]*"
1026 rname
1027 ":[ \t]*$\\)"))
1029 ;; Header start plus name
1030 (header-re (concat "\\(" idlwave-doclib-start "\\).*\n"
1031 "\\(^;+.*\n\\)*"
1032 "\\(" name-re "\\)"))
1033 ;; A keywords section
1034 (kwds-re (concat ; forgiving
1035 "^;+\\*?[ \t]*"
1036 "\\([-A-Z_ ]*"
1037 idlwave-help-doclib-keyword
1038 "[-A-Z_ ]*\\)"
1039 "\\(:\\|[ \t]*\n\\)"))
1041 ;; The individual keyword description line.
1042 (kwd-re (if keyword ; hard (well...)
1043 (concat
1044 "^;+[ \t]+"
1045 "\\(/" (regexp-quote (upcase keyword))
1046 "\\|" (regexp-quote (upcase keyword)) "[ \t]*[-=:\n]"
1047 "\\)")))
1048 (kwd-re2 (if keyword ; forgiving
1049 (concat
1050 "^;+[ \t]+"
1051 (regexp-quote (upcase keyword))
1052 "\\>")))
1053 dstart dend name-pos kwds-pos kwd-pos)
1054 (catch 'exit
1055 (save-excursion
1056 (goto-char (point-min))
1057 (while (and (setq dstart (re-search-forward idlwave-doclib-start nil t))
1058 (setq dend (re-search-forward idlwave-doclib-end nil t)))
1059 ;; found a routine header
1060 (goto-char dstart)
1061 (if (setq name-pos (re-search-forward name-re dend t))
1062 (progn
1063 (if keyword
1064 ;; We do need a keyword
1065 (progn
1066 ;; Try to find a keyword section, but don't force it.
1067 (goto-char name-pos)
1068 (if (let ((case-fold-search nil))
1069 (re-search-forward kwds-re dend t))
1070 (setq kwds-pos (match-beginning 0)))
1071 ;; Find the keyword description
1072 (if (or (let ((case-fold-search nil))
1073 (re-search-forward kwd-re dend t))
1074 (re-search-forward kwd-re dend t)
1075 (let ((case-fold-search nil))
1076 (re-search-forward kwd-re2 dend t))
1077 (re-search-forward kwd-re2 dend t))
1078 (setq kwd-pos (match-beginning 0))
1079 (if exact
1080 (progn
1081 (idlwave-help-diagnostics
1082 (format "Could not find description of kwd %s"
1083 (upcase keyword)))
1084 (throw 'exit nil))))))
1085 ;; Return the best position we got
1086 (throw 'exit (or kwd-pos kwds-pos name-pos dstart)))
1087 (goto-char dend))))
1088 (idlwave-help-diagnostics "Could not find doclib header")
1089 (throw 'exit nil))))
1091 (defun idlwave-help-diagnostics (string &optional ding)
1092 "Add a diagnostics string to the list.
1093 When DING is non-nil, ring the bell as well."
1094 (if (boundp 'idlwave-help-diagnostics)
1095 (progn
1096 (setq idlwave-help-diagnostics
1097 (cons string idlwave-help-diagnostics))
1098 (if ding (ding)))))
1100 (defun idlwave-help-toggle-header-top-and-def (arg)
1101 (interactive "P")
1102 (let (pos)
1103 (if idlwave-help-in-header
1104 ;; Header was the last thing displayed
1105 (progn
1106 (setq idlwave-help-in-header nil)
1107 (setq pos idlwave-help-def-pos))
1108 ;; Try to display header
1109 (setq pos (idlwave-help-find-in-doc-header
1110 (nth 0 idlwave-help-args)
1111 (nth 1 idlwave-help-args)
1112 (nth 2 idlwave-help-args)
1113 nil))
1114 (if pos
1115 (setq idlwave-help-in-header t)
1116 (error "Cannot find doclib header for routine %s"
1117 (idlwave-make-full-name (nth 2 idlwave-help-args)
1118 (nth 0 idlwave-help-args)))))
1119 (if pos
1120 (progn
1121 (goto-char pos)
1122 (recenter 0)))))
1124 (defun idlwave-help-find-first-header (arg)
1125 (interactive "P")
1126 (let (pos)
1127 (save-excursion
1128 (goto-char (point-min))
1129 (if (re-search-forward idlwave-doclib-start nil t)
1130 (setq pos (match-beginning 0))))
1131 (if pos
1132 (progn
1133 (goto-char pos)
1134 (recenter 0))
1135 (error "No DocLib Header in current file"))))
1137 (defun idlwave-help-find-header (arg)
1138 "Jump to the DocLib Header."
1139 (interactive "P")
1140 (if arg
1141 (idlwave-help-find-first-header nil)
1142 (setq idlwave-help-in-header nil)
1143 (idlwave-help-toggle-header-match-and-def arg 'top)))
1145 (defun idlwave-help-toggle-header-match-and-def (arg &optional top)
1146 (interactive "P")
1147 (let ((args idlwave-help-args)
1148 pos)
1149 (if idlwave-help-in-header
1150 ;; Header was the last thing displayed
1151 (progn
1152 (setq idlwave-help-in-header nil)
1153 (setq pos idlwave-help-def-pos))
1154 ;; Try to display header
1155 (setq pos (apply 'idlwave-help-find-in-doc-header
1156 (if top
1157 (list (car args) (nth 1 args) (nth 2 args) nil)
1158 args)))
1159 (if pos
1160 (setq idlwave-help-in-header t)
1161 (error "Cannot find doclib header for routine %s"
1162 (idlwave-make-full-name (nth 2 idlwave-help-args)
1163 (nth 0 idlwave-help-args)))))
1164 (if pos
1165 (progn
1166 (goto-char pos)
1167 (recenter 0)))))
1169 (defvar font-lock-verbose)
1170 (defvar idlwave-mode-syntax-table)
1171 (defvar idlwave-font-lock-defaults)
1172 (defun idlwave-help-fontify ()
1173 "Fontify the Help buffer as source code.
1174 Useful when source code is displayed as help. See the option
1175 `idlwave-help-fontify-source-code'."
1176 (interactive)
1177 (if (featurep 'font-lock)
1178 (let ((major-mode 'idlwave-mode)
1179 (font-lock-verbose
1180 (if (interactive-p) font-lock-verbose nil))
1181 (syntax-table (syntax-table)))
1182 (unwind-protect
1183 (progn
1184 (set-syntax-table idlwave-mode-syntax-table)
1185 (set (make-local-variable 'font-lock-defaults)
1186 idlwave-font-lock-defaults)
1187 (font-lock-fontify-buffer))
1188 (set-syntax-table syntax-table)))))
1191 (defun idlwave-help-error (name type class keyword)
1192 (error "Can't find help on %s%s %s"
1193 (or (and (or class name) (idlwave-make-full-name class name))
1194 "<unknown>")
1195 (if keyword (format ", keyword %s" (upcase keyword)) "")
1196 (if idlwave-html-help-location
1198 "(help location unknown)")))
1200 (defun idlwave-help-show-help-frame ()
1201 "Show the help frame, creating it if necessary."
1202 ;; Use a special frame for this
1203 (unless (frame-live-p idlwave-help-frame)
1204 (setq idlwave-help-frame
1205 (make-frame idlwave-help-frame-parameters))
1206 ;; Strip menubar (?) and toolbar from the Help frame.
1207 (if (fboundp 'set-specifier)
1208 (progn
1209 ;; XEmacs
1210 (let ((sval (cons idlwave-help-frame nil)))
1211 ;; (set-specifier menubar-visible-p sval)
1212 (set-specifier default-toolbar-visible-p sval)))
1213 ;; Emacs
1214 (modify-frame-parameters idlwave-help-frame
1215 '(;;(menu-bar-lines . 0)
1216 (tool-bar-lines . 0)))))
1217 (select-frame idlwave-help-frame))
1219 (defun idlwave-help-get-help-buffer ()
1220 "Return the IDLWAVE Help buffer. Make it first if necessary."
1221 (let ((buf (get-buffer "*IDLWAVE Help*")))
1222 (if buf
1224 (setq buf (get-buffer-create "*IDLWAVE Help*"))
1225 (with-current-buffer buf
1226 (idlwave-help-mode)))
1227 buf))
1229 (defun idlwave-grep (regexp list)
1230 (let (rtn)
1231 (while list
1232 (if (string-match regexp (car list))
1233 (setq rtn (cons (car list) rtn)))
1234 (setq list (cdr list)))
1235 (nreverse rtn)))
1237 (defun idlwave-entry-has-help (entry)
1238 (and entry (car (nth 5 entry))))
1240 (defun idlwave-has-help (name type class)
1241 "Does this have help associated with it?"
1242 (let ((entry (idlwave-best-rinfo-assoc name type class (idlwave-routines))))
1243 (idlwave-entry-has-help entry)))
1245 ;;----- Control the IDL Assistant, which shipped with IDL v6.2
1246 (defvar idlwave-help-assistant-process nil)
1247 (defvar idlwave-help-assistant-socket nil)
1249 ;; The Windows version does not have a !DIR/bin/* set of front-end
1250 ;; scripts, but instead only links directly to bin.x86. As a result,
1251 ;; we must pass the -profile argument as well.
1252 (defvar idlwave-help-assistant-command
1253 (if (memq system-type '(ms-dos windows-nt))
1254 "bin/bin.x86/idl_assistant.exe"
1255 "bin/idl_assistant")
1256 "The command, rooted at `idlwave-system-directory', which invokes the
1257 IDL assistant.")
1259 (defun idlwave-help-assistant-available ()
1260 (if idlwave-help-assistant-available
1261 (eq idlwave-help-assistant-available t)
1262 (setq idlwave-help-assistant-available
1263 (if (file-executable-p (idlwave-help-assistant-command))
1265 'not-available))))
1267 (defun idlwave-help-assistant-command ()
1268 (expand-file-name idlwave-help-assistant-command (idlwave-sys-dir)))
1270 (defun idlwave-help-assistant-start (&optional full-link)
1271 "Start the IDL Assistant, loading link FULL-LINK, if passed."
1272 (when (or (not idlwave-help-assistant-socket)
1273 (not (eq (process-status idlwave-help-assistant-socket) 'open)))
1274 (let* ((help-loc (idlwave-html-help-location))
1275 (command (idlwave-help-assistant-command))
1276 (extra-args
1277 (nconc
1278 (if (memq system-type '(ms-dos windows-nt))
1279 `("-profile" ,(expand-file-name "idl.adp" help-loc)))
1280 (if full-link `("-file" ,full-link))))
1281 port)
1282 (if idlwave-help-assistant-socket
1283 (delete-process idlwave-help-assistant-socket))
1285 (setq idlwave-help-assistant-process
1286 (apply 'start-process
1287 "IDL_ASSISTANT_PROC" nil command "-server" extra-args))
1289 (set-process-filter idlwave-help-assistant-process
1290 (lambda (proc string)
1291 (setq port (string-to-number string))))
1292 (unless (accept-process-output idlwave-help-assistant-process 15)
1293 (error "Failed binding IDL_ASSISTANT socket"))
1294 (if (not port)
1295 (error "Unable to open IDL_ASSISTANT")
1296 (set-process-filter idlwave-help-assistant-process nil)
1297 (setq idlwave-help-assistant-socket
1298 (open-network-stream "IDL_ASSISTANT_SOCK"
1299 nil "localhost" port))
1300 (if (eq (process-status idlwave-help-assistant-socket) 'open)
1301 (progn
1302 (process-send-string idlwave-help-assistant-socket
1303 (concat "setHelpPath " help-loc "\n"))
1305 (idlwave-help-assistant-close)
1306 (error "Cannot communicate with IDL_ASSISTANT"))))))
1308 (defun idlwave-help-assistant-raise ()
1309 (idlwave-help-assistant-start)
1310 (process-send-string idlwave-help-assistant-socket "raise\n"))
1312 (defun idlwave-help-assistant-open-link (&optional link)
1313 ;; Open a link (file name with anchor, no leading path) in the assistant.
1314 (let ((help-loc (idlwave-html-help-location))
1315 topic anchor file just-started exists full-link)
1317 (if (string-match "\.html" link)
1318 (setq topic (substring link 0 (match-beginning 0))
1319 anchor (substring link (match-end 0)))
1320 (error "Malformed help link"))
1322 (setq file (expand-file-name (concat topic ".html") help-loc))
1323 (if (file-exists-p file)
1324 (setq exists t)
1325 (setq file (expand-file-name
1326 (concat (upcase topic) ".html") help-loc))
1327 (setq exists (file-exists-p file)))
1329 (setq full-link (concat file anchor)
1330 just-started (idlwave-help-assistant-start (if exists full-link)))
1331 (if exists
1332 (progn
1333 (if (not just-started)
1334 (process-send-string idlwave-help-assistant-socket
1335 (concat "openLink " full-link "\n")))
1336 (process-send-string idlwave-help-assistant-socket
1337 (concat "searchIndexNoOpen " topic "\n")))
1338 (process-send-string idlwave-help-assistant-socket
1339 (concat "searchIndexAndOpen " topic "\n"))))
1340 (idlwave-help-assistant-raise))
1342 (defvar idlwave-help-assistant-help-with-topic-history nil
1343 "The history of help topics selected with the minibuffer.")
1345 (defvar idlwave-system-routines)
1347 (defun idlwave-help-assistant-help-with-topic (&optional topic)
1348 "Prompt for and provide help with TOPIC."
1349 (interactive)
1350 (let (list)
1351 (unless topic
1352 (idlwave-routines)
1353 (setq list (append (mapcar (lambda (x)
1354 (concat (nth 2 x) (car x)))
1355 idlwave-system-routines)
1356 (mapcar (lambda (x)
1357 (concat "." (car x)))
1358 idlwave-executive-commands-alist)
1359 idlwave-system-class-info))
1360 (setq topic
1361 (idlwave-completing-read
1362 "Help Topic: " list
1363 nil nil nil
1364 'idlwave-help-assistant-help-with-topic-history)))
1365 (if (and topic (not (string= topic "")))
1366 (idlwave-help-assistant-open-link (concat topic ".html")))))
1368 (defun idlwave-help-assistant-close ()
1369 (when (and idlwave-help-assistant-process
1370 (eq (process-status idlwave-help-assistant-process) 'run))
1371 (when idlwave-help-assistant-socket
1372 (process-send-string idlwave-help-assistant-socket "quit\n")
1373 (delete-process idlwave-help-assistant-socket))
1374 (stop-process idlwave-help-assistant-process)
1375 (delete-process idlwave-help-assistant-process)
1376 (setq idlwave-help-assistant-socket nil
1377 idlwave-help-assistant-process nil)))
1380 (provide 'idlw-help)
1381 (provide 'idlwave-help)
1383 ;;; idlw-help.el ends here