1 ;;; ada-xref.el --- for lookup and completion in Ada mode
3 ;; Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 2001, 2002, 2003
4 ;; Free Software Foundation, Inc.
6 ;; Author: Markus Heritsch <Markus.Heritsch@studbox.uni-stuttgart.de>
7 ;; Rolf Ebert <ebert@inf.enst.fr>
8 ;; Emmanuel Briot <briot@gnat.com>
9 ;; Maintainer: Emmanuel Briot <briot@gnat.com>
10 ;; Ada Core Technologies's version: Revision: 1.181
11 ;; Keywords: languages ada xref
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
31 ;;; This Package provides a set of functions to use the output of the
32 ;;; cross reference capabilities of the GNAT Ada compiler
33 ;;; for lookup and completion in Ada mode.
35 ;;; If a file *.`adp' exists in the ada-file directory, then it is
36 ;;; read for configuration informations. It is read only the first
37 ;;; time a cross-reference is asked for, and is not read later.
39 ;;; You need Emacs >= 20.2 to run this package
43 ;; ----- Requirements -----------------------------------------------------
48 ;; ------ Use variables
49 (defcustom ada-xref-other-buffer t
50 "*If nil, always display the cross-references in the same buffer.
51 Otherwise create either a new buffer or a new frame."
52 :type 'boolean :group 'ada)
54 (defcustom ada-xref-create-ali nil
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."
57 :type 'boolean :group 'ada)
59 (defcustom ada-xref-confirm-compile nil
60 "*If non-nil, always ask for user confirmation before compiling or running
62 :type 'boolean :group 'ada)
64 (defcustom ada-krunch-args "0"
65 "*Maximum number of characters for filenames created by gnatkr.
66 Set to 0, if you don't use crunched filenames. This should be a string."
67 :type 'string :group 'ada)
69 (defcustom ada-gnatls-args '("-v")
70 "*Arguments to pass to gnatfind when the location of the runtime is searched.
71 Typical use is to pass --RTS=soft-floats on some systems that support it.
73 You can also add -I- if you do not want the current directory to be included.
74 Otherwise, going from specs to bodies and back will first look for files in the
75 current directory. This only has an impact if you are not using project files,
76 but only ADA_INCLUDE_PATH."
77 :type '(repeat string) :group 'ada)
79 (defcustom ada-prj-default-comp-opt "-gnatq -gnatQ"
80 "Default compilation options."
81 :type 'string :group 'ada)
83 (defcustom ada-prj-default-bind-opt ""
84 "Default binder options."
85 :type 'string :group 'ada)
87 (defcustom ada-prj-default-link-opt ""
88 "Default linker options."
89 :type 'string :group 'ada)
91 (defcustom ada-prj-default-gnatmake-opt "-g"
92 "Default options for gnatmake."
93 :type 'string :group 'ada)
95 (defcustom ada-prj-gnatfind-switches "-rf"
96 "Default switches to use for gnatfind.
97 You should modify this variable, for instance to add -a, if you are working
98 in an environment where most ALI files are write-protected.
99 The command gnatfind is used every time you choose the menu
100 \"Show all references\"."
101 :type 'string :group 'ada)
103 (defcustom ada-prj-default-comp-cmd
104 (concat "${cross_prefix}gnatmake -u -c ${gnatmake_opt} ${full_current} -cargs"
106 "*Default command to be used to compile a single file.
107 Emacs will add the filename at the end of this command. This is the same
108 syntax as in the project file."
109 :type 'string :group 'ada)
111 (defcustom ada-prj-default-debugger "${cross_prefix}gdb"
112 "*Default name of the debugger. We recommend either `gdb',
113 `gdb --emacs_gdbtk' or `ddd --tty -fullname'."
114 :type 'string :group 'ada)
116 (defcustom ada-prj-default-make-cmd
117 (concat "${cross_prefix}gnatmake -o ${main} ${main_unit} ${gnatmake_opt} "
118 "-cargs ${comp_opt} -bargs ${bind_opt} -largs ${link_opt}")
119 "*Default command to be used to compile the application.
120 This is the same syntax as in the project file."
121 :type 'string :group 'ada)
123 (defcustom ada-prj-default-project-file ""
124 "*Name of the project file to use for every Ada file.
125 Emacs will not try to use the standard algorithm to find the project file if
126 this string is not empty."
127 :type '(file :must-match t) :group 'ada)
129 (defcustom ada-gnatstub-opts "-q -I${src_dir}"
130 "*List of the options to pass to gnatsub to generate the body of a package.
131 This has the same syntax as in the project file (with variable substitution)."
132 :type 'string :group 'ada)
134 (defcustom ada-always-ask-project nil
135 "*If nil, use default values when no project file was found.
136 Otherwise, ask the user for the name of the project file to use."
137 :type 'boolean :group 'ada)
139 (defconst is-windows (memq system-type (quote (windows-nt)))
140 "True if we are running on windows NT or windows 95.")
142 (defcustom ada-tight-gvd-integration nil
143 "*If non-nil, a new Emacs frame will be swallowed in GVD when debugging.
144 If GVD is not the debugger used, nothing happens.")
146 (defcustom ada-xref-search-with-egrep t
147 "*If non-nil, use egrep to find the possible declarations for an entity.
148 This alternate method is used when the exact location was not found in the
149 information provided by GNAT. However, it might be expensive if you have a lot
150 of sources, since it will search in all the files in your project."
151 :type 'boolean :group 'ada)
153 (defvar ada-load-project-hook nil
154 "Hook that is run when loading a project file.
155 Each function in this hook takes one argument FILENAME, that is the name of
156 the project file to load.
157 This hook should be used to support new formats for the project files.
159 If the function can load the file with the given filename, it should create a
160 buffer that contains a conversion of the file to the standard format of the
161 project files, and return that buffer. (the usual \"src_dir=\" or \"obj_dir=\"
162 lines). It should return nil if it doesn't know how to convert that project
166 ;; ------- Nothing to be modified by the user below this
167 (defvar ada-last-prj-file ""
168 "Name of the last project file entered by the user.")
170 (defvar ada-check-switch "-gnats"
171 "Switch added to the command line to check the current file.")
173 (defconst ada-project-file-extension ".adp"
174 "The extension used for project files.")
176 (defvar ada-xref-runtime-library-specs-path '()
177 "Directories where the specs for the standard library is found.
178 This is used for cross-references.")
180 (defvar ada-xref-runtime-library-ali-path '()
181 "Directories where the ali for the standard library is found.
182 This is used for cross-references.")
184 (defvar ada-xref-pos-ring '()
185 "List of positions selected by the cross-references functions.
186 Used to go back to these positions.")
188 (defvar ada-cd-command
189 (if (string-match "cmdproxy.exe" shell-file-name)
192 "Command to use to change to a specific directory. On windows systems
193 using cmdproxy.exe as the shell, we need to use /d or the drive is never
196 (defvar ada-command-separator (if is-windows " && " "\n")
197 "Separator to use when sending multiple commands to `compile' or
199 cmdproxy.exe doesn't recognize multiple-line commands, so we have to use
202 (defconst ada-xref-pos-ring-max 16
203 "Number of positions kept in the list ada-xref-pos-ring.")
205 (defvar ada-operator-re
206 "\\+\\|-\\|/\\|\\*\\*\\|\\*\\|=\\|&\\|abs\\|mod\\|rem\\|and\\|not\\|or\\|xor\\|<=\\|<\\|>=\\|>"
207 "Regexp to match for operators.")
209 (defvar ada-xref-project-files '()
210 "Associative list of project files.
211 It has the following format:
212 \((project_name . value) (project_name . value) ...)
213 As always, the values of the project file are defined through properties.")
216 ;; ----- Identlist manipulation -------------------------------------------
217 ;; An identlist is a vector that is used internally to reference an identifier
218 ;; To facilitate its use, we provide the following macros
220 (defmacro ada-make-identlist () (make-vector 8 nil))
221 (defmacro ada-name-of (identlist) (list 'aref identlist 0))
222 (defmacro ada-line-of (identlist) (list 'aref identlist 1))
223 (defmacro ada-column-of (identlist) (list 'aref identlist 2))
224 (defmacro ada-file-of (identlist) (list 'aref identlist 3))
225 (defmacro ada-ali-index-of (identlist) (list 'aref identlist 4))
226 (defmacro ada-declare-file-of (identlist) (list 'aref identlist 5))
227 (defmacro ada-references-of (identlist) (list 'aref identlist 6))
228 (defmacro ada-on-declaration (identlist) (list 'aref identlist 7))
230 (defmacro ada-set-name (identlist name) (list 'aset identlist 0 name))
231 (defmacro ada-set-line (identlist line) (list 'aset identlist 1 line))
232 (defmacro ada-set-column (identlist col) (list 'aset identlist 2 col))
233 (defmacro ada-set-file (identlist file) (list 'aset identlist 3 file))
234 (defmacro ada-set-ali-index (identlist index) (list 'aset identlist 4 index))
235 (defmacro ada-set-declare-file (identlist file) (list 'aset identlist 5 file))
236 (defmacro ada-set-references (identlist ref) (list 'aset identlist 6 ref))
237 (defmacro ada-set-on-declaration (ident value) (list 'aset ident 7 value))
239 (defsubst ada-get-ali-buffer (file)
240 "Reads the ali file into a new buffer, and returns this buffer's name"
241 (find-file-noselect (ada-get-ali-file-name file)))
244 ;; -----------------------------------------------------------------------
246 (defun ada-quote-cmd (cmd)
247 "Duplicates all \\ characters in CMD so that it can be passed to `compile'"
248 (mapconcat 'identity (split-string cmd "\\\\") "\\\\"))
250 (defun ada-initialize-runtime-library (cross-prefix)
251 "Initializes the variables for the runtime library location.
252 CROSS-PREFIX is the prefix to use for the gnatls command"
254 (setq ada-xref-runtime-library-specs-path '()
255 ada-xref-runtime-library-ali-path '())
256 (set-buffer (get-buffer-create "*gnatls*"))
259 ;; Catch any error in the following form (i.e gnatls was not found)
261 ;; Even if we get an error, delete the *gnatls* buffer
264 (apply 'call-process (concat cross-prefix "gnatls")
265 (append '(nil t nil) ada-gnatls-args))
266 (goto-char (point-min))
270 (search-forward "Source Search Path:")
272 (while (not (looking-at "^$"))
273 (back-to-indentation)
274 (if (looking-at "<Current_Directory>")
275 (add-to-list 'ada-xref-runtime-library-specs-path ".")
276 (add-to-list 'ada-xref-runtime-library-specs-path
277 (buffer-substring-no-properties
279 (save-excursion (end-of-line) (point)))))
284 (search-forward "Object Search Path:")
286 (while (not (looking-at "^$"))
287 (back-to-indentation)
288 (if (looking-at "<Current_Directory>")
289 (add-to-list 'ada-xref-runtime-library-ali-path ".")
290 (add-to-list 'ada-xref-runtime-library-ali-path
291 (buffer-substring-no-properties
293 (save-excursion (end-of-line) (point)))))
298 (set 'ada-xref-runtime-library-specs-path
299 (reverse ada-xref-runtime-library-specs-path))
300 (set 'ada-xref-runtime-library-ali-path
301 (reverse ada-xref-runtime-library-ali-path))
305 (defun ada-treat-cmd-string (cmd-string)
306 "Replace meta-sequences like ${...} in CMD-STRING with the appropriate value.
307 The project file must have been loaded first.
308 As a special case, ${current} is replaced with the name of the currently
309 edited file, minus extension but with directory, and ${full_current} is
310 replaced by the name including the extension."
312 (while (string-match "\\(-[^-\$IO]*[IO]\\)?\${\\([^}]+\\)}" cmd-string)
314 (name (match-string 2 cmd-string)))
316 ((string= name "current")
317 (setq value (file-name-sans-extension (buffer-file-name))))
318 ((string= name "full_current")
319 (setq value (buffer-file-name)))
322 (setq value (ada-xref-get-project-field (intern name))))))
324 ;; Check if there is an environment variable with the same name
326 (if (not (setq value (getenv name)))
327 (message (concat "No environment variable " name " found"))))
331 (setq cmd-string (replace-match "" t t cmd-string)))
333 (setq cmd-string (replace-match value t t cmd-string)))
335 (let ((prefix (match-string 1 cmd-string)))
336 (setq cmd-string (replace-match
337 (mapconcat (lambda(x) (concat prefix x)) value " ")
342 (defun ada-xref-set-default-prj-values (symbol ada-buffer)
343 "Reset the properties in SYMBOL to the default values for ADA-BUFFER."
345 (let ((file (buffer-file-name ada-buffer))
348 (set-buffer ada-buffer)
351 ;; Try hard to find a default value for filename, so that the user
352 ;; can edit his project file even if the current buffer is not an
353 ;; Ada file or not even associated with a file
354 (list 'filename (expand-file-name
356 (ada-prj-default-project-file
357 ada-prj-default-project-file)
358 (file (ada-prj-find-prj-file file t))
360 (message (concat "Not editing an Ada file,"
361 "and no default project "
364 'build_dir (file-name-as-directory (expand-file-name "."))
367 'casing (if (listp ada-case-exception-file)
368 ada-case-exception-file
369 (list ada-case-exception-file))
370 'comp_opt ada-prj-default-comp-opt
371 'bind_opt ada-prj-default-bind-opt
372 'link_opt ada-prj-default-link-opt
373 'gnatmake_opt ada-prj-default-gnatmake-opt
374 'gnatfind_opt ada-prj-gnatfind-switches
376 (file-name-nondirectory
377 (file-name-sans-extension file))
380 (file-name-nondirectory
381 (file-name-sans-extension file))
385 'comp_cmd (list (concat ada-cd-command " ${build_dir}")
386 ada-prj-default-comp-cmd)
387 'check_cmd (list (concat ada-prj-default-comp-cmd " "
389 'make_cmd (list (concat ada-cd-command " ${build_dir}")
390 ada-prj-default-make-cmd)
391 'run_cmd (list (concat ada-cd-command " ${build_dir}")
393 (if is-windows ".exe")))
394 'debug_pre_cmd (list (concat ada-cd-command
396 'debug_cmd (concat ada-prj-default-debugger
397 (if is-windows " ${main}.exe"
399 'debug_post_cmd (list nil)))
403 (defun ada-xref-get-project-field (field)
404 "Extract the value of FIELD from the current project file.
405 The project file must have been loaded first.
406 A default value is returned if the file was not found.
408 Note that for src_dir and obj_dir, you should rather use
409 `ada-xref-get-src-dir-field' or `ada-xref-get-obj-dir-field' which will in
410 addition return the default paths."
412 (let ((file-name ada-prj-default-project-file)
415 ;; Get the project file (either the current one, or a default one)
416 (setq file (or (assoc file-name ada-xref-project-files)
417 (assoc nil ada-xref-project-files)))
419 ;; If the file was not found, use the default values
421 ;; Get the value from the file
422 (set 'value (plist-get (cdr file) field))
424 ;; Create a default nil file that contains the default values
425 (ada-xref-set-default-prj-values 'value (current-buffer))
426 (add-to-list 'ada-xref-project-files (cons nil value))
427 (ada-xref-update-project-menu)
428 (set 'value (plist-get value field))
431 ;; Substitute the ${...} constructs in all the strings, including
435 (ada-treat-cmd-string value))
439 (mapcar (lambda(x) (if x (ada-treat-cmd-string x) x)) value))
446 (defun ada-xref-get-src-dir-field ()
447 "Return the full value for src_dir, including the default directories.
448 All the directories are returned as absolute directories."
450 (let ((build-dir (ada-xref-get-project-field 'build_dir)))
452 ;; Add ${build_dir} in front of the path
455 (ada-get-absolute-dir-list (ada-xref-get-project-field 'src_dir)
458 ;; Add the standard runtime at the end
459 ada-xref-runtime-library-specs-path)))
461 (defun ada-xref-get-obj-dir-field ()
462 "Return the full value for obj_dir, including the default directories.
463 All the directories are returned as absolute directories."
465 (let ((build-dir (ada-xref-get-project-field 'build_dir)))
467 ;; Add ${build_dir} in front of the path
470 (ada-get-absolute-dir-list (ada-xref-get-project-field 'obj_dir)
473 ;; Add the standard runtime at the end
474 ada-xref-runtime-library-ali-path)))
476 (defun ada-xref-update-project-menu ()
477 "Update the menu Ada->Project, with the list of available project files."
480 ;; Create the standard items
481 (set 'submenu (list (cons 'Load (cons "Load..."
482 'ada-set-default-project-file))
483 (cons 'New (cons "New..." 'ada-prj-new))
484 (cons 'Edit (cons "Edit..." 'ada-prj-edit))
485 (cons 'sep (cons "---" nil))))
490 (let ((name (or (car x) "<default>"))
492 "Change the active project file."
494 (ada-parse-prj-file ,(car x))
495 (set 'ada-prj-default-project-file ,(car x))
496 (ada-xref-update-project-menu))))
499 (list (cons (intern name)
502 (if (string= (file-name-extension name)
503 ada-project-file-extension)
504 (file-name-sans-extension
505 (file-name-nondirectory name))
506 (file-name-nondirectory name))
510 (equal ada-prj-default-project-file
514 ;; Parses all the known project files, and insert at least the default
515 ;; one (in case ada-xref-project-files is nil)
516 (or ada-xref-project-files '(nil)))
519 (if (lookup-key ada-mode-map [menu-bar Ada Project])
520 (setcdr (lookup-key ada-mode-map [menu-bar Ada Project])
525 ;;-------------------------------------------------------------
526 ;;-- Searching a file anywhere on the source path.
528 ;;-- The following functions provide support for finding a file anywhere
529 ;;-- on the source path, without providing an explicit directory.
530 ;;-- They also provide file name completion in the minibuffer.
532 ;;-- Public subprograms: ada-find-file
534 ;;-------------------------------------------------------------
536 (defun ada-do-file-completion (string predicate flag)
537 "Completion function when reading a file from the minibuffer.
538 Completion is attempted in all the directories in the source path, as
539 defined in the project file."
541 (dirs (ada-xref-get-src-dir-field)))
544 (if (file-directory-p (car dirs))
545 (set 'list (append list (file-name-all-completions string (car dirs)))))
546 (set 'dirs (cdr dirs)))
547 (cond ((equal flag 'lambda)
552 (try-completion string
553 (mapcar (lambda (x) (cons x 1)) list)
557 (defun ada-find-file (filename)
558 "Open a file anywhere in the source path.
559 Completion is available."
561 (list (completing-read "File: " 'ada-do-file-completion)))
562 (let ((file (ada-find-src-file-in-dir filename)))
565 (error (concat filename " not found in src_dir")))))
568 ;; ----- Utilities -------------------------------------------------
570 (defun ada-require-project-file ()
571 "If no project file is currently active, load a default one."
572 (if (or (not ada-prj-default-project-file)
573 (not ada-xref-project-files)
574 (string= ada-prj-default-project-file ""))
575 (ada-reread-prj-file)))
577 (defun ada-xref-push-pos (filename position)
578 "Push (FILENAME, POSITION) on the position ring for cross-references."
579 (setq ada-xref-pos-ring (cons (list position filename) ada-xref-pos-ring))
580 (if (> (length ada-xref-pos-ring) ada-xref-pos-ring-max)
581 (setcdr (nthcdr (1- ada-xref-pos-ring-max) ada-xref-pos-ring) nil)))
583 (defun ada-xref-goto-previous-reference ()
584 "Go to the previous cross-reference we were on."
586 (if ada-xref-pos-ring
587 (let ((pos (car ada-xref-pos-ring)))
588 (setq ada-xref-pos-ring (cdr ada-xref-pos-ring))
589 (find-file (car (cdr pos)))
590 (goto-char (car pos)))))
592 (defun ada-convert-file-name (name)
593 "Converts from NAME to a name that can be used by the compilation commands.
594 This is overriden on VMS to convert from VMS filenames to Unix filenames."
597 (defun ada-set-default-project-file (name &optional keep-existing)
598 "Set the file whose name is NAME as the default project file.
599 If KEEP-EXISTING is true and a project file has already been loaded, nothing
600 is done. This is meant to be used from ada-mode-hook, for instance to force
601 a project file unless the user has already loaded one."
602 (interactive "fProject file:")
603 (if (or (not keep-existing)
604 (not ada-prj-default-project-file)
605 (equal ada-prj-default-project-file ""))
607 (setq ada-prj-default-project-file name)
608 (ada-reread-prj-file name))))
610 ;; ------ Handling the project file -----------------------------
612 (defun ada-prj-find-prj-file (&optional file no-user-question)
613 "Find the prj file associated with FILE (or the current buffer if nil).
614 If NO-USER-QUESTION is non-nil, use a default file if not project file was
615 found, and do not ask the user.
616 If the buffer is not an Ada buffer, associate it with the default project
617 file. If none is set, return nil."
621 ;; Use the active project file if there is one.
622 ;; This is also valid if we don't currently have an Ada buffer, or if
623 ;; the current buffer is not a real file (for instance an emerge buffer)
625 (if (or (not (string= mode-name "Ada"))
626 (not (buffer-file-name)))
628 (if (and ada-prj-default-project-file
629 (not (string= ada-prj-default-project-file "")))
630 (setq selected ada-prj-default-project-file)
633 ;; other cases: use a more complex algorithm
635 (let* ((current-file (or file (buffer-file-name)))
636 (first-choice (concat
637 (file-name-sans-extension current-file)
638 ada-project-file-extension))
639 (dir (file-name-directory current-file))
641 ;; on Emacs 20.2, directory-files does not work if
642 ;; parse-sexp-lookup-properties is set
643 (parse-sexp-lookup-properties nil)
644 (prj-files (directory-files
646 (concat ".*" (regexp-quote
647 ada-project-file-extension) "$")))
652 ;; Else if there is a project file with the same name as the Ada
653 ;; file, but not the same extension.
654 ((file-exists-p first-choice)
655 (set 'selected first-choice))
657 ;; Else if only one project file was found in the current directory
658 ((= (length prj-files) 1)
659 (set 'selected (car prj-files)))
661 ;; Else if there are multiple files, ask the user
662 ((and (> (length prj-files) 1) (not no-user-question))
663 (save-window-excursion
664 (with-output-to-temp-buffer "*choice list*"
665 (princ "There are more than one possible project file.\n")
666 (princ "Which one should we use ?\n\n")
667 (princ " no. file name \n")
668 (princ " --- ------------------------\n")
670 (while (<= counter (length prj-files))
671 (princ (format " %2d) %s\n"
673 (nth (1- counter) prj-files)))
674 (setq counter (1+ counter))
676 ))) ; end of with-output-to ...
680 (not (integerp choice))
682 (> choice (length prj-files)))
683 (setq choice (string-to-int
684 (read-from-minibuffer "Enter No. of your choice: "))))
685 (set 'selected (nth (1- choice) prj-files))))
687 ;; Else if no project file was found in the directory, ask a name
688 ;; to the user, using as a default value the last one entered by
690 ((= (length prj-files) 0)
691 (unless (or no-user-question (not ada-always-ask-project))
692 (setq ada-last-prj-file
694 (concat "project file [" ada-last-prj-file "]:")
695 nil ada-last-prj-file))
696 (unless (string= ada-last-prj-file "")
697 (set 'selected ada-last-prj-file))))
700 (or selected "default.adp")
704 (defun ada-parse-prj-file (prj-file)
705 "Reads and parses the PRJ-FILE file if it was found.
706 The current buffer should be the ada-file buffer."
708 (let (project src_dir obj_dir make_cmd comp_cmd check_cmd casing
709 run_cmd debug_pre_cmd debug_post_cmd
710 (ada-buffer (current-buffer)))
711 (setq prj-file (expand-file-name prj-file))
713 ;; Set the project file as the active one.
714 (setq ada-prj-default-project-file prj-file)
716 ;; Initialize the project with the default values
717 (ada-xref-set-default-prj-values 'project (current-buffer))
719 ;; Do not use find-file below, since we don't want to show this
720 ;; buffer. If the file is open through speedbar, we can't use
721 ;; find-file anyway, since the speedbar frame is special and does not
722 ;; allow the selection of a file in it.
724 (if (file-exists-p prj-file)
726 (let* ((buffer (run-hook-with-args-until-success
727 'ada-load-project-hook prj-file)))
729 (setq buffer (find-file-noselect prj-file nil)))
733 (goto-char (point-min))
735 ;; Now overrides these values with the project file
737 (if (looking-at "^\\([^=]+\\)=\\(.*\\)")
739 ((string= (match-string 1) "src_dir")
740 (add-to-list 'src_dir
741 (file-name-as-directory (match-string 2))))
742 ((string= (match-string 1) "obj_dir")
743 (add-to-list 'obj_dir
744 (file-name-as-directory (match-string 2))))
745 ((string= (match-string 1) "casing")
746 (set 'casing (cons (match-string 2) casing)))
747 ((string= (match-string 1) "build_dir")
749 (plist-put project 'build_dir
750 (file-name-as-directory (match-string 2)))))
751 ((string= (match-string 1) "make_cmd")
752 (add-to-list 'make_cmd (match-string 2)))
753 ((string= (match-string 1) "comp_cmd")
754 (add-to-list 'comp_cmd (match-string 2)))
755 ((string= (match-string 1) "check_cmd")
756 (add-to-list 'check_cmd (match-string 2)))
757 ((string= (match-string 1) "run_cmd")
758 (add-to-list 'run_cmd (match-string 2)))
759 ((string= (match-string 1) "debug_pre_cmd")
760 (add-to-list 'debug_pre_cmd (match-string 2)))
761 ((string= (match-string 1) "debug_post_cmd")
762 (add-to-list 'debug_post_cmd (match-string 2)))
764 (set 'project (plist-put project (intern (match-string 1))
765 (match-string 2))))))
768 (if src_dir (set 'project (plist-put project 'src_dir
770 (if obj_dir (set 'project (plist-put project 'obj_dir
772 (if casing (set 'project (plist-put project 'casing
774 (if make_cmd (set 'project (plist-put project 'make_cmd
775 (reverse make_cmd))))
776 (if comp_cmd (set 'project (plist-put project 'comp_cmd
777 (reverse comp_cmd))))
778 (if check_cmd (set 'project (plist-put project 'check_cmd
779 (reverse check_cmd))))
780 (if run_cmd (set 'project (plist-put project 'run_cmd
782 (set 'project (plist-put project 'debug_post_cmd
783 (reverse debug_post_cmd)))
784 (set 'project (plist-put project 'debug_pre_cmd
785 (reverse debug_pre_cmd)))
787 ;; Kill the project buffer
789 (set-buffer ada-buffer)
792 ;; Else the file wasn't readable (probably the default project).
793 ;; We initialize it with the current environment variables.
794 ;; We need to add the startup directory in front so that
795 ;; files locally redefined are properly found. We cannot
796 ;; add ".", which varies too much depending on what the
797 ;; current buffer is.
799 (plist-put project 'src_dir
801 (list command-line-default-directory)
802 (split-string (or (getenv "ADA_INCLUDE_PATH") "") ":")
803 (list "." default-directory))))
805 (plist-put project 'obj_dir
807 (list command-line-default-directory)
808 (split-string (or (getenv "ADA_OBJECTS_PATH") "") ":")
809 (list "." default-directory))))
813 ;; Delete the default project file from the list, if it is there.
814 ;; Note that in that case, this default project is the only one in
816 (if (assoc nil ada-xref-project-files)
817 (setq ada-xref-project-files nil))
819 ;; Memorize the newly read project file
820 (if (assoc prj-file ada-xref-project-files)
821 (setcdr (assoc prj-file ada-xref-project-files) project)
822 (add-to-list 'ada-xref-project-files (cons prj-file project)))
824 ;; Sets up the compilation-search-path so that Emacs is able to
825 ;; go to the source of the errors in a compilation buffer
826 (setq compilation-search-path (ada-xref-get-src-dir-field))
828 ;; Set the casing exceptions file list
831 (setq ada-case-exception-file (reverse casing))
832 (ada-case-read-exceptions)))
834 ;; Add the directories to the search path for ff-find-other-file
835 ;; Do not add the '/' or '\' at the end
836 (setq ada-search-directories
837 (append (mapcar 'directory-file-name compilation-search-path)
838 ada-search-directories))
840 (ada-xref-update-project-menu)
843 ;; No prj file ? => Setup default values
844 ;; Note that nil means that all compilation modes will first look in the
845 ;; current directory, and only then in the current file's directory. This
846 ;; current file is assumed at this point to be in the common source
848 (setq compilation-search-path (list nil default-directory))
852 (defun ada-find-references (&optional pos arg local-only)
853 "Find all references to the entity under POS.
854 Calls gnatfind to find the references.
855 if ARG is t, the contents of the old *gnatfind* buffer is preserved.
856 if LOCAL-ONLY is t, only the declarations in the current file are returned."
859 (ada-require-project-file)
861 (let* ((identlist (ada-read-identifier pos))
862 (alifile (ada-get-ali-file-name (ada-file-of identlist)))
863 (process-environment (ada-set-environment)))
865 (set-buffer (get-file-buffer (ada-file-of identlist)))
867 ;; if the file is more recent than the executable
868 (if (or (buffer-modified-p (current-buffer))
869 (file-newer-than-file-p (ada-file-of identlist) alifile))
870 (ada-find-any-references (ada-name-of identlist)
871 (ada-file-of identlist)
872 nil nil local-only arg)
873 (ada-find-any-references (ada-name-of identlist)
874 (ada-file-of identlist)
875 (ada-line-of identlist)
876 (ada-column-of identlist) local-only arg)))
879 (defun ada-find-local-references (&optional pos arg)
880 "Find all references to the entity under POS.
881 Calls gnatfind to find the references.
882 if ARG is t, the contents of the old *gnatfind* buffer is preserved."
885 (ada-find-references pos arg t))
887 (defun ada-find-any-references
888 (entity &optional file line column local-only append)
889 "Search for references to any entity whose name is ENTITY.
890 ENTITY was first found the location given by FILE, LINE and COLUMN.
891 If LOCAL-ONLY is t, then only the references in file will be listed, which
893 If APPEND is t, then the output of the command will be append to the existing
894 buffer *gnatfind* if it exists."
895 (interactive "sEntity name: ")
896 (ada-require-project-file)
898 ;; Prepare the gnatfind command. Note that we must protect the quotes
899 ;; around operators, so that they are correctly handled and can be
900 ;; processed (gnatfind \"+\":...).
902 (if (= (aref entity 0) ?\")
904 (concat "\\\"" (substring entity 1 -1) "\\\"")
905 (concat "'\"" (substring entity 1 -1) "\"'"))
907 (switches (ada-xref-get-project-field 'gnatfind_opt))
908 (command (concat "gnatfind " switches " "
910 (if file (concat ":" (file-name-nondirectory file)))
911 (if line (concat ":" line))
912 (if column (concat ":" column))
913 (if local-only (concat " " (file-name-nondirectory file)))
917 ;; If a project file is defined, use it
918 (if (and ada-prj-default-project-file
919 (not (string= ada-prj-default-project-file "")))
920 (setq command (concat command " -p" ada-prj-default-project-file)))
922 (if (and append (get-buffer "*gnatfind*"))
924 (set-buffer "*gnatfind*")
925 (setq old-contents (buffer-string))))
927 (compile-internal command "No more references" "gnatfind")
929 ;; Hide the "Compilation" menu
931 (set-buffer "*gnatfind*")
932 (local-unset-key [menu-bar compilation-menu])
937 (insert old-contents)
938 (goto-char (point-max)))))
942 (defalias 'ada-change-prj (symbol-function 'ada-set-default-project-file))
944 ;; ----- Identifier Completion --------------------------------------------
945 (defun ada-complete-identifier (pos)
946 "Tries to complete the identifier around POS.
947 The feature is only available if the files where compiled not using the -gnatx
950 (ada-require-project-file)
952 ;; Initialize function-local variables and jump to the .ali buffer
953 ;; Note that for regexp search is case insensitive too
954 (let* ((curbuf (current-buffer))
955 (identlist (ada-read-identifier pos))
956 (sofar (concat "^[0-9]+[a-zA-Z][0-9]+[ *]\\("
957 (regexp-quote (ada-name-of identlist))
962 ;; Open the .ali file
963 (set-buffer (ada-get-ali-buffer (buffer-file-name)))
964 (goto-char (point-max))
966 ;; build an alist of possible completions
967 (while (re-search-backward sofar nil t)
968 (setq symalist (cons (cons (match-string 1) nil) symalist)))
970 (setq completed (try-completion "" symalist))
975 ;; deletes the incomplete identifier in the buffer
977 (looking-at "[a-zA-Z0-9_]+")
979 ;; inserts the completed symbol
983 ;; ----- Cross-referencing ----------------------------------------
985 (defun ada-point-and-xref ()
986 "Jump to the declaration of the entity below the cursor."
988 (mouse-set-point last-input-event)
989 (ada-goto-declaration (point)))
991 (defun ada-point-and-xref-body ()
992 "Jump to the body of the entity under the cursor."
994 (mouse-set-point last-input-event)
995 (ada-goto-body (point)))
997 (defun ada-goto-body (pos &optional other-frame)
998 "Display the body of the entity around POS.
999 If the entity doesn't have a body, display its declaration.
1000 As a side effect, the buffer for the declaration is also open."
1002 (ada-goto-declaration pos other-frame)
1004 ;; Temporarily force the display in the same buffer, since we
1005 ;; already changed previously
1006 (let ((ada-xref-other-buffer nil))
1007 (ada-goto-declaration (point) nil)))
1009 (defun ada-goto-declaration (pos &optional other-frame)
1010 "Display the declaration of the identifier around POS.
1011 The declaration is shown in another buffer if `ada-xref-other-buffer' is
1013 If OTHER-FRAME is non-nil, display the cross-reference in another frame."
1015 (ada-require-project-file)
1017 (ada-xref-push-pos (buffer-file-name) pos)
1019 ;; First try the standard algorithm by looking into the .ali file, but if
1020 ;; that file was too old or even did not exist, try to look in the whole
1021 ;; object path for a possible location.
1022 (let ((identlist (ada-read-identifier pos)))
1024 (ada-find-in-ali identlist other-frame)
1026 (let ((ali-file (ada-get-ali-file-name (ada-file-of identlist))))
1028 ;; If the ALI file was up-to-date, then we probably have a predefined
1029 ;; entity, whose references are not given by GNAT
1030 (if (and (file-exists-p ali-file)
1031 (file-newer-than-file-p ali-file (ada-file-of identlist)))
1032 (message "No cross-reference found. It might be a predefined entity.")
1034 ;; Else, look in every ALI file, except if the user doesn't want that
1035 (if ada-xref-search-with-egrep
1036 (ada-find-in-src-path identlist other-frame)
1037 (message "Cross-referencing information is not up-to-date. Please recompile.")
1040 (defun ada-goto-declaration-other-frame (pos &optional other-frame)
1041 "Display the declaration of the identifier around POS.
1042 The declation is shown in another frame if `ada-xref-other-buffer' is non-nil."
1044 (ada-goto-declaration pos t))
1046 (defun ada-remote (command)
1047 "Return the remote version of COMMAND, or COMMAND if remote_machine is nil."
1048 (let ((machine (ada-xref-get-project-field 'remote_machine)))
1049 (if (or (not machine) (string= machine ""))
1051 (format "%s %s '(%s)'"
1052 remote-shell-program
1056 (defun ada-get-absolute-dir-list (dir-list root-dir)
1057 "Returns the list of absolute directories found in dir-list.
1058 If a directory is a relative directory, the value of ROOT-DIR is added in
1060 (mapcar (lambda (x) (expand-file-name x root-dir)) dir-list))
1062 (defun ada-set-environment ()
1063 "Return the new value for process-environment.
1064 It modifies the source path and object path with the values found in the
1066 (let ((include (getenv "ADA_INCLUDE_PATH"))
1067 (objects (getenv "ADA_OBJECTS_PATH"))
1068 (build-dir (ada-xref-get-project-field 'build_dir)))
1070 (set 'include (concat path-separator include)))
1072 (set 'objects (concat path-separator objects)))
1074 (concat "ADA_INCLUDE_PATH="
1075 (mapconcat (lambda(x) (expand-file-name x build-dir))
1076 (ada-xref-get-project-field 'src_dir)
1080 (concat "ADA_OBJECTS_PATH="
1081 (mapconcat (lambda(x) (expand-file-name x build-dir))
1082 (ada-xref-get-project-field 'obj_dir)
1085 process-environment))))
1087 (defun ada-compile-application (&optional arg)
1088 "Compiles the application, using the command found in the project file.
1089 If ARG is not nil, ask for user confirmation."
1091 (ada-require-project-file)
1092 (let ((cmd (ada-xref-get-project-field 'make_cmd))
1093 (process-environment (ada-set-environment))
1094 (compilation-scroll-output t))
1096 (setq compilation-search-path (ada-xref-get-src-dir-field))
1098 ;; If no project file was found, ask the user
1100 (setq cmd '("") arg t))
1102 ;; Make a single command from the list of commands, including the
1103 ;; commands to run it on a remote machine.
1104 (setq cmd (ada-remote (mapconcat 'identity cmd ada-command-separator)))
1106 (if (or ada-xref-confirm-compile arg)
1107 (setq cmd (read-from-minibuffer "enter command to compile: " cmd)))
1109 ;; Insert newlines so as to separate the name of the commands to run
1110 ;; and the output of the commands. this doesn't work with cmdproxy.exe,
1111 ;; which gets confused by newline characters.
1112 (if (not (string-match ".exe" shell-file-name))
1113 (setq cmd (concat cmd "\n\n")))
1115 (compile (ada-quote-cmd cmd))))
1117 (defun ada-compile-current (&optional arg prj-field)
1118 "Recompile the current file.
1119 If ARG is not nil, ask for user confirmation of the command.
1120 PRJ-FIELD is the name of the field to use in the project file to get the
1121 command, and should be either comp_cmd (default) or check_cmd."
1123 (ada-require-project-file)
1124 (let* ((field (if prj-field prj-field 'comp_cmd))
1125 (cmd (ada-xref-get-project-field field))
1126 (process-environment (ada-set-environment))
1127 (compilation-scroll-output t))
1129 (setq compilation-search-path (ada-xref-get-src-dir-field))
1132 (setq cmd '("") arg t))
1134 ;; Make a single command from the list of commands, including the
1135 ;; commands to run it on a remote machine.
1136 (setq cmd (ada-remote (mapconcat 'identity cmd ada-command-separator)))
1138 ;; If no project file was found, ask the user
1139 (if (or ada-xref-confirm-compile arg)
1140 (setq cmd (read-from-minibuffer "enter command to compile: " cmd)))
1142 ;; Insert newlines so as to separate the name of the commands to run
1143 ;; and the output of the commands. this doesn't work with cmdproxy.exe,
1144 ;; which gets confused by newline characters.
1145 (if (not (string-match ".exe" shell-file-name))
1146 (setq cmd (concat cmd "\n\n")))
1148 (compile (ada-quote-cmd cmd))))
1150 (defun ada-check-current (&optional arg)
1151 "Recompile the current file.
1152 If ARG is not nil, ask for user confirmation of the command."
1154 (ada-compile-current arg 'check_cmd))
1156 (defun ada-run-application (&optional arg)
1157 "Run the application.
1158 if ARG is not-nil, asks for user confirmation."
1160 (ada-require-project-file)
1162 (let ((machine (ada-xref-get-project-field 'cross_prefix)))
1163 (if (and machine (not (string= machine "")))
1164 (error "This feature is not supported yet for cross environments")))
1166 (let ((command (ada-xref-get-project-field 'run_cmd)))
1168 ;; Guess the command if it wasn't specified
1170 (set 'command (list (file-name-sans-extension (buffer-name)))))
1172 ;; Modify the command to run remotely
1173 (setq command (ada-remote (mapconcat 'identity command
1174 ada-command-separator)))
1176 ;; Ask for the arguments to the command if required
1177 (if (or ada-xref-confirm-compile arg)
1178 (setq command (read-from-minibuffer "Enter command to execute: "
1183 (set-buffer (get-buffer-create "*run*"))
1184 (set 'buffer-read-only nil)
1187 (start-process "run" (current-buffer) shell-file-name
1190 ;; Set these two variables to their default values, since otherwise
1191 ;; the output buffer is scrolled so that only the last output line
1192 ;; is visible at the top of the buffer.
1193 (set (make-local-variable 'scroll-step) 0)
1194 (set (make-local-variable 'scroll-conservatively) 0)
1196 (display-buffer "*run*")
1198 ;; change to buffer *run* for interactive programs
1200 (switch-to-buffer "*run*")
1203 (defun ada-gdb-application (&optional arg executable-name)
1204 "Start the debugger on the application.
1205 EXECUTABLE-NAME, if non-nil, is debugged instead of the file specified in the
1207 If ARG is non-nil, ask the user to confirm the command."
1209 (let ((buffer (current-buffer))
1210 cmd pre-cmd post-cmd)
1211 (ada-require-project-file)
1212 (setq cmd (if executable-name
1213 (concat ada-prj-default-debugger " " executable-name)
1214 (ada-xref-get-project-field 'debug_cmd))
1215 pre-cmd (ada-xref-get-project-field 'debug_pre_cmd)
1216 post-cmd (ada-xref-get-project-field 'debug_post_cmd))
1218 ;; If the command was not given in the project file, start a bare gdb
1220 (set 'cmd (concat ada-prj-default-debugger
1223 (file-name-sans-extension (buffer-file-name))))))
1225 ;; For gvd, add an extra switch so that the Emacs window is completly
1226 ;; swallowed inside the Gvd one
1227 (if (and ada-tight-gvd-integration
1228 (string-match "^[^ \t]*gvd" cmd))
1229 ;; Start a new frame, so that when gvd exists we do not kill Emacs
1230 ;; We make sure that gvd swallows the new frame, not the one the
1231 ;; user has been using until now
1232 ;; The frame is made invisible initially, so that GtkPlug gets a
1233 ;; chance to fully manage it. Then it works fine with Enlightenment
1235 (let ((frame (make-frame '((visibility . nil)))))
1237 cmd " --editor-window="
1238 (cdr (assoc 'outer-window-id (frame-parameters frame)))))
1239 (select-frame frame)))
1241 ;; Add a -fullname switch
1242 ;; Use the remote machine
1243 (set 'cmd (ada-remote (concat cmd " -fullname ")))
1245 ;; Ask for confirmation if required
1246 (if (or arg ada-xref-confirm-compile)
1247 (set 'cmd (read-from-minibuffer "enter command to debug: " cmd)))
1249 (let ((old-comint-exec (symbol-function 'comint-exec))
1252 gud-gdb-massage-args)
1254 ;; Do not add -fullname, since we can have a 'rsh' command in front.
1255 (fset 'gud-gdb-massage-args (lambda (file args) args))
1257 (set 'pre-cmd (mapconcat 'identity pre-cmd ada-command-separator))
1258 (if (not (equal pre-cmd ""))
1259 (setq pre-cmd (concat pre-cmd ada-command-separator)))
1261 (set 'post-cmd (mapconcat 'identity post-cmd "\n"))
1263 (set 'post-cmd (concat post-cmd "\n")))
1266 ;; Temporarily replaces the definition of `comint-exec' so that we
1267 ;; can execute commands before running gdb.
1268 (make-local-variable 'comint-exec)
1270 `(lambda (buffer name command startfile switches)
1271 (let (compilation-buffer-name-function)
1273 (set 'compilation-buffer-name-function
1274 (lambda(x) (buffer-name buffer)))
1275 (compile (ada-quote-cmd
1278 (mapconcat 'identity switches " "))))))
1281 ;; Tight integration should force the tty mode
1282 (if (and (string-match "gvd" (comint-arguments cmd 0 0))
1283 ada-tight-gvd-integration
1284 (not (string-match "--tty" cmd)))
1285 (setq cmd (concat cmd "--tty")))
1287 (if (and (string-match "jdb" (comint-arguments cmd 0 0))
1289 (funcall (symbol-function 'jdb) cmd)
1292 ;; Restore the standard fset command (or for instance C-U M-x shell
1293 ;; wouldn't work anymore
1295 (fset 'comint-exec old-comint-exec)
1297 ;; Send post-commands to the debugger
1298 (process-send-string (get-buffer-process (current-buffer)) post-cmd)
1300 ;; Move to the end of the debugger buffer, so that it is automatically
1301 ;; scrolled from then on.
1304 ;; Display both the source window and the debugger window (the former
1305 ;; above the latter). No need to show the debugger window unless it
1306 ;; is going to have some relevant information.
1307 (if (or (not (string-match "gvd" (comint-arguments cmd 0 0)))
1308 (string-match "--tty" cmd))
1309 (split-window-vertically))
1310 (switch-to-buffer buffer)
1314 (defun ada-reread-prj-file (&optional filename)
1315 "Forces Emacs to read either FILENAME or the project file associated
1316 with the current buffer.
1317 Otherwise, this file is only read once, and never read again.
1318 Since the information in the project file is shared between all buffers, this
1319 automatically modifies the setup for all the Ada buffer that use this file."
1322 (ada-parse-prj-file filename)
1323 (ada-parse-prj-file (ada-prj-find-prj-file)))
1325 ;; Reread the location of the standard runtime library
1326 (ada-initialize-runtime-library
1327 (or (ada-xref-get-project-field 'cross_prefix) ""))
1330 ;; ------ Private routines
1332 (defun ada-xref-current (file &optional ali-file-name)
1333 "Update the cross-references for FILE.
1334 This in fact recompiles FILE to create ALI-FILE-NAME.
1335 This function returns the name of the file that was recompiled to generate
1336 the cross-reference information. Note that the ali file can then be deduced by
1337 replacing the file extension with .ali"
1339 (if (and ali-file-name
1340 (get-file-buffer ali-file-name))
1341 (kill-buffer (get-file-buffer ali-file-name)))
1343 (let* ((name (ada-convert-file-name file))
1344 (body-name (or (ada-get-body-name name) name)))
1346 ;; Always recompile the body when we can. We thus temporarily switch to a
1347 ;; buffer than contains the body of the unit
1349 (let ((body-visible (find-buffer-visiting body-name))
1352 (set-buffer body-visible)
1353 (find-file body-name))
1355 ;; Execute the compilation. Note that we must wait for the end of the
1356 ;; process, or the ALI file would still not be available.
1357 ;; Unfortunately, the underlying `compile' command that we use is
1359 (ada-compile-current)
1360 (setq process (get-buffer-process "*compilation*"))
1363 (not (equal (process-status process) 'exit)))
1366 ;; remove the buffer for the body if it wasn't there before
1367 (unless body-visible
1368 (kill-buffer (find-buffer-visiting body-name)))
1372 (defun ada-find-file-in-dir (file dir-list)
1373 "Search for FILE in DIR-LIST."
1375 (while (and (not found) dir-list)
1376 (set 'found (concat (file-name-as-directory (car dir-list))
1377 (file-name-nondirectory file)))
1379 (unless (file-exists-p found)
1381 (set 'dir-list (cdr dir-list)))
1384 (defun ada-find-ali-file-in-dir (file)
1385 "Find an .ali file in obj_dir. The current buffer must be the Ada file.
1386 Adds build_dir in front of the search path to conform to gnatmake's behavior,
1387 and the standard runtime location at the end."
1388 (ada-find-file-in-dir file (ada-xref-get-obj-dir-field)))
1390 (defun ada-find-src-file-in-dir (file)
1391 "Find a source file in src_dir. The current buffer must be the Ada file.
1392 Adds src_dir in front of the search path to conform to gnatmake's behavior,
1393 and the standard runtime location at the end."
1394 (ada-find-file-in-dir file (ada-xref-get-src-dir-field)))
1396 (defun ada-get-ali-file-name (file)
1397 "Create the ali file name for the ada-file FILE.
1398 The file is searched for in every directory shown in the obj_dir lines of
1401 ;; This function has to handle the special case of non-standard
1402 ;; file names (i.e. not .adb or .ads)
1403 ;; The trick is the following:
1404 ;; 1- replace the extension of the current file with .ali,
1405 ;; and look for this file
1406 ;; 2- If this file is found:
1407 ;; grep the "^U" lines, and make sure we are not reading the
1408 ;; .ali file for a spec file. If we are, go to step 3.
1409 ;; 3- If the file is not found or step 2 failed:
1410 ;; find the name of the "other file", ie the body, and look
1411 ;; for its associated .ali file by subtituing the extension
1413 ;; We must also handle the case of separate packages and subprograms:
1414 ;; 4- If no ali file was found, we try to modify the file name by removing
1415 ;; everything after the last '-' or '.' character, so as to get the
1416 ;; ali file for the parent unit. If we found an ali file, we check that
1417 ;; it indeed contains the definition for the separate entity by checking
1418 ;; the 'D' lines. This is done repeatedly, in case the direct parent is
1422 (set-buffer (get-file-buffer file))
1423 (let ((short-ali-file-name
1424 (concat (file-name-sans-extension (file-name-nondirectory file))
1429 ;; If we have a non-standard file name, and this is a spec, we first
1430 ;; look for the .ali file of the body, since this is the one that
1431 ;; contains the most complete information. If not found, we will do what
1432 ;; we can with the .ali file for the spec...
1434 (if (not (string= (file-name-extension file) "ads"))
1435 (let ((specs ada-spec-suffixes))
1437 (if (string-match (concat (regexp-quote (car specs)) "$")
1440 (set 'specs (cdr specs)))))
1444 (ada-find-ali-file-in-dir
1445 (concat (file-name-sans-extension
1446 (file-name-nondirectory
1447 (ada-other-file-name)))
1454 ;; Else we take the .ali file associated with the unit
1455 (ada-find-ali-file-in-dir short-ali-file-name)
1458 ;; else we did not find the .ali file Second chance: in case
1459 ;; the files do not have standard names (such as for instance
1460 ;; file_s.ada and file_b.ada), try to go to the other file
1461 ;; and look for its ali file
1462 (ada-find-ali-file-in-dir
1463 (concat (file-name-sans-extension
1464 (file-name-nondirectory (ada-other-file-name)))
1468 ;; If we still don't have an ali file, try to get the one
1469 ;; from the parent unit, in case we have a separate entity.
1470 (let ((parent-name (file-name-sans-extension
1471 (file-name-nondirectory file))))
1473 (while (and (not ali-file-name)
1474 (string-match "^\\(.*\\)[.-][^.-]*" parent-name))
1476 (set 'parent-name (match-string 1 parent-name))
1477 (set 'ali-file-name (ada-find-ali-file-in-dir
1478 (concat parent-name ".ali")))
1482 ;; If still not found, try to recompile the file
1483 (if (not ali-file-name)
1484 ;; recompile only if the user asked for this. and search the ali
1485 ;; filename again. We avoid a possible infinite recursion by
1486 ;; temporarily disabling the automatic compilation.
1488 (if ada-xref-create-ali
1490 (concat (file-name-sans-extension (ada-xref-current file))
1493 (error "Ali file not found. Recompile your file"))
1496 ;; same if the .ali file is too old and we must recompile it
1497 (if (and (file-newer-than-file-p file ali-file-name)
1498 ada-xref-create-ali)
1499 (ada-xref-current file ali-file-name)))
1501 ;; Always return the correct absolute file name
1502 (expand-file-name ali-file-name))
1505 (defun ada-get-ada-file-name (file original-file)
1506 "Create the complete file name (+directory) for FILE.
1507 The original file (where the user was) is ORIGINAL-FILE. Search in project
1508 file for possible paths."
1512 ;; If the buffer for original-file, use it to get the values from the
1513 ;; project file, otherwise load the file and its project file
1514 (let ((buffer (get-file-buffer original-file)))
1517 (find-file original-file)
1518 (ada-require-project-file)))
1520 ;; we choose the first possible completion and we
1521 ;; return the absolute file name
1522 (let ((filename (ada-find-src-file-in-dir file)))
1524 (expand-file-name filename)
1526 (file-name-nondirectory file)
1527 " not found in src_dir. Please check your project file")))
1531 (defun ada-find-file-number-in-ali (file)
1532 "Returns the file number for FILE in the associated ali file."
1533 (set-buffer (ada-get-ali-buffer file))
1534 (goto-char (point-min))
1536 (let ((begin (re-search-forward "^D")))
1538 (re-search-forward (concat "^D " (file-name-nondirectory file)))
1539 (count-lines begin (point))))
1541 (defun ada-read-identifier (pos)
1542 "Returns the identlist around POS and switch to the .ali buffer.
1543 The returned list represents the entity, and can be manipulated through the
1544 macros `ada-name-of', `ada-line-of', `ada-column-of', `ada-file-of',..."
1546 ;; If at end of buffer (e.g the buffer is empty), error
1547 (if (>= (point) (point-max))
1548 (error "No identifier on point"))
1550 ;; goto first character of the identifier/operator (skip backward < and >
1551 ;; since they are part of multiple character operators
1553 (skip-chars-backward "a-zA-Z0-9_<>")
1555 ;; check if it really is an identifier
1556 (if (ada-in-comment-p)
1557 (error "Inside comment"))
1559 (let (identifier identlist)
1560 ;; Just in front of a string => we could have an operator declaration,
1561 ;; as in "+", "-", ..
1562 (if (= (char-after) ?\")
1565 ;; if looking at an operator
1566 ;; This is only true if:
1567 ;; - the symbol is +, -, ...
1568 ;; - the symbol is made of letters, and not followed by _ or a letter
1569 (if (and (looking-at ada-operator-re)
1570 (or (not (= (char-syntax (char-after)) ?w))
1571 (not (or (= (char-syntax (char-after (match-end 0))) ?w)
1572 (= (char-after (match-end 0)) ?_)))))
1574 (if (and (= (char-before) ?\")
1575 (= (char-after (+ (length (match-string 0)) (point))) ?\"))
1577 (set 'identifier (regexp-quote (concat "\"" (match-string 0) "\""))))
1579 (if (ada-in-string-p)
1580 (error "Inside string or character constant"))
1581 (if (looking-at (concat ada-keywords "[^a-zA-Z_]"))
1582 (error "No cross-reference available for reserved keyword"))
1583 (if (looking-at "[a-zA-Z0-9_]+")
1584 (set 'identifier (match-string 0))
1585 (error "No identifier around")))
1587 ;; Build the identlist
1588 (set 'identlist (ada-make-identlist))
1589 (ada-set-name identlist (downcase identifier))
1590 (ada-set-line identlist
1591 (number-to-string (count-lines 1 (point))))
1592 (ada-set-column identlist
1593 (number-to-string (1+ (current-column))))
1594 (ada-set-file identlist (buffer-file-name))
1598 (defun ada-get-all-references (identlist)
1599 "Completes and returns IDENTLIST with the information extracted
1600 from the ali file (definition file and places where it is referenced)."
1602 (let ((ali-buffer (ada-get-ali-buffer (ada-file-of identlist)))
1604 (set-buffer ali-buffer)
1605 (goto-char (point-min))
1606 (ada-set-on-declaration identlist nil)
1608 ;; First attempt: we might already be on the declaration of the identifier
1609 ;; We want to look for the declaration only in a definite interval (after
1610 ;; the "^X ..." line for the current file, and before the next "^X" line
1612 (if (re-search-forward
1613 (concat "^X [0-9]+ " (file-name-nondirectory (ada-file-of identlist)))
1615 (let ((bound (save-excursion (re-search-forward "^X " nil t))))
1616 (set 'declaration-found
1618 (concat "^" (ada-line-of identlist)
1619 "." (ada-column-of identlist)
1620 "[ *]" (ada-name-of identlist)
1621 "[{\(<= ]?\\(.*\\)$") bound t))
1622 (if declaration-found
1623 (ada-set-on-declaration identlist t))
1626 ;; If declaration is still nil, then we were not on a declaration, and
1627 ;; have to fall back on other algorithms
1629 (unless declaration-found
1631 ;; Since we alread know the number of the file, search for a direct
1633 (goto-char (point-min))
1634 (set 'declaration-found t)
1637 (number-to-string (ada-find-file-number-in-ali
1638 (ada-file-of identlist))))
1639 (unless (re-search-forward (concat (ada-ali-index-of identlist)
1640 "|\\([0-9]+[^0-9][0-9]+\\(\n\\.\\)? \\)*"
1641 (ada-line-of identlist)
1643 (ada-column-of identlist) "\\>")
1646 ;; if we did not find it, it may be because the first reference
1647 ;; is not required to have a 'unit_number|' item included.
1648 ;; Or maybe we are already on the declaration...
1649 (unless (re-search-forward
1651 "^[0-9]+.[0-9]+[ *]"
1652 (ada-name-of identlist)
1653 "[ <{=\(]\\(.\\|\n\\.\\)*\\<"
1654 (ada-line-of identlist)
1656 (ada-column-of identlist) "\\>")
1659 ;; If still not found, then either the declaration is unknown
1660 ;; or the source file has been modified since the ali file was
1662 (set 'declaration-found nil)
1666 ;; Last check to be completly sure we have found the correct line (the
1667 ;; ali might not be up to date for instance)
1668 (if declaration-found
1671 ;; while we have a continuation line, go up one line
1672 (while (looking-at "^\\.")
1674 (unless (looking-at (concat "[0-9]+.[0-9]+[ *]"
1675 (ada-name-of identlist) "[ <{=\(]"))
1676 (set 'declaration-found nil))))
1678 ;; Still no success ! The ali file must be too old, and we need to
1679 ;; use a basic algorithm based on guesses. Note that this only happens
1680 ;; if the user does not want us to automatically recompile files
1682 (unless declaration-found
1683 (if (ada-xref-find-in-modified-ali identlist)
1684 (set 'declaration-found t)
1685 ;; no more idea to find the declaration. Give up
1687 (kill-buffer ali-buffer)
1688 (error (concat "No declaration of " (ada-name-of identlist)
1694 ;; Now that we have found a suitable line in the .ali file, get the
1695 ;; information available
1697 (if declaration-found
1698 (let ((current-line (buffer-substring
1699 (point) (save-excursion (end-of-line) (point)))))
1703 (while (looking-at "^\\.\\(.*\\)")
1704 (set 'current-line (concat current-line (match-string 1)))
1708 (if (re-search-backward "^X [0-9]+ \\([a-zA-Z0-9_.-]+\\)" nil t)
1710 ;; If we can find the file
1712 (ada-set-declare-file
1714 (ada-get-ada-file-name (match-string 1)
1715 (ada-file-of identlist)))
1717 ;; Else clean up the ali file
1719 (kill-buffer ali-buffer)
1720 (error (error-message-string err)))
1723 (ada-set-references identlist current-line)
1727 (defun ada-xref-find-in-modified-ali (identlist)
1728 "Find the matching position for IDENTLIST in the current ali buffer.
1729 This function is only called when the file was not up-to-date, so we need
1730 to make some guesses.
1731 This function is disabled for operators, and only works for identifiers."
1733 (unless (= (string-to-char (ada-name-of identlist)) ?\")
1735 (let ((declist '()) ;;; ( (line_in_ali_file line_in_ada) ( ... ))
1736 (my-regexp (concat "[ *]"
1737 (regexp-quote (ada-name-of identlist)) " "))
1743 (ali-buffer (current-buffer)))
1745 (goto-char (point-max))
1746 (while (re-search-backward my-regexp nil t)
1748 (set 'line-ali (count-lines 1 (point)))
1750 ;; have a look at the line and column numbers
1751 (if (looking-at "^\\([0-9]+\\).\\([0-9]+\\)[ *]")
1753 (setq line-ada (match-string 1))
1754 (setq col-ada (match-string 2)))
1755 (setq line-ada "--")
1758 ;; construct a list with the file names and the positions within
1759 (if (re-search-backward "^X [0-9]+ \\([a-zA-Z0-9._-]+\\)" nil t)
1761 'declist (list line-ali (match-string 1) line-ada col-ada))
1766 ;; how many possible declarations have we found ?
1767 (setq len (length declist))
1771 (kill-buffer (current-buffer))
1772 (error (concat "No declaration of "
1773 (ada-name-of identlist)
1774 " recorded in .ali file")))
1776 ;; one => should be the right one
1778 (goto-line (caar declist)))
1780 ;; more than one => display choice list
1782 (save-window-excursion
1783 (with-output-to-temp-buffer "*choice list*"
1785 (princ "Identifier is overloaded and Xref information is not up to date.\n")
1786 (princ "Possible declarations are:\n\n")
1787 (princ " no. in file at line col\n")
1788 (princ " --- --------------------- ---- ----\n")
1790 (while (< counter len)
1791 (princ (format " %2d) %-21s %4s %4s\n"
1793 (ada-get-ada-file-name
1794 (nth 1 (nth counter declist))
1795 (ada-file-of identlist))
1796 (nth 2 (nth counter declist))
1797 (nth 3 (nth counter declist))
1799 (setq counter (1+ counter))
1802 ) ; end of with-output-to ...
1806 (not (integerp choice))
1811 (read-from-minibuffer "Enter No. of your choice: "))))
1813 (set-buffer ali-buffer)
1814 (goto-line (car (nth (1- choice) declist)))
1818 (defun ada-find-in-ali (identlist &optional other-frame)
1819 "Look in the .ali file for the definition of the identifier in IDENTLIST.
1820 If OTHER-FRAME is non nil, and `ada-xref-other-buffer' is non nil,
1821 opens a new window to show the declaration."
1823 (ada-get-all-references identlist)
1824 (let ((ali-line (ada-references-of identlist))
1829 ;; Note: in some cases, an entity can have multiple references to the
1830 ;; bodies (this is for instance the case for a separate subprogram, that
1831 ;; has a reference both to the stub and to the real body).
1832 ;; In that case, we simply go to each one in turn.
1834 ;; Get all the possible locations
1835 (string-match "^\\([0-9]+\\)[a-zA-Z+]\\([0-9]+\\)[ *]" ali-line)
1836 (set 'locations (list (list (match-string 1 ali-line) ;; line
1837 (match-string 2 ali-line) ;; column
1838 (ada-declare-file-of identlist))))
1839 (while (string-match "\\([0-9]+\\)[bc]\\(<[^>]+>\\)?\\([0-9]+\\)"
1841 (setq line (match-string 1 ali-line)
1842 col (match-string 3 ali-line)
1843 start (match-end 3))
1845 ;; it there was a file number in the same line
1846 (if (string-match (concat "[^{(<]\\([0-9]+\\)|\\([^|bc]+\\)?"
1847 (match-string 0 ali-line))
1849 (let ((file-number (match-string 1 ali-line)))
1850 (goto-char (point-min))
1851 (re-search-forward "^D \\([a-zA-Z0-9_.-]+\\)" nil t
1852 (string-to-number file-number))
1853 (set 'file (match-string 1))
1855 ;; Else get the nearest file
1856 (set 'file (ada-declare-file-of identlist)))
1858 (set 'locations (append locations (list (list line col file)))))
1860 ;; Add the specs at the end again, so that from the last body we go to
1862 (set 'locations (append locations (list (car locations))))
1864 ;; Find the new location we want to go to.
1865 ;; If we are on none of the locations listed, we simply go to the specs.
1867 (setq line (caar locations)
1868 col (nth 1 (car locations))
1869 file (nth 2 (car locations)))
1872 (if (and (string= (caar locations) (ada-line-of identlist))
1873 (string= (nth 1 (car locations)) (ada-column-of identlist))
1874 (string= (file-name-nondirectory (nth 2 (car locations)))
1875 (file-name-nondirectory (ada-file-of identlist))))
1876 (setq locations (cadr locations)
1877 line (car locations)
1878 col (nth 1 locations)
1879 file (nth 2 locations)
1881 (set 'locations (cdr locations))))
1883 ;; Find the file in the source path
1884 (set 'file (ada-get-ada-file-name file (ada-file-of identlist)))
1886 ;; Kill the .ali buffer
1887 (kill-buffer (current-buffer))
1889 ;; Now go to the buffer
1890 (ada-xref-change-buffer file
1891 (string-to-number line)
1892 (1- (string-to-number col))
1897 (defun ada-find-in-src-path (identlist &optional other-frame)
1898 "More general function for cross-references.
1899 This function should be used when the standard algorithm that parses the
1900 .ali file has failed, either because that file was too old or even did not
1902 This function attempts to find the possible declarations for the identifier
1903 anywhere in the object path.
1904 This command requires the external `egrep' program to be available.
1906 This works well when one is using an external librarie and wants
1907 to find the declaration and documentation of the subprograms one is
1911 (dirs (ada-xref-get-obj-dir-field))
1912 (regexp (concat "[ *]" (ada-name-of identlist)))
1919 ;; Do the grep in all the directories. We do multiple shell
1920 ;; commands instead of one in case there is no .ali file in one
1921 ;; of the directory and the shell stops because of that.
1923 (set-buffer (get-buffer-create "*grep*"))
1925 (insert (shell-command-to-string
1926 (concat "egrep -i -h '^X|" regexp "( |$)' "
1927 (file-name-as-directory (car dirs)) "*.ali")))
1928 (set 'dirs (cdr dirs)))
1930 ;; Now parse the output
1931 (set 'case-fold-search t)
1932 (goto-char (point-min))
1933 (while (re-search-forward regexp nil t)
1936 (if (not (= (char-after) ?X))
1938 (looking-at "\\([0-9]+\\).\\([0-9]+\\)")
1939 (setq line (match-string 1)
1940 column (match-string 2))
1941 (re-search-backward "^X [0-9]+ \\(.*\\)$")
1942 (set 'file (list (match-string 1) line column))
1944 ;; There could be duplicate choices, because of the structure
1945 ;; of the .ali files
1946 (unless (member file list)
1947 (set 'list (append list (list file))))))))
1949 ;; Current buffer is still "*grep*"
1950 (kill-buffer "*grep*")
1953 ;; Now display the list of possible matches
1956 ;; No choice found => Error
1958 (error "No cross-reference found, please recompile your file"))
1960 ;; Only one choice => Do the cross-reference
1961 ((= (length list) 1)
1962 (set 'file (ada-find-src-file-in-dir (caar list)))
1964 (ada-xref-change-buffer file
1965 (string-to-number (nth 1 (car list)))
1966 (string-to-number (nth 2 (car list)))
1969 (error (concat (caar list) " not found in src_dir")))
1970 (message "This is only a (good) guess at the cross-reference.")
1973 ;; Else, ask the user
1975 (save-window-excursion
1976 (with-output-to-temp-buffer "*choice list*"
1978 (princ "Identifier is overloaded and Xref information is not up to date.\n")
1979 (princ "Possible declarations are:\n\n")
1980 (princ " no. in file at line col\n")
1981 (princ " --- --------------------- ---- ----\n")
1983 (while (< counter (length list))
1984 (princ (format " %2d) %-21s %4s %4s\n"
1986 (nth 0 (nth counter list))
1987 (nth 1 (nth counter list))
1988 (nth 2 (nth counter list))
1990 (setq counter (1+ counter))
1993 (while (or (not choice)
1994 (not (integerp choice))
1996 (> choice (length list)))
1999 (read-from-minibuffer "Enter No. of your choice: "))))
2001 (set 'choice (1- choice))
2002 (kill-buffer "*choice list*")
2004 (set 'file (ada-find-src-file-in-dir (car (nth choice list))))
2006 (ada-xref-change-buffer file
2007 (string-to-number (nth 1 (nth choice list)))
2008 (string-to-number (nth 2 (nth choice list)))
2011 (error (concat (car (nth choice list)) " not found in src_dir")))
2012 (message "This is only a (good) guess at the cross-reference.")
2015 (defun ada-xref-change-buffer
2016 (file line column identlist &optional other-frame)
2017 "Select and display FILE, at LINE and COLUMN.
2018 If we do not end on the same identifier as IDENTLIST, find the closest
2019 match. Kills the .ali buffer at the end.
2020 If OTHER-FRAME is non-nil, creates a new frame to show the file."
2022 (let (declaration-buffer)
2024 ;; Select and display the destination buffer
2025 (if ada-xref-other-buffer
2027 (find-file-other-frame file)
2028 (set 'declaration-buffer (find-file-noselect file))
2029 (set-buffer declaration-buffer)
2030 (switch-to-buffer-other-window declaration-buffer)
2035 ;; move the cursor to the correct position
2038 (move-to-column column)
2040 ;; If we are not on the identifier, the ali file was not up-to-date.
2041 ;; Try to find the nearest position where the identifier is found,
2042 ;; this is probably the right one.
2043 (unless (looking-at (ada-name-of identlist))
2044 (ada-xref-search-nearest (ada-name-of identlist)))
2048 (defun ada-xref-search-nearest (name)
2049 "Searches for NAME nearest to the position recorded in the Xref file.
2050 It returns the position of the declaration in the buffer or nil if not found."
2051 (let ((orgpos (point))
2055 (goto-char (point-max))
2057 ;; loop - look for all declarations of name in this file
2058 (while (search-backward name nil t)
2060 ;; check if it really is a complete Ada identifier
2062 (not (save-excursion
2063 (goto-char (match-end 0))
2065 (not (ada-in-string-or-comment-p))
2067 ;; variable declaration ?
2069 (skip-chars-forward "a-zA-Z_0-9" )
2070 (ada-goto-next-non-ws)
2071 (looking-at ":[^=]"))
2072 ;; procedure, function, task or package declaration ?
2074 (ada-goto-previous-word)
2075 (looking-at "\\<[pP][rR][oO][cC][eE][dD][uU][rR][eE]\\>\\|\\<[fF][uU][nN][cC][tT][iI][oO][nN]\\>\\|\\<[tT][yY][pP][eE]\\>\\|\\<[tT][aA][sS][kK]\\>\\|\\<[pP][aA][cC][kK][aA][gG][eE]\\>\\|\\<[bB][oO][dD][yY]\\>"))))
2077 ;; check if it is nearer than the ones before if any
2079 (< (abs (- (point) orgpos)) diff))
2081 (setq newpos (point)
2082 diff (abs (- newpos orgpos))))))
2087 (message "ATTENTION: this declaration is only a (good) guess ...")
2092 ;; Find the parent library file of the current file
2093 (defun ada-goto-parent ()
2094 "Go to the parent library file."
2096 (ada-require-project-file)
2098 (let ((buffer (ada-get-ali-buffer (buffer-file-name)))
2104 (goto-char (point-min))
2105 (re-search-forward "^U \\([^ \t%]+\\)%[bs][ \t]+\\([^ \t]+\\)")
2106 (setq unit-name (match-string 1))
2107 (if (not (string-match "\\(.*\\)\\.[^.]+" unit-name))
2109 (kill-buffer buffer)
2110 (error "No parent unit !"))
2111 (setq unit-name (match-string 1 unit-name))
2114 ;; look for the file name for the parent unit specification
2115 (goto-char (point-min))
2116 (re-search-forward (concat "^W " unit-name
2117 "%s[ \t]+\\([^ \t]+\\)[ \t]+"
2119 (setq body-name (match-string 1))
2120 (setq ali-name (match-string 2))
2121 (kill-buffer buffer)
2124 (setq ali-name (ada-find-ali-file-in-dir ali-name))
2127 ;; Tries to open the new ali file to find the spec file
2130 (find-file ali-name)
2131 (goto-char (point-min))
2132 (re-search-forward (concat "^U " unit-name "%s[ \t]+"
2134 (setq body-name (match-string 1))
2135 (kill-buffer (current-buffer))
2140 (find-file body-name)
2143 (defun ada-make-filename-from-adaname (adaname)
2144 "Determine the filename in which ADANAME is found.
2145 This is a GNAT specific function that uses gnatkrunch."
2147 (setq krunch-buf (generate-new-buffer "*gkrunch*"))
2149 (set-buffer krunch-buf)
2150 ;; send adaname to external process `gnatkr'.
2151 (call-process "gnatkr" nil krunch-buf nil
2152 adaname ada-krunch-args)
2153 ;; fetch output of that process
2154 (setq adaname (buffer-substring
2157 (goto-char (point-min))
2160 (kill-buffer krunch-buf)))
2164 (defun ada-make-body-gnatstub ()
2165 "Create an Ada package body in the current buffer.
2166 This function uses the `gnatstub' program to create the body.
2167 This function typically is to be hooked into `ff-file-created-hooks'."
2170 (save-some-buffers nil nil)
2172 ;; If the current buffer is the body (as is the case when calling this
2173 ;; function from ff-file-created-hooks), then kill this temporary buffer
2174 (unless (interactive-p)
2176 (set-buffer-modified-p nil)
2177 (kill-buffer (current-buffer))))
2180 ;; Make sure the current buffer is the spec (this might not be the case
2181 ;; if for instance the user was asked for a project file)
2183 (unless (buffer-file-name (car (buffer-list)))
2184 (set-buffer (cadr (buffer-list))))
2186 ;; Make sure we have a project file (for parameters to gnatstub). Note that
2187 ;; this might have already been done if we have been called from the hook,
2188 ;; but this is not an expensive call)
2189 (ada-require-project-file)
2191 ;; Call the external process gnatstub
2192 (let* ((gnatstub-opts (ada-treat-cmd-string ada-gnatstub-opts))
2193 (filename (buffer-file-name (car (buffer-list))))
2194 (output (concat (file-name-sans-extension filename) ".adb"))
2195 (gnatstub-cmd (concat "gnatstub " gnatstub-opts " " filename))
2196 (buffer (get-buffer-create "*gnatstub*")))
2200 (compilation-minor-mode 1)
2202 (insert gnatstub-cmd)
2205 ;; call gnatstub to create the body file
2206 (call-process shell-file-name nil buffer nil "-c" gnatstub-cmd)
2210 (goto-char (point-min))
2211 (search-forward "command not found" nil t))
2213 (message "gnatstub was not found -- using the basic algorithm")
2215 (kill-buffer buffer)
2218 ;; Else clean up the output
2220 (if (file-exists-p output)
2223 (kill-buffer buffer))
2225 ;; display the error buffer
2226 (display-buffer buffer)
2230 (defun ada-xref-initialize ()
2231 "Function called by `ada-mode-hook' to initialize the ada-xref.el package.
2232 For instance, it creates the gnat-specific menus, sets some hooks for
2234 (make-local-hook 'ff-file-created-hooks)
2235 ;; This should really be an `add-hook'. -stef
2236 (setq ff-file-created-hooks 'ada-make-body-gnatstub)
2238 ;; Completion for file names in the mini buffer should ignore .ali files
2239 (add-to-list 'completion-ignored-extensions ".ali")
2241 (ada-xref-update-project-menu)
2245 ;; ----- Add to ada-mode-hook ---------------------------------------------
2247 ;; Use gvd or ddd as the default debugger if it was found
2248 ;; On windows, do not use the --tty switch for GVD, since this is
2249 ;; not supported. Actually, we do not use this on Unix either, since otherwise
2250 ;; there is no console window left in GVD, and people have to use the
2252 ;; This must be done before initializing the Ada menu.
2253 (if (ada-find-file-in-dir "gvd" exec-path)
2254 (set 'ada-prj-default-debugger "gvd ")
2255 (if (ada-find-file-in-dir "gvd.exe" exec-path)
2256 (set 'ada-prj-default-debugger "gvd ")
2257 (if (ada-find-file-in-dir "ddd" exec-path)
2258 (set 'ada-prj-default-debugger "ddd --tty -fullname -toolbar"))))
2260 (add-hook 'ada-mode-hook 'ada-xref-initialize)
2262 ;; Initializes the cross references to the runtime library
2263 (ada-initialize-runtime-library "")
2265 ;; Add these standard directories to the search path
2266 (set 'ada-search-directories
2267 (append (mapcar 'directory-file-name ada-xref-runtime-library-specs-path)
2268 ada-search-directories))
2272 ;;; ada-xref.el ends here