idlw-help.el 50 KB

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