[Emacs-ada-mode] Default build command is stuck to the first "Compile file" command line
Stephen Leake
stephen_leake at stephe-leake.org
Sat Nov 17 14:36:26 PST 2007
Alexy Khrabrov <deliverable at gmail.com> writes:
> I'm using gnatmake, etc., installed in /usr/local/ada/bin, and the
> latter directory is not on my PATH -- so that GNAT's gcc is not
> confused with the system-wide one.
I would handle this by changing PATH to what I need at the moment. For
example:
(defun sal-cygwin ()
(interactive)
(setq exec-path
(list
(expand-file-name "~/bin")
"c:/Gnu/Emacs/emacs-22.1/bin"
"c:/Gnu/gtkwave-3.0.10-1/bin"
"c:/bin"
"c:/windows/system32"))
(setenv "PATH" (mapconcat 'identity exec-path path-separator))
)
(defun sal-mingw ()
(interactive)
(setq exec-path
(list
"c:/Apps/mingw/local/bin" ;; can't put /mingw/bin first, for some reason
"/mingw/bin" ;; MinGW g++ is installed to /mingw/bin, not /bin
"c:/Apps/mingw/bin"
"c:/Gnu/monotone.basic_io.inventory-build_mingw" ; working version
(expand-file-name "~/bin")
"c:/Gnu/GNAT-6.0.2/bin" ; for gdb
"c:/Gnu/Emacs/emacs-22.1/bin"
"c:/windows/system32"))
(setenv "PATH" (mapconcat 'identity exec-path path-separator))
)
Now I can invoke sal-cygwin or sal-mingw to change what's in PATH. If
I'm compiling Ada, I run sal-mingw. If I'm not, I run sal-cygwin.
> I'd like ada-mode to find it properly. At first I thought I'll just
> create a system-wide gnat.adp file, with one line:
>
> cross_prefix=/usr/local/ada/bin/
>
> and then, in my ~/.emacs, will set that as my default project.
You said "at first". Did this not work? It seems a reasonable
approach.
Unless the GNAT tools require the GNAT bin directory on PATH; I've
never tried your approach.
> That works in the same way as another approach:
>
> (setq gnat-bin-dir "/usr/local/ada/bin")
> (setenv "PATH" (concat gnat-bin-dir ":" (getenv "PATH")))
There's no need for the variable here; 'gnat-bin-dir' is not used by
anything in Ada mode.
> By the way, the following, which I tried before setenv "PATH", didn't
> work:
>
> (add-to-list 'exec-path gnat-bin-dir)
>
> -- apparently the commands form ada-mode invoke my shell, zsh,
> directly, and its PATH is searched, without any exec-path usage at
> all.
Right. I always set both exec-prefix and PATH together.
> Thus an elisp question: how do we ensure, instead of just
> prepending, that we prepend gnat-bin-dir to PATH only once, when
> it's not there already? Is there a standard way to do it with elisp,
> similar to the add-to-list function for adding an element to a list
> (such as exec-path) just once?
Since PATH is just a string, not a list, I don't think there is a
defined way. You'd have to parse PATH into a list first, then rebuild
it.
I always just set all of PATH, rather than trying to track what's been
added to it.
> In both cases, I get the same undesirable behavior -- the build
> command gets stuck on whatever form it got on the first try.
Ok, this is a completely separate issue; it has nothing to do with
finding the executables or setting PATH.
> If I first try to build with C-c C-c, Emacs asks me, "enter command
> to compile:"
Hmm. You must have set ada-prj-default-make-cmd to nil. With the
default Ada mode this uses the default command (gnatmake) for me.
Can you be more specific? Start with emacs -q (to not load your
.emacs), and say how to reproduce the problem.
> How does Ada Mode knows which is the main procedure, and how are we
> supposed to start the compile/build sequence to end up with the
> correct C-c C-c?
There is a menu entry Ada | Set main and build; that sets the main
procedure.
> I unpacked the latest ada-mode, 2007-11-14, and made it first on my
> load-path. Do I need any of the other three .el files in addition to
> that? They are
>
> ada-mode-patches.el
> ada-mode-keys.el
These two are my personal customizations/additions to Ada mode; they
are provided as examples. If you like what they do, you can use them.
> gnat-fix-error.el
This is an additional package; it provides automatic correction of
many compilation errors reported by GNAT. I bind `next-error' to F6,
and `gnat-fix-compiler-error' to C-F6. Then I can fix many errors by
hitting F6, C-F6, repeat.
> BTW, a minor suggestion: when I don't specify the default Ada Mode
> project and try editing it with C-c u, and then enter /usr/local/ada/
> bin/ into cross_prefix field and hit [Save], I get an error: Wrong
> type argument: stringp, nil.
Ah, that's a bug. ada-prj-save should prompt for a filename in this
case. Here's a patch:
============================================================
--- emacs_stephe_site_lisp/ada-prj.el
+++ emacs_stephe_site_lisp/ada-prj.el
@@ -1,6 +1,6 @@
;;; ada-prj.el --- GUI editing of project files for the ada-mode
-;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
+;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
;; Free Software Foundation, Inc.
;; Author: Emmanuel Briot <briot at gnat.com>
@@ -124,7 +124,8 @@ If the current value of FIELD is the def
(defun ada-prj-save ()
"Save the edited project file."
(interactive)
- (let ((file-name (plist-get ada-prj-current-values 'filename))
+ (let ((file-name (or (plist-get ada-prj-current-values 'filename)
+ (read-file-name "Save project as: ")))
output)
(set 'output
(concat
============================================================
> Also learned to specify the cross_prefix with a trailing slash, as
> it's being concatenated to the commands without an interceding
> slash, such as in ${cross_prefix} gnatmake. Perhaps it's safer to
> code it up as ${cross_prefix}/ gnatmake in case folks forget to add
> the trailing slash when editing the project files.
The intended use is for cross-compiler target names, not paths. For
example, for the powerpc cross target, the gnat executables are named
powerpc-gnat, powerpc-gnatls, etc. So cross_prefix would be set to
"powerpc-". Always inserting a slash would break that usage.
--
-- Stephe
More information about the Emacs-ada-mode
mailing list