Function: idlwave-retrieve-expression-from-level
idlwave-retrieve-expression-from-level is a byte-compiled function
defined in idlw-shell.el.gz.
Signature
(idlwave-retrieve-expression-from-level EXPR LEVEL)
Documentation
Return IDL command to print the expression EXPR from stack level LEVEL.
It does not seem possible to evaluate an expression on a different level than the current. Therefore, this function retrieves variables by reference from other levels, and then includes that variable in place of the chosen one.
Since this function depends upon the undocumented IDL routine routine_names, there is no guarantee that this will work with future versions of IDL.
Source Code
;; Defined in /usr/src/emacs/lisp/obsolete/idlw-shell.el.gz
(defun idlwave-retrieve-expression-from-level (expr level)
"Return IDL command to print the expression EXPR from stack level LEVEL.
It does not seem possible to evaluate an expression on a different
level than the current. Therefore, this function retrieves variables
by reference from other levels, and then includes that variable in
place of the chosen one.
Since this function depends upon the undocumented IDL routine
routine_names, there is no guarantee that this will work with future
versions of IDL."
(let ((fetch (- 0 level))
(start 0)
var fetch-start fetch-end pre post)
;; FIXME: In the following we try to find the variables in expression
;; This is quite empirical - I don't know in what situations this will
;; break. We will look for identifiers and exclude cases where we
;; know it is not a variable. To distinguish array references from
;; function calls, we require that arrays use [] instead of ()
(while (string-match
"\\(\\`\\|[^a-zA-Z0-9$_][ \t]*\\)\\([a-zA-Z][a-zA-Z0-9$_]*\\)\\([ \t]*[^a-zA-Z0-9$_]\\|\\'\\)" expr start)
(setq var (match-string 2 expr)
start (match-end 2)
pre (substring expr 0 (match-beginning 2))
post (substring expr (match-end 2)))
(cond
((or
;; Exclude identifiers which are not variables
(string-match ",[ \t$\n]*/\\'" pre) ;; a `/' KEYWORD
(and (string-match "[,(][ \t\n]*\\'" pre)
(string-match "\\`[ \t]*=" post)) ;; a `=' KEYWORD
(string-match "\\`(" post) ;; a function
(string-match "->[ \t]*\\'" pre) ;; a method
(string-match "\\.\\'" pre))) ;; structure member
;; Skip over strings
((and (string-match "\\([\"']\\)[^\1]*$" pre)
(string-match (concat "^[^" (match-string 1 pre) "]*"
(match-string 1 pre)) post))
(setq start (+ start (match-end 0))))
;; seems to be a variable - delimit its name
(t
(put-text-property start (- start (length var)) 'fetch t expr))))
(setq start 0)
(while (setq fetch-start
(next-single-property-change start 'fetch expr))
(if (get-text-property start 'fetch expr) ; it's on in range
(setq fetch-end fetch-start ;it's off in range
fetch-start start)
(setq fetch-end (next-single-property-change fetch-start 'fetch expr)))
(unless fetch-end (setq fetch-end (length expr)))
(remove-text-properties fetch-start fetch-end '(fetch nil) expr)
(setq expr (concat (substring expr 0 fetch-start)
(format "(routine_names('%s',fetch=%d))"
(substring expr fetch-start fetch-end)
fetch)
(substring expr fetch-end)))
(setq start fetch-end))
(if (get-text-property 0 'fetch expr) ; Full expression, left over
(setq expr (format "(routine_names('%s',fetch=%d))" expr fetch)))
expr))