aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2006-11-14 16:19:48 +0000
committerJuanma Barranquero2006-11-14 16:19:48 +0000
commit85187d83684bb1796072e25a66a57e9730abbf22 (patch)
treefa989a87b6c70aa62fcbb0b40b93a253cce10d12
parentd4ee31d348048e7327c6542a814706f817f5bcac (diff)
downloademacs-85187d83684bb1796072e25a66a57e9730abbf22.tar.gz
emacs-85187d83684bb1796072e25a66a57e9730abbf22.zip
(ada-parse-prj-file): Don't delete project buffer; user may want to edit it.
(ada-xref-set-project-field, ada-xref-current-project-file, ada-xref-current-project, ada-show-current-project, ada-set-main-compile-application): New functions. (ada-xref-get-project-field, ada-require-project-file): Normalize use of ada-prj-default-project-file. (ada-gdb-application, ada-get-ada-file-name, ada-make-body-gnatstub): Normalize use of ada-require-project-file. (ada-prj-find-prj-file): Improve doc string, comments.
-rw-r--r--lisp/progmodes/ada-xref.el123
1 files changed, 76 insertions, 47 deletions
diff --git a/lisp/progmodes/ada-xref.el b/lisp/progmodes/ada-xref.el
index 1ee89027975..a24dbfffd6c 100644
--- a/lisp/progmodes/ada-xref.el
+++ b/lisp/progmodes/ada-xref.el
@@ -421,24 +421,10 @@ Note that for src_dir and obj_dir, you should rather use
421`ada-xref-get-src-dir-field' or `ada-xref-get-obj-dir-field' which will in 421`ada-xref-get-src-dir-field' or `ada-xref-get-obj-dir-field' which will in
422addition return the default paths." 422addition return the default paths."
423 423
424 (let ((file-name ada-prj-default-project-file) 424 (let* ((project-plist (cdr (ada-xref-current-project)))
425 file value) 425 value)
426 426
427 ;; Get the project file (either the current one, or a default one) 427 (set 'value (plist-get project-plist field))
428 (setq file (or (assoc file-name ada-xref-project-files)
429 (assoc nil ada-xref-project-files)))
430
431 ;; If the file was not found, use the default values
432 (if file
433 ;; Get the value from the file
434 (set 'value (plist-get (cdr file) field))
435
436 ;; Create a default nil file that contains the default values
437 (ada-xref-set-default-prj-values 'value (current-buffer))
438 (add-to-list 'ada-xref-project-files (cons nil value))
439 (ada-xref-update-project-menu)
440 (set 'value (plist-get value field))
441 )
442 428
443 ;; Substitute the ${...} constructs in all the strings, including 429 ;; Substitute the ${...} constructs in all the strings, including
444 ;; inside lists 430 ;; inside lists
@@ -484,6 +470,15 @@ All the directories are returned as absolute directories."
484 ;; Add the standard runtime at the end 470 ;; Add the standard runtime at the end
485 ada-xref-runtime-library-ali-path))) 471 ada-xref-runtime-library-ali-path)))
486 472
473(defun ada-xref-set-project-field (field value)
474 "Set FIELD to VALUE in current project. Assumes project exists."
475 ;; same algorithm to find project-plist as ada-xref-current-project
476 (let* ((file-name (ada-xref-current-project-file))
477 (project-plist (cdr (assoc file-name ada-xref-project-files))))
478
479 (setq project-plist (plist-put project-plist field value))
480 (setcdr (assoc file-name ada-xref-project-files) project-plist)))
481
487(defun ada-xref-update-project-menu () 482(defun ada-xref-update-project-menu ()
488 "Update the menu Ada->Project, with the list of available project files." 483 "Update the menu Ada->Project, with the list of available project files."
489 ;; Create the standard items. 484 ;; Create the standard items.
@@ -571,12 +566,36 @@ Completion is available."
571;; ----- Utilities ------------------------------------------------- 566;; ----- Utilities -------------------------------------------------
572 567
573(defun ada-require-project-file () 568(defun ada-require-project-file ()
574 "If no project file is currently active, load a default one." 569 "If the current project does not exist, load or create a default one.
575 (if (or (not ada-prj-default-project-file) 570Should only be called from interactive functions."
576 (not ada-xref-project-files) 571 (if (not (ada-xref-current-project t))
577 (string= ada-prj-default-project-file ""))
578 (ada-reread-prj-file))) 572 (ada-reread-prj-file)))
579 573
574(defun ada-xref-current-project-file (&optional no-user-question)
575 "Return the current project file name; never nil unless NO-USER-QUESTION.
576If NO-USER-QUESTION, don't prompt user for file. Call
577`ada-require-project-file' first if a project must exist."
578 (if (not (string= "" ada-prj-default-project-file))
579 ada-prj-default-project-file
580 (ada-prj-find-prj-file nil no-user-question)))
581
582(defun ada-xref-current-project (&optional no-user-question)
583 "Return the current project; nil if none.
584If NO-USER-QUESTION, don't prompt user for file. Call
585`ada-require-project-file' first if a project must exist."
586 (let* ((file-name (ada-xref-current-project-file no-user-question)))
587 (assoc file-name ada-xref-project-files)))
588
589(defun ada-show-current-project ()
590 "Display current project file name in message buffer."
591 (interactive)
592 (message (ada-xref-current-project-file)))
593
594(defun ada-show-current-main ()
595 "Display current main unit name in message buffer."
596 (interactive)
597 (message "ada-mode main_unit: %s" (ada-xref-get-project-field 'main_unit)))
598
580(defun ada-xref-push-pos (filename position) 599(defun ada-xref-push-pos (filename position)
581 "Push (FILENAME, POSITION) on the position ring for cross-references." 600 "Push (FILENAME, POSITION) on the position ring for cross-references."
582 (setq ada-xref-pos-ring (cons (list position filename) ada-xref-pos-ring)) 601 (setq ada-xref-pos-ring (cons (list position filename) ada-xref-pos-ring))
@@ -614,21 +633,23 @@ a project file unless the user has already loaded one."
614;; ------ Handling the project file ----------------------------- 633;; ------ Handling the project file -----------------------------
615 634
616(defun ada-prj-find-prj-file (&optional file no-user-question) 635(defun ada-prj-find-prj-file (&optional file no-user-question)
617 "Find the prj file associated with FILE (or the current buffer if nil). 636 "Find the project file associated with FILE (or the current buffer if nil).
618If NO-USER-QUESTION is non-nil, use a default file if not project file was 637If the buffer is not in Ada mode, or not associated with a file,
619found, and do not ask the user. 638return `ada-prj-default-project-file'. Otherwise, search for a file with
620If the buffer is not an Ada buffer, associate it with the default project 639the same base name as the Ada file, but extension given by
621file. If none is set, return nil." 640`ada-prj-file-extension' (default .adp). If not found, search for *.adp
641in the current directory; if several are found, and NO-USER-QUESTION
642is non-nil, prompt the user to select one. If none are found, return
643'default.adp'."
622 644
623 (let (selected) 645 (let (selected)
624 646
625 ;; Use the active project file if there is one.
626 ;; This is also valid if we don't currently have an Ada buffer, or if
627 ;; the current buffer is not a real file (for instance an emerge buffer)
628
629 (if (or (not (string= mode-name "Ada")) 647 (if (or (not (string= mode-name "Ada"))
630 (not (buffer-file-name))) 648 (not (buffer-file-name)))
631 649
650 ;; Not in an Ada buffer, or current buffer not associated
651 ;; with a file (for instance an emerge buffer)
652
632 (if (and ada-prj-default-project-file 653 (if (and ada-prj-default-project-file
633 (not (string= ada-prj-default-project-file ""))) 654 (not (string= ada-prj-default-project-file "")))
634 (setq selected ada-prj-default-project-file) 655 (setq selected ada-prj-default-project-file)
@@ -653,17 +674,16 @@ file. If none is set, return nil."
653 674
654 (cond 675 (cond
655 676
656 ;; Else if there is a project file with the same name as the Ada
657 ;; file, but not the same extension.
658 ((file-exists-p first-choice) 677 ((file-exists-p first-choice)
678 ;; filename.adp
659 (set 'selected first-choice)) 679 (set 'selected first-choice))
660 680
661 ;; Else if only one project file was found in the current directory
662 ((= (length prj-files) 1) 681 ((= (length prj-files) 1)
682 ;; Exactly one project file was found in the current directory
663 (set 'selected (car prj-files))) 683 (set 'selected (car prj-files)))
664 684
665 ;; Else if there are multiple files, ask the user
666 ((and (> (length prj-files) 1) (not no-user-question)) 685 ((and (> (length prj-files) 1) (not no-user-question))
686 ;; multiple project files in current directory, ask the user
667 (save-window-excursion 687 (save-window-excursion
668 (with-output-to-temp-buffer "*choice list*" 688 (with-output-to-temp-buffer "*choice list*"
669 (princ "There are more than one possible project file.\n") 689 (princ "There are more than one possible project file.\n")
@@ -688,10 +708,8 @@ file. If none is set, return nil."
688 (read-from-minibuffer "Enter No. of your choice: ")))) 708 (read-from-minibuffer "Enter No. of your choice: "))))
689 (set 'selected (nth (1- choice) prj-files)))) 709 (set 'selected (nth (1- choice) prj-files))))
690 710
691 ;; Else if no project file was found in the directory, ask a name
692 ;; to the user, using as a default value the last one entered by
693 ;; the user
694 ((= (length prj-files) 0) 711 ((= (length prj-files) 0)
712 ;; No project file in the current directory; ask user
695 (unless (or no-user-question (not ada-always-ask-project)) 713 (unless (or no-user-question (not ada-always-ask-project))
696 (setq ada-last-prj-file 714 (setq ada-last-prj-file
697 (read-file-name 715 (read-file-name
@@ -791,8 +809,6 @@ file. If none is set, return nil."
791 (if debug_pre_cmd (set 'project (plist-put project 'debug_pre_cmd 809 (if debug_pre_cmd (set 'project (plist-put project 'debug_pre_cmd
792 (reverse debug_pre_cmd)))) 810 (reverse debug_pre_cmd))))
793 811
794 ;; Kill the project buffer
795 (kill-buffer nil)
796 (set-buffer ada-buffer) 812 (set-buffer ada-buffer)
797 ) 813 )
798 814
@@ -1128,6 +1144,24 @@ If ARG is not nil, ask for user confirmation."
1128 1144
1129 (compile (ada-quote-cmd cmd)))) 1145 (compile (ada-quote-cmd cmd))))
1130 1146
1147(defun ada-set-main-compile-application ()
1148 "Set main_unit and main project variables to current buffer, build main."
1149 (interactive)
1150 (ada-require-project-file)
1151 (let* ((file (buffer-file-name (current-buffer)))
1152 main)
1153 (if (not file)
1154 (error "No file for current buffer")
1155
1156 (setq main
1157 (if file
1158 (file-name-nondirectory
1159 (file-name-sans-extension file))
1160 ""))
1161 (ada-xref-set-project-field 'main main)
1162 (ada-xref-set-project-field 'main_unit main)
1163 (ada-compile-application))))
1164
1131(defun ada-compile-current (&optional arg prj-field) 1165(defun ada-compile-current (&optional arg prj-field)
1132 "Recompile the current file. 1166 "Recompile the current file.
1133If ARG is not nil, ask for user confirmation of the command. 1167If ARG is not nil, ask for user confirmation of the command.
@@ -1214,9 +1248,9 @@ If ARG is non-nil, ask the user to confirm the command.
1214EXECUTABLE-NAME, if non-nil, is debugged instead of the file specified in the 1248EXECUTABLE-NAME, if non-nil, is debugged instead of the file specified in the
1215project file." 1249project file."
1216 (interactive "P") 1250 (interactive "P")
1251 (ada-require-project-file)
1217 (let ((buffer (current-buffer)) 1252 (let ((buffer (current-buffer))
1218 cmd pre-cmd post-cmd) 1253 cmd pre-cmd post-cmd)
1219 (ada-require-project-file)
1220 (setq cmd (if executable-name 1254 (setq cmd (if executable-name
1221 (concat ada-prj-default-debugger " " executable-name) 1255 (concat ada-prj-default-debugger " " executable-name)
1222 (ada-xref-get-project-field 'debug_cmd)) 1256 (ada-xref-get-project-field 'debug_cmd))
@@ -1515,8 +1549,7 @@ file for possible paths."
1515 (let ((buffer (get-file-buffer original-file))) 1549 (let ((buffer (get-file-buffer original-file)))
1516 (if buffer 1550 (if buffer
1517 (set-buffer buffer) 1551 (set-buffer buffer)
1518 (find-file original-file) 1552 (find-file original-file)))
1519 (ada-require-project-file)))
1520 1553
1521 ;; we choose the first possible completion and we 1554 ;; we choose the first possible completion and we
1522 ;; return the absolute file name 1555 ;; return the absolute file name
@@ -2181,6 +2214,7 @@ This is a GNAT specific function that uses gnatkrunch."
2181This function uses the `gnatstub' program to create the body. 2214This function uses the `gnatstub' program to create the body.
2182This function typically is to be hooked into `ff-file-created-hooks'." 2215This function typically is to be hooked into `ff-file-created-hooks'."
2183 (interactive "p") 2216 (interactive "p")
2217 (ada-require-project-file)
2184 2218
2185 (save-some-buffers nil nil) 2219 (save-some-buffers nil nil)
2186 2220
@@ -2198,11 +2232,6 @@ This function typically is to be hooked into `ff-file-created-hooks'."
2198 (unless (buffer-file-name (car (buffer-list))) 2232 (unless (buffer-file-name (car (buffer-list)))
2199 (set-buffer (cadr (buffer-list)))) 2233 (set-buffer (cadr (buffer-list))))
2200 2234
2201 ;; Make sure we have a project file (for parameters to gnatstub). Note that
2202 ;; this might have already been done if we have been called from the hook,
2203 ;; but this is not an expensive call)
2204 (ada-require-project-file)
2205
2206 ;; Call the external process gnatstub 2235 ;; Call the external process gnatstub
2207 (let* ((gnatstub-opts (ada-treat-cmd-string ada-gnatstub-opts)) 2236 (let* ((gnatstub-opts (ada-treat-cmd-string ada-gnatstub-opts))
2208 (filename (buffer-file-name (car (buffer-list)))) 2237 (filename (buffer-file-name (car (buffer-list))))