emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ELPA-diffs] /srv/bzr/emacs/elpa r247: New function f90-list-in-scope-va


From: Stefan Monnier
Subject: [ELPA-diffs] /srv/bzr/emacs/elpa r247: New function f90-list-in-scope-vars.
Date: Fri, 10 Aug 2012 17:27:03 -0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 247 [merge]
committer: Stefan Monnier <address@hidden>
branch nick: elpa
timestamp: Fri 2012-08-10 17:27:03 -0400
message:
  New function f90-list-in-scope-vars.
modified:
  packages/f90-interface-browser/f90-interface-browser.el
=== modified file 'packages/f90-interface-browser/f90-interface-browser.el'
--- a/packages/f90-interface-browser/f90-interface-browser.el   2012-02-06 
02:11:54 +0000
+++ b/packages/f90-interface-browser/f90-interface-browser.el   2012-08-10 
21:27:03 +0000
@@ -5,7 +5,7 @@
 ;; Author: Lawrence Mitchell <address@hidden>
 ;; Created: 2011-07-06
 ;; Available-from: http://github.com/wence-/f90-iface/
-;; Version: 1.0
+;; Version: 1.1
 
 ;; COPYRIGHT NOTICE
 
@@ -44,6 +44,12 @@
 ;; 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 @@
           (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.
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]