* erc-stamp.el (erc-echo-timestamp):
[bpt/emacs.git] / lisp / progmodes / idlwave.el
index 3ee01d0..49e8859 100644 (file)
@@ -1,19 +1,20 @@
 ;; idlwave.el --- IDL editing mode for GNU Emacs
-;; Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005
-;;    Free Software Foundation
+
+;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+;;   Free Software Foundation, Inc.
 
 ;; Authors: J.D. Smith <jdsmith@as.arizona.edu>
 ;;          Carsten Dominik <dominik@science.uva.nl>
 ;;          Chris Chase <chase@att.com>
 ;; Maintainer: J.D. Smith <jdsmith@as.arizona.edu>
-;; Version: 5.7_22
+;; Version: 6.1_em22
 ;; Keywords: languages
 
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 
 ;;; Commentary:
 
-;; IDLWAVE enables feature-rich development and interaction with IDL.
+;; IDLWAVE enables feature-rich development and interaction with IDL,
+;; the Interactive Data Language. It provides a compelling,
+;; full-featured alternative to the IDLDE development environment
+;; bundled with IDL.
 
 ;; In the remotely distant past, based on pascal.el, though bears
 ;; little resemblance to it now.
   (defalias 'line-end-position 'point-at-eol))
 (unless (fboundp 'char-valid-p)
   (defalias 'char-valid-p 'characterp))
+(unless (fboundp 'match-string-no-properties)
+  (defalias 'match-string-no-properties 'match-string))
 
 (if (not (fboundp 'cancel-timer))
     (condition-case nil
     (defmacro defcustom (var value doc &rest args)
       `(defvar ,var ,value ,doc))))
 
+(declare-function idlwave-shell-get-path-info "idlw-shell")
+(declare-function idlwave-shell-temp-file "idlw-shell")
+(declare-function idlwave-shell-is-running "idlw-shell")
+(declare-function widget-value "wid-edit" (widget))
+(declare-function comint-dynamic-complete-filename "comint" ())
+(declare-function Info-goto-node "info" (nodename &optional fork))
+
 (defgroup idlwave nil
   "Major mode for editing IDL .pro files."
   :tag "IDLWAVE"
   "Indentation and formatting options for IDLWAVE mode."
   :group 'idlwave)
 
-(defcustom idlwave-main-block-indent 0
+(defcustom idlwave-main-block-indent 2
   "*Extra indentation for the main block of code.
 That is the block between the FUNCTION/PRO statement and the END
 statement for that program unit."
   :group 'idlwave-code-formatting
   :type 'integer)
 
-(defcustom idlwave-block-indent 4
+(defcustom idlwave-block-indent 3
   "*Extra indentation applied to block lines.
 If you change this, you probably also want to change `idlwave-end-offset'."
   :group 'idlwave-code-formatting
   :type 'integer)
 
-(defcustom idlwave-end-offset -4
+(defcustom idlwave-end-offset -3
   "*Extra indentation applied to block END lines.
 A value equal to negative `idlwave-block-indent' will make END lines
 line up with the block BEGIN lines."
   :group 'idlwave-code-formatting
   :type 'integer)
 
-(defcustom idlwave-continuation-indent 2
+(defcustom idlwave-continuation-indent 3
   "*Extra indentation applied to continuation lines.
 This extra offset applies to the first of a set of continuation lines.
 The following lines receive the same indentation as the first."
   :group 'idlwave-code-formatting
   :type 'integer)
 
-(defcustom idlwave-max-extra-continuation-indent 20
+(defcustom idlwave-max-extra-continuation-indent 40
   "*Maximum additional indentation for special continuation indent.
 Several special indentations are tried to help line up continuation
 lines in routine calls or definitions, other statements with
@@ -354,17 +367,20 @@ usually a good idea.."
   :type 'boolean)
 
 (defcustom idlwave-init-rinfo-when-idle-after 10
-  "*Seconds of idle time before routine info is automatically initialized.
-Initializing the routine info can take long, in particular if a large
-library catalog is involved.  When Emacs is idle for more than the number
-of seconds specified by this variable, it starts the initialization.
-The process is split into five steps, in order to keep possible work
-interruption as short as possible.  If one of the steps finishes, and no
-user input has arrived in the mean time, initialization proceeds immediately
-to the next step.
-A good value for this variable is about 1/3 of the time initialization
-take in you setup.  So if you have a fast machine and no problems with a slow network connection, don't hesitate to set this to 2 seconds.
-A Value of 0 means, don't initialize automatically."
+  "*Seconds of idle time before routine info is automatically
+initialized.  Initializing the routine info can take a long time, in
+particular if a large number of library catalogs are involved.  When
+Emacs is idle for more than the number of seconds specified by this
+variable, it starts the initialization.  The process is split into
+five steps, in order to keep work interruption as short as possible.
+If one of the steps finishes, and no user input has arrived in the
+mean time, initialization proceeds immediately to the next step.  A
+good value for this variable is about 1/3 of the time initialization
+take in your setup.  So if you have a fast machine and no problems
+with a slow network connection, don't hesitate to set this to 2
+seconds.  A Value of 0 means, don't initialize automatically, but
+instead wait until routine information is needed, and initialize
+then."
   :group 'idlwave-routine-info
   :type 'number)
 
@@ -419,16 +435,17 @@ t means to show all source files."
   :type 'integer)
 
 (defcustom idlwave-library-path nil
-  "Library path for Windows and MacOS.  Not needed under Unix.  When
-selecting the directories to scan for IDL user catalog routine info,
-IDLWAVE can, under UNIX, query the shell for the exact search path
-\(the value of !PATH).  However, under Windows and MacOS (pre-OSX),
-the IDLWAVE shell does not work.  In this case, this variable can be
-set to specify the paths where IDLWAVE can find PRO files.  The shell
-will only be asked for a list of paths when this variable is nil.  The
-value is a list of directories.  A directory preceeded by a `+' will
-be searched recursively.  If you set this variable on a UNIX system,
-the shell will not be queried.  See also `idlwave-system-directory'."
+  "Library path for Windows and MacOS (OS9).  Not needed under UNIX.
+When selecting the directories to scan for IDL user catalog routine
+info, IDLWAVE can, under UNIX, query the shell for the exact search
+path \(the value of !PATH).  However, under Windows and MacOS
+\(pre-OSX), the IDLWAVE shell does not work.  In this case, this
+variable can be set to specify the paths where IDLWAVE can find PRO
+files.  The shell will only be asked for a list of paths when this
+variable is nil.  The value is a list of directories.  A directory
+preceeded by a `+' will be searched recursively.  If you set this
+variable on a UNIX system, the shell will not be queried.  See also
+`idlwave-system-directory'."
   :group 'idlwave-routine-info
   :type '(repeat (directory)))
 
@@ -443,6 +460,7 @@ value of `!DIR'.  See also `idlwave-library-path'."
   :group 'idlwave-routine-info
   :type 'directory)
 
+;; Configuration files
 (defcustom idlwave-config-directory
   (convert-standard-filename "~/.idlwave")
   "*Directory for configuration files and user-library catalog."
@@ -450,6 +468,7 @@ value of `!DIR'.  See also `idlwave-library-path'."
   :type 'file)
 
 (defvar idlwave-user-catalog-file "idlusercat.el")
+(defvar idlwave-xml-system-rinfo-converted-file "idl_xml_rinfo.el")
 (defvar idlwave-path-file "idlpath.el")
 
 (defvar idlwave-libinfo-file nil
@@ -668,7 +687,7 @@ method, add an entry (\"INIT\" . t).  The method name must be ALL-CAPS."
           (cons (string  :tag "MODULE" :value "")
                 (boolean :tag "Determine class for this method")))))
 
-(defcustom idlwave-store-inquired-class nil
+(defcustom idlwave-store-inquired-class t
   "*Non-nil means, store class of a method call as text property on `->'.
 IDLWAVE sometimes has to ask the user for the class associated with a
 particular object method call.  This happens during the commands
@@ -950,7 +969,7 @@ Otherwise STRING is used. If nil, the file summary will be omitted.
 For example you might set PATHNAME to the path for the
 lib_template.pro file included in the IDL distribution.")
 
-(defcustom idlwave-header-to-beginning-of-file nil
+(defcustom idlwave-header-to-beginning-of-file t
   "*Non-nil means, the documentation header will always be at start of file.
 When nil, the header is positioned between the PRO/FUNCTION line of
 the current routine and the code, allowing several routine headers in
@@ -987,10 +1006,6 @@ If nil it will not be inserted."
   "Path locations of external commands used by IDLWAVE."
   :group 'idlwave)
 
-;; WARNING: The following variable has recently been moved from
-;; idlw-shell.el to this file.  I hope this does not break
-;; anything.
-
 (defcustom idlwave-shell-explicit-file-name "idl"
   "*If non-nil, this is the command to run IDL.
 Should be an absolute file path or path relative to the current environment
@@ -1015,7 +1030,8 @@ split it for you."
   :group 'idlwave-external-programs)
 
 (defcustom idlwave-help-application "idlhelp"
-  "*The external application providing reference help for programming."
+  "*The external application providing reference help for programming.
+Obsolete, if the IDL Assistant is being used for help."
   :group 'idlwave-external-programs
   :type 'string)
 
@@ -1158,7 +1174,7 @@ As a user, you should not set this to t.")
        '("\\<\\(common\\)\\>[ \t]*\\(\\sw+\\)?[ \t]*,?"
          (1 font-lock-keyword-face)              ; "common"
          (2 font-lock-reference-face nil t)      ; block name
-         (font-lock-match-c++-style-declaration-item-and-skip-to-next
+         ("[ \t]*\\(\\sw+\\)[ ,]*"
           ;; Start with point after block name and comma
           (goto-char (match-end 0))  ; needed for XEmacs, could be nil
           nil
@@ -1200,8 +1216,8 @@ As a user, you should not set this to t.")
        ;; Treats continuation lines, works only during whole buffer
        ;; fontification.  Slow, use it only in fancy fontification.
        (keyword-parameters
-       '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\\(\n[ \t]*;.*\\)*\n[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
-         (5 font-lock-reference-face)))
+       '("\\(,\\|[a-zA-Z0-9_](\\)[ \t]*\\(\\$[ \t]*\\(;.*\\)?\n\\([ \t]*\\(;.*\\)?\n\\)*[ \t]*\\)?\\(/[a-zA-Z_]\\sw*\\|[a-zA-Z_]\\sw*[ \t]*=\\)"
+         (6 font-lock-reference-face)))
 
        ;; System variables start with a bang.
        (system-variables
@@ -1385,7 +1401,7 @@ Normally a space.")
   "Character which is inserted as a last character on previous line by
    \\[idlwave-split-line] to begin a continuation line.  Normally $.")
 
-(defconst idlwave-mode-version "5.7_22")
+(defconst idlwave-mode-version "6.1_em22")
 
 (defmacro idlwave-keyword-abbrev (&rest args)
   "Creates a function for abbrev hooks to call `idlwave-check-abbrev' with args."
@@ -1536,7 +1552,7 @@ Capitalize system variables - action only
 (define-key idlwave-mode-map "\C-c\C-n" 'idlwave-next-statement)
 ;; (define-key idlwave-mode-map "\r"       'idlwave-newline)
 ;; (define-key idlwave-mode-map "\t"       'idlwave-indent-line)
-(define-key idlwave-mode-map [(shift tab)] 'idlwave-indent-statement)
+(define-key idlwave-mode-map [(shift iso-lefttab)] 'idlwave-indent-statement)
 (define-key idlwave-mode-map "\C-c\C-a" 'idlwave-auto-fill-mode)
 (define-key idlwave-mode-map "\M-q"     'idlwave-fill-paragraph)
 (define-key idlwave-mode-map "\M-s"     'idlwave-edit-in-idlde)
@@ -1587,7 +1603,8 @@ Capitalize system variables - action only
 (define-key idlwave-mode-map "\C-c\C-t"   'idlwave-find-module-this-file)
 (define-key idlwave-mode-map "\C-c?"      'idlwave-routine-info)
 (define-key idlwave-mode-map "\M-?"       'idlwave-context-help)
-(define-key idlwave-mode-map [(control meta ?\?)] 'idlwave-online-help)
+(define-key idlwave-mode-map [(control meta ?\?)]
+  'idlwave-help-assistant-help-with-topic)
 ;; Pickup both forms of Esc/Meta binding
 (define-key idlwave-mode-map [(meta tab)] 'idlwave-complete)
 (define-key idlwave-mode-map [?\e?\t] 'idlwave-complete)
@@ -1601,18 +1618,21 @@ Capitalize system variables - action only
 ;; Set action and key bindings.
 ;; See description of the function `idlwave-action-and-binding'.
 ;; Automatically add spaces for the following characters
-;(idlwave-action-and-binding "&"  '(idlwave-surround -1 -1 '(?&) 1
-;                                                  (lambda (char) 0)))
-(idlwave-action-and-binding "<"  '(idlwave-surround -1 -1))
-;; Binding works for both > and ->, by changing the length of the token.
-(idlwave-action-and-binding ">"  '(idlwave-surround -1 -1 '(?-) 1
-                                                   'idlwave-gtr-pad-hook))
-(idlwave-action-and-binding "->" '(idlwave-surround -1 -1 nil 2) t)
-(idlwave-action-and-binding ","  '(idlwave-surround 0 -1))
-
-;; Automatically add spaces to equal sign if not keyword
+
+;; Actions for & are complicated by &&
+(idlwave-action-and-binding "&"  'idlwave-custom-ampersand-surround)
+
+;; Automatically add spaces to equal sign if not keyword.  This needs
+;; to go ahead of > and <, so >= and <= will be treated correctly
 (idlwave-action-and-binding "="  '(idlwave-expand-equal -1 -1))
 
+;; Actions for > and < are complicated by >=, <=, and ->...
+(idlwave-action-and-binding "<"  '(idlwave-custom-ltgtr-surround nil))
+(idlwave-action-and-binding ">"  '(idlwave-custom-ltgtr-surround 'gtr))
+
+(idlwave-action-and-binding ","  '(idlwave-surround 0 -1 1))
+
+
 ;;;
 ;;; Abbrev Section
 ;;;
@@ -1768,7 +1788,7 @@ idlwave-mode-abbrev-table unless TABLE is non-nil."
 
 ;;;###autoload
 (defun idlwave-mode ()
-  "Major mode for editing IDL source files (version 5.7_22).
+  "Major mode for editing IDL source files (version 6.1_em22).
 
 The main features of this mode are
 
@@ -1817,11 +1837,10 @@ The main features of this mode are
 
 3. Online IDL Help
    ---------------
+
    \\[idlwave-context-help] displays the IDL documentation relevant
-   for the system variable, keyword, or routine at point.  A single
-   key stroke gets you directly to the right place in the docs.  The
-   HTML help files package must be installed for this to work -- check
-   the IDLWAVE webpage for the correct package for your version.  See
+   for the system variable, keyword, or routines at point.  A single
+   key stroke gets you directly to the right place in the docs.  See
    the manual to configure where and how the HTML help is displayed.
 
 4. Completion
@@ -1905,7 +1924,8 @@ The main features of this mode are
 
   (set (make-local-variable 'comment-start-skip) ";+[ \t]*")
   (set (make-local-variable 'comment-start) ";")
-  (set (make-local-variable 'require-final-newline) mode-require-final-newline)
+  (set (make-local-variable 'comment-add) 1) ; ";;" for new and regions
+  (set (make-local-variable 'require-final-newline) t)
   (set (make-local-variable 'abbrev-all-caps) t)
   (set (make-local-variable 'indent-tabs-mode) nil)
   (set (make-local-variable 'completion-ignore-case) t)
@@ -1929,14 +1949,22 @@ The main features of this mode are
   (set (make-local-variable 'paragraph-ignore-fill-prefix) nil)
   (set (make-local-variable 'parse-sexp-ignore-comments) t)
 
+  ;; ChangeLog
+  (set (make-local-variable 'add-log-current-defun-function)
+       'idlwave-current-routine-fullname)
+
   ;; Set tag table list to use IDLTAGS as file name.
   (if (boundp 'tag-table-alist)
       (add-to-list 'tag-table-alist '("\\.pro$" . "IDLTAGS")))
 
-  ;; Font-lock additions - originally Phil Williams, then Ulrik Dickow
+  ;; Font-lock additions
   ;; Following line is for Emacs - XEmacs uses the corresponding property
   ;; on the `idlwave-mode' symbol.
   (set (make-local-variable 'font-lock-defaults) idlwave-font-lock-defaults)
+  (set (make-local-variable 'font-lock-mark-block-function)
+       'idlwave-mark-subprogram)
+  (set (make-local-variable 'font-lock-fontify-region-function)
+       'idlwave-font-lock-fontify-region)
 
   ;; Imenu setup
   (set (make-local-variable 'imenu-create-index-function)
@@ -1946,11 +1974,24 @@ The main features of this mode are
   (set (make-local-variable 'imenu-prev-index-position-function)
        'idlwave-prev-index-position)
 
+  ;; HideShow setup
+  (add-to-list 'hs-special-modes-alist
+              (list 'idlwave-mode
+                    idlwave-begin-block-reg
+                    idlwave-end-block-reg
+                    ";"
+                    'idlwave-forward-block nil))
+
   ;; Make a local post-command-hook and add our hook to it
+  ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
+  ;; (make-local-hook 'post-command-hook)
   (add-hook 'post-command-hook 'idlwave-command-hook nil 'local)
 
   ;; Make local hooks for buffer updates
+  ;; NB: `make-local-hook' needed for older/alternative Emacs compatibility
+  ;; (make-local-hook 'kill-buffer-hook)
   (add-hook 'kill-buffer-hook 'idlwave-kill-buffer-update nil 'local)
+  ;; (make-local-hook 'after-save-hook)
   (add-hook 'after-save-hook 'idlwave-save-buffer-update nil 'local)
   (add-hook 'after-save-hook 'idlwave-revoke-license-to-kill nil 'local)
 
@@ -1960,6 +2001,9 @@ The main features of this mode are
   ;; Update the routine info with info about current buffer?
   (idlwave-new-buffer-update)
 
+  ;; Check help location
+  (idlwave-help-check-locations)
+
   ;; Run the mode hook
   (run-mode-hooks 'idlwave-mode-hook))
 
@@ -1968,25 +2012,36 @@ The main features of this mode are
   (unless idlwave-setup-done
     (if (not (file-directory-p idlwave-config-directory))
        (make-directory idlwave-config-directory))
-    (setq idlwave-user-catalog-file (expand-file-name
-                                    idlwave-user-catalog-file
-                                    idlwave-config-directory)
-       idlwave-path-file (expand-file-name
-                          idlwave-path-file
-                          idlwave-config-directory))
+    (setq
+     idlwave-user-catalog-file (expand-file-name
+                               idlwave-user-catalog-file
+                               idlwave-config-directory)
+     idlwave-xml-system-rinfo-converted-file
+     (expand-file-name
+      idlwave-xml-system-rinfo-converted-file
+      idlwave-config-directory)
+     idlwave-path-file (expand-file-name
+                       idlwave-path-file
+                       idlwave-config-directory))
     (idlwave-read-paths)  ; we may need these early
     (setq idlwave-setup-done t)))
 
+(defun idlwave-font-lock-fontify-region (beg end &optional verbose)
+  "Fontify continuation lines correctly."
+  (let (pos)
+    (save-excursion
+      (goto-char beg)
+      (forward-line -1)
+      (when (setq pos (idlwave-is-continuation-line))
+       (goto-char pos)
+       (idlwave-beginning-of-statement)
+       (setq beg (point)))))
+  (font-lock-default-fontify-region beg end verbose))
+
 ;;
 ;; Code Formatting ----------------------------------------------------
 ;;
 
-(defun idlwave-push-mark (&rest rest)
-  "Push mark for compatibility with Emacs 18/19."
-  (if (fboundp 'iconify-frame)
-      (apply 'push-mark rest)
-    (push-mark)))
-
 (defun idlwave-hard-tab ()
   "Inserts TAB in buffer in current position."
   (interactive)
@@ -2180,7 +2235,6 @@ Also checks if the correct end statement has been used."
 (defun idlwave-close-block ()
   "Terminate the current block with the correct END statement."
   (interactive)
-
   ;; Start new line if we are not in a new line
   (unless (save-excursion
            (skip-chars-backward " \t")
@@ -2191,12 +2245,27 @@ Also checks if the correct end statement has been used."
     (insert "end")
     (idlwave-show-begin)))
 
-(defun idlwave-gtr-pad-hook (char)
-  "Let the > symbol expand around -> if present.  The new token length
-is returned."
-  2)
-
-(defun idlwave-surround (&optional before after escape-chars length ec-hook)
+(defun idlwave-custom-ampersand-surround (&optional is-action)
+  "Surround &, leaving room for && (which surrround as well)."
+  (let* ((prev-char (char-after (- (point) 2)))
+        (next-char (char-after (point)))
+        (amp-left (eq prev-char ?&))
+        (amp-right (eq next-char ?&))
+        (len (if amp-left 2 1)))
+    (unless amp-right ;no need to do it twice, amp-left will catch it.
+      (idlwave-surround -1 (if (or is-action amp-left) -1) len))))
+
+(defun idlwave-custom-ltgtr-surround (gtr &optional is-action)
+  "Surround > and < by blanks, leaving room for >= and <=, and considering ->."
+  (let* ((prev-char (char-after (- (point) 2)))
+       (next-char (char-after (point)))
+       (method-invoke (and gtr (eq prev-char ?-)))
+       (len (if method-invoke 2 1)))
+    (unless  (eq next-char ?=)
+      ;; Key binding: pad only on left, to save for possible >=/<=
+      (idlwave-surround -1 (if (or is-action method-invoke) -1) len))))
+
+(defun idlwave-surround (&optional before after length is-action)
   "Surround the LENGTH characters before point with blanks.
 LENGTH defaults to 1.
 Optional arguments BEFORE and AFTER affect the behavior before and
@@ -2209,42 +2278,28 @@ integer < 0    at least |n| spaces
 
 The function does nothing if any of the following conditions is true:
 - `idlwave-surround-by-blank' is nil
-- the character before point is inside a string or comment
-- the char preceeding the string to be surrounded is a member of ESCAPE-CHARS.
-  This hack is used to avoid padding of `>' when it is part of
-  the '->' operator.  In this case, ESCAPE-CHARS would be '(?-).
-
-If a function is passed in EC-HOOK, and an ESCAPE-CHARS match occurs,
-the named function will be called with a single argument of the
-preceeding character.  Then idlwave-surround will run as usual if
-EC-HOOK returns non-nil, and a new length will be taken from the
-return value."
+- the character before point is inside a string or comment"
   (when (and idlwave-surround-by-blank (not (idlwave-quoted)))
-    (let* ((length (or length 1)) ; establish a default for LENGTH
-          (prev-char (char-after (- (point) (1+ length)))))
-      (when (or (not (memq prev-char escape-chars))
-               (and (fboundp ec-hook)
-                    (setq length
-                          (save-excursion (funcall ec-hook prev-char)))))
-       (backward-char length)
-       (save-restriction
-         (let ((here (point)))
-           (skip-chars-backward " \t")
-           (if (bolp)
-               ;; avoid clobbering indent
-               (progn
-                 (move-to-column (idlwave-calculate-indent))
-                 (if (<= (point) here)
-                     (narrow-to-region (point) here))
-                 (goto-char here)))
-           (idlwave-make-space before))
-         (skip-chars-forward " \t"))
-       (forward-char length)
-       (idlwave-make-space after)
-       ;; Check to see if the line should auto wrap
-       (if (and (equal (char-after (1- (point))) ?\ )
-                (> (current-column) fill-column))
-           (funcall auto-fill-function))))))
+    (let ((length (or length 1))) ; establish a default for LENGTH
+      (backward-char length)
+      (save-restriction
+       (let ((here (point)))
+         (skip-chars-backward " \t")
+         (if (bolp)
+             ;; avoid clobbering indent
+             (progn
+               (move-to-column (idlwave-calculate-indent))
+               (if (<= (point) here)
+                   (narrow-to-region (point) here))
+               (goto-char here)))
+         (idlwave-make-space before))
+       (skip-chars-forward " \t"))
+      (forward-char length)
+      (idlwave-make-space after)
+      ;; Check to see if the line should auto wrap
+      (if (and (equal (char-after (1- (point))) ?\ )
+              (> (current-column) fill-column))
+         (funcall auto-fill-function)))))
 
 (defun idlwave-make-space (n)
   "Make space at point.
@@ -2363,16 +2418,18 @@ non-nil."
     ;; Reindent new line
     (idlwave-indent-line)))
 
-(defun idlwave-beginning-of-subprogram ()
-  "Moves point to the beginning of the current program unit."
+(defun idlwave-beginning-of-subprogram (&optional nomark)
+  "Moves point to the beginning of the current program unit.
+If NOMARK is non-nil, do not push mark."
   (interactive)
-  (idlwave-find-key idlwave-begin-unit-reg -1))
+  (idlwave-find-key idlwave-begin-unit-reg -1 nomark))
 
-(defun idlwave-end-of-subprogram ()
-  "Moves point to the start of the next program unit."
+(defun idlwave-end-of-subprogram (&optional nomark)
+  "Moves point to the start of the next program unit.
+If NOMARK is non-nil, do not push mark."
   (interactive)
   (idlwave-end-of-statement)
-  (idlwave-find-key idlwave-end-unit-reg 1))
+  (idlwave-find-key idlwave-end-unit-reg 1 nomark))
 
 (defun idlwave-mark-statement ()
   "Mark current IDL statement."
@@ -2380,7 +2437,7 @@ non-nil."
   (idlwave-end-of-statement)
   (let ((end (point)))
     (idlwave-beginning-of-statement)
-    (idlwave-push-mark end nil t)))
+    (push-mark end nil t)))
 
 (defun idlwave-mark-block ()
   "Mark containing block."
@@ -2391,7 +2448,7 @@ non-nil."
   (let ((end (point)))
     (idlwave-backward-block)
     (idlwave-beginning-of-statement)
-    (idlwave-push-mark end nil t)))
+    (push-mark end nil t)))
 
 
 (defun idlwave-mark-subprogram ()
@@ -2402,7 +2459,7 @@ The marks are pushed."
   (idlwave-beginning-of-subprogram)
   (let ((beg (point)))
     (idlwave-forward-block)
-    (idlwave-push-mark beg nil t))
+    (push-mark beg nil t))
   (exchange-point-and-mark))
 
 (defun idlwave-backward-up-block (&optional arg)
@@ -2423,11 +2480,12 @@ If prefix ARG < 0 then move forward to enclosing block end."
   (idlwave-block-jump-out 1 'nomark)
   (backward-word 1))
 
-(defun idlwave-forward-block ()
+(defun idlwave-forward-block (&optional arg)
   "Move across next nested block."
   (interactive)
-  (if (idlwave-down-block 1)
-      (idlwave-block-jump-out 1 'nomark)))
+  (let ((arg (or arg 1)))
+    (if (idlwave-down-block arg)
+       (idlwave-block-jump-out arg 'nomark))))
 
 (defun idlwave-backward-block ()
   "Move backward across previous nested block."
@@ -2473,17 +2531,20 @@ The marks are pushed."
          (if (re-search-forward idlwave-doclib-end nil t)
              (progn
                (forward-line 1)
-               (idlwave-push-mark beg nil t)
+               (push-mark beg nil t)
                (message "Could not find end of doc library header.")))
          (message "Could not find doc library header start.")
          (goto-char here)))))
 
+(defun idlwave-current-routine-fullname ()
+  (let ((name (idlwave-current-routine)))
+    (idlwave-make-full-name (nth 2 name) (car name))))
 
 (defun idlwave-current-routine ()
   "Return (NAME TYPE CLASS) of current routine."
   (idlwave-routines)
   (save-excursion
-    (idlwave-beginning-of-subprogram)
+    (idlwave-beginning-of-subprogram 'nomark)
     (if (looking-at "[ \t]*\\<\\(pro\\|function\\)\\>\\s-+\\(\\([a-zA-Z0-9$_]+\\)::\\)?\\([a-zA-Z0-9$_]+\\)")
        (let* ((type (if (string= (downcase (match-string 1)) "pro")
                         'pro 'function))
@@ -2665,7 +2726,7 @@ statement."
       (if st
           (append st (match-end 0))))))
 
-(defun idlwave-expand-equal (&optional before after)
+(defun idlwave-expand-equal (&optional before after is-action)
   "Pad '=' with spaces.  Two cases: Assignment statement, and keyword
 assignment.  Which case is determined using
 `idlwave-start-of-substatement' and `idlwave-statement-type'.  The
@@ -2686,6 +2747,8 @@ only post-padded.  You must use a space before these to disambiguate
 \(not just for padding, but for proper parsing by IDL too!).  Other
 operators, such as ##=, ^=, etc., will be pre-padded.
 
+IS-ACTION is ignored.
+
 See `idlwave-surround'."
   (if idlwave-surround-by-blank
       (let
@@ -2708,7 +2771,7 @@ See `idlwave-surround'."
 
        (if (eq t idlwave-pad-keyword)
            ;; Everything gets padded equally
-           (idlwave-surround before after nil len)
+           (idlwave-surround before after len)
          ;; Treating keywords/for variables specially...
          (let ((st (save-excursion   ; To catch "for" variables
                      (idlwave-start-of-substatement t)
@@ -2723,7 +2786,7 @@ See `idlwave-surround'."
                     (idlwave-surround 0 0)
                     ) ; remove space
                    (t))) ; leave any spaces alone
-                 (t (idlwave-surround before after nil len))))))))
+                 (t (idlwave-surround before after len))))))))
 
 
 (defun idlwave-indent-and-action (&optional arg)
@@ -2771,10 +2834,10 @@ If the optional argument EXPAND is non-nil then the actions in
         ;; Before indenting, run action routines.
         ;;
         (if (and expand idlwave-do-actions)
-            (mapcar 'idlwave-do-action idlwave-indent-expand-table))
+            (mapc 'idlwave-do-action idlwave-indent-expand-table))
         ;;
         (if idlwave-do-actions
-            (mapcar 'idlwave-do-action idlwave-indent-action-table))
+            (mapc 'idlwave-do-action idlwave-indent-action-table))
         ;;
         ;; No longer expand abbrevs on the line.  The user can do this
         ;; manually using expand-region-abbrevs.
@@ -2804,18 +2867,20 @@ If the optional argument EXPAND is non-nil then the actions in
     (set-marker mloc nil)))
 
 (defun idlwave-do-action (action)
-  "Perform an action repeatedly on a line.
-ACTION is a list (REG . FUNC).  REG is a regular expression.  FUNC is
-either a function name to be called with `funcall' or a list to be
-evaluated with `eval'.  The action performed by FUNC should leave point
-after the match for REG - otherwise an infinite loop may be entered."
+  "Perform an action repeatedly on a line.  ACTION is a list (REG
+. FUNC).  REG is a regular expression.  FUNC is either a function name
+to be called with `funcall' or a list to be evaluated with `eval'.
+The action performed by FUNC should leave point after the match for
+REG - otherwise an infinite loop may be entered.  FUNC is always
+passed a final argument of 'is-action, so it can discriminate between
+being run as an action, or a key binding"
   (let ((action-key (car action))
         (action-routine (cdr action)))
     (beginning-of-line)
     (while (idlwave-look-at action-key)
       (if (listp action-routine)
-          (eval action-routine)
-        (funcall action-routine)))))
+          (eval (append action-routine '('is-action)))
+        (funcall action-routine 'is-action)))))
 
 (defun idlwave-indent-to (col &optional min)
   "Indent from point with spaces until column COL.
@@ -3167,13 +3232,14 @@ Skips any whitespace. Returns 0 if the end-of-line follows the whitespace."
   "Tests if current line is continuation line.
 Blank or comment-only lines following regular continuation lines (with
 `$') count as continuations too."
-  (save-excursion
-    (or
-     (idlwave-look-at "\\<\\$")
-     (catch 'loop
-       (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
-                  (eq (forward-line -1) 0))
-        (if (idlwave-look-at "\\<\\$") (throw 'loop t)))))))
+  (let (p)
+    (save-excursion
+      (or
+       (idlwave-look-at "\\<\\$")
+       (catch 'loop
+        (while (and (looking-at "^[ \t]*\\(;.*\\)?$")
+                    (eq (forward-line -1) 0))
+          (if (setq p (idlwave-look-at "\\<\\$")) (throw 'loop p))))))))
 
 (defun idlwave-is-comment-line ()
   "Tests if the current line is a comment line."
@@ -3430,7 +3496,6 @@ if `idlwave-auto-fill-split-string' is non-nil."
          (idlwave-indent-line)
          ;; Prevent actions do-auto-fill which calls indent-line-function.
          (let (idlwave-do-actions
-               (paragraph-start ".")
                (paragraph-separate ".")
                (fill-nobreak-predicate
                 (if (and (idlwave-in-quote)
@@ -3442,8 +3507,7 @@ if `idlwave-auto-fill-split-string' is non-nil."
          (save-excursion
            (end-of-line 0)
            ;; Indent the split line
-           (idlwave-indent-line)
-           )
+           (idlwave-indent-line))
          (if (save-excursion
                (beginning-of-line)
                (looking-at idlwave-comment-line-start-skip))
@@ -3603,6 +3667,7 @@ location on mark ring so that the user can return to previous point."
          (run-hooks 'idlwave-timestamp-hook))
       (error "No valid DOCLIB header"))))
 
+
 ;;; CJC 3/16/93
 ;;; Interface to expand-region-abbrevs which did not work when the
 ;;; abbrev hook associated with an abbrev moves point backwards
@@ -3734,7 +3799,7 @@ unless the optional second argument NOINDENT is non-nil."
       (if (not noindent)
          (indent-region beg end nil))
       (if (stringp prompt)
-         (message prompt)))))
+         (message "%s" prompt)))))
 
 (defun idlwave-rw-case (string)
   "Make STRING have the case required by `idlwave-reserved-word-upcase'."
@@ -4109,9 +4174,9 @@ blank lines."
       for var = (car entry)
       do (if (not (consp (symbol-value var))) (set var (list nil))))
 
+    ;; Reset the system & library hash
     (when (or (eq what t) (eq what 'syslib)
              (null (cdr idlwave-sint-routines)))
-      ;; Reset the system & library hash
       (loop for entry in entries
        for var = (car entry) for size = (nth 1 entry)
        do (setcdr (symbol-value var)
@@ -4119,9 +4184,9 @@ blank lines."
       (setq idlwave-sint-dirs nil
            idlwave-sint-libnames nil))
 
+    ;; Reset the buffer & shell hash
     (when (or (eq what t) (eq what 'bufsh)
              (null (car idlwave-sint-routines)))
-      ;; Reset the buffer & shell hash
       (loop for entry in entries
        for var = (car entry) for size = (nth 1 entry)
        do (setcar (symbol-value var)
@@ -4184,9 +4249,9 @@ blank lines."
 
 (defun idlwave-sintern-keyword-list (kwd-list &optional set)
   "Sintern a set of keywords (file (key . link) (key2 . link2) ...)"
-  (mapcar (lambda(x)
-           (setcar x (idlwave-sintern-keyword (car x) set)))
-         (cdr kwd-list))
+  (mapc (lambda(x)
+         (setcar x (idlwave-sintern-keyword (car x) set)))
+       (cdr kwd-list))
   kwd-list)
 
 (defun idlwave-sintern-rinfo-list (list &optional set default-dir)
@@ -4284,7 +4349,7 @@ catalog \('lib).")
 (defvar idlwave-true-path-alist nil
   "Like `idlwave-path-alist', but with true filenames.")
 (defvar idlwave-routines nil
-  "Holds the combinded procedure/function/method routine-info.")
+  "Holds the combined procedure/function/method routine-info.")
 (defvar idlwave-class-alist nil
   "Holds the class names known to IDLWAVE.")
 (defvar idlwave-class-history nil
@@ -4339,7 +4404,7 @@ Does not run after automatic updates of buffer or the shell.")
   (idlwave-update-routine-info '(16)))
 
 (defun idlwave-rescan-asynchronously ()
-  "Dispatch another emacs instance to update the idlwave catalog.
+  "Dispatch another Emacs instance to update the idlwave catalog.
 After the process finishes normally, the first access to routine info
 will re-read the catalog."
   (interactive)
@@ -4359,7 +4424,7 @@ will re-read the catalog."
          (not (stringp idlwave-user-catalog-file))
          (not (file-regular-p idlwave-user-catalog-file)))
       (error "No catalog has been produced yet"))
-  (let* ((emacs (expand-file-name (invocation-name) (invocation-directory)))
+  (let* ((emacs (concat invocation-directory invocation-name))
         (args (list "-batch"
                     "-l" (expand-file-name "~/.emacs")
                     "-l" "idlwave"
@@ -4384,7 +4449,8 @@ will re-read the catalog."
 ;; ("ROUTINE" type class
 ;;  (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
 ;;  (buffer pro_file dir) | (compiled pro_file dir)
-;;   "calling_string" ("HELPFILE" (("KWD1" . link1) ...)))
+;;   "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
+;;                    ("HELPFILE2" (("KWD2" . link) ...)) ...)
 ;;
 ;; DIR will be supplied dynamically while loading library catalogs,
 ;; and is sinterned to save space, as is LIBNAME.  PRO_FILE can be a
@@ -4458,9 +4524,9 @@ information updated immediately, leave NO-CONCATENATE nil."
          ;; We can safely scan the buffer stuff first
          (progn
            (idlwave-update-buffer-routine-info)
-           (and load (idlwave-load-system-rinfo override-idle)))
+           (and load (idlwave-load-all-rinfo override-idle)))
        ;; We first do the system info, and then the buffers
-       (and load (idlwave-load-system-rinfo override-idle))
+       (and load (idlwave-load-all-rinfo override-idle))
        (idlwave-update-buffer-routine-info))
 
       ;; Let's see if there is a shell
@@ -4521,16 +4587,434 @@ information updated immediately, leave NO-CONCATENATE nil."
 
 (defvar idlwave-library-routines nil "Obsolete variable.")
 
+;;------ XML Help routine info system
+(defun idlwave-load-system-routine-info ()
+  ;; Load the system routine info from the cached routine info file,
+  ;; which, if necessary, will be re-created from the XML file on
+  ;; disk.  As a last fallback, load the (likely outdated) idlw-rinfo
+  ;; file distributed with older IDLWAVE versions (<6.0)
+  (unless (and (load idlwave-xml-system-rinfo-converted-file
+                    'noerror 'nomessage)
+              (idlwave-xml-system-routine-info-up-to-date))
+    ;; See if we can create it from XML source
+    (condition-case nil
+       (idlwave-convert-xml-system-routine-info)
+      (error
+       (unless (load idlwave-xml-system-rinfo-converted-file
+                    'noerror 'nomessage)
+        (if idlwave-system-routines
+            (message
+             "Failed to load converted routine info, using old conversion.")
+          (message
+           "Failed to convert XML routine info, falling back on idlw-rinfo.")
+          (if (not (load "idlw-rinfo" 'noerror 'nomessage))
+              (message
+               "Could not locate any system routine information."))))))))
+
+(defun idlwave-xml-system-routine-info-up-to-date()
+  (let* ((dir (file-name-as-directory
+              (expand-file-name "help/online_help" (idlwave-sys-dir))))
+        (catalog-file (expand-file-name "idl_catalog.xml" dir)))
+    (file-newer-than-file-p ;converted file is newer than catalog
+     idlwave-xml-system-rinfo-converted-file
+     catalog-file)))
+
+(defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
+(defvar idlwave-system-variables-alist nil
+  "Alist of system variables and the associated structure tags.
+Gets set in cached XML rinfo, or `idlw-rinfo.el'.")
+(defvar idlwave-executive-commands-alist nil
+  "Alist of system variables and their help files.")
+(defvar idlwave-help-special-topic-words nil)
+
+
+(defun idlwave-shorten-syntax (syntax name &optional class)
+  ;; From a list of syntax statments, shorten with %s and group with "or"
+  (let ((case-fold-search t))
+    (mapconcat
+     (lambda (x)
+       (while (string-match name x)
+        (setq x (replace-match "%s" t t x)))
+       (if class
+          (while (string-match class x)
+            (setq x (replace-match "%s" t t x))))
+       x)
+     (nreverse syntax)
+     " or ")))
+
+(defun idlwave-xml-create-class-method-lists (xml-entry)
+  ;; Create a class list entry from the xml parsed list., returning a
+  ;; cons of form (class-entry method-entries).
+  (let* ((nameblock (nth 1 xml-entry))
+        (class (cdr (assq 'name nameblock)))
+        (link (cdr (assq 'link nameblock)))
+        (params (cddr xml-entry))
+        (case-fold-search t)
+        class-entry
+        method methods-entry extra-kwds
+        props get-props set-props init-props inherits
+        pelem ptype)
+    (while params
+      (setq pelem (car params))
+      (when (listp pelem)
+       (setq ptype (car pelem)
+             props (car (cdr pelem)))
+       (cond
+        ((eq ptype 'SUPERCLASS)
+         (let ((pname (cdr (assq 'name props)))
+               (plink (cdr (assq 'link props))))
+           (unless (and (string= pname "None")
+                        (string= plink "None"))
+             (push pname inherits))))
+
+        ((eq ptype 'PROPERTY)
+         (let ((pname (cdr (assq 'name props)))
+               (plink (cdr (assq 'link props)))
+               (get (string= (cdr (assq 'get props)) "Yes"))
+               (set (string= (cdr (assq 'set props)) "Yes"))
+               (init (string= (cdr (assq 'init props)) "Yes")))
+           (if get (push (list pname plink) get-props))
+           (if set (push (list pname plink) set-props))
+           (if init (push (list pname plink) init-props))))
+
+        ((eq ptype 'METHOD)
+         (setq method (cdr (assq 'name props)))
+         (setq extra-kwds ;;Assume all property keywords are gathered already
+               (cond
+                ((string-match (concat class "::Init") method)
+                 (put 'init-props 'matched t)
+                 init-props)
+                ((string-match (concat class "::GetProperty") method)
+                 (put 'get-props 'matched t)
+                 get-props)
+                ((string-match (concat class "::SetProperty") method)
+                 (put 'set-props 'matched t)
+                 set-props)
+                (t nil)))
+         (setq methods-entry
+               (nconc (idlwave-xml-create-rinfo-list pelem class extra-kwds)
+                      methods-entry)))
+        (t)))
+      (setq params (cdr params)))
+    ;(unless (get 'init-props 'matched)
+    ;  (message "Failed to match Init in class %s" class))
+    ;(unless (get 'get-props 'matched)
+    ;  (message "Failed to match GetProperty in class %s" class))
+    ;(unless (get 'set-props 'matched)
+    ;  (message "Failed to match SetProperty in class %s" class))
+    (setq class-entry
+         (if inherits
+             (list class (append '(inherits) inherits) (list 'link link))
+           (list class (list 'link link))))
+    (cons class-entry methods-entry)))
+
+(defun idlwave-xml-create-rinfo-list (xml-entry &optional class extra-kws)
+  ;; Create correctly structured list elements from ROUTINE or METHOD
+  ;; XML list structures.  Return a list of list elements, with more
+  ;; than one sub-list possible if a routine can serve as both
+  ;; procedure and function (e.g. call_method).
+  (let* ((nameblock (nth 1 xml-entry))
+        (name (cdr (assq 'name nameblock)))
+        (link (cdr (assq 'link nameblock)))
+        (params (cddr xml-entry))
+        (syntax-vec (make-vector 3 nil)) ; procedure, function, exec command
+        (case-fold-search t)
+        syntax kwd klink pref-list kwds pelem ptype entry props result type)
+    (if class ;; strip out class name from class method name string
+       (if (string-match (concat class "::") name)
+           (setq name (substring name (match-end 0)))))
+    (while params
+      (setq pelem (car params))
+      (when (listp pelem)
+       (setq ptype (car pelem)
+             props (car (cdr pelem)))
+       (cond
+        ((eq ptype 'SYNTAX)
+         (setq syntax (cdr (assq 'name props)))
+         (if (string-match "-&gt;" syntax)
+             (setq syntax (replace-match "->" t nil syntax)))
+         (setq type (cdr (assq 'type props)))
+         (push syntax
+               (aref syntax-vec (cond
+                                 ((string-match "^pro" type) 0)
+                                 ((string-match "^fun" type) 1)
+                                 ((string-match "^exec" type) 2)))))
+        ((eq ptype 'KEYWORD)
+         (setq kwd (cdr (assq 'name props))
+               klink (cdr (assq 'link props)))
+         (if (string-match "^\\[XY\\(Z?\\)\\]" kwd)
+             (progn
+               (setq pref-list
+                     (if (match-string 1 kwd) '("X" "Y" "Z") '("X" "Y"))
+                     kwd (substring kwd (match-end 0)))
+               (loop for x in pref-list do
+                     (push (list (concat x kwd) klink) kwds)))
+           (push (list kwd klink) kwds)))
+
+        (t))); Do nothing for the others
+      (setq params (cdr params)))
+
+    ;; Debug
+;    (if (and (null (aref syntax-vec 0))
+;           (null (aref syntax-vec 1))
+;           (null (aref syntax-vec 2)))
+;      (with-current-buffer (get-buffer-create "IDL_XML_catalog_complaints")
+;        (if class
+;            (insert (format "Missing SYNTAX entry for %s::%s\n" class name))
+;          (insert (message "Missing SYNTAX entry for %s\n" name)))))
+
+    ;; Executive commands are treated specially
+    (if (aref syntax-vec 2)
+       (cons (substring name 1) link)
+      (if extra-kws (setq kwds (nconc kwds extra-kws)))
+      (setq kwds (idlwave-rinfo-group-keywords kwds link))
+      (loop for idx from 0 to 1 do
+           (if (aref syntax-vec idx)
+               (push (append (list name (if (eq idx 0) 'pro 'fun)
+                                   class '(system)
+                                   (idlwave-shorten-syntax
+                                    (aref syntax-vec idx) name class))
+                             kwds) result)))
+      result)))
+
+
+(defun idlwave-rinfo-group-keywords (kwds master-link)
+  ;; Group keywords by link file, as a list with elements
+  ;; (linkfile ( ("KWD1" . link1) ("KWD2" . link2))
+  (let (kwd link anchor linkfiles block master-elt)
+    (while kwds
+      (setq kwd (car kwds)
+           link (idlwave-split-link-target (nth 1 kwd))
+           anchor (cdr link)
+           link (car link)
+           kwd (car kwd))
+      (if (setq block (assoc link linkfiles))
+         (push (cons kwd anchor) (cdr block))
+       (push (list link (cons kwd anchor)) linkfiles))
+      (setq kwds (cdr kwds)))
+    ;; Ensure the master link is there
+    (if (setq master-elt (assoc master-link linkfiles))
+       (if (eq (car linkfiles) master-elt)
+           linkfiles
+         (cons master-elt (delq master-elt linkfiles)))
+      (push (list master-link) linkfiles))))
+
+(defun idlwave-convert-xml-clean-statement-aliases (aliases)
+  ;; Clean up the syntax of routines which are actually aliases by
+  ;; removing the "OR" from the statements
+  (let (syntax entry)
+    (loop for x in aliases do
+         (setq entry (assoc x idlwave-system-routines))
+         (when entry
+           (while (string-match " +or +" (setq syntax (nth 4 entry)))
+             (setf (nth 4 entry) (replace-match ", " t t syntax)))))))
+
+(defun idlwave-convert-xml-clean-routine-aliases (aliases)
+  ;; Duplicate and trim original routine aliases from rinfo list
+  ;; This if for, e.g. OPENR/OPENW/OPENU
+  (let (alias remove-list new parts all-parts)
+    (loop for x in aliases do
+         (when (setq parts (split-string (cdr x) "/"))
+           (setq new (assoc (cdr x) all-parts))
+           (unless new
+             (setq new (cons (cdr x) parts))
+             (push new all-parts))
+           (setcdr new (delete (car x) (cdr new)))))
+
+    ;; Add any missing aliases (separate by slashes)
+    (loop for x in all-parts do
+         (if (cdr x)
+             (push (cons (nth 1 x) (car x)) aliases)))
+
+    (loop for x in aliases do
+         (when (setq alias (assoc (cdr x) idlwave-system-routines))
+           (unless (memq alias remove-list) (push alias remove-list))
+           (setq alias (copy-sequence alias))
+           (setcar alias (car x))
+           (push alias idlwave-system-routines)))
+    (loop for x in remove-list do
+         (delq x idlwave-system-routines))))
+
+(defun idlwave-convert-xml-clean-sysvar-aliases (aliases)
+  ;; Duplicate and trim original routine aliases from rinfo list
+  ;; This if for, e.g. !X, !Y, !Z.
+  (let (alias remove-list new parts all-parts)
+    (loop for x in aliases do
+         (when (setq alias (assoc (cdr x) idlwave-system-variables-alist))
+           (unless (memq alias remove-list) (push alias remove-list))
+           (setq alias (copy-sequence alias))
+           (setcar alias (car x))
+           (push alias idlwave-system-variables-alist)))
+    (loop for x in remove-list do
+         (delq x idlwave-system-variables-alist))))
+
+
+(defun idlwave-xml-create-sysvar-alist (xml-entry)
+  ;; Create a sysvar list entry from the xml parsed list.
+  (let* ((nameblock (nth 1 xml-entry))
+        (name (cdr (assq 'name nameblock)))
+        (sysvar (substring name (progn (string-match "^ *!" name)
+                                       (match-end 0))))
+        (link (cdr (assq 'link nameblock)))
+        (params (cddr xml-entry))
+        (case-fold-search t)
+        pelem ptype props fields tags)
+    (while params
+      (setq pelem (car params))
+      (when (listp pelem)
+       (setq ptype (car pelem)
+             props (car (cdr pelem)))
+       (cond
+        ((eq ptype 'FIELD)
+         (push (cons (cdr (assq 'name props))
+                     (cdr
+                      (idlwave-split-link-target (cdr (assq 'link props)))))
+               tags))))
+       (setq params (cdr params)))
+    (delq nil
+         (list sysvar (if tags (cons 'tags tags)) (list 'link link)))))
+
+
+(defvar idlwave-xml-routine-info-file nil)
+
+(defun idlwave-save-routine-info ()
+  (if idlwave-xml-routine-info-file
+      (with-temp-file idlwave-xml-system-rinfo-converted-file
+       (insert
+        (concat ";; *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+;; IDLWAVE Routine Information File (IDLWAVE version " idlwave-mode-version ")
+;; Automatically generated from source file:
+;;  " idlwave-xml-routine-info-file "
+;; on " (current-time-string) "
+;; Do not edit."))
+       (insert (format "\n(setq idlwave-xml-routine-info-file \n    \"%s\")"
+                       idlwave-xml-routine-info-file))
+       (insert "\n(setq idlwave-system-routines\n    '")
+       (prin1 idlwave-system-routines (current-buffer))
+       (insert ")")
+       (insert "\n(setq idlwave-system-variables-alist\n    '")
+       (prin1 idlwave-system-variables-alist (current-buffer))
+       (insert ")")
+       (insert "\n(setq idlwave-system-class-info\n    '")
+       (prin1 idlwave-system-class-info (current-buffer))
+       (insert ")")
+       (insert "\n(setq idlwave-executive-commands-alist\n    '")
+       (prin1 idlwave-executive-commands-alist (current-buffer))
+       (insert ")")
+       (insert "\n(setq idlwave-help-special-topic-words\n    '")
+       (prin1 idlwave-help-special-topic-words (current-buffer))
+       (insert ")"))))
+
+(defun idlwave-convert-xml-system-routine-info ()
+  "Convert XML supplied IDL routine info into internal form.
+Cache to disk for quick recovery."
+  (interactive)
+  (let* ((dir (file-name-as-directory
+              (expand-file-name "help/online_help" (idlwave-sys-dir))))
+        (catalog-file (expand-file-name "idl_catalog.xml" dir))
+        (elem-cnt 0)
+        props rinfo msg-cnt elem type nelem class-result alias
+        routines routine-aliases statement-aliases sysvar-aliases
+        version-string)
+    (if (not (file-exists-p catalog-file))
+       (error "No such XML routine info file: %s" catalog-file)
+      (if (not (file-readable-p catalog-file))
+         (error "Cannot read XML routine info file: %s" catalog-file)))
+    (require 'xml)
+    (message "Reading XML routine info...")
+    (setq rinfo (xml-parse-file catalog-file))
+    (message "Reading XML routine info...done")
+    (setq rinfo (assq 'CATALOG rinfo))
+    (unless rinfo (error "Failed to parse XML routine info"))
+    ;;(setq rinfo (car rinfo)) ; Skip the catalog stuff.
+
+    (setq version-string (cdr (assq 'version (nth 1 rinfo)))
+         rinfo (cddr rinfo))
+
+    (setq nelem (length rinfo)
+         msg-cnt (/ nelem 20))
+
+    (setq idlwave-xml-routine-info-file nil)
+    (message "Converting XML routine info...")
+    (setq idlwave-system-routines nil
+         idlwave-system-variables-alist nil
+         idlwave-system-class-info nil
+         idlwave-executive-commands-alist nil
+         idlwave-help-special-topic-words nil)
+
+    (while rinfo
+      (setq elem (car rinfo)
+           rinfo (cdr rinfo))
+      (incf elem-cnt)
+      (when (listp elem)
+       (setq type (car elem)
+             props (car (cdr elem)))
+       (if (= (mod elem-cnt msg-cnt) 0)
+           (message "Converting XML routine info...%2d%%"
+                    (/ (* elem-cnt 100) nelem)))
+       (cond
+        ((eq type 'ROUTINE)
+         (if (setq alias (assq 'alias_to props))
+             (push (cons (cdr (assq 'name props)) (cdr alias))
+                   routine-aliases)
+           (setq routines (idlwave-xml-create-rinfo-list elem))
+           (if (listp (cdr routines))
+               (setq idlwave-system-routines
+                     (nconc idlwave-system-routines routines))
+             ;; a cons cell is an executive commands
+             (push routines idlwave-executive-commands-alist))))
+
+        ((eq type 'CLASS)
+         (setq class-result (idlwave-xml-create-class-method-lists elem))
+         (push (car class-result) idlwave-system-class-info)
+         (setq idlwave-system-routines
+         (nconc idlwave-system-routines (cdr class-result))))
+
+        ((eq type 'STATEMENT)
+         (push (cons (cdr (assq 'name props))
+                     (cdr (assq 'link props)))
+         idlwave-help-special-topic-words)
+         ;; Save the links to those which are statement aliases (not routines)
+         (if (setq alias (assq 'alias_to props))
+             (unless (member (cdr alias) statement-aliases)
+               (push (cdr alias) statement-aliases))))
+
+        ((eq type 'SYSVAR)
+         (if (setq alias (cdr (assq 'alias_to props)))
+             (push (cons (substring (cdr (assq 'name props)) 1)
+                         (substring alias 1))
+                   sysvar-aliases)
+           (push (idlwave-xml-create-sysvar-alist elem)
+                 idlwave-system-variables-alist)))
+        (t))))
+    (idlwave-convert-xml-clean-routine-aliases routine-aliases)
+    (idlwave-convert-xml-clean-statement-aliases statement-aliases)
+    (idlwave-convert-xml-clean-sysvar-aliases sysvar-aliases)
+
+    (setq idlwave-xml-routine-info-file catalog-file)
+    (idlwave-save-routine-info)
+    (message "Converting XML routine info...done")))
+
+
+;; ("ROUTINE" type class
+;;  (system) | (lib pro_file dir "LIBNAME") | (user pro_file dir "USERLIB") |
+;;  (buffer pro_file dir) | (compiled pro_file dir)
+;;   "calling_string" ("HELPFILE" (("KWD1" . link1) ...))
+;;                    ("HELPFILE2" (("KWD2" . link) ...)) ...)
+
+
 (defun idlwave-load-rinfo-next-step ()
   (let ((inhibit-quit t)
        (arr idlwave-load-rinfo-steps-done))
-    (when (catch 'exit
+    (if (catch 'exit
          (when (not (aref arr 0))
-           (message "Loading idlw-rinfo.el in idle time...")
-           (load "idlw-rinfo" 'noerror 'nomessage)
-           (message "Loading idlw-rinfo.el in idle time...done")
+           (message "Loading system routine info in idle time...")
+           (idlwave-load-system-routine-info)
+           ;;(load "idlw-rinfo" 'noerror 'nomessage)
+           (message "Loading system routine info in idle time...done")
            (aset arr 0 t)
            (throw 'exit t))
+
          (when (not (aref arr 1))
            (message "Normalizing idlwave-system-routines in idle time...")
            (idlwave-reset-sintern t)
@@ -4540,6 +5024,7 @@ information updated immediately, leave NO-CONCATENATE nil."
            (message "Normalizing idlwave-system-routines in idle time...done")
            (aset arr 1 t)
            (throw 'exit t))
+
          (when (not (aref arr 2))
            (when (and (stringp idlwave-user-catalog-file)
                       (file-regular-p idlwave-user-catalog-file))
@@ -4556,9 +5041,10 @@ information updated immediately, leave NO-CONCATENATE nil."
                    (ding)
                    (message "Outdated user catalog: %s... recreate"
                             idlwave-user-catalog-file))
-               (message "Loading user catalog in idle time...done"))
-             (aset arr 2 t)
-             (throw 'exit t)))
+               (message "Loading user catalog in idle time...done")))
+           (aset arr 2 t)
+           (throw 'exit t))
+
          (when (not (aref arr 3))
            (when idlwave-user-catalog-routines
              (message "Normalizing user catalog routines in idle time...")
@@ -4569,6 +5055,7 @@ information updated immediately, leave NO-CONCATENATE nil."
               "Normalizing user catalog routines in idle time...done"))
            (aset arr 3 t)
            (throw 'exit t))
+
          (when (not (aref arr 4))
            (idlwave-scan-library-catalogs
             "Loading and normalizing library catalogs in idle time...")
@@ -4578,6 +5065,7 @@ information updated immediately, leave NO-CONCATENATE nil."
            (message "Finishing initialization in idle time...")
            (idlwave-routines)
            (message "Finishing initialization in idle time...done")
+           (aset arr 5 t)
            (throw 'exit nil)))
        ;; restart the timer
        (if (sit-for 1)
@@ -4587,27 +5075,37 @@ information updated immediately, leave NO-CONCATENATE nil."
                 idlwave-init-rinfo-when-idle-after
                 nil 'idlwave-load-rinfo-next-step))))))
 
-(defun idlwave-load-system-rinfo (&optional force)
-  ;; Load and case-treat the system and catalog files.
+(defun idlwave-load-all-rinfo (&optional force)
+  ;; Load and case-treat the system, user catalog, and library routine
+  ;; info files.
+
+  ;; System
   (when (or force (not (aref idlwave-load-rinfo-steps-done 0)))
-    (load "idlw-rinfo" 'noerror 'nomessage))
+    ;;(load "idlw-rinfo" 'noerror 'nomessage))
+    (idlwave-load-system-routine-info))
   (when (or force (not (aref idlwave-load-rinfo-steps-done 1)))
     (message "Normalizing idlwave-system-routines...")
     (setq idlwave-system-routines
          (idlwave-sintern-rinfo-list idlwave-system-routines 'sys))
     (message "Normalizing idlwave-system-routines...done"))
-  (setq idlwave-routines (copy-sequence idlwave-system-routines))
-  (setq idlwave-last-system-routine-info-cons-cell
-       (nthcdr (1- (length idlwave-routines)) idlwave-routines))
+  (when idlwave-system-routines
+    (setq idlwave-routines (copy-sequence idlwave-system-routines))
+    (setq idlwave-last-system-routine-info-cons-cell
+         (nthcdr (1- (length idlwave-routines)) idlwave-routines)))
+
+  ;; User catalog
   (when (and (stringp idlwave-user-catalog-file)
             (file-regular-p idlwave-user-catalog-file))
     (condition-case nil
        (when (or force (not (aref idlwave-load-rinfo-steps-done 2)))
          (load-file idlwave-user-catalog-file))
       (error nil))
-    (when (boundp 'idlwave-library-routines)
+    (when (and
+          (boundp 'idlwave-library-routines)
+          idlwave-library-routines)
       (setq idlwave-library-routines nil)
-      (error "Outdated user catalog: %s... recreate" idlwave-user-catalog-file))
+      (error "Outdated user catalog: %s... recreate"
+            idlwave-user-catalog-file))
     (setq idlwave-true-path-alist nil)
     (when (or force (not (aref idlwave-load-rinfo-steps-done 3)))
       (message "Normalizing user catalog routines...")
@@ -4615,6 +5113,8 @@ information updated immediately, leave NO-CONCATENATE nil."
            (idlwave-sintern-rinfo-list
             idlwave-user-catalog-routines 'sys))
       (message "Normalizing user catalog routines...done")))
+
+  ;; Library catalog
   (when (or force (not (aref idlwave-load-rinfo-steps-done 4)))
     (idlwave-scan-library-catalogs
      "Loading and normalizing library catalogs..."))
@@ -4837,7 +5337,6 @@ information updated immediately, leave NO-CONCATENATE nil."
    (t "@@@@@@@@")))
 
 
-
 (defun idlwave-create-user-catalog-file (&optional arg)
   "Scan all files on selected dirs of IDL search path for routine information.
 
@@ -5068,11 +5567,11 @@ directories and save the routine info.
     ;; Define the routine info list
     (insert "\n(setq idlwave-user-catalog-routines\n    '(")
     (let ((standard-output (current-buffer)))
-      (mapcar (lambda (x)
-               (insert "\n    ")
-               (prin1 x)
-               (goto-char (point-max)))
-             idlwave-user-catalog-routines))
+      (mapc (lambda (x)
+             (insert "\n    ")
+             (prin1 x)
+             (goto-char (point-max)))
+           idlwave-user-catalog-routines))
     (insert (format "))\n\n;;; %s ends here\n"
                    (file-name-nondirectory idlwave-user-catalog-file)))
     (goto-char (point-min))
@@ -5112,11 +5611,11 @@ directories and save the routine info.
     ;; Define the variable which contains a list of all scanned directories
     (insert "\n(setq idlwave-path-alist\n    '(")
     (let ((standard-output (current-buffer)))
-      (mapcar (lambda (x)
-               (insert "\n      ")
-               (prin1 x)
-               (goto-char (point-max)))
-             idlwave-path-alist))
+      (mapc (lambda (x)
+             (insert "\n      ")
+             (prin1 x)
+             (goto-char (point-max)))
+           idlwave-path-alist))
     (insert "))\n")
     (save-buffer 0)
     (kill-buffer (current-buffer))))
@@ -5190,7 +5689,7 @@ be set to nil to disable library catalog scanning."
                     (not (string= idlwave-library-catalog-libname
                                   old-libname)))
                (message "%s" (concat message-base
-                                idlwave-library-catalog-libname))
+                                     idlwave-library-catalog-libname))
                (setq old-libname idlwave-library-catalog-libname))
              (when idlwave-library-catalog-routines
                (setq all-routines
@@ -5213,6 +5712,17 @@ be set to nil to disable library catalog scanning."
 (defconst idlwave-routine-info.pro
   "
 ;; START OF IDLWAVE SUPPORT ROUTINES
+pro idlwave_print_safe,item,limit
+  catch,err
+  if err ne 0 then begin
+     print,'Could not print item.'
+     return
+  endif
+  if n_elements(item) gt limit then $
+     print,item[0:limit-1],'<... truncated at ',strtrim(limit,2),' elements>' $
+  else print,item
+end
+
 pro idlwave_print_info_entry,name,func=func,separator=sep
   ;; See if it's an object method
   if name eq '' then return
@@ -5269,16 +5779,26 @@ pro idlwave_print_info_entry,name,func=func,separator=sep
     + sep + cs + sep + kwstring
 end
 
-pro idlwave_routine_info
+pro idlwave_routine_info,file
   on_error,1
   sep = '<@>'
   print,'>>>BEGIN OF IDLWAVE ROUTINE INFO (\"' + sep + '\" IS THE SEPARATOR)'
   all = routine_info()
-  for i=0,n_elements(all)-1 do $
-    idlwave_print_info_entry,all[i],separator=sep
+  fileQ=n_elements(file) ne 0
+  if fileQ then file=strtrim(file,2)
+  for i=0L,n_elements(all)-1L do begin
+     if fileQ then begin
+        if (routine_info(all[i],/SOURCE)).path eq file then $
+           idlwave_print_info_entry,all[i],separator=sep
+     endif else idlwave_print_info_entry,all[i],separator=sep
+  endfor
   all = routine_info(/functions)
-  for i=0,n_elements(all)-1 do $
-    idlwave_print_info_entry,all[i],/func,separator=sep
+  for i=0L,n_elements(all)-1L do begin
+     if fileQ then begin
+        if (routine_info(all[i],/FUNCTIONS,/SOURCE)).path eq file then $
+           idlwave_print_info_entry,all[i],separator=sep,/FUNC
+     endif else idlwave_print_info_entry,all[i],separator=sep,/FUNC
+  endfor
   print,'>>>END OF IDLWAVE ROUTINE INFO'
 end
 
@@ -5291,7 +5811,7 @@ pro idlwave_get_sysvars
       help,/brief,output=s,/system_variables  ; ? unsafe use of OUTPUT=
       s = strtrim(strjoin(s,' ',/single),2)   ; make one line
       v = strsplit(s,' +',/regex,/extract)    ; get variables
-      for i=0,n_elements(v)-1 do begin
+      for i=0L,n_elements(v)-1 do begin
           t = ['']                            ; get tag list
           a=execute('if n_tags('+v[i]+') gt 0 then t=tag_names('+v[i]+')')
           print, 'IDLWAVE-SYSVAR: '+v[i]+' '+strjoin(t,' ',/single)
@@ -5312,13 +5832,8 @@ end
 
 (defvar idlwave-shell-temp-pro-file)
 (defvar idlwave-shell-temp-rinfo-save-file)
-(defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait)
-  "Query the shell for routine_info of compiled modules and update the lists."
-  ;; Save and compile the procedure.  The compiled procedure is then
-  ;; saved into an IDL SAVE file, to allow for fast RESTORE.
-  ;; We need to RESTORE the procedure each time we use it, since
-  ;; the user may have killed or redefined it.  In particular,
-  ;; .RESET_SESSION will kill all user procedures.
+
+(defun idlwave-shell-compile-helper-routines (&optional wait)
   (unless (and idlwave-idlwave_routine_info-compiled
               (file-readable-p (idlwave-shell-temp-file 'rinfo)))
     (save-excursion
@@ -5328,19 +5843,36 @@ end
       (insert idlwave-routine-info.pro)
       (save-buffer 0))
     (idlwave-shell-send-command
-     (concat ".run " idlwave-shell-temp-pro-file)
+     (concat ".run \"" idlwave-shell-temp-pro-file "\"")
      nil 'hide wait)
-;    (message "SENDING SAVE") ; ????????????????????????
     (idlwave-shell-send-command
-     (format "save,'idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
+     (format "save,'idlwave_print_safe','idlwave_routine_info','idlwave_print_info_entry','idlwave_get_class_tags','idlwave_get_sysvars',FILE='%s',/ROUTINES"
             (idlwave-shell-temp-file 'rinfo))
-     nil 'hide wait))
+     nil 'hide)
+    (setq idlwave-idlwave_routine_info-compiled t))
 
-  ;; Restore and execute the procedure, analyze the output
-;  (message "SENDING RESTORE & EXECUTE") ; ????????????????????????
+  ;; Restore if necessary.  Must use execute to hide lame routine_info
+  ;; errors on undefinded routine
   (idlwave-shell-send-command
-   (format "RESTORE, '%s' & idlwave_routine_info"
+   (format "if execute(\"_v=routine_info('idlwave_routine_info',/SOURCE)\") eq 0 then restore,'%s' else if _v.path eq '' then restore,'%s'"
+          idlwave-shell-temp-rinfo-save-file
           idlwave-shell-temp-rinfo-save-file)
+   nil 'hide))
+
+
+(defun idlwave-shell-update-routine-info (&optional quiet run-hooks wait file)
+  "Query the shell for routine_info of compiled modules and update the lists."
+  ;; Save and compile the procedure.  The compiled procedure is then
+  ;; saved into an IDL SAVE file, to allow for fast RESTORE.  We may
+  ;; need to test for and possibly RESTORE the procedure each time we
+  ;; use it, since the user may have killed or redefined it.  In
+  ;; particular, .RESET_SESSION will kill all user procedures.  If
+  ;; FILE is set, only update routine info for routines in that file.
+
+  (idlwave-shell-compile-helper-routines wait)
+  ; execute the routine_info procedure, and analyze the output
+  (idlwave-shell-send-command
+   (format "idlwave_routine_info%s" (if file (concat ",'" file "'") ""))
    `(progn
       (idlwave-shell-routine-info-filter)
       (idlwave-concatenate-rinfo-lists ,quiet ,run-hooks))
@@ -5794,12 +6326,12 @@ When TYPE is not specified, both procedures and functions will be considered."
   (if (null method)
       (mapcar 'car (idlwave-class-alist))
     (let (rtn)
-      (mapcar (lambda (x)
-               (and (nth 2 x)
-                    (or (not type)
-                        (eq type (nth 1 x)))
-                    (push (nth 2 x) rtn)))
-             (idlwave-all-assq method (idlwave-routines)))
+      (mapc (lambda (x)
+             (and (nth 2 x)
+                  (or (not type)
+                      (eq type (nth 1 x)))
+                  (push (nth 2 x) rtn)))
+           (idlwave-all-assq method (idlwave-routines)))
       (idlwave-uniquify rtn))))
 
 (defun idlwave-all-method-keyword-classes (method keyword &optional type)
@@ -5810,13 +6342,13 @@ When TYPE is not specified, both procedures and functions will be considered."
          (null keyword))
       nil
     (let (rtn)
-      (mapcar (lambda (x)
-               (and (nth 2 x)           ; non-nil class
-                    (or (not type)      ; correct or unspecified type
-                        (eq type (nth 1 x)))
-                    (assoc keyword (idlwave-entry-keywords x))
-                    (push (nth 2 x) rtn)))
-             (idlwave-all-assq method (idlwave-routines)))
+      (mapc (lambda (x)
+             (and (nth 2 x)            ; non-nil class
+                  (or (not type)       ; correct or unspecified type
+                      (eq type (nth 1 x)))
+                  (assoc keyword (idlwave-entry-keywords x))
+                  (push (nth 2 x) rtn)))
+           (idlwave-all-assq method (idlwave-routines)))
       (idlwave-uniquify rtn))))
 
 (defun idlwave-members-only (list club)
@@ -6260,12 +6792,12 @@ accumulate information on matching completions."
       (message "Making completion list...")
 
       (unless idlwave-completion-help-links ; already set somewhere?
-       (mapcar (lambda (x)  ; Pass link prop through to highlight-linked
-                 (let ((link (get-text-property 0 'link (car x))))
-                   (if link
-                       (push (cons (car x) link)
-                             idlwave-completion-help-links))))
-               list))
+       (mapc (lambda (x)  ; Pass link prop through to highlight-linked
+               (let ((link (get-text-property 0 'link (car x))))
+                 (if link
+                     (push (cons (car x) link)
+                           idlwave-completion-help-links))))
+             list))
       (let* ((list all-completions)
             ;; "complete" means, this is already a valid completion
             (complete (memq spart all-completions))
@@ -6506,7 +7038,7 @@ sort the list before displaying"
                         (select-window win)
                         (eval idlwave-complete-after-success-form))
                     (set-window-start cwin (point-min)))))
-         (and message (message message)))
+         (and message (message "%s" message)))
       (select-window win))))
 
 (defun idlwave-display-completion-list (list &optional message beg complete)
@@ -6537,7 +7069,7 @@ sort the list before displaying"
   (run-hooks 'idlwave-completion-setup-hook)
 
   ;; Display the message
-  (message (or message "Making completion list...done")))
+  (message "%s" (or message "Making completion list...done")))
 
 (defun idlwave-choose (function &rest args)
   "Call FUNCTION as a completion chooser and pass ARGS to it."
@@ -6570,7 +7102,7 @@ sort the list before displaying"
   "Make the user select an element from the alist in the variable SYM.
 The keys of the alist are expected to be strings.  The function returns the
 car of the selected association.
-To do this, PROMPT is displayed and and the user must hit a letter key to
+To do this, PROMPT is displayed and the user must hit a letter key to
 select an entry.  If the user does not reply within DELAY seconds, a help
 window with the options is displayed automatically.
 The key which is associated with each option is generated automatically.
@@ -6863,7 +7395,6 @@ backward."
          (match-string-no-properties 5)))))
 
 (defvar idlwave-class-info nil)
-(defvar idlwave-system-class-info nil) ; Gathered from idlw-rinfo
 (defvar idlwave-class-reset nil) ; to reset buffer-local classes
 
 (add-hook 'idlwave-update-rinfo-hook
@@ -7027,7 +7558,7 @@ The list is cached in `idlwave-class-info' for faster access."
 If RECORD-LINK is non-nil, the keyword text is copied and a text
 property indicating the link is added."
   (let (kwds)
-    (mapcar
+    (mapc
      (lambda (key-list)
        (let ((file (car key-list)))
         (mapcar (lambda (key-cons)
@@ -7075,6 +7606,7 @@ property indicating the link is added."
 (defvar idlwave-current-class-tags nil)
 (defvar idlwave-current-native-class-tags nil)
 (defvar idlwave-sint-class-tags nil)
+(declare-function idlwave-sintern-class-tag "idlwave" t t)
 (idlwave-new-sintern-type 'class-tag)
 (add-to-list 'idlwave-complete-special 'idlwave-complete-class-structure-tag)
 (add-hook 'idlwave-update-rinfo-hook 'idlwave-class-tag-reset)
@@ -7133,18 +7665,14 @@ property indicating the link is added."
 
 (defvar idlwave-sint-sysvars nil)
 (defvar idlwave-sint-sysvartags nil)
+(declare-function idlwave-sintern-sysvar    "idlwave" t t)
+(declare-function idlwave-sintern-sysvartag "idlwave" t t)
 (idlwave-new-sintern-type 'sysvar)
 (idlwave-new-sintern-type 'sysvartag)
 (add-to-list 'idlwave-complete-special 'idlwave-complete-sysvar-or-tag)
 (add-hook 'idlwave-update-rinfo-hook 'idlwave-sysvars-reset)
 (add-hook 'idlwave-after-load-rinfo-hook 'idlwave-sintern-sysvar-alist)
 
-(defvar idlwave-executive-commands-alist nil
-  "Alist of system variables and their help files.")
-
-(defvar idlwave-system-variables-alist nil
-  "Alist of system variables and the associated structure tags.
-Gets set in `idlw-rinfo.el'.")
 
 (defun idlwave-complete-sysvar-or-tag ()
   "Complete a system variable."
@@ -7182,7 +7710,8 @@ Gets set in `idlw-rinfo.el'.")
             t)) ; return t to skip other completions
          (t nil))))
 
-(defvar link) ;dynamic
+(defvar link) ;dynamic variables set by help callback
+(defvar props)
 (defun idlwave-complete-sysvar-help (mode word)
   (let ((word (or (nth 1 idlwave-completion-help-info) word))
        (entry (assoc word idlwave-system-variables-alist)))
@@ -7205,11 +7734,17 @@ Gets set in `idlw-rinfo.el'.")
      ((eq mode 'set)
       (if entry
          (setq link
-               (if (setq target (cdr (assoc word tags)))
+               (if (setq target (cdr (assoc-string word tags t)))
                  (idlwave-substitute-link-target main target)
                main)))) ;; setting dynamic!!!
      (t (error "This should not happen")))))
 
+(defun idlwave-split-link-target (link)
+  "Split a given link into link file and anchor."
+  (if (string-match idlwave-html-link-sep link)
+      (cons (substring link 0 (match-beginning 0))
+           (string-to-number (substring link (match-end 0))))))
+
 (defun idlwave-substitute-link-target (link target)
   "Substitute the target anchor for the given link."
   (let (main-base)
@@ -7248,8 +7783,7 @@ Gets set in `idlw-rinfo.el'.")
 (defun idlwave-class-or-superclass-with-tag (class tag)
   "Find and return the CLASS or one of its superclass with the
 associated TAG, if any."
-  (let ((sclasses (cons class (cdr (assq 'all-inherits
-                                        (idlwave-class-info class)))))
+  (let ((sclasses (cons class (idlwave-all-class-inherits class)))
        cl)
    (catch 'exit
      (while sclasses
@@ -7753,8 +8287,8 @@ demand _EXTRA in the keyword list."
                 (memq (nth 2 entry) super-classes)      ; an inherited class
                 (eq (nth 1 entry) type)                 ; correct type
                 (eq (car entry) name)                   ; correct name
-                (mapcar (lambda (k) (add-to-list 'keywords k))
-                        (idlwave-entry-keywords entry 'do-link))))
+                (mapc (lambda (k) (add-to-list 'keywords k))
+                      (idlwave-entry-keywords entry 'do-link))))
       (setq keywords (idlwave-uniquify keywords)))
 
     ;; Return the final list
@@ -7855,7 +8389,7 @@ If we do not know about MODULE, just return KEYWORD literally."
         (col 0)
         (data (list name type class (current-buffer) nil initial-class))
         (km-prop (if (featurep 'xemacs) 'keymap 'local-map))
-        (face 'idlwave-help-link-face)
+        (face 'idlwave-help-link)
         beg props win cnt total)
     ;; Fix keywords, but don't add chained super-classes, since these
     ;; are shown separately for that super-class
@@ -7913,7 +8447,7 @@ If we do not know about MODULE, just return KEYWORD literally."
        (if (null keywords)
            (insert " No keywords accepted.")
          (setq col 9)
-         (mapcar
+         (mapc
           (lambda (x)
             (if (>= (+ col 1 (length (car x)))
                     (window-width))
@@ -8207,9 +8741,8 @@ command can be used to detect possible name clashes during this process."
                      km-prop keymap
                      'help-echo "Mouse2: Find source"))
         (nroutines (length (or special-routines routines)))
-        (step (/ nroutines 99))
+        (step (/ nroutines 100))
         (n 0)
-        (next-perc 1)
         (cnt 0)
         (idlwave-sort-prefer-buffer-info nil)
         routine twins dtwins twin done props1 lroutines)
@@ -8245,11 +8778,9 @@ command can be used to detect possible name clashes during this process."
       (setq buffer-read-only nil)
       (erase-buffer)
       (while (setq routine (pop routines))
-       (setq n (1+ n))
-       (if (= (* next-perc step) n)
-           (progn
-             (message "Compiling list...(%2d%%)" next-perc)
-             (setq next-perc (1+ next-perc))))
+       (if (= (mod (setq n (1+ n)) step) 0)
+           (message "Compiling list...(%2d%%)" (/ (* n 100) nroutines)))
+
        ;; Get a list of all twins
        (setq twins (idlwave-routine-twins routine (or lroutines routines)))
        (if (memq routine done)
@@ -8611,12 +9142,15 @@ Assumes that point is at the beginning of the unit as found by
   (interactive)
   (start-process "idldeclient" nil
                 idlwave-shell-explicit-file-name "-c" "-e"
-                 (buffer-file-name) "&"))
+                 (buffer-file-name)))
 
+(defvar idlwave-help-use-assistant)
 (defun idlwave-launch-idlhelp ()
   "Start the IDLhelp application."
   (interactive)
-  (start-process "idlhelp" nil idlwave-help-application))
+  (if idlwave-help-use-assistant
+      (idlwave-help-assistant-raise)
+    (start-process "idlhelp" nil idlwave-help-application)))
 
 ;; Menus - using easymenu.el
 (defvar idlwave-mode-menu-def
@@ -8636,8 +9170,10 @@ Assumes that point is at the beginning of the unit as found by
      ["Block" idlwave-mark-block t]
      ["Header" idlwave-mark-doclib t])
     ("Format"
+     ["Indent Entire Statement" idlwave-indent-statement
+      :active t :keys "C-u \\[indent-for-tab-command]" ]
      ["Indent Subprogram" idlwave-indent-subprogram t]
-     ["(Un)Comment Region" idlwave-toggle-comment-region "C-c ;"]
+     ["(Un)Comment Region" idlwave-toggle-comment-region t]
      ["Continue/Split line" idlwave-split-line t]
      "--"
      ["Toggle Auto Fill" idlwave-auto-fill-mode :style toggle
@@ -8656,7 +9192,7 @@ Assumes that point is at the beginning of the unit as found by
      ["Close Block" idlwave-close-block t])
     ("Completion"
      ["Complete" idlwave-complete t]
-     ("Complete Special"
+     ("Complete Specific"
       ["1 Procedure Name" (idlwave-complete 'procedure) t]
       ["2 Procedure Keyword" (idlwave-complete 'procedure-keyword) t]
       "--"
@@ -8678,6 +9214,7 @@ Assumes that point is at the beginning of the unit as found by
      ["Resolve Routine" idlwave-resolve (featurep 'idlw-shell)]
      "--"
      ["Update Routine Info" idlwave-update-routine-info t]
+     ["Rescan XML Help Catalog" idlwave-convert-xml-system-routine-info t]
      "--"
      "IDL User Catalog"
      ["Select Catalog Directories" (idlwave-create-user-catalog-file nil) t]
@@ -8696,7 +9233,6 @@ Assumes that point is at the beginning of the unit as found by
      ["Insert TAB character" idlwave-hard-tab t])
      "--"
     ("External"
-     ["Generate IDL tags" idlwave-make-tags t]
      ["Start IDL shell" idlwave-shell t]
      ["Edit file in IDLDE" idlwave-edit-in-idlde t]
      ["Launch IDL Help" idlwave-launch-idlhelp t])
@@ -8715,6 +9251,8 @@ Assumes that point is at the beginning of the unit as found by
      "--"
      ["Info" idlwave-info t]
      "--"
+     ["Help with Topic" idlwave-help-assistant-help-with-topic
+      idlwave-help-use-assistant]
      ["Launch IDL Help" idlwave-launch-idlhelp t])))
 
 (defvar idlwave-mode-debug-menu-def
@@ -8852,7 +9390,7 @@ This function was written since `list-abbrevs' looks terrible for IDLWAVE mode."
 ;; Will only work on systems which support this.
 (or idlwave-routines (idlwave-start-load-rinfo-timer))
 
-;;;###autoload(add-to-list 'auto-mode-alist '("\\.[Pp][Rr][Oo]\\'" . idlwave-mode))
+;;;###autoload (add-to-list 'auto-mode-alist '("\\.[Pp][Rr][Oo]\\'" . idlwave-mode))
 
 ;; Run the hook
 (run-hooks 'idlwave-load-hook)