]> code.delx.au - gnu-emacs-elpa/commitdiff
New function f90-list-in-scope-vars.
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 10 Aug 2012 21:27:03 +0000 (17:27 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 10 Aug 2012 21:27:03 +0000 (17:27 -0400)
git-subtree-dir: packages/f90-interface-browser
git-subtree-mainline: da0d153e1520b5af5d008412187bbcb1d686de48
git-subtree-split: 9f6f434475bb724916506dba7b780db13544def2

packages/f90-interface-browser/f90-interface-browser.el

index 58ed588de5fa85ee90c92b18bef2f21b84ecdc96..c33996cc76440c414b39d81fe063897f0eca0966 100644 (file)
@@ -5,7 +5,7 @@
 ;; Author: Lawrence Mitchell <wence@gmx.li>
 ;; Created: 2011-07-06
 ;; Available-from: http://github.com/wence-/f90-iface/
-;; Version: 1.0
+;; Version: 1.1
 
 ;; COPYRIGHT NOTICE
 
 ;; so that you can use it on the M-.  keybinding and it will fall back
 ;; to completing tag names if you don't want to look for an interface
 ;; definition.
+;; In addition, if you're in a large procedure and want the list of
+;; the variables in scope (perhaps you want to define a new loop
+;; variable), you can use `f90-list-in-scope-vars' to pop up a buffer
+;; giving a reasonable guess.  Note this doesn't give you module
+;; variables, or the variables of parent procedures if the current
+;; subroutine is contained within another.
 
 ;; Derived types are also parsed, so that slot types of derived types
 ;; are given the correct type (rather than a UNION-TYPE) when arglist
@@ -875,6 +881,51 @@ needs a reference count interface, so insert one."
           (goto-char (point-min))
           (f90-arg-types names))))))
 
+(defun f90-list-in-scope-vars ()
+  "Pop up a buffer showing all variables in scope in the procedure at `point'"
+  (interactive)
+  (let* ((e (save-excursion (f90-end-of-subprogram) (point)))
+         (b (save-excursion (f90-beginning-of-subprogram) (point)))
+         (str (buffer-substring-no-properties b e))
+         types)
+    (with-temp-buffer
+      (with-syntax-table f90-mode-syntax-table
+        (insert str)
+        (goto-char (point-min))
+        (f90-clean-comments)
+        (f90-clean-continuation-lines)
+        (forward-line 1)                ; skip procedure name
+        (let ((not-done t)
+              type)
+          (while (and not-done (not (eobp)))
+            ;; skip "implicit none" which may appear at top of procedure
+            (when (looking-at "\\s-*implicit\\s-+none")
+              (forward-line 1))
+            (when (not (looking-at "^\\s-*$"))
+              (setq type (ignore-errors (f90-parse-single-type-declaration)))
+              ;; If we were on a line with text and failed to parse a
+              ;; type, we must have reached the end of the type
+              ;; definitions, so don't push it on and finish.
+              (if type
+                  (push type types)
+                (setq not-done nil)))
+            (forward-line 1)))))
+    (with-current-buffer (get-buffer-create "*Variables in scope*")
+      (setq buffer-read-only nil)
+      (erase-buffer)
+      (f90-mode)
+      ;; Show types of the same type together
+      (setq types (sort types (lambda (x y)
+                                (string< (cadar x) (cadar y)))))
+      (loop for (type name) in types
+            do
+            (insert (format "%s :: %s\n"
+                            (f90-format-parsed-slot-type type)
+                            (f90-get-parsed-type-varname type))))
+      (pop-to-buffer (current-buffer))
+      (goto-char (point-min))
+      (setq buffer-read-only t))))
+
 (defun f90-arg-types (names)
   "Given NAMES of arguments return their types.