comparison lisp/progmodes/ada-xref.el @ 45930:dd1d952f59c2

Update copyright notice. (ada-xref-create-ali): The default is now not to create automatically the ALI files by compiling the unit, since this isn't always reliable and requires an up-to-date project file. (ada-prj-default-comp-cmd): No longer use gcc directly to compile a file, but use gnatmake instead, since this gives access to the GNAT project files. (ada-xref-search-with-egrep): New variable, suggested by P. Waroquiers. (ada-load-project-hook): New variable, for support of GNAT project files. (ada-update-project-menu): Fix the detection of the project file name. (ada-add-keymap): Change key binding for ada-find-file, that conflicted with another binding in ada-mode.el. (ada-add-menu): New menu "List Local References", to list the reference to the entity only in the current file, instead of looking in the whole project. Much faster. (ada-find-references): New parameters arg and local-only. (ada-find-any-references): New parameters local-only and append. (ada-goto-declaration): Fix handling of predefined entities in xref. (ada-get-all-references): Updated to the new xref format in GNAT 3.15, still compatible with GNAT 3.14 of course. Fix various calls to count-lines, that didn't work correctly when the buffer was narrowed.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 20 Jun 2002 17:31:56 +0000
parents fc042127981b
children 36d9421bf776
comparison
equal deleted inserted replaced
45929:8542d59b76af 45930:dd1d952f59c2
1 ;;; ada-xref.el --- for lookup and completion in Ada mode 1 ;;; ada-xref.el --- for lookup and completion in Ada mode
2 2
3 ;; Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 2001 3 ;; Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 2001, 2002
4 ;; Free Software Foundation, Inc. 4 ;; Free Software Foundation, Inc.
5 5
6 ;; Author: Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de> 6 ;; Author: Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de>
7 ;; Rolf Ebert <ebert@inf.enst.fr> 7 ;; Rolf Ebert <ebert@inf.enst.fr>
8 ;; Emmanuel Briot <briot@gnat.com> 8 ;; Emmanuel Briot <briot@gnat.com>
9 ;; Maintainer: Emmanuel Briot <briot@gnat.com> 9 ;; Maintainer: Emmanuel Briot <briot@gnat.com>
10 ;; Ada Core Technologies's version: $Revision: 1.9 $ 10 ;; Ada Core Technologies's version: Revision: 1.155.2.8 (GNAT 3.15)
11 ;; Keywords: languages ada xref 11 ;; Keywords: languages ada xref
12 12
13 ;; This file is part of GNU Emacs. 13 ;; This file is part of GNU Emacs.
14 14
15 ;; GNU Emacs is free software; you can redistribute it and/or modify 15 ;; GNU Emacs is free software; you can redistribute it and/or modify
49 (defcustom ada-xref-other-buffer t 49 (defcustom ada-xref-other-buffer t
50 "*If nil, always display the cross-references in the same buffer. 50 "*If nil, always display the cross-references in the same buffer.
51 Otherwise create either a new buffer or a new frame." 51 Otherwise create either a new buffer or a new frame."
52 :type 'boolean :group 'ada) 52 :type 'boolean :group 'ada)
53 53
54 (defcustom ada-xref-create-ali t 54 (defcustom ada-xref-create-ali nil
55 "*If non-nil, run gcc whenever the cross-references are not up-to-date. 55 "*If non-nil, run gcc whenever the cross-references are not up-to-date.
56 If nil, the cross-reference mode will never run gcc." 56 If nil, the cross-reference mode will never run gcc."
57 :type 'boolean :group 'ada) 57 :type 'boolean :group 'ada)
58 58
59 (defcustom ada-xref-confirm-compile nil 59 (defcustom ada-xref-confirm-compile nil
89 The command gnatfind is used every time you choose the menu 89 The command gnatfind is used every time you choose the menu
90 \"Show all references\"." 90 \"Show all references\"."
91 :type 'string :group 'ada) 91 :type 'string :group 'ada)
92 92
93 (defcustom ada-prj-default-comp-cmd 93 (defcustom ada-prj-default-comp-cmd
94 "${cross_prefix}gcc -x ada -c ${comp_opt} ${full_current}" 94 (concat "${cross_prefix}gnatmake -u -c ${gnatmake_opt} ${full_current} -cargs"
95 " ${comp_opt}")
95 "*Default command to be used to compile a single file. 96 "*Default command to be used to compile a single file.
96 Emacs will add the filename at the end of this command. This is the same 97 Emacs will add the filename at the end of this command. This is the same
97 syntax as in the project file." 98 syntax as in the project file."
98 :type 'string :group 'ada) 99 :type 'string :group 'ada)
99 100
129 "True if we are running on windows NT or windows 95.") 130 "True if we are running on windows NT or windows 95.")
130 131
131 (defcustom ada-tight-gvd-integration nil 132 (defcustom ada-tight-gvd-integration nil
132 "*If non-nil, a new Emacs frame will be swallowed in GVD when debugging. 133 "*If non-nil, a new Emacs frame will be swallowed in GVD when debugging.
133 If GVD is not the debugger used, nothing happens.") 134 If GVD is not the debugger used, nothing happens.")
135
136 (defcustom ada-xref-search-with-egrep t
137 "*If non-nil, use egrep to find the possible declarations for an entity.
138 This alternate method is used when the exact location was not found in the
139 information provided by GNAT. However, it might be expensive if you have a lot
140 of sources, since it will search in all the files in your project."
141 :type 'boolean :group 'ada)
142
143 (defvar ada-load-project-hook nil
144 "Hook that is run when loading a project file.
145 Each function in this hook takes one argument FILENAME, that is the name of
146 the project file to load.
147 This hook should be used to support new formats for the project files.
148
149 If the function can load the file with the given filename, it should create a
150 buffer that contains a conversion of the file to the standard format of the
151 project files, and return that buffer. (the usual \"src_dir=\" or \"obj_dir=\"
152 lines). It should return nil if it doesn't know how to convert that project
153 file.")
154
134 155
135 ;; ------- Nothing to be modified by the user below this 156 ;; ------- Nothing to be modified by the user below this
136 (defvar ada-last-prj-file "" 157 (defvar ada-last-prj-file ""
137 "Name of the last project file entered by the user.") 158 "Name of the last project file entered by the user.")
138 159
287 ;; Try hard to find a default value for filename, so that the user 308 ;; Try hard to find a default value for filename, so that the user
288 ;; can edit his project file even if the current buffer is not an 309 ;; can edit his project file even if the current buffer is not an
289 ;; Ada file or not even associated with a file 310 ;; Ada file or not even associated with a file
290 (list 'filename (expand-file-name 311 (list 'filename (expand-file-name
291 (cond 312 (cond
313 (ada-prj-default-project-file
314 ada-prj-default-project-file)
292 (file 315 (file
293 (ada-prj-get-prj-dir file)) 316 (ada-prj-get-prj-dir file))
294 (ada-prj-default-project-file
295 ada-prj-default-project-file)
296 (t 317 (t
297 (message (concat "Not editing an Ada file," 318 (message (concat "Not editing an Ada file,"
298 "and no default project " 319 "and no default project "
299 "file specified!")) 320 "file specified!"))
300 ""))) 321 "")))
434 (ada-xref-update-project-menu)))) 455 (ada-xref-update-project-menu))))
435 (set 'submenu 456 (set 'submenu
436 (append submenu 457 (append submenu
437 (list (cons (intern name) 458 (list (cons (intern name)
438 (list 459 (list
439 'menu-item (file-name-sans-extension 460 'menu-item
440 (file-name-nondirectory name)) 461 (if (string= (file-name-extension name)
462 ada-project-file-extension)
463 (file-name-sans-extension
464 (file-name-nondirectory name))
465 (file-name-nondirectory name))
441 command 466 command
442 :button (cons 467 :button (cons
443 :toggle 468 :toggle
444 (equal ada-prj-default-project-file 469 (equal ada-prj-default-project-file
445 (car x)) 470 (car x))
513 538
514 (define-key ada-mode-map "\C-co" 'ff-find-other-file) 539 (define-key ada-mode-map "\C-co" 'ff-find-other-file)
515 (define-key ada-mode-map "\C-c5\C-d" 'ada-goto-declaration-other-frame) 540 (define-key ada-mode-map "\C-c5\C-d" 'ada-goto-declaration-other-frame)
516 (define-key ada-mode-map "\C-c\C-d" 'ada-goto-declaration) 541 (define-key ada-mode-map "\C-c\C-d" 'ada-goto-declaration)
517 (define-key ada-mode-map "\C-c\C-s" 'ada-xref-goto-previous-reference) 542 (define-key ada-mode-map "\C-c\C-s" 'ada-xref-goto-previous-reference)
518 (define-key ada-mode-map "\C-c\C-x" 'ada-reread-prj-file)
519 (define-key ada-mode-map "\C-c\C-c" 'ada-compile-application) 543 (define-key ada-mode-map "\C-c\C-c" 'ada-compile-application)
520 (define-key ada-mode-map "\C-cc" 'ada-change-prj) 544 (define-key ada-mode-map "\C-cc" 'ada-change-prj)
521 (define-key ada-mode-map "\C-cd" 'ada-set-default-project-file) 545 (define-key ada-mode-map "\C-cd" 'ada-set-default-project-file)
522 (define-key ada-mode-map "\C-cg" 'ada-gdb-application) 546 (define-key ada-mode-map "\C-cg" 'ada-gdb-application)
523 (define-key ada-mode-map "\C-cr" 'ada-run-application) 547 (define-key ada-mode-map "\C-cr" 'ada-run-application)
524 (define-key ada-mode-map "\C-c\C-o" 'ada-goto-parent) 548 (define-key ada-mode-map "\C-c\C-o" 'ada-goto-parent)
525 (define-key ada-mode-map "\C-c\C-r" 'ada-find-references) 549 (define-key ada-mode-map "\C-c\C-r" 'ada-find-references)
550 (define-key ada-mode-map "\C-cl" 'ada-find-local-references)
526 (define-key ada-mode-map "\C-c\C-v" 'ada-check-current) 551 (define-key ada-mode-map "\C-c\C-v" 'ada-check-current)
527 (define-key ada-mode-map "\C-c\C-f" 'ada-find-file) 552 (define-key ada-mode-map "\C-cf" 'ada-find-file)
528 ) 553 )
529 554
530 ;; ----- Menus -------------------------------------------------------------- 555 ;; ----- Menus --------------------------------------------------------------
531 (defun ada-add-ada-menu () 556 (defun ada-add-ada-menu ()
532 "Add some items to the standard Ada mode menu. 557 "Add some items to the standard Ada mode menu.
560 goto-menu ["Goto References to any entity" 585 goto-menu ["Goto References to any entity"
561 ada-find-any-references t] 586 ada-find-any-references t]
562 "Next compilation error") 587 "Next compilation error")
563 (funcall (symbol-function 'add-menu-button) 588 (funcall (symbol-function 'add-menu-button)
564 goto-menu ["List References" ada-find-references t] 589 goto-menu ["List References" ada-find-references t]
590 "Next compilation error")
591 (funcall (symbol-function 'add-menu-button)
592 goto-menu ["List Local References" ada-find-local-references t]
565 "Next compilation error") 593 "Next compilation error")
566 (funcall (symbol-function 'add-menu-button) 594 (funcall (symbol-function 'add-menu-button)
567 goto-menu ["Goto Declaration Other Frame" 595 goto-menu ["Goto Declaration Other Frame"
568 ada-goto-declaration-other-frame t] 596 ada-goto-declaration-other-frame t]
569 "Next compilation error") 597 "Next compilation error")
618 (not ada-tight-gvd-integration)) 646 (not ada-tight-gvd-integration))
619 :style toggle :selected ada-tight-gvd-integration])) 647 :style toggle :selected ada-tight-gvd-integration]))
620 ) 648 )
621 649
622 ;; for Emacs 650 ;; for Emacs
623 (let* ((menu (lookup-key ada-mode-map [menu-bar ada])) 651 (let* ((menu (or (lookup-key ada-mode-map [menu-bar Ada])
624 (edit-menu (lookup-key ada-mode-map [menu-bar ada edit])) 652 ;; Emacs-21.4's easymenu.el downcases the events.
625 (help-menu (lookup-key ada-mode-map [menu-bar ada help])) 653 (lookup-key ada-mode-map [menu-bar ada])))
626 (goto-menu (lookup-key ada-mode-map [menu-bar ada goto])) 654 (edit-menu (or (lookup-key menu [Edit]) (lookup-key menu [edit])))
627 (options-menu (lookup-key ada-mode-map [menu-bar ada options]))) 655 (help-menu (or (lookup-key menu [Help]) (lookup-key menu [help])))
656 (goto-menu (or (lookup-key menu [Goto]) (lookup-key menu [goto])))
657 (options-menu (or (lookup-key menu [Options])
658 (lookup-key menu [options]))))
628 659
629 (define-key-after menu [Check] '("Check file" . ada-check-current) 660 (define-key-after menu [Check] '("Check file" . ada-check-current)
630 'Customize) 661 'Customize)
631 (define-key-after menu [Compile] '("Compile file" . ada-compile-current) 662 (define-key-after menu [Compile] '("Compile file" . ada-compile-current)
632 'Check) 663 'Check)
654 . ada-goto-parent)) 685 . ada-goto-parent))
655 (define-key goto-menu [References-any] 686 (define-key goto-menu [References-any]
656 '("Goto References to any entity" . ada-find-any-references)) 687 '("Goto References to any entity" . ada-find-any-references))
657 (define-key goto-menu [References] 688 (define-key goto-menu [References]
658 '("List References" . ada-find-references)) 689 '("List References" . ada-find-references))
690 (define-key goto-menu [Local-References]
691 '("List Local References" . ada-find-local-references))
659 (define-key goto-menu [Prev] 692 (define-key goto-menu [Prev]
660 '("Goto Previous Reference" . ada-xref-goto-previous-reference)) 693 '("Goto Previous Reference" . ada-xref-goto-previous-reference))
661 (define-key goto-menu [Decl-other] 694 (define-key goto-menu [Decl-other]
662 '("Goto Declaration Other Frame" . ada-goto-declaration-other-frame)) 695 '("Goto Declaration Other Frame" . ada-goto-declaration-other-frame))
663 (define-key goto-menu [Decl] 696 (define-key goto-menu [Decl]
730 name) 763 name)
731 764
732 (defun ada-set-default-project-file (name) 765 (defun ada-set-default-project-file (name)
733 "Set the file whose name is NAME as the default project file." 766 "Set the file whose name is NAME as the default project file."
734 (interactive "fProject file:") 767 (interactive "fProject file:")
735 (set 'ada-prj-default-project-file name) 768 (setq ada-prj-default-project-file name)
736 (ada-reread-prj-file name) 769 (ada-reread-prj-file name)
737 ) 770 )
738 771
739 ;; ------ Handling the project file ----------------------------- 772 ;; ------ Handling the project file -----------------------------
740 773
841 ;; Do not use find-file below, since we don't want to show this 874 ;; Do not use find-file below, since we don't want to show this
842 ;; buffer. If the file is open through speedbar, we can't use 875 ;; buffer. If the file is open through speedbar, we can't use
843 ;; find-file anyway, since the speedbar frame is special and does not 876 ;; find-file anyway, since the speedbar frame is special and does not
844 ;; allow the selection of a file in it. 877 ;; allow the selection of a file in it.
845 878
846 (set-buffer (find-file-noselect prj-file)) 879 (let* ((buffer (run-hook-with-args-until-success
847 880 'ada-load-project-hook prj-file)))
881 (unless buffer
882 (setq buffer (find-file-noselect prj-file nil)))
883 (set-buffer buffer))
884
848 (widen) 885 (widen)
849 (goto-char (point-min)) 886 (goto-char (point-min))
850 887
851 ;; Now overrides these values with the project file 888 ;; Now overrides these values with the project file
852 (while (not (eobp)) 889 (while (not (eobp))
928 ;; Do not add the '/' or '\' at the end 965 ;; Do not add the '/' or '\' at the end
929 (setq ada-search-directories 966 (setq ada-search-directories
930 (append (mapcar 'directory-file-name compilation-search-path) 967 (append (mapcar 'directory-file-name compilation-search-path)
931 ada-search-directories)) 968 ada-search-directories))
932 969
933 ;; Kill the .ali buffer 970 ;; Kill the project buffer
934 (kill-buffer nil) 971 (kill-buffer nil)
935 (set-buffer ada-buffer) 972 (set-buffer ada-buffer)
936 973
937 (ada-xref-update-project-menu) 974 (ada-xref-update-project-menu)
938 ) 975 )
944 ;; directory. 981 ;; directory.
945 (setq compilation-search-path (list nil default-directory)) 982 (setq compilation-search-path (list nil default-directory))
946 )) 983 ))
947 984
948 985
949 (defun ada-find-references (&optional pos) 986 (defun ada-find-references (&optional pos arg local-only)
950 "Find all references to the entity under POS. 987 "Find all references to the entity under POS.
951 Calls gnatfind to find the references." 988 Calls gnatfind to find the references.
952 (interactive "") 989 if ARG is t, the contents of the old *gnatfind* buffer is preserved.
953 (unless pos 990 if LOCAL-ONLY is t, only the declarations in the current file are returned."
954 (set 'pos (point))) 991 (interactive "d
992 P")
955 (ada-require-project-file) 993 (ada-require-project-file)
956 994
957 (let* ((identlist (ada-read-identifier pos)) 995 (let* ((identlist (ada-read-identifier pos))
958 (alifile (ada-get-ali-file-name (ada-file-of identlist))) 996 (alifile (ada-get-ali-file-name (ada-file-of identlist)))
959 (process-environment (ada-set-environment))) 997 (process-environment (ada-set-environment)))
963 ;; if the file is more recent than the executable 1001 ;; if the file is more recent than the executable
964 (if (or (buffer-modified-p (current-buffer)) 1002 (if (or (buffer-modified-p (current-buffer))
965 (file-newer-than-file-p (ada-file-of identlist) alifile)) 1003 (file-newer-than-file-p (ada-file-of identlist) alifile))
966 (ada-find-any-references (ada-name-of identlist) 1004 (ada-find-any-references (ada-name-of identlist)
967 (ada-file-of identlist) 1005 (ada-file-of identlist)
968 nil nil) 1006 nil nil local-only arg)
969 (ada-find-any-references (ada-name-of identlist) 1007 (ada-find-any-references (ada-name-of identlist)
970 (ada-file-of identlist) 1008 (ada-file-of identlist)
971 (ada-line-of identlist) 1009 (ada-line-of identlist)
972 (ada-column-of identlist)))) 1010 (ada-column-of identlist) local-only arg)))
973 ) 1011 )
974 1012
975 (defun ada-find-any-references (entity &optional file line column) 1013 (defun ada-find-local-references (&optional pos arg)
1014 "Find all references to the entity under POS.
1015 Calls gnatfind to find the references.
1016 if ARG is t, the contents of the old *gnatfind* buffer is preserved."
1017 (interactive "d
1018 P")
1019 (ada-find-references pos arg t))
1020
1021 (defun ada-find-any-references
1022 (entity &optional file line column local-only append)
976 "Search for references to any entity whose name is ENTITY. 1023 "Search for references to any entity whose name is ENTITY.
977 ENTITY was first found the location given by FILE, LINE and COLUMN." 1024 ENTITY was first found the location given by FILE, LINE and COLUMN.
1025 If LOCAL-ONLY is t, then only the references in file will be listed, which
1026 is much faster.
1027 If APPEND is t, then the output of the command will be append to the existing
1028 buffer *gnatfind* if it exists."
978 (interactive "sEntity name: ") 1029 (interactive "sEntity name: ")
979 (ada-require-project-file) 1030 (ada-require-project-file)
980 1031
981 ;; Prepare the gnatfind command. Note that we must protect the quotes 1032 ;; Prepare the gnatfind command. Note that we must protect the quotes
982 ;; around operators, so that they are correctly handled and can be 1033 ;; around operators, so that they are correctly handled and can be
990 (switches (ada-xref-get-project-field 'gnatfind_opt)) 1041 (switches (ada-xref-get-project-field 'gnatfind_opt))
991 (command (concat "gnatfind " switches " " 1042 (command (concat "gnatfind " switches " "
992 quote-entity 1043 quote-entity
993 (if file (concat ":" (file-name-nondirectory file))) 1044 (if file (concat ":" (file-name-nondirectory file)))
994 (if line (concat ":" line)) 1045 (if line (concat ":" line))
995 (if column (concat ":" column))))) 1046 (if column (concat ":" column))
1047 (if local-only (concat " " (file-name-nondirectory file)))
1048 ))
1049 old-contents)
996 1050
997 ;; If a project file is defined, use it 1051 ;; If a project file is defined, use it
998 (if (and ada-prj-default-project-file 1052 (if (and ada-prj-default-project-file
999 (not (string= ada-prj-default-project-file ""))) 1053 (not (string= ada-prj-default-project-file "")))
1000 (setq command (concat command " -p" ada-prj-default-project-file))) 1054 (setq command (concat command " -p" ada-prj-default-project-file)))
1001 1055
1056 (if (and append (get-buffer "*gnatfind*"))
1057 (save-excursion
1058 (set-buffer "*gnatfind*")
1059 (setq old-contents (buffer-string))))
1060
1002 (compile-internal command "No more references" "gnatfind") 1061 (compile-internal command "No more references" "gnatfind")
1003 1062
1004 ;; Hide the "Compilation" menu 1063 ;; Hide the "Compilation" menu
1005 (save-excursion 1064 (save-excursion
1006 (set-buffer "*gnatfind*") 1065 (set-buffer "*gnatfind*")
1007 (local-unset-key [menu-bar compilation-menu])) 1066 (local-unset-key [menu-bar compilation-menu])
1067
1068 (if old-contents
1069 (progn
1070 (goto-char 1)
1071 (insert old-contents)
1072 (goto-char (point-max)))))
1008 ) 1073 )
1009 ) 1074 )
1010 1075
1011 (defalias 'ada-change-prj (symbol-function 'ada-set-default-project-file)) 1076 (defalias 'ada-change-prj (symbol-function 'ada-set-default-project-file))
1012 1077
1100 ;; that file was too old or even did not exist, try to look in the whole 1165 ;; that file was too old or even did not exist, try to look in the whole
1101 ;; object path for a possible location. 1166 ;; object path for a possible location.
1102 (let ((identlist (ada-read-identifier pos))) 1167 (let ((identlist (ada-read-identifier pos)))
1103 (condition-case nil 1168 (condition-case nil
1104 (ada-find-in-ali identlist other-frame) 1169 (ada-find-in-ali identlist other-frame)
1105 (error (ada-find-in-src-path identlist other-frame))))) 1170 (error
1171 (let ((ali-file (ada-get-ali-file-name (ada-file-of identlist))))
1172
1173 ;; If the ALI file was up-to-date, then we probably have a predefined
1174 ;; entity, whose references are not given by GNAT
1175 (if (and (file-exists-p ali-file)
1176 (file-newer-than-file-p ali-file (ada-file-of identlist)))
1177 (message "No cross-reference found. It might be a predefined entity.")
1178
1179 ;; Else, look in every ALI file, except if the user doesn't want that
1180 (if ada-xref-search-with-egrep
1181 (ada-find-in-src-path identlist other-frame)
1182 (message "Cross-referencing information is not up-to-date. Please recompile.")
1183 )))))))
1106 1184
1107 (defun ada-goto-declaration-other-frame (pos &optional other-frame) 1185 (defun ada-goto-declaration-other-frame (pos &optional other-frame)
1108 "Display the declaration of the identifier around POS. 1186 "Display the declaration of the identifier around POS.
1109 The declation is shown in another frame if `ada-xref-other-buffer' is non-nil." 1187 The declation is shown in another frame if `ada-xref-other-buffer' is non-nil."
1110 (interactive "d") 1188 (interactive "d")
1645 1723
1646 ;; Build the identlist 1724 ;; Build the identlist
1647 (set 'identlist (ada-make-identlist)) 1725 (set 'identlist (ada-make-identlist))
1648 (ada-set-name identlist (downcase identifier)) 1726 (ada-set-name identlist (downcase identifier))
1649 (ada-set-line identlist 1727 (ada-set-line identlist
1650 (number-to-string (count-lines (point-min) (point)))) 1728 (number-to-string (count-lines 1 (point))))
1651 (ada-set-column identlist 1729 (ada-set-column identlist
1652 (number-to-string (1+ (current-column)))) 1730 (number-to-string (1+ (current-column))))
1653 (ada-set-file identlist (buffer-file-name)) 1731 (ada-set-file identlist (buffer-file-name))
1654 identlist 1732 identlist
1655 )) 1733 ))
1675 (set 'declaration-found 1753 (set 'declaration-found
1676 (re-search-forward 1754 (re-search-forward
1677 (concat "^" (ada-line-of identlist) 1755 (concat "^" (ada-line-of identlist)
1678 "." (ada-column-of identlist) 1756 "." (ada-column-of identlist)
1679 "[ *]" (ada-name-of identlist) 1757 "[ *]" (ada-name-of identlist)
1680 " \\(.*\\)$") bound t)) 1758 "[{\(<= ]?\\(.*\\)$") bound t))
1681 (if declaration-found 1759 (if declaration-found
1682 (ada-set-on-declaration identlist t)) 1760 (ada-set-on-declaration identlist t))
1683 )) 1761 ))
1684 1762
1685 ;; If declaration is still nil, then we were not on a declaration, and 1763 ;; If declaration is still nil, then we were not on a declaration, and
1694 (ada-set-ali-index 1772 (ada-set-ali-index
1695 identlist 1773 identlist
1696 (number-to-string (ada-find-file-number-in-ali 1774 (number-to-string (ada-find-file-number-in-ali
1697 (ada-file-of identlist)))) 1775 (ada-file-of identlist))))
1698 (unless (re-search-forward (concat (ada-ali-index-of identlist) 1776 (unless (re-search-forward (concat (ada-ali-index-of identlist)
1699 "|\\([0-9]+.[0-9]+ \\)*" 1777 "|\\([0-9]+[^0-9][0-9]+\\(\n\\.\\)? \\)*"
1700 (ada-line-of identlist) 1778 (ada-line-of identlist)
1701 "[^0-9]" 1779 "[^etp]"
1702 (ada-column-of identlist)) 1780 (ada-column-of identlist) "\\>")
1703 nil t) 1781 nil t)
1704 1782
1705 ;; if we did not find it, it may be because the first reference 1783 ;; if we did not find it, it may be because the first reference
1706 ;; is not required to have a 'unit_number|' item included. 1784 ;; is not required to have a 'unit_number|' item included.
1707 ;; Or maybe we are already on the declaration... 1785 ;; Or maybe we are already on the declaration...
1708 (unless (re-search-forward 1786 (unless (re-search-forward
1709 (concat 1787 (concat
1710 "^\\(\\([a-zA-Z0-9_.]+\\|\"[<>=+*-/a-z]\"\\)[ *]\\)*" 1788 "^[0-9]+.[0-9]+[ *]"
1789 (ada-name-of identlist)
1790 "[ <{=\(]\\(.\\|\n\\.\\)*\\<"
1711 (ada-line-of identlist) 1791 (ada-line-of identlist)
1712 "[^0-9]" 1792 "[^0-9]"
1713 (ada-column-of identlist)) 1793 (ada-column-of identlist) "\\>")
1714 nil t) 1794 nil t)
1715 1795
1716 ;; If still not found, then either the declaration is unknown 1796 ;; If still not found, then either the declaration is unknown
1717 ;; or the source file has been modified since the ali file was 1797 ;; or the source file has been modified since the ali file was
1718 ;; created 1798 ;; created
1727 (beginning-of-line) 1807 (beginning-of-line)
1728 ;; while we have a continuation line, go up one line 1808 ;; while we have a continuation line, go up one line
1729 (while (looking-at "^\\.") 1809 (while (looking-at "^\\.")
1730 (previous-line 1)) 1810 (previous-line 1))
1731 (unless (looking-at (concat "[0-9]+.[0-9]+[ *]" 1811 (unless (looking-at (concat "[0-9]+.[0-9]+[ *]"
1732 (ada-name-of identlist) "[ <]")) 1812 (ada-name-of identlist) "[ <{=\(]"))
1733 (set 'declaration-found nil)))) 1813 (set 'declaration-found nil))))
1734 1814
1735 ;; Still no success ! The ali file must be too old, and we need to 1815 ;; Still no success ! The ali file must be too old, and we need to
1736 ;; use a basic algorithm based on guesses. Note that this only happens 1816 ;; use a basic algorithm based on guesses. Note that this only happens
1737 ;; if the user does not want us to automatically recompile files 1817 ;; if the user does not want us to automatically recompile files
1800 (ali-buffer (current-buffer))) 1880 (ali-buffer (current-buffer)))
1801 1881
1802 (goto-char (point-max)) 1882 (goto-char (point-max))
1803 (while (re-search-backward my-regexp nil t) 1883 (while (re-search-backward my-regexp nil t)
1804 (save-excursion 1884 (save-excursion
1805 (set 'line-ali (count-lines (point-min) (point))) 1885 (setq line-ali (count-lines 1 (point)))
1806 (beginning-of-line) 1886 (beginning-of-line)
1807 ;; have a look at the line and column numbers 1887 ;; have a look at the line and column numbers
1808 (if (looking-at "^\\([0-9]+\\).\\([0-9]+\\)[ *]") 1888 (if (looking-at "^\\([0-9]+\\).\\([0-9]+\\)[ *]")
1809 (progn 1889 (progn
1810 (setq line-ada (match-string 1)) 1890 (setq line-ada (match-string 1))
2289 find-file...." 2369 find-file...."
2290 (make-local-hook 'ff-file-created-hooks) 2370 (make-local-hook 'ff-file-created-hooks)
2291 ;; This should really be an `add-hook'. -stef 2371 ;; This should really be an `add-hook'. -stef
2292 (setq ff-file-created-hooks 'ada-make-body-gnatstub) 2372 (setq ff-file-created-hooks 'ada-make-body-gnatstub)
2293 2373
2294 ;; Read the project file and update the search path
2295 ;; before looking for the other file
2296 (make-local-hook 'ff-pre-find-hooks)
2297 (add-hook 'ff-pre-find-hooks 'ada-require-project-file nil t)
2298
2299 ;; Completion for file names in the mini buffer should ignore .ali files 2374 ;; Completion for file names in the mini buffer should ignore .ali files
2300 (add-to-list 'completion-ignored-extensions ".ali") 2375 (add-to-list 'completion-ignored-extensions ".ali")
2301 ) 2376 )
2302 2377
2303 2378
2332 ada-search-directories)) 2407 ada-search-directories))
2333 2408
2334 ;; Make sure that the files are always associated with a project file. Since 2409 ;; Make sure that the files are always associated with a project file. Since
2335 ;; the project file has some fields that are used for the editor (like the 2410 ;; the project file has some fields that are used for the editor (like the
2336 ;; casing exceptions), it has to be read before the user edits a file). 2411 ;; casing exceptions), it has to be read before the user edits a file).
2337 (add-hook 'ada-mode-hook 2412 ;; (add-hook 'ada-mode-hook
2338 (lambda() 2413 ;; (lambda()
2339 (let ((file (ada-prj-find-prj-file t))) 2414 ;; (let ((file (ada-prj-find-prj-file t)))
2340 (if file (ada-reread-prj-file file))))) 2415 ;; (if file (ada-reread-prj-file file)))))
2341 2416
2342 (provide 'ada-xref) 2417 (provide 'ada-xref)
2343 2418
2344 ;;; ada-xref.el ends here 2419 ;;; ada-xref.el ends here