Remove some function declarations, no longer needed or correct
[bpt/emacs.git] / lisp / progmodes / ada-prj.el
CommitLineData
d759dcce 1;;; ada-prj.el --- GUI editing of project files for the ada-mode
d41832c5 2
ba318903 3;; Copyright (C) 1998-2014 Free Software Foundation, Inc.
d41832c5
GM
4
5;; Author: Emmanuel Briot <briot@gnat.com>
d759dcce 6;; Maintainer: Stephen Leake <stephen_leake@stephe-leake.org>
d41832c5 7;; Keywords: languages, ada, project file
bd78fa1d 8;; Package: ada-mode
d41832c5 9
874d7995 10;; This file is part of GNU Emacs.
d41832c5 11
b1fc2b50 12;; GNU Emacs is free software: you can redistribute it and/or modify
d41832c5 13;; it under the terms of the GNU General Public License as published by
b1fc2b50
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
d41832c5 16
2be7dabc 17;; GNU Emacs is distributed in the hope that it will be useful,
d41832c5
GM
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
b1fc2b50 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
d41832c5 24
3afbc435
PJ
25;;; Commentary:
26
d41832c5
GM
27;;; This package provides a set of functions to easily edit the project
28;;; files used by the ada-mode.
c6fa13e3
GM
29;;; The only function publicly available here is `ada-customize'.
30;;; See the documentation of the Ada mode for more information on the project
31;;; files.
32;;; Internally, a project file is represented as a property list, with each
33;;; field of the project file matching one property of the list.
d41832c5 34
d759dcce
JB
35
36;;; History:
37;;
38
3afbc435 39;;; Code:
d41832c5
GM
40
41
42;; ----- Requirements -----------------------------------------------------
43
44(require 'cus-edit)
ce20e709 45(require 'ada-xref)
d41832c5 46
6f9a2614
JB
47(eval-when-compile
48 (require 'ada-mode))
49
d41832c5 50;; ----- Buffer local variables -------------------------------------------
d41832c5 51
c6fa13e3 52(defvar ada-prj-current-values nil
6f9a2614 53 "Hold the current value of the fields, This is a property list.")
c6fa13e3
GM
54(make-variable-buffer-local 'ada-prj-current-values)
55
56(defvar ada-prj-default-values nil
6f9a2614 57 "Hold the default value for the fields, This is a property list.")
c6fa13e3
GM
58(make-variable-buffer-local 'ada-prj-default-values)
59
60(defvar ada-prj-ada-buffer nil
61 "Indicates what Ada source file was being edited.")
62
da2a1edf
SM
63(defvar ada-old-cross-prefix nil
64 "The cross-prefix associated with the currently loaded runtime library.")
65
c6fa13e3
GM
66
67;; ----- Functions --------------------------------------------------------
68
69(defun ada-prj-new ()
d759dcce 70 "Open a new project file."
d41832c5 71 (interactive)
c6fa13e3 72 (let* ((prj
da2a1edf
SM
73 (if (and ada-prj-default-project-file
74 (not (string= ada-prj-default-project-file "")))
75 ada-prj-default-project-file
c6fa13e3
GM
76 "default.adp"))
77 (filename (read-file-name "Project file: "
78 (if prj "" nil)
79 nil
80 nil
81 prj)))
82 (if (not (string= (file-name-extension filename t) ".adp"))
83 (error "File name extension for project files must be .adp"))
a1506d29 84
c6fa13e3
GM
85 (ada-customize nil filename)))
86
87(defun ada-prj-edit ()
88 "Editing the project file associated with the current Ada buffer.
32b1a27f 89If there is none, opens a new project file."
c6fa13e3 90 (interactive)
61c08d00
SM
91 (if ada-prj-default-project-file
92 (ada-customize)
93 (ada-prj-new)))
d41832c5 94
e02f48d7 95(defun ada-prj-initialize-values (symbol _ada-buffer filename)
c6fa13e3 96 "Set SYMBOL to the property list of the project file FILENAME.
32b1a27f
JB
97If FILENAME is null, read the file associated with ADA-BUFFER.
98If no project file is found, return the default values."
d759dcce 99;; FIXME: rationalize arguments; make ada-buffer optional?
ce20e709
JB
100 (if (and filename
101 (not (string= filename ""))
102 (assoc filename ada-xref-project-files))
103 (set symbol (copy-sequence (cdr (assoc filename ada-xref-project-files))))
a1506d29 104
ce20e709
JB
105 ;; Set default values (except for the file name if this was given
106 ;; in the buffer
ff6d2a9e 107 (set symbol (ada-default-prj-properties))
ce20e709
JB
108 (if (and filename (not (string= filename "")))
109 (set symbol (plist-put (eval symbol) 'filename filename)))
110 ))
a1506d29 111
d41832c5 112
c6fa13e3 113(defun ada-prj-save-specific-option (field)
d759dcce 114 "Return the string to print in the project file to save FIELD.
32b1a27f 115If the current value of FIELD is the default value, return an empty string."
c6fa13e3
GM
116 (if (string= (plist-get ada-prj-current-values field)
117 (plist-get ada-prj-default-values field))
118 ""
119 (concat (symbol-name field)
120 "=" (plist-get ada-prj-current-values field) "\n")))
d41832c5
GM
121
122(defun ada-prj-save ()
c6fa13e3 123 "Save the edited project file."
d41832c5 124 (interactive)
d5875b25
JB
125 (let ((file-name (or (plist-get ada-prj-current-values 'filename)
126 (read-file-name "Save project as: ")))
c6fa13e3
GM
127 output)
128 (set 'output
129 (concat
130
131 ;; Save the fields that do not depend on the current buffer
132 ;; only if they are different from the default value
a1506d29 133
c6fa13e3
GM
134 (ada-prj-save-specific-option 'comp_opt)
135 (ada-prj-save-specific-option 'bind_opt)
136 (ada-prj-save-specific-option 'link_opt)
137 (ada-prj-save-specific-option 'gnatmake_opt)
da2a1edf 138 (ada-prj-save-specific-option 'gnatfind_opt)
c6fa13e3
GM
139 (ada-prj-save-specific-option 'cross_prefix)
140 (ada-prj-save-specific-option 'remote_machine)
c6fa13e3
GM
141 (ada-prj-save-specific-option 'debug_cmd)
142
143 ;; Always save the fields that depend on the current buffer
da2a1edf 144 "main=" (plist-get ada-prj-current-values 'main) "\n"
da2a1edf
SM
145 "build_dir=" (plist-get ada-prj-current-values 'build_dir) "\n"
146 (ada-prj-set-list "check_cmd"
147 (plist-get ada-prj-current-values 'check_cmd)) "\n"
148 (ada-prj-set-list "make_cmd"
149 (plist-get ada-prj-current-values 'make_cmd)) "\n"
150 (ada-prj-set-list "comp_cmd"
151 (plist-get ada-prj-current-values 'comp_cmd)) "\n"
152 (ada-prj-set-list "run_cmd"
153 (plist-get ada-prj-current-values 'run_cmd)) "\n"
c6fa13e3 154 (ada-prj-set-list "src_dir"
da2a1edf
SM
155 (plist-get ada-prj-current-values 'src_dir)
156 t) "\n"
c6fa13e3 157 (ada-prj-set-list "obj_dir"
da2a1edf
SM
158 (plist-get ada-prj-current-values 'obj_dir)
159 t) "\n"
160 (ada-prj-set-list "debug_pre_cmd"
161 (plist-get ada-prj-current-values 'debug_pre_cmd))
162 "\n"
163 (ada-prj-set-list "debug_post_cmd"
164 (plist-get ada-prj-current-values 'debug_post_cmd))
165 "\n"
c6fa13e3 166 ))
a1506d29 167
d41832c5
GM
168 (find-file file-name)
169 (erase-buffer)
170 (insert output)
171 (save-buffer)
172 ;; kill the project buffer
173 (kill-buffer nil)
174
175 ;; kill the editor buffer
d759dcce 176 (kill-buffer "*Edit Ada Mode Project*")
d41832c5 177
da2a1edf
SM
178 ;; automatically set the new project file as the active one
179 (set 'ada-prj-default-project-file file-name)
d41832c5 180
c6fa13e3
GM
181 ;; force Emacs to reread the project files
182 (ada-reread-prj-file file-name)
d41832c5
GM
183 )
184 )
185
c6fa13e3 186(defun ada-prj-load-from-file (symbol)
32b1a27f
JB
187 "Load SYMBOL value from file.
188One item per line should be found in the file."
c6fa13e3
GM
189 (save-excursion
190 (let ((file (read-file-name "File name: " nil nil t))
191 (buffer (current-buffer))
192 line
193 list)
194 (find-file file)
195 (widen)
196 (goto-char (point-min))
197 (while (not (eobp))
e180ab9f 198 (set 'line (buffer-substring-no-properties (point) (point-at-eol)))
c6fa13e3 199 (add-to-list 'list line)
e180ab9f 200 (forward-line 1))
c6fa13e3
GM
201 (kill-buffer nil)
202 (set-buffer buffer)
203 (set 'ada-prj-current-values
204 (plist-put ada-prj-current-values
205 symbol
206 (append (plist-get ada-prj-current-values symbol)
e180ab9f
GM
207 (reverse list)))))
208 (ada-prj-display-page 2)))
c6fa13e3
GM
209
210(defun ada-prj-subdirs-of (dir)
d759dcce 211 "Return a list of all the subdirectories of DIR, recursively."
c6fa13e3
GM
212 (let ((subdirs (directory-files dir t "^[^.].*"))
213 (dirlist (list dir)))
214 (while subdirs
215 (if (file-directory-p (car subdirs))
216 (let ((sub (ada-prj-subdirs-of (car subdirs))))
217 (if sub
218 (set 'dirlist (append sub dirlist)))))
219 (set 'subdirs (cdr subdirs)))
220 dirlist))
221
222(defun ada-prj-load-directory (field &optional file-name)
d759dcce 223 "Append to FIELD in the current project the subdirectories of FILE-NAME.
c6fa13e3 224If FILE-NAME is nil, ask the user for the name."
61c08d00
SM
225
226 ;; Do not use an external dialog for this, since it wouldn't allow
227 ;; the user to select a directory
228 (let ((use-dialog-box nil))
229 (unless file-name
7e27ce9c 230 (set 'file-name (read-directory-name "Root directory: " nil nil t))))
c6fa13e3
GM
231
232 (set 'ada-prj-current-values
233 (plist-put ada-prj-current-values
234 field
235 (append (plist-get ada-prj-current-values field)
236 (reverse (ada-prj-subdirs-of
237 (expand-file-name file-name))))))
238 (ada-prj-display-page 2))
239
240(defun ada-prj-display-page (tab-num)
d759dcce 241 "Display page TAB-NUM in the notebook.
c6fa13e3
GM
242The current buffer must be the project editing buffer."
243
244 (let ((inhibit-read-only t))
245 (erase-buffer))
246
da2a1edf 247 ;; Widget support in Emacs 21 requires that we clear the buffer first
6f9a2614 248 (if (and (not (featurep 'xemacs)) (>= emacs-major-version 21))
da2a1edf
SM
249 (progn
250 (setq widget-field-new nil
251 widget-field-list nil)
88f43129
JB
252 (mapc (lambda (x) (delete-overlay x)) (car (overlay-lists)))
253 (mapc (lambda (x) (delete-overlay x)) (cdr (overlay-lists)))))
a1506d29 254
c6fa13e3 255 ;; Display the tabs
a1506d29 256
d759dcce 257 (widget-insert "\n Project configuration.\n
da2a1edf 258 ___________ ____________ ____________ ____________ ____________\n / ")
c6fa13e3 259 (widget-create 'push-button :notify
e02f48d7 260 (lambda (&rest _dummy) (ada-prj-display-page 1)) "General")
c6fa13e3
GM
261 (widget-insert " \\ / ")
262 (widget-create 'push-button :notify
e02f48d7 263 (lambda (&rest _dummy) (ada-prj-display-page 2)) "Paths")
c6fa13e3
GM
264 (widget-insert " \\ / ")
265 (widget-create 'push-button :notify
e02f48d7 266 (lambda (&rest _dummy) (ada-prj-display-page 3)) "Switches")
c6fa13e3
GM
267 (widget-insert " \\ / ")
268 (widget-create 'push-button :notify
e02f48d7 269 (lambda (&rest _dummy) (ada-prj-display-page 4)) "Ada Menu")
da2a1edf
SM
270 (widget-insert " \\ / ")
271 (widget-create 'push-button :notify
e02f48d7 272 (lambda (&rest _dummy) (ada-prj-display-page 5)) "Debugger")
c6fa13e3
GM
273 (widget-insert " \\\n")
274
275 ;; Display the currently selected page
a1506d29 276
c6fa13e3 277 (cond
a1506d29 278
c6fa13e3
GM
279 ;;
280 ;; First page (General)
281 ;;
282 ((= tab-num 1)
da2a1edf 283 (widget-insert "/ \\/______________\\/______________\\/______________\\/______________\\\n")
c6fa13e3
GM
284
285 (widget-insert "Project file name:\n")
286 (widget-insert (plist-get ada-prj-current-values 'filename))
287 (widget-insert "\n\n")
d5875b25
JB
288 (ada-prj-field 'casing "Casing Exceptions"
289"List of files that contain casing exception
290dictionaries. All these files contain one
291identifier per line, with a special casing.
292The first file has the highest priority."
293 t nil
294 (mapconcat (lambda(x)
295 (concat " " x))
296 (ada-xref-get-project-field 'casing)
297 "\n")
298 )
c6fa13e3
GM
299 (ada-prj-field 'main "Executable file name"
300"Name of the executable generated when you
301compile your application. This should include
302the full directory name, using ${build_dir} if
303you wish.")
c6fa13e3
GM
304 (ada-prj-field 'build_dir "Build directory"
305 "Reference directory for relative paths in
306src_dir and obj_dir below. This is also the directory
307where the compilation is done.")
308 (ada-prj-field 'remote_machine "Name of the remote machine (if any)"
309"If you want to remotely compile, debug and
310run your application, specify the name of a
311remote machine here. This capability requires
312the 'rsh' protocol on the remote machine.")
313 (ada-prj-field 'cross_prefix "Prefix used in for the cross tool chain"
314"When working on multiple cross targets, it is
315most convenient to specify the prefix of the
316tool chain here. For instance, on PowerPc
317vxworks, you would enter 'powerpc-wrs-vxworks-'.
318To use JGNAT, enter 'j'.")
319 )
d41832c5 320
a1506d29 321
c6fa13e3
GM
322 ;;
323 ;; Second page (Paths)
324 ;;
325 ((= tab-num 2)
da2a1edf
SM
326 (if (not (equal (plist-get ada-prj-current-values 'cross_prefix)
327 ada-old-cross-prefix))
328 (progn
329 (setq ada-old-cross-prefix
330 (plist-get ada-prj-current-values 'cross_prefix))
331 (ada-initialize-runtime-library ada-old-cross-prefix)))
332
a1506d29 333
da2a1edf 334 (widget-insert "/_____________\\/ \\/______________\\/______________\\/______________\\\n")
c6fa13e3
GM
335 (ada-prj-field 'src_dir "Source directories"
336"Enter the list of directories where your Ada
337sources can be found. These directories will be
338used for the cross-references and for the default
339compilation commands.
340Note that src_dir includes both the build directory
341and the standard runtime."
342 t t
343 (mapconcat (lambda(x)
d759dcce
JB
344 (concat " " x))
345 ada-xref-runtime-library-specs-path
346 "\n")
c6fa13e3
GM
347 )
348 (widget-insert "\n\n")
a1506d29 349
c6fa13e3
GM
350 (ada-prj-field 'obj_dir "Object directories"
351"Enter the list of directories where the GNAT
352library files (ALI files) can be found. These
353files are used for cross-references and by the
354gnatmake command.
355Note that obj_dir includes both the build directory
356and the standard runtime."
357 t t
358 (mapconcat (lambda(x)
d759dcce
JB
359 (concat " " x))
360 ada-xref-runtime-library-ali-path
361 "\n")
c6fa13e3
GM
362 )
363 (widget-insert "\n\n")
364 )
d41832c5 365
c6fa13e3
GM
366 ;;
367 ;; Third page (Switches)
368 ;;
369 ((= tab-num 3)
da2a1edf 370 (widget-insert "/_____________\\/______________\\/ \\/______________\\/______________\\\n")
c6fa13e3
GM
371 (ada-prj-field 'comp_opt "Switches for the compiler"
372"These switches are used in the default
373compilation commands, both for compiling a
374single file and rebuilding the whole project")
375 (ada-prj-field 'bind_opt "Switches for the binder"
376"These switches are used in the default build
377command and are passed to the binder")
378 (ada-prj-field 'link_opt "Switches for the linker"
379"These switches are used in the default build
380command and are passed to the linker")
381 (ada-prj-field 'gnatmake_opt "Switches for gnatmake"
382"These switches are used in the default gnatmake
a1506d29 383command.")
da2a1edf
SM
384 (ada-prj-field 'gnatfind_opt "Switches for gnatfind"
385"The command gnatfind is run every time the Ada/Goto/List_References menu.
386You should for instance add -a if you are working in an environment
387where most ALI files are write-protected, since otherwise they get
388ignored by gnatfind and you don't see the references within.")
c6fa13e3 389 )
d41832c5 390
c6fa13e3
GM
391 ;;
392 ;; Fourth page
393 ;;
394 ((= tab-num 4)
da2a1edf 395 (widget-insert "/_____________\\/______________\\/______________\\/ \\/______________\\\n")
c6fa13e3 396 (widget-insert
32b1a27f 397"All the fields below can use variable substitution. The syntax is ${name},
da2a1edf
SM
398where name is the name that appears after the Help buttons in this buffer. As
399a special case, ${current} is replaced with the name of the file currently
400edited, with directory name but no extension, whereas ${full_current} is
401replaced with the name of the current file with directory name and
402extension.\n")
c6fa13e3 403 (widget-insert
da2a1edf
SM
404"The environment variables ADA_INCLUDE_PATH and ADA_OBJECTS_PATH are set to
405${src_dir} and ${obj_dir} before running the compilation commands, so that you
406don't need to specify the -aI and -aO switches on the command line\n")
c6fa13e3 407 (widget-insert
da2a1edf
SM
408"You can reference any environment variable using the same ${...} syntax as
409above, and put the name of the variable between the quotes.\n\n")
c6fa13e3
GM
410 (ada-prj-field 'check_cmd
411 "Check syntax of a single file (menu Ada->Check File)"
412"This command is run to check the syntax and semantics of a file.
da2a1edf 413The file name is added at the end of this command." t)
c6fa13e3
GM
414 (ada-prj-field 'comp_cmd
415 "Compiling a single file (menu Ada->Compile File)"
416"This command is run when the recompilation
417of a single file is needed. The file name is
da2a1edf 418added at the end of this command." t)
c6fa13e3
GM
419 (ada-prj-field 'make_cmd "Rebuilding the whole project (menu Ada->Build)"
420"This command is run when you want to rebuild
421your whole application. It is never issues
422automatically and you will need to ask for it.
423If remote_machine has been set, this command
da2a1edf 424will be executed on the remote machine." t)
c6fa13e3
GM
425 (ada-prj-field 'run_cmd "Running the application (menu Ada->Run)"
426"This command specifies how to run the
427application, including any switch you need to
428specify. If remote_machine has been set, this
da2a1edf
SM
429command will be executed on the remote host." t)
430 )
431
432 ;;
433 ;; Fifth page
434 ;;
435 ((= tab-num 5)
436 (widget-insert "/_____________\\/______________\\/______________\\/______________\\/ \\\n")
437 (ada-prj-field 'debug_pre_cmd "Commands to execute before launching the
438debugger"
439"The following commands are executed one after the other before starting
440the debugger. These can be used to set up your environment." t)
a1506d29 441
c6fa13e3
GM
442 (ada-prj-field 'debug_cmd "Debugging the application"
443"Specifies how to debug the application, possibly
444remotely if remote_machine has been set. We
445recommend the following debuggers:
446 > gdb
da2a1edf 447 > gvd --tty
c6fa13e3 448 > ddd --tty -fullname -toolbar")
da2a1edf
SM
449
450 (ada-prj-field 'debug_post_cmd "Commands to execute in the debugger"
451"The following commands are executed one in the debugger once it has been
452started. These can be used to initialize the debugger, for instance to
453connect to the target when working with cross-environments" t)
c6fa13e3 454 )
a1506d29 455
c6fa13e3
GM
456 )
457
458
459 (widget-insert "______________________________________________________________________\n\n ")
460 (widget-create 'push-button
e02f48d7 461 :notify (lambda (&rest _ignore)
ff6d2a9e 462 (setq ada-prj-current-values (ada-default-prj-properties))
c6fa13e3
GM
463 (ada-prj-display-page 1))
464 "Reset to Default Values")
465 (widget-insert " ")
e02f48d7 466 (widget-create 'push-button :notify (lambda (&rest _ignore) (kill-buffer nil))
c6fa13e3
GM
467 "Cancel")
468 (widget-insert " ")
e02f48d7 469 (widget-create 'push-button :notify (lambda (&rest _ignore) (ada-prj-save))
c6fa13e3
GM
470 "Save")
471 (widget-insert "\n\n")
472
473 (widget-setup)
300ee850
RS
474 (with-no-warnings
475 (beginning-of-buffer))
c6fa13e3 476 )
d41832c5 477
d41832c5 478
c6fa13e3
GM
479(defun ada-customize (&optional new-file filename)
480 "Edit the project file associated with the current buffer.
481If there is none or NEW-FILE is non-nil, make a new one.
482If FILENAME is given, edit that file."
483 (interactive)
d41832c5 484
c6fa13e3
GM
485 (let ((ada-buffer (current-buffer))
486 (inhibit-read-only t))
d41832c5 487
61c08d00
SM
488 ;; We can only edit interactively the standard ada-mode project files. If
489 ;; the user is using other formats for the project file (through hooks in
490 ;; `ada-load-project-hook', we simply edit the file
a1506d29 491
61c08d00
SM
492 (if (and (not new-file)
493 (or ada-prj-default-project-file filename)
494 (string= (file-name-extension
495 (or filename ada-prj-default-project-file))
496 "gpr"))
497 (progn
498 (find-file ada-prj-default-project-file)
499 (add-hook 'after-save-hook 'ada-reread-prj-file t t)
500 )
da2a1edf 501
ce20e709
JB
502 (if filename
503 (ada-reread-prj-file filename)
504 (if (not (string= ada-prj-default-project-file ""))
505 (ada-reread-prj-file ada-prj-default-project-file)
506 (ada-reread-prj-file)))
507
d759dcce 508 (switch-to-buffer "*Edit Ada Mode Project*")
a1506d29 509
ce20e709
JB
510 (ada-prj-initialize-values 'ada-prj-current-values
511 ada-buffer
512 ada-prj-default-project-file)
a1506d29 513
61c08d00 514 (set (make-local-variable 'ada-prj-ada-buffer) ada-buffer)
a1506d29 515
175069ef
SM
516 (use-local-map
517 (let ((map (make-sparse-keymap)))
518 (set-keymap-parent map custom-mode-map)
519 (define-key map "\C-x\C-s" 'ada-prj-save)
520 map))
521
522 ;; FIXME: Not sure if this works!!
523 (set (make-local-variable 'widget-keymap)
524 (let ((map (make-sparse-keymap)))
525 (set-keymap-parent map widget-keymap)
526 (define-key map "\C-x\C-s" 'ada-prj-save)
527 map))
a1506d29 528
61c08d00
SM
529 (set (make-local-variable 'ada-old-cross-prefix)
530 (ada-xref-get-project-field 'cross-prefix))
a1506d29 531
61c08d00
SM
532 (ada-prj-display-page 1)
533 )))
d41832c5
GM
534
535;; ---------------- Utilities --------------------------------
536
da2a1edf 537(defun ada-prj-set-list (string ada-list &optional is-directory)
d759dcce
JB
538 "Prepend STRING to strings in ADA-LIST, return new-line separated string.
539If IS-DIRECTORY is non-nil, each element of ADA-LIST is explicitly
540converted to a directory name."
da2a1edf
SM
541
542 (mapconcat (lambda (x) (concat string "="
543 (if is-directory
544 (file-name-as-directory x)
545 x)))
d759dcce 546 ada-list "\n"))
d41832c5 547
c6fa13e3 548
e02f48d7 549(defun ada-prj-field-modified (widget &rest _dummy)
d759dcce
JB
550 "Callback for modification of WIDGET.
551Remaining args DUMMY are ignored.
552Save the change in `ada-prj-current-values' so that selecting
553another page and coming back keeps the new value."
c6fa13e3
GM
554 (set 'ada-prj-current-values
555 (plist-put ada-prj-current-values
da2a1edf 556 (widget-get widget ':prj-field)
c6fa13e3
GM
557 (widget-value widget))))
558
e02f48d7 559(defun ada-prj-display-help (widget _widget-modified event)
d759dcce
JB
560 "Callback for help button in WIDGET.
561Parameters WIDGET-MODIFIED, EVENT match :notify for the widget."
c6fa13e3
GM
562 (let ((text (widget-get widget 'prj-help)))
563 (if event
564 ;; If we have a mouse-event, popup a menu
565 (widget-choose "Help"
566 (mapcar (lambda (a) (cons a t))
567 (split-string text "\n"))
568 event)
569 ;; Else display the help string just before the next group of
570 ;; variables
571 (momentary-string-display
572 (concat "*****Help*****\n" text "\n**************\n")
e180ab9f 573 (point-at-bol 2)))))
c6fa13e3 574
e02f48d7 575(defun ada-prj-show-value (widget _widget-modified event)
d759dcce
JB
576 "Show the current field value in WIDGET.
577Parameters WIDGET-MODIFIED, EVENT match :notify for the widget."
da2a1edf
SM
578 (let* ((field (widget-get widget ':prj-field))
579 (value (plist-get ada-prj-current-values field))
580 (inhibit-read-only t)
581 w)
c6fa13e3
GM
582
583 ;; If the other widget is already visible, delete it
584 (if (widget-get widget 'prj-other-widget)
585 (progn
586 (widget-delete (widget-get widget 'prj-other-widget))
587 (widget-put widget 'prj-other-widget nil)
da2a1edf 588 (widget-put widget ':prj-field field)
c6fa13e3
GM
589 (widget-default-value-set widget "Show Value")
590 )
591
592 ;; Else create it
593 (save-excursion
594 (mouse-set-point event)
595 (forward-line 1)
596 (beginning-of-line)
da2a1edf
SM
597 (setq w (widget-create 'editable-list
598 :entry-format "%i%d %v"
599 :notify 'ada-prj-field-modified
600 :help-echo (widget-get widget 'prj-help)
601 :value value
602 (list 'editable-field :keymap widget-keymap)))
603 (widget-put widget 'prj-other-widget w)
604 (widget-put w ':prj-field field)
605 (widget-put widget ':prj-field field)
c6fa13e3
GM
606 (widget-default-value-set widget "Hide Value")
607 )
608 )
609 (widget-setup)
610 ))
611
612(defun ada-prj-field (field text help-text &optional is-list is-paths after-text)
613 "Create a widget to edit FIELD in the current buffer.
614TEXT is a short explanation of what the field means, whereas HELP-TEXT
615is the text displayed when the user pressed the help button.
32b1a27f 616If IS-LIST is non-nil, the field contains a list. Otherwise, it contains
c6fa13e3 617a single string.
32b1a27f 618If IS-PATHS is true, some special buttons are added to load paths,...
c6fa13e3
GM
619AFTER-TEXT is inserted just after the widget."
620 (let ((value (plist-get ada-prj-current-values field))
621 (inhibit-read-only t)
622 widget)
623 (unless value
624 (set 'value
625 (if is-list '() "")))
626 (widget-insert text)
627 (widget-insert ":")
628 (move-to-column 54 t)
629 (widget-put (widget-create 'push-button
630 :notify 'ada-prj-display-help
631 "Help")
632 'prj-help
633 help-text)
634 (widget-insert (concat " (" (symbol-name field) ")\n"))
635 (if is-paths
636 (progn
637 (widget-create 'push-button
638 :notify
639 (list 'lambda '(&rest dummy) '(interactive)
640 (list 'ada-prj-load-from-file
641 (list 'quote field)))
642 "Load From File")
643 (widget-insert " ")
644 (widget-create 'push-button
645 :notify
646 (list 'lambda '(&rest dummy) '(interactive)
647 (list 'ada-prj-load-directory
648 (list 'quote field)))
649 "Load Recursive Directory")
650 (widget-insert "\n ${build_dir}\n")))
da2a1edf 651
c6fa13e3
GM
652 (set 'widget
653 (if is-list
654 (if (< (length value) 15)
655 (widget-create 'editable-list
656 :entry-format "%i%d %v"
657 :notify 'ada-prj-field-modified
658 :help-echo help-text
659 :value value
660 (list 'editable-field :keymap widget-keymap))
da2a1edf 661
c6fa13e3
GM
662 (let ((w (widget-create 'push-button
663 :notify 'ada-prj-show-value
664 "Show value")))
665 (widget-insert "\n")
c6fa13e3
GM
666 (widget-put w 'prj-help help-text)
667 (widget-put w 'prj-other-widget nil)
668 w)
669 )
670 (widget-create 'editable-field
671 :format "%v"
672 :notify 'ada-prj-field-modified
673 :help-echo help-text
674 :keymap widget-keymap
675 value)))
da2a1edf 676 (widget-put widget ':prj-field field)
c6fa13e3
GM
677 (if after-text
678 (widget-insert after-text))
679 (widget-insert "\n")
680 ))
d41832c5 681
d41832c5 682
d41832c5 683(provide 'ada-prj)
3afbc435
PJ
684
685;;; ada-prj.el ends here