[Emacs-ada-mode] [Emacs][ada-mode] ada-xref.el -- missing gnatls in PATH
Stephen Leake
stephen_leake at stephe-leake.org
Sat Nov 17 04:35:17 PST 2007
Stephen Leake <stephen_leake at stephe-leake.org> writes:
> Pierre-Louis Escouflaire <pierre-louis.escouflaire at eurocontrol.int> writes:
>
>>> I don't think there's any point in attempting to handle the error in
>>> ada-initialize-runtime-library; if gnatls isn't found, nothing else
>>> will work either, because gnat won't be found.
>>
>> This is perfectly correct... based on a developer's point of view.
>>
>> However, I think that Emacs should start properly:
>> . for users that only need to read Ada sources,
>> . for users in a restrained environment,
>> . for users not using the GNAT compiler and tools.
>>
>> Thus, the 'ada-initialize-runtime-library' behavior might be to warn
>> users that some features are not available because of one of the two
>> last reasons.
>
> Hmm. I was assuming that if you are not using GNAT, you would not be
> using ada-xref. But that's false, since ada-xref provides project
> files, which support other compilers.
>
> We really should factor out the project file support from the GNAT
> support, but that's a lot of work.
>
>> An extension of this might be to enable/disable shortcuts, menu items,
>> etc. whether or not the user is in a restrained environments or
>> without the GNAT compiler and tools.
>
> Yes, this is the right approach.
>
> I'll see what I can do for a minimal fix at the moment.
Here's a patch.
There was code in ada-initialize-runtime-library that was trying to do
the right thing, but it wasn't working. Now it is.
In addition, ada-xref.el was running ada-initialize-runtime-library at
load time; it should wait until it's needed, since the user may
specify a cross-prefix.
I tested this with no GNAT in my path; Ada mode loads cleanly, code is
displayed with font-lock properly. Trying to use anything that needs
GNAT gives a fairly clear error message (ie "gnatkr not found").
It also works properly _with_ GNAT in my path :).
============================================================
--- emacs_stephe_site_lisp/ada-xref.el
+++ emacs_stephe_site_lisp/ada-xref.el
@@ -274,72 +274,73 @@ are retrieved with `ada-xref-get-project
(defun ada-find-executable (exec-name)
"Find the full path to the executable file EXEC-NAME.
+If not found, throw an error.
On Windows systems, this will properly handle .exe extension as well"
- (or (ada-find-file-in-dir exec-name exec-path)
- (ada-find-file-in-dir (concat exec-name ".exe") exec-path)
- exec-name))
+ (let ((result (or (ada-find-file-in-dir exec-name exec-path)
+ (ada-find-file-in-dir (concat exec-name ".exe") exec-path))))
+ (if result
+ result
+ (error "'%s' not found in path" exec-name))))
(defun ada-initialize-runtime-library (cross-prefix)
- "Initialize the variables for the runtime library location.
-CROSS-PREFIX is the prefix to use for the `gnatls' command."
- (let (gnatls)
- (condition-case nil
- ;; if gnatls not found, just give up (may not be using GNAT)
- (ada-find-executable (concat cross-prefix "gnatls"))
- (error nil))
+ "Initialize the variables for the runtime library location."
+ (let ((gnatls
+ (condition-case nil
+ ;; if gnatls not found, just give up (may not be using GNAT)
+ (ada-find-executable (concat cross-prefix "gnatls"))
+ (error nil))))
+ (if gnatls
+ (save-excursion
+ (setq ada-xref-runtime-library-specs-path '()
+ ada-xref-runtime-library-ali-path '())
+ (set-buffer (get-buffer-create "*gnatls*"))
+ (widen)
+ (erase-buffer)
+ ;; Even if we get an error, delete the *gnatls* buffer
+ (unwind-protect
+ (let* ((status (call-process gnatls nil t nil "-v")))
+ (goto-char (point-min))
- (save-excursion
- (setq ada-xref-runtime-library-specs-path '()
- ada-xref-runtime-library-ali-path '())
- (set-buffer (get-buffer-create "*gnatls*"))
- (widen)
- (erase-buffer)
- ;; Even if we get an error, delete the *gnatls* buffer
- (unwind-protect
- (let* ((gnatls (ada-find-executable (concat cross-prefix "gnatls")))
- (status (call-process gnatls nil t nil "-v")))
- (goto-char (point-min))
+ ;; Since we didn't provide all the inputs gnatls expects, it returns status 4
+ (if (/= 4 status)
+ (error (buffer-substring (point) (line-end-position))))
- ;; Since we didn't provide all the inputs gnatls expects, it returns status 4
- (if (/= 4 status)
- (error (buffer-substring (point) (line-end-position))))
+ ;; Source path
- ;; Source path
+ (search-forward "Source Search Path:")
+ (forward-line 1)
+ (while (not (looking-at "^$"))
+ (back-to-indentation)
+ (if (looking-at "<Current_Directory>")
+ (add-to-list 'ada-xref-runtime-library-specs-path ".")
+ (add-to-list 'ada-xref-runtime-library-specs-path
+ (buffer-substring-no-properties
+ (point)
+ (save-excursion (end-of-line) (point)))))
+ (forward-line 1))
- (search-forward "Source Search Path:")
- (forward-line 1)
- (while (not (looking-at "^$"))
- (back-to-indentation)
- (if (looking-at "<Current_Directory>")
- (add-to-list 'ada-xref-runtime-library-specs-path ".")
- (add-to-list 'ada-xref-runtime-library-specs-path
- (buffer-substring-no-properties
- (point)
- (save-excursion (end-of-line) (point)))))
- (forward-line 1))
+ ;; Object path
- ;; Object path
+ (search-forward "Object Search Path:")
+ (forward-line 1)
+ (while (not (looking-at "^$"))
+ (back-to-indentation)
+ (if (looking-at "<Current_Directory>")
+ (add-to-list 'ada-xref-runtime-library-ali-path ".")
+ (add-to-list 'ada-xref-runtime-library-ali-path
+ (buffer-substring-no-properties
+ (point)
+ (save-excursion (end-of-line) (point)))))
+ (forward-line 1))
+ )
+ (kill-buffer nil))))
- (search-forward "Object Search Path:")
- (forward-line 1)
- (while (not (looking-at "^$"))
- (back-to-indentation)
- (if (looking-at "<Current_Directory>")
- (add-to-list 'ada-xref-runtime-library-ali-path ".")
- (add-to-list 'ada-xref-runtime-library-ali-path
- (buffer-substring-no-properties
- (point)
- (save-excursion (end-of-line) (point)))))
- (forward-line 1))
- )
- (kill-buffer nil))))
+ (set 'ada-xref-runtime-library-specs-path
+ (reverse ada-xref-runtime-library-specs-path))
+ (set 'ada-xref-runtime-library-ali-path
+ (reverse ada-xref-runtime-library-ali-path))
+ ))
- (set 'ada-xref-runtime-library-specs-path
- (reverse ada-xref-runtime-library-specs-path))
- (set 'ada-xref-runtime-library-ali-path
- (reverse ada-xref-runtime-library-ali-path))
- )
-
(defun ada-gnat-parse-gpr (plist gpr-file)
"Set gpr_file, src_dir and obj_dir properties in PLIST by parsing GPR-FILE.
Returns new value of PLIST.
@@ -2381,14 +2382,6 @@ For instance, it creates the gnat-specif
'error-message
"File not found in src-dir (check project file): ")
-;; Initializes the cross references to the runtime library
-(ada-initialize-runtime-library "")
-
-;; Add these standard directories to the search path
-(set 'ada-search-directories-internal
- (append (mapcar 'directory-file-name ada-xref-runtime-library-specs-path)
- ada-search-directories))
-
(provide 'ada-xref)
--
-- Stephe
More information about the Emacs-ada-mode
mailing list