]> 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

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

index 58ed588de5fa85ee90c92b18bef2f21b84ecdc96,4840f6743546f345ed6b2f63575565dada88003b..c33996cc76440c414b39d81fe063897f0eca0966
@@@ -1,26 -1,29 +1,26 @@@
  ;;; f90-interface-browser.el --- Parse and browse f90 interfaces
  
 -;; This file is NOT part of Emacs.
 +;; Copyright (C) 2011, 2012  Free Software Foundation, Inc
  
 -;; Copyright (C) 2011, 2012 Lawrence Mitchell <wence@gmx.li>
 -;; Filename: f90-interface-browser.el
 +;; 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
  
 -;; This program 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 of the
 -;; License, or (at your option) any later version.
 -;;
 -;; This program is distributed in the hope that it will be useful, but
 -;; WITHOUT ANY WARRANTY; without even the implied warranty of
 -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -;; General Public License for more
 -;; details. http://www.gnu.org/copyleft/gpl.html
 -;;
 +;; This program 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 3 of the License, or
 +;; (at your option) any later version.
 +
 +;; This program is distributed in the hope that it will be useful,
 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +;; GNU General Public License for more details.
 +
  ;; You should have received a copy of the GNU General Public License
 -;; along with GNU Emacs. If you did not, write to the Free Software
 -;; Foundation, Inc., 675 Mass Ave., Cambridge, MA 02139, USA.
 +;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  
  ;;; Commentary:
  ;; You write (or work on) large, modern fortran code bases.  These
  ;; 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 -884,51 +881,51 @@@ needs a reference count interface, so i
            (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.