Commit | Line | Data |
---|---|---|
acc33231 CY |
1 | ;;; ede.el --- Emacs Development Environment gloss |
2 | ||
3 | ;;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, | |
4 | ;;; 2007, 2008, 2009 Free Software Foundation, Inc. | |
5 | ||
6 | ;; Author: Eric M. Ludlam <zappo@gnu.org> | |
7 | ;; Keywords: project, make | |
8 | ||
9 | ;; This file is part of GNU Emacs. | |
10 | ||
11 | ;; GNU Emacs is free software: you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
13 | ;; the Free Software Foundation, either version 3 of the License, or | |
14 | ;; (at your option) any later version. | |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
22 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. | |
23 | ||
24 | ;;; Commentary: | |
25 | ;; | |
26 | ;; EDE is the top level Lisp interface to a project management scheme | |
27 | ;; for Emacs. Emacs does many things well, including editing, | |
28 | ;; building, and debugging. Folks migrating from other IDEs don't | |
29 | ;; seem to think this qualifies, however, because they still have to | |
30 | ;; write the makefiles, and specify parameters to programs. | |
31 | ;; | |
32 | ;; This EDE mode will attempt to link these diverse programs together | |
33 | ;; into a comprehensive single interface, instead of a bunch of | |
34 | ;; different ones. | |
35 | ||
36 | ;;; Install | |
37 | ;; | |
38 | ;; This command enables project mode on all files. | |
39 | ;; | |
40 | ;; (global-ede-mode t) | |
41 | ||
715f35a5 | 42 | (require 'cedet) |
acc33231 CY |
43 | (require 'eieio) |
44 | (require 'eieio-speedbar) | |
45 | (require 'ede/source) | |
46 | (require 'ede/loaddefs) | |
47 | ||
48 | (declare-function ede-convert-path "ede/files") | |
49 | (declare-function ede-directory-get-open-project "ede/files") | |
50 | (declare-function ede-directory-get-toplevel-open-project "ede/files") | |
51 | (declare-function ede-directory-project-p "ede/files") | |
52 | (declare-function ede-find-subproject-for-directory "ede/files") | |
53 | (declare-function ede-project-directory-remove-hash "ede/files") | |
54 | (declare-function ede-project-root "ede/files") | |
55 | (declare-function ede-project-root-directory "ede/files") | |
56 | (declare-function ede-toplevel "ede/files") | |
57 | (declare-function ede-toplevel-project "ede/files") | |
58 | (declare-function ede-up-directory "ede/files") | |
59 | (declare-function data-debug-new-buffer "data-debug") | |
60 | (declare-function data-debug-insert-object-slots "eieio-datadebug") | |
61 | (declare-function semantic-lex-make-spp-table "semantic/lex-spp") | |
62 | ||
63 | (defconst ede-version "1.0pre7" | |
64 | "Current version of the Emacs EDE.") | |
65 | ||
66 | ;;; Code: | |
67 | (defun ede-version () | |
68 | "Display the current running version of EDE." | |
69 | (interactive) (message "EDE %s" ede-version)) | |
70 | ||
71 | (defgroup ede nil | |
72 | "Emacs Development Environment gloss." | |
73 | :group 'tools | |
74 | :group 'convenience | |
75 | ) | |
76 | ||
77 | (defcustom ede-auto-add-method 'ask | |
78 | "Whether a new source file shoud be automatically added to a target. | |
79 | Whenever a new file is encountered in a directory controlled by a | |
80 | project file, all targets are queried to see if it should be added. | |
81 | If the value is 'always, then the new file is added to the first | |
82 | target encountered. If the value is 'multi-ask, then if more than one | |
83 | target wants the file, the user is asked. If only one target wants | |
84 | the file, then then it is automatically added to that target. If the | |
85 | value is 'ask, then the user is always asked, unless there is no | |
86 | target willing to take the file. 'never means never perform the check." | |
87 | :group 'ede | |
88 | :type '(choice (const always) | |
89 | (const multi-ask) | |
90 | (const ask) | |
91 | (const never))) | |
92 | ||
93 | (defcustom ede-debug-program-function 'gdb | |
94 | "Default Emacs command used to debug a target." | |
95 | :group 'ede | |
96 | :type 'sexp) ; make this be a list of options some day | |
97 | ||
98 | ||
99 | ;;; Top level classes for projects and targets | |
100 | ||
101 | (defclass ede-project-autoload () | |
102 | ((name :initarg :name | |
103 | :documentation "Name of this project type") | |
104 | (file :initarg :file | |
105 | :documentation "The lisp file belonging to this class.") | |
106 | (proj-file :initarg :proj-file | |
107 | :documentation "Name of a project file of this type.") | |
108 | (proj-root :initarg :proj-root | |
109 | :type function | |
110 | :documentation "A function symbol to call for the project root. | |
111 | This function takes no arguments, and returns the current directories | |
112 | root, if available. Leave blank to use the EDE directory walking | |
113 | routine instead.") | |
114 | (initializers :initarg :initializers | |
115 | :initform nil | |
116 | :documentation | |
117 | "Initializers passed to the project object. | |
118 | These are used so there can be multiple types of projects | |
119 | associated with a single object class, based on the initilizeres used.") | |
120 | (load-type :initarg :load-type | |
121 | :documentation "Fn symbol used to load this project file.") | |
122 | (class-sym :initarg :class-sym | |
123 | :documentation "Symbol representing the project class to use.") | |
124 | (new-p :initarg :new-p | |
125 | :initform t | |
126 | :documentation | |
127 | "Non-nil if this is an option when a user creates a project.") | |
128 | ) | |
129 | "Class representing minimal knowledge set to run preliminary EDE functions. | |
130 | When more advanced functionality is needed from a project type, that projects | |
131 | type is required and the load function used.") | |
132 | ||
133 | (defvar ede-project-class-files | |
134 | (list | |
135 | (ede-project-autoload "edeproject-makefile" | |
136 | :name "Make" :file 'ede/proj | |
137 | :proj-file "Project.ede" | |
138 | :load-type 'ede-proj-load | |
139 | :class-sym 'ede-proj-project) | |
140 | (ede-project-autoload "edeproject-automake" | |
141 | :name "Automake" :file 'ede/proj | |
142 | :proj-file "Project.ede" | |
143 | :initializers '(:makefile-type Makefile.am) | |
144 | :load-type 'ede-proj-load | |
145 | :class-sym 'ede-proj-project) | |
146 | (ede-project-autoload "automake" | |
147 | :name "automake" :file 'ede/project-am | |
148 | :proj-file "Makefile.am" | |
149 | :load-type 'project-am-load | |
150 | :class-sym 'project-am-makefile | |
151 | :new-p nil) | |
152 | (ede-project-autoload "cpp-root" | |
153 | :name "CPP ROOT" :file 'ede/cpp-root | |
154 | :proj-file 'ede-cpp-root-project-file-for-dir | |
155 | :proj-root 'ede-cpp-root-project-root | |
156 | :load-type 'ede-cpp-root-load | |
157 | :class-sym 'ede-cpp-root | |
158 | :new-p nil) | |
159 | (ede-project-autoload "emacs" | |
160 | :name "EMACS ROOT" :file 'ede/emacs | |
161 | :proj-file "src/emacs.c" | |
162 | :proj-root 'ede-emacs-project-root | |
163 | :load-type 'ede-emacs-load | |
164 | :class-sym 'ede-emacs-project | |
165 | :new-p nil) | |
166 | (ede-project-autoload "linux" | |
167 | :name "LINUX ROOT" :file 'ede/linux | |
168 | :proj-file "scripts/ver_linux" | |
169 | :proj-root 'ede-linux-project-root | |
170 | :load-type 'ede-linux-load | |
171 | :class-sym 'ede-linux-project | |
172 | :new-p nil) | |
173 | (ede-project-autoload "simple-overlay" | |
174 | :name "Simple" :file 'ede/simple | |
175 | :proj-file 'ede-simple-projectfile-for-dir | |
176 | :load-type 'ede-simple-load | |
177 | :class-sym 'ede-simple-project)) | |
178 | "List of vectos defining how to determine what type of projects exist.") | |
179 | ||
180 | ;;; Generic project information manager objects | |
181 | ||
182 | (defclass ede-target (eieio-speedbar-directory-button) | |
183 | ((buttonface :initform speedbar-file-face) ;override for superclass | |
184 | (name :initarg :name | |
185 | :type string | |
186 | :custom string | |
187 | :label "Name" | |
188 | :group (default name) | |
189 | :documentation "Name of this target.") | |
190 | ;; @todo - I think this should be "dir", and not "path". | |
191 | (path :initarg :path | |
192 | :type string | |
193 | ;:custom string | |
194 | ;:label "Path to target" | |
195 | ;:group (default name) | |
196 | :documentation "The path to the sources of this target. | |
197 | Relative to the path of the project it belongs to.") | |
198 | (source :initarg :source | |
199 | :initform nil | |
200 | ;; I'd prefer a list of strings. | |
201 | :type list | |
202 | :custom (repeat (string :tag "File")) | |
203 | :label "Source Files" | |
204 | :group (default source) | |
205 | :documentation "Source files in this target.") | |
206 | (versionsource :initarg :versionsource | |
207 | :initform nil | |
208 | :type list | |
209 | :custom (repeat (string :tag "File")) | |
210 | :label "Source Files with Version String" | |
211 | :group (source) | |
212 | :documentation | |
213 | "Source files with a version string in them. | |
214 | These files are checked for a version string whenever the EDE version | |
215 | of the master project is changed. When strings are found, the version | |
216 | previously there is updated.") | |
217 | ;; Class level slots | |
218 | ;; | |
219 | ; (takes-compile-command :allocation :class | |
220 | ; :initarg :takes-compile-command | |
221 | ; :type boolean | |
222 | ; :initform nil | |
223 | ; :documentation | |
224 | ; "Non-nil if this target requires a user approved command.") | |
225 | (sourcetype :allocation :class | |
226 | :type list ;; list of symbols | |
227 | :documentation | |
228 | "A list of `ede-sourcecode' objects this class will handle. | |
229 | This is used to match target objects with the compilers they can use, and | |
230 | which files this object is interested in." | |
231 | :accessor ede-object-sourcecode) | |
232 | (keybindings :allocation :class | |
233 | :initform (("D" . ede-debug-target)) | |
234 | :documentation | |
235 | "Keybindings specialized to this type of target." | |
236 | :accessor ede-object-keybindings) | |
237 | (menu :allocation :class | |
238 | :initform ( [ "Debug target" ede-debug-target | |
239 | (and ede-object | |
240 | (obj-of-class-p ede-object ede-target)) ] | |
241 | ) | |
242 | :documentation "Menu specialized to this type of target." | |
243 | :accessor ede-object-menu) | |
244 | ) | |
245 | "A top level target to build.") | |
246 | ||
247 | (defclass ede-project-placeholder (eieio-speedbar-directory-button) | |
248 | ((name :initarg :name | |
249 | :initform "Untitled" | |
250 | :type string | |
251 | :custom string | |
252 | :label "Name" | |
253 | :group (default name) | |
254 | :documentation "The name used when generating distribution files.") | |
255 | (version :initarg :version | |
256 | :initform "1.0" | |
257 | :type string | |
258 | :custom string | |
259 | :label "Version" | |
260 | :group (default name) | |
261 | :documentation "The version number used when distributing files.") | |
262 | (directory :type string | |
263 | :initarg :directory | |
264 | :documentation "Directory this project is associated with.") | |
265 | (dirinode :documentation "The inode id for :directory.") | |
266 | (file :type string | |
267 | :initarg :file | |
268 | :documentation "File name where this project is stored.") | |
269 | (rootproject ; :initarg - no initarg, don't save this slot! | |
270 | :initform nil | |
271 | :type (or null ede-project-placeholder-child) | |
272 | :documentation "Pointer to our root project.") | |
273 | ) | |
274 | "Placeholder object for projects not loaded into memory. | |
275 | Projects placeholders will be stored in a user specific location | |
276 | and querying them will cause the actual project to get loaded.") | |
277 | ||
278 | (defclass ede-project (ede-project-placeholder) | |
279 | ((subproj :initform nil | |
280 | :type list | |
281 | :documentation "Sub projects controlled by this project. | |
282 | For Automake based projects, each directory is treated as a project.") | |
283 | (targets :initarg :targets | |
284 | :type list | |
285 | :custom (repeat (object :objectcreatefcn ede-new-target-custom)) | |
286 | :label "Local Targets" | |
287 | :group (targets) | |
288 | :documentation "List of top level targets in this project.") | |
289 | (locate-obj :type (or null ede-locate-base-child) | |
290 | :documentation | |
291 | "A locate object to use as a backup to `ede-expand-filename'.") | |
292 | (tool-cache :initarg :tool-cache | |
293 | :type list | |
294 | :custom (repeat object) | |
295 | :label "Tool: " | |
296 | :group tools | |
297 | :documentation "List of tool cache configurations in this project. | |
298 | This allows any tool to create, manage, and persist project-specific settings.") | |
299 | (mailinglist :initarg :mailinglist | |
300 | :initform "" | |
301 | :type string | |
302 | :custom string | |
303 | :label "Mailing List Address" | |
304 | :group name | |
305 | :documentation | |
306 | "An email address where users might send email for help.") | |
307 | (web-site-url :initarg :web-site-url | |
308 | :initform "" | |
309 | :type string | |
310 | :custom string | |
311 | :label "Web Site URL" | |
312 | :group name | |
313 | :documentation "URL to this projects web site. | |
314 | This is a URL to be sent to a web site for documentation.") | |
315 | (web-site-directory :initarg :web-site-directory | |
316 | :initform "" | |
317 | :custom string | |
318 | :label "Web Page Directory" | |
319 | :group name | |
320 | :documentation | |
321 | "A directory where web pages can be found by Emacs. | |
322 | For remote locations use a path compatible with ange-ftp or EFS. | |
323 | You can also use TRAMP for use with rcp & scp.") | |
324 | (web-site-file :initarg :web-site-file | |
325 | :initform "" | |
326 | :custom string | |
327 | :label "Web Page File" | |
328 | :group name | |
329 | :documentation | |
330 | "A file which contains the home page for this project. | |
331 | This file can be relative to slot `web-site-directory'. | |
332 | This can be a local file, use ange-ftp, EFS, or TRAMP.") | |
333 | (ftp-site :initarg :ftp-site | |
334 | :initform "" | |
335 | :type string | |
336 | :custom string | |
337 | :label "FTP site" | |
338 | :group name | |
339 | :documentation | |
340 | "FTP site where this project's distribution can be found. | |
341 | This FTP site should be in Emacs form, as needed by `ange-ftp', but can | |
342 | also be of a form used by TRAMP for use with scp, or rcp.") | |
343 | (ftp-upload-site :initarg :ftp-upload-site | |
344 | :initform "" | |
345 | :type string | |
346 | :custom string | |
347 | :label "FTP Upload site" | |
348 | :group name | |
349 | :documentation | |
350 | "FTP Site to upload new distributions to. | |
351 | This FTP site should be in Emacs form as needed by `ange-ftp'. | |
352 | If this slot is nil, then use `ftp-site' instead.") | |
353 | (configurations :initarg :configurations | |
354 | :initform ("debug" "release") | |
355 | :type list | |
356 | :custom (repeat string) | |
357 | :label "Configuration Options" | |
358 | :group (settings) | |
359 | :documentation "List of available configuration types. | |
360 | Individual target/project types can form associations between a configuration, | |
361 | and target specific elements such as build variables.") | |
362 | (configuration-default :initarg :configuration-default | |
363 | :initform "debug" | |
364 | :custom string | |
365 | :label "Current Configuration" | |
366 | :group (settings) | |
367 | :documentation "The default configuration.") | |
368 | (local-variables :initarg :local-variables | |
369 | :initform nil | |
370 | :custom (repeat (cons (sexp :tag "Variable") | |
371 | (sexp :tag "Value"))) | |
372 | :label "Project Local Variables" | |
373 | :group (settings) | |
374 | :documentation "Project local variables") | |
375 | (keybindings :allocation :class | |
376 | :initform (("D" . ede-debug-target)) | |
377 | :documentation "Keybindings specialized to this type of target." | |
378 | :accessor ede-object-keybindings) | |
379 | (menu :allocation :class | |
380 | :initform | |
381 | ( | |
382 | [ "Update Version" ede-update-version ede-object ] | |
383 | [ "Version Control Status" ede-vc-project-directory ede-object ] | |
384 | [ "Edit Project Homepage" ede-edit-web-page | |
385 | (and ede-object (oref (ede-toplevel) web-site-file)) ] | |
386 | [ "Browse Project URL" ede-web-browse-home | |
387 | (and ede-object | |
388 | (not (string= "" (oref (ede-toplevel) web-site-url)))) ] | |
389 | "--" | |
390 | [ "Rescan Project Files" ede-rescan-toplevel t ] | |
391 | [ "Edit Projectfile" ede-edit-file-target | |
392 | (and ede-object | |
393 | (or (listp ede-object) | |
394 | (not (obj-of-class-p ede-object ede-project)))) ] | |
395 | ) | |
396 | :documentation "Menu specialized to this type of target." | |
397 | :accessor ede-object-menu) | |
398 | ) | |
399 | "Top level EDE project specification. | |
400 | All specific project types must derive from this project." | |
401 | :method-invocation-order :depth-first) | |
402 | \f | |
403 | ;;; Management variables | |
404 | ||
405 | (defvar ede-projects nil | |
406 | "A list of all active projects currently loaded in Emacs.") | |
407 | ||
408 | (defvar ede-object-root-project nil | |
409 | "The current buffer's current root project. | |
410 | If a file is under a project, this specifies the project that is at | |
411 | the root of a project tree.") | |
412 | (make-variable-buffer-local 'ede-object-root-project) | |
413 | ||
414 | (defvar ede-object-project nil | |
415 | "The current buffer's current project at that level. | |
416 | If a file is under a project, this specifies the project that contains the | |
417 | current target.") | |
418 | (make-variable-buffer-local 'ede-object-project) | |
419 | ||
420 | (defvar ede-object nil | |
421 | "The current buffer's target object. | |
422 | This object's class determines how to compile and debug from a buffer.") | |
423 | (make-variable-buffer-local 'ede-object) | |
424 | ||
425 | (defvar ede-selected-object nil | |
426 | "The currently user-selected project or target. | |
427 | If `ede-object' is nil, then commands will operate on this object.") | |
428 | ||
429 | (defvar ede-constructing nil | |
430 | "Non nil when constructing a project hierarchy.") | |
431 | ||
432 | (defvar ede-deep-rescan nil | |
433 | "Non nil means scan down a tree, otherwise rescans are top level only. | |
434 | Do not set this to non-nil globally. It is used internally.") | |
435 | \f | |
436 | ;;; The EDE persistent cache. | |
437 | ;; | |
438 | (defcustom ede-project-placeholder-cache-file | |
439 | (expand-file-name "~/.projects.ede") | |
440 | "File containing the list of projects EDE has viewed." | |
441 | :group 'ede | |
442 | :type 'file) | |
443 | ||
444 | (defvar ede-project-cache-files nil | |
445 | "List of project files EDE has seen before.") | |
446 | ||
447 | (defun ede-save-cache () | |
448 | "Save a cache of EDE objects that Emacs has seen before." | |
449 | (interactive) | |
450 | (let ((p ede-projects) | |
451 | (c ede-project-cache-files) | |
452 | (recentf-exclude '(ignore)) | |
453 | ) | |
454 | (condition-case nil | |
455 | (progn | |
456 | (set-buffer (find-file-noselect ede-project-placeholder-cache-file t)) | |
457 | (erase-buffer) | |
458 | (insert ";; EDE project cache file. | |
459 | ;; This contains a list of projects you have visited.\n(") | |
460 | (while p | |
461 | (when (and (car p) (ede-project-p p)) | |
462 | (let ((f (oref (car p) file))) | |
463 | (when (file-exists-p f) | |
464 | (insert "\n \"" f "\"")))) | |
465 | (setq p (cdr p))) | |
466 | (while c | |
467 | (insert "\n \"" (car c) "\"") | |
468 | (setq c (cdr c))) | |
469 | (insert "\n)\n") | |
470 | (condition-case nil | |
471 | (save-buffer 0) | |
472 | (error | |
473 | (message "File %s could not be saved." | |
474 | ede-project-placeholder-cache-file))) | |
475 | (kill-buffer (current-buffer)) | |
476 | ) | |
477 | (error | |
478 | (message "File %s could not be read." | |
479 | ede-project-placeholder-cache-file)) | |
480 | ||
481 | ))) | |
482 | ||
483 | (defun ede-load-cache () | |
484 | "Load the cache of EDE projects." | |
485 | (save-excursion | |
486 | (let ((cachebuffer nil)) | |
487 | (condition-case nil | |
488 | (progn | |
489 | (setq cachebuffer | |
490 | (find-file-noselect ede-project-placeholder-cache-file t)) | |
491 | (set-buffer cachebuffer) | |
492 | (goto-char (point-min)) | |
493 | (let ((c (read (current-buffer))) | |
494 | (new nil) | |
495 | (p ede-projects)) | |
496 | ;; Remove loaded projects from the cache. | |
497 | (while p | |
498 | (setq c (delete (oref (car p) file) c)) | |
499 | (setq p (cdr p))) | |
500 | ;; Remove projects that aren't on the filesystem | |
501 | ;; anymore. | |
502 | (while c | |
503 | (when (file-exists-p (car c)) | |
504 | (setq new (cons (car c) new))) | |
505 | (setq c (cdr c))) | |
506 | ;; Save it | |
507 | (setq ede-project-cache-files (nreverse new)))) | |
508 | (error nil)) | |
509 | (when cachebuffer (kill-buffer cachebuffer)) | |
510 | ))) | |
511 | \f | |
512 | ;;; Important macros for doing commands. | |
513 | ;; | |
514 | (defmacro ede-with-projectfile (obj &rest forms) | |
515 | "For the project in which OBJ resides, execute FORMS." | |
516 | (list 'save-window-excursion | |
517 | (list 'let* (list | |
518 | (list 'pf | |
519 | (list 'if (list 'obj-of-class-p | |
520 | obj 'ede-target) | |
521 | ;; @todo -I think I can change | |
522 | ;; this to not need ede-load-project-file | |
523 | ;; but I'm not sure how to test well. | |
524 | (list 'ede-load-project-file | |
525 | (list 'oref obj 'path)) | |
526 | obj)) | |
527 | '(dbka (get-file-buffer (oref pf file)))) | |
528 | '(if (not dbka) (find-file (oref pf file)) | |
529 | (switch-to-buffer dbka)) | |
530 | (cons 'progn forms) | |
531 | '(if (not dbka) (kill-buffer (current-buffer)))))) | |
532 | (put 'ede-with-projectfile 'lisp-indent-function 1) | |
533 | ||
534 | \f | |
535 | ;;; Prompting | |
536 | ;; | |
537 | (defun ede-singular-object (prompt) | |
538 | "Using PROMPT, choose a single object from the current buffer." | |
539 | (if (listp ede-object) | |
540 | (ede-choose-object prompt ede-object) | |
541 | ede-object)) | |
542 | ||
543 | (defun ede-choose-object (prompt list-o-o) | |
544 | "Using PROMPT, ask the user which OBJECT to use based on the name field. | |
545 | Argument LIST-O-O is the list of objects to choose from." | |
546 | (let* ((al (object-assoc-list 'name list-o-o)) | |
547 | (ans (completing-read prompt al nil t))) | |
548 | (setq ans (assoc ans al)) | |
549 | (cdr ans))) | |
550 | \f | |
551 | ;;; Menu and Keymap | |
552 | ||
715f35a5 | 553 | (defvar ede-minor-mode-map |
acc33231 CY |
554 | (let ((map (make-sparse-keymap)) |
555 | (pmap (make-sparse-keymap))) | |
556 | (define-key pmap "e" 'ede-edit-file-target) | |
557 | (define-key pmap "a" 'ede-add-file) | |
558 | (define-key pmap "d" 'ede-remove-file) | |
559 | (define-key pmap "t" 'ede-new-target) | |
560 | (define-key pmap "g" 'ede-rescan-toplevel) | |
561 | (define-key pmap "s" 'ede-speedbar) | |
562 | (define-key pmap "l" 'ede-load-project-file) | |
563 | (define-key pmap "f" 'ede-find-file) | |
564 | (define-key pmap "C" 'ede-compile-project) | |
565 | (define-key pmap "c" 'ede-compile-target) | |
566 | (define-key pmap "\C-c" 'ede-compile-selected) | |
567 | (define-key pmap "D" 'ede-debug-target) | |
568 | ;; bind our submap into map | |
569 | (define-key map "\C-c." pmap) | |
570 | map) | |
571 | "Keymap used in project minor mode.") | |
572 | ||
715f35a5 CY |
573 | (defvar global-ede-mode-map |
574 | (let ((map (make-sparse-keymap))) | |
575 | (define-key map [menu-bar cedet-menu] | |
576 | (cons "Development" cedet-menu-map)) | |
577 | map) | |
578 | "Keymap used in `global-ede-mode'") | |
579 | ||
580 | ;; Activate the EDE items in cedet-menu-map | |
581 | ||
582 | (define-key cedet-menu-map [ede-find-file] | |
583 | '(menu-item "Find File in Project..." ede-find-file :enable ede-object)) | |
584 | (define-key cedet-menu-map [ede-speedbar] | |
585 | '(menu-item "View Project Tree" ede-speedbar :enable ede-object)) | |
586 | (define-key cedet-menu-map [ede] | |
587 | '(menu-item "Load Project" ede)) | |
588 | (define-key cedet-menu-map [ede-new] | |
589 | '(menu-item "Create Project" ede-new | |
590 | :enable (not ede-object))) | |
591 | (define-key cedet-menu-map [ede-target-options] | |
592 | '(menu-item "Target Options" ede-target-options | |
593 | :filter ede-target-forms-menu)) | |
594 | (define-key cedet-menu-map [ede-project-options] | |
595 | '(menu-item "Project Options" ede-project-options | |
596 | :filter ede-project-forms-menu)) | |
597 | (define-key cedet-menu-map [ede-build-forms-menu] | |
598 | '(menu-item "Build Project" ede-build-forms-menu | |
599 | :filter ede-build-forms-menu | |
600 | :enable ede-object)) | |
601 | (define-key cedet-menu-map [semantic-menu-separator] 'undefined) | |
602 | (define-key cedet-menu-map [cedet-menu-separator] 'undefined) | |
603 | (define-key cedet-menu-map [ede-menu-separator] '("--")) | |
acc33231 CY |
604 | |
605 | (defun ede-menu-obj-of-class-p (class) | |
606 | "Return non-nil if some member of `ede-object' is a child of CLASS." | |
607 | (if (listp ede-object) | |
608 | (ede-or (mapcar (lambda (o) (obj-of-class-p o class)) ede-object)) | |
609 | (obj-of-class-p ede-object class))) | |
610 | ||
611 | (defun ede-build-forms-menu (menu-def) | |
612 | "Create a sub menu for building different parts of an EDE system. | |
613 | Argument MENU-DEF is the menu definition to use." | |
614 | (easy-menu-filter-return | |
615 | (easy-menu-create-menu | |
616 | "Build Forms" | |
617 | (let ((obj (ede-current-project)) | |
618 | (newmenu nil) ;'([ "Build Selected..." ede-compile-selected t ])) | |
619 | targets | |
620 | targitems | |
621 | ede-obj | |
622 | (tskip nil)) | |
623 | (if (not obj) | |
624 | nil | |
625 | (setq targets (when (slot-boundp obj 'targets) | |
626 | (oref obj targets)) | |
627 | ede-obj (if (listp ede-object) ede-object (list ede-object))) | |
628 | ;; First, collect the build items from the project | |
629 | (setq newmenu (append newmenu (ede-menu-items-build obj t))) | |
630 | ;; Second, Declare the current target menu items | |
631 | (if (and ede-obj (ede-menu-obj-of-class-p ede-target)) | |
632 | (while ede-obj | |
633 | (setq newmenu (append newmenu | |
634 | (ede-menu-items-build (car ede-obj) t)) | |
635 | tskip (car ede-obj) | |
636 | ede-obj (cdr ede-obj)))) | |
637 | ;; Third, by name, enable builds for other local targets | |
638 | (while targets | |
639 | (unless (eq tskip (car targets)) | |
640 | (setq targitems (ede-menu-items-build (car targets) nil)) | |
641 | (setq newmenu | |
642 | (append newmenu | |
643 | (if (= 1 (length targitems)) | |
644 | targitems | |
645 | (cons (ede-name (car targets)) | |
646 | targitems)))) | |
647 | ) | |
648 | (setq targets (cdr targets))) | |
649 | ;; Fourth, build sub projects. | |
650 | ;; -- nerp | |
651 | ;; Fifth, Add make distribution | |
652 | (append newmenu (list [ "Make distribution" ede-make-dist t ])) | |
653 | ))))) | |
654 | ||
655 | (defun ede-target-forms-menu (menu-def) | |
656 | "Create a target MENU-DEF based on the object belonging to this buffer." | |
657 | (easy-menu-filter-return | |
658 | (easy-menu-create-menu | |
659 | "Target Forms" | |
660 | (let ((obj (or ede-selected-object ede-object))) | |
661 | (append | |
662 | '([ "Add File" ede-add-file (ede-current-project) ] | |
663 | [ "Remove File" ede-remove-file | |
664 | (and ede-object | |
665 | (or (listp ede-object) | |
666 | (not (obj-of-class-p ede-object ede-project)))) ] | |
667 | "-") | |
668 | (if (not obj) | |
669 | nil | |
670 | (if (and (not (listp obj)) (oref obj menu)) | |
671 | (oref obj menu) | |
672 | (when (listp obj) | |
673 | ;; This is bad, but I'm not sure what else to do. | |
674 | (oref (car obj) menu))))))))) | |
675 | ||
676 | (defun ede-project-forms-menu (menu-def) | |
677 | "Create a target MENU-DEF based on the object belonging to this buffer." | |
678 | (easy-menu-filter-return | |
679 | (easy-menu-create-menu | |
680 | "Project Forms" | |
681 | (let* ((obj (ede-current-project)) | |
682 | (class (if obj (object-class obj))) | |
683 | (menu nil)) | |
684 | (condition-case err | |
685 | (progn | |
686 | (while (and class (slot-exists-p class 'menu)) | |
687 | ;;(message "Looking at class %S" class) | |
688 | (setq menu (append menu (oref class menu)) | |
689 | class (class-parent class)) | |
690 | (if (listp class) (setq class (car class)))) | |
691 | (append | |
692 | '( [ "Add Target" ede-new-target (ede-current-project) ] | |
693 | [ "Remove Target" ede-delete-target ede-object ] | |
694 | "-") | |
695 | menu | |
696 | )) | |
697 | (error (message "Err found: %S" err) | |
698 | menu) | |
699 | ))))) | |
700 | ||
701 | (defun ede-customize-forms-menu (menu-def) | |
702 | "Create a menu of the project, and targets that can be customized. | |
703 | Argument MENU-DEF is the definition of the current menu." | |
704 | (easy-menu-filter-return | |
705 | (easy-menu-create-menu | |
706 | "Customize Project" | |
707 | (let* ((obj (ede-current-project)) | |
8bf997ef | 708 | targ) |
acc33231 | 709 | (when obj |
8bf997ef CY |
710 | (setq targ (when (slot-boundp obj 'targets) |
711 | (oref obj targets))) | |
acc33231 CY |
712 | ;; Make custom menus for everything here. |
713 | (append (list | |
714 | (cons (concat "Project " (ede-name obj)) | |
715 | (eieio-customize-object-group obj)) | |
716 | [ "Reorder Targets" ede-project-sort-targets t ] | |
717 | ) | |
718 | (mapcar (lambda (o) | |
719 | (cons (concat "Target " (ede-name o)) | |
720 | (eieio-customize-object-group o))) | |
721 | targ))))))) | |
722 | ||
723 | ||
724 | (defun ede-apply-object-keymap (&optional default) | |
725 | "Add target specific keybindings into the local map. | |
726 | Optional argument DEFAULT indicates if this should be set to the default | |
727 | version of the keymap." | |
728 | (let ((object (or ede-object ede-selected-object))) | |
729 | (condition-case nil | |
730 | (let ((keys (ede-object-keybindings object))) | |
731 | (while keys | |
732 | (local-set-key (concat "\C-c." (car (car keys))) | |
733 | (cdr (car keys))) | |
734 | (setq keys (cdr keys)))) | |
735 | (error nil)))) | |
736 | ||
737 | ;;; Menu building methods for building | |
738 | ;; | |
739 | (defmethod ede-menu-items-build ((obj ede-project) &optional current) | |
740 | "Return a list of menu items for building project OBJ. | |
741 | If optional argument CURRENT is non-nil, return sub-menu code." | |
742 | (if current | |
743 | (list [ "Build Current Project" ede-compile-project t ]) | |
744 | (list (vector | |
745 | (list | |
746 | (concat "Build Project " (ede-name obj)) | |
747 | `(project-compile-project ,obj)))))) | |
748 | ||
749 | (defmethod ede-menu-items-build ((obj ede-target) &optional current) | |
750 | "Return a list of menu items for building target OBJ. | |
751 | If optional argument CURRENT is non-nil, return sub-menu code." | |
752 | (if current | |
753 | (list [ "Build Current Target" ede-compile-target t ]) | |
754 | (list (vector | |
755 | (concat "Build Target " (ede-name obj)) | |
756 | `(project-compile-target ,obj) | |
757 | t)))) | |
758 | \f | |
759 | ;;; Mode Declarations | |
760 | ;; | |
761 | (eval-and-compile | |
8bf997ef | 762 | (autoload 'ede-dired-minor-mode "ede/dired" "EDE commands for dired" t)) |
acc33231 CY |
763 | |
764 | (defun ede-apply-target-options () | |
765 | "Apply options to the current buffer for the active project/target." | |
766 | (if (ede-current-project) | |
767 | (ede-set-project-variables (ede-current-project))) | |
768 | (ede-apply-object-keymap) | |
769 | (ede-apply-preprocessor-map) | |
770 | ) | |
771 | ||
772 | (defun ede-turn-on-hook () | |
773 | "Turn on EDE minor mode in the current buffer if needed. | |
774 | To be used in hook functions." | |
775 | (if (or (and (stringp (buffer-file-name)) | |
776 | (stringp default-directory)) | |
777 | ;; Emacs 21 has no buffer file name for directory edits. | |
778 | ;; so we need to add these hacks in. | |
779 | (eq major-mode 'dired-mode) | |
780 | (eq major-mode 'vc-dired-mode)) | |
781 | (ede-minor-mode 1))) | |
782 | ||
715f35a5 CY |
783 | (define-minor-mode ede-minor-mode |
784 | "Toggle EDE (Emacs Development Environment) minor mode. | |
785 | With non-nil argument ARG, enable EDE minor mode if ARG is | |
786 | positive; otherwise, disable it. | |
acc33231 | 787 | |
715f35a5 CY |
788 | If this file is contained, or could be contained in an EDE |
789 | controlled project, then this mode is activated automatically | |
790 | provided `global-ede-mode' is enabled." | |
791 | :group 'ede | |
792 | (cond ((or (eq major-mode 'dired-mode) | |
793 | (eq major-mode 'vc-dired-mode)) | |
794 | (ede-dired-minor-mode (if ede-minor-mode 1 -1))) | |
795 | (ede-minor-mode | |
796 | (if (and (not ede-constructing) | |
797 | (ede-directory-project-p default-directory t)) | |
798 | (let* ((ROOT nil) | |
799 | (proj (ede-directory-get-open-project default-directory | |
800 | 'ROOT))) | |
801 | (when (not proj) | |
802 | ;; @todo - this could be wasteful. | |
803 | (setq proj (ede-load-project-file default-directory 'ROOT))) | |
804 | (setq ede-object-project proj) | |
805 | (setq ede-object-root-project | |
806 | (or ROOT (ede-project-root proj))) | |
807 | (setq ede-object (ede-buffer-object)) | |
808 | (if (and (not ede-object) ede-object-project) | |
809 | (ede-auto-add-to-target)) | |
810 | (ede-apply-target-options)) | |
811 | ;; If we fail to have a project here, turn it back off. | |
812 | (ede-minor-mode -1))))) | |
acc33231 CY |
813 | |
814 | (defun ede-reset-all-buffers (onoff) | |
815 | "Reset all the buffers due to change in EDE. | |
816 | ONOFF indicates enabling or disabling the mode." | |
817 | (let ((b (buffer-list))) | |
818 | (while b | |
819 | (when (buffer-file-name (car b)) | |
820 | (ede-buffer-object (car b)) | |
821 | ) | |
822 | (setq b (cdr b))))) | |
823 | ||
824 | ;;;###autoload | |
715f35a5 CY |
825 | (define-minor-mode global-ede-mode |
826 | "Toggle global EDE (Emacs Development Environment) mode. | |
827 | With non-nil argument ARG, enable global EDE mode if ARG is | |
828 | positive; otherwise, disable it. | |
829 | ||
830 | This global minor mode enables `ede-minor-mode' in all buffers in | |
831 | an EDE controlled project." | |
832 | :global t | |
833 | :group 'ede | |
834 | (if global-ede-mode | |
835 | ;; Turn on global-ede-mode | |
836 | (progn | |
837 | (add-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p) | |
838 | (add-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil) | |
839 | (add-hook 'ecb-source-path-functions 'ede-ecb-project-paths) | |
840 | (add-hook 'find-file-hook 'ede-turn-on-hook) | |
841 | (add-hook 'dired-mode-hook 'ede-turn-on-hook) | |
842 | (add-hook 'kill-emacs-hook 'ede-save-cache) | |
843 | (ede-load-cache) | |
844 | (ede-reset-all-buffers 1)) | |
845 | ;; Turn off global-ede-mode | |
846 | (remove-hook 'semanticdb-project-predicate-functions 'ede-directory-project-p) | |
847 | (remove-hook 'semanticdb-project-root-functions 'ede-toplevel-project-or-nil) | |
848 | (remove-hook 'ecb-source-path-functions 'ede-ecb-project-paths) | |
849 | (remove-hook 'find-file-hook 'ede-turn-on-hook) | |
850 | (remove-hook 'dired-mode-hook 'ede-turn-on-hook) | |
851 | (remove-hook 'kill-emacs-hook 'ede-save-cache) | |
852 | (ede-save-cache) | |
853 | (ede-reset-all-buffers -1))) | |
acc33231 CY |
854 | |
855 | (defvar ede-ignored-file-alist | |
856 | '( "\\.cvsignore$" | |
857 | "\\.#" | |
858 | "~$" | |
859 | ) | |
860 | "List of file name patters that EDE will never ask about.") | |
861 | ||
862 | (defun ede-ignore-file (filename) | |
863 | "Should we ignore FILENAME?" | |
864 | (let ((any nil) | |
865 | (F ede-ignored-file-alist)) | |
866 | (while (and (not any) F) | |
867 | (when (string-match (car F) filename) | |
868 | (setq any t)) | |
869 | (setq F (cdr F))) | |
870 | any)) | |
871 | ||
872 | (defun ede-auto-add-to-target () | |
873 | "Look for a target that wants to own the current file. | |
874 | Follow the preference set with `ede-auto-add-method' and get the list | |
875 | of objects with the `ede-want-file-p' method." | |
876 | (if ede-object (error "Ede-object already defined for %s" (buffer-name))) | |
877 | (if (or (eq ede-auto-add-method 'never) | |
878 | (ede-ignore-file (buffer-file-name))) | |
879 | nil | |
880 | (let (wants desires) | |
881 | ;; Find all the objects. | |
882 | (setq wants (oref (ede-current-project) targets)) | |
883 | (while wants | |
884 | (if (ede-want-file-p (car wants) (buffer-file-name)) | |
885 | (setq desires (cons (car wants) desires))) | |
886 | (setq wants (cdr wants))) | |
887 | (if desires | |
888 | (cond ((or (eq ede-auto-add-method 'ask) | |
889 | (and (eq ede-auto-add-method 'multi-ask) | |
890 | (< 1 (length desires)))) | |
891 | (let* ((al (append | |
892 | ;; some defaults | |
893 | '(("none" . nil) | |
894 | ("new target" . new)) | |
895 | ;; If we are in an unparented subdir, | |
896 | ;; offer new a subproject | |
897 | (if (ede-directory-project-p default-directory) | |
898 | () | |
899 | '(("create subproject" . project))) | |
900 | ;; Here are the existing objects we want. | |
901 | (object-assoc-list 'name desires))) | |
902 | (case-fold-search t) | |
903 | (ans (completing-read | |
904 | (format "Add %s to target: " (buffer-file-name)) | |
905 | al nil t))) | |
906 | (setq ans (assoc ans al)) | |
907 | (cond ((eieio-object-p (cdr ans)) | |
908 | (ede-add-file (cdr ans))) | |
909 | ((eq (cdr ans) 'new) | |
910 | (ede-new-target)) | |
911 | (t nil)))) | |
912 | ((or (eq ede-auto-add-method 'always) | |
913 | (and (eq ede-auto-add-method 'multi-ask) | |
914 | (= 1 (length desires)))) | |
915 | (ede-add-file (car desires))) | |
916 | (t nil)))))) | |
917 | ||
918 | \f | |
919 | ;;; Interactive method invocations | |
920 | ;; | |
921 | (defun ede (file) | |
922 | "Start up EDE on something. | |
923 | Argument FILE is the file or directory to load a project from." | |
924 | (interactive "fProject File: ") | |
925 | (if (not (file-exists-p file)) | |
926 | (ede-new file) | |
927 | (ede-load-project-file (file-name-directory file)))) | |
928 | ||
929 | (defun ede-new (type &optional name) | |
930 | "Create a new project starting of project type TYPE. | |
931 | Optional argument NAME is the name to give this project." | |
932 | (interactive | |
933 | (list (completing-read "Project Type: " | |
934 | (object-assoc-list | |
935 | 'name | |
936 | (let* ((l ede-project-class-files) | |
937 | (cp (ede-current-project)) | |
938 | (cs (when cp (object-class cp))) | |
939 | (r nil)) | |
940 | (while l | |
941 | (if cs | |
942 | (if (eq (oref (car l) :class-sym) | |
943 | cs) | |
944 | (setq r (cons (car l) r))) | |
945 | (if (oref (car l) new-p) | |
946 | (setq r (cons (car l) r)))) | |
947 | (setq l (cdr l))) | |
948 | (when (not r) | |
949 | (if cs | |
950 | (error "No valid interactive sub project types for %s" | |
951 | cs) | |
952 | (error "EDE error: Can't fin project types to create"))) | |
953 | r) | |
954 | ) | |
955 | nil t))) | |
956 | ;; Make sure we have a valid directory | |
957 | (when (not (file-exists-p default-directory)) | |
958 | (error "Cannot create project in non-existant directory %s" default-directory)) | |
959 | (when (not (file-writable-p default-directory)) | |
960 | (error "No write permissions for %s" default-directory)) | |
961 | ;; Create the project | |
962 | (let* ((obj (object-assoc type 'name ede-project-class-files)) | |
963 | (nobj (let ((f (oref obj file)) | |
964 | (pf (oref obj proj-file))) | |
965 | ;; We are about to make something new, changing the | |
966 | ;; state of existing directories. | |
967 | (ede-project-directory-remove-hash default-directory) | |
968 | ;; Make sure this class gets loaded! | |
969 | (require f) | |
970 | (make-instance (oref obj class-sym) | |
971 | :name (or name (read-string "Name: ")) | |
972 | :directory default-directory | |
973 | :file (cond ((stringp pf) | |
974 | (expand-file-name pf)) | |
975 | ((fboundp pf) | |
976 | (funcall pf)) | |
977 | (t | |
978 | (error | |
979 | "Unknown file name specifier %S" | |
980 | pf))) | |
981 | :targets nil))) | |
982 | (inits (oref obj initializers))) | |
983 | ;; Force the name to match for new objects. | |
984 | (object-set-name-string nobj (oref nobj :name)) | |
985 | ;; Handle init args. | |
986 | (while inits | |
987 | (eieio-oset nobj (car inits) (car (cdr inits))) | |
988 | (setq inits (cdr (cdr inits)))) | |
989 | (let ((pp (ede-parent-project))) | |
990 | (when pp | |
991 | (ede-add-subproject pp nobj) | |
992 | (ede-commit-project pp))) | |
993 | (ede-commit-project nobj)) | |
994 | ;; Have the menu appear | |
995 | (setq ede-minor-mode t) | |
996 | ;; Allert the user | |
997 | (message "Project created and saved. You may now create targets.")) | |
998 | ||
999 | (defmethod ede-add-subproject ((proj-a ede-project) proj-b) | |
1000 | "Add into PROJ-A, the subproject PROJ-B." | |
1001 | (oset proj-a subproj (cons proj-b (oref proj-a subproj)))) | |
1002 | ||
1003 | (defmethod ede-subproject-relative-path ((proj ede-project) &optional parent-in) | |
1004 | "Get a path name for PROJ which is relative to the parent project. | |
1005 | If PARENT is specified, then be relative to the PARENT project. | |
1006 | Specifying PARENT is useful for sub-sub projects relative to the root project." | |
1007 | (let* ((parent (or parent-in (ede-parent-project proj))) | |
1008 | (dir (file-name-directory (oref proj file)))) | |
1009 | (if (and parent (not (eq parent proj))) | |
1010 | (file-relative-name dir (file-name-directory (oref parent file))) | |
1011 | ""))) | |
1012 | ||
1013 | (defmethod ede-subproject-p ((proj ede-project)) | |
1014 | "Return non-nil if PROJ is a sub project." | |
1015 | (ede-parent-project proj)) | |
1016 | ||
1017 | (defun ede-invoke-method (sym &rest args) | |
1018 | "Invoke method SYM on the current buffer's project object. | |
1019 | ARGS are additional arguments to pass to method sym." | |
1020 | (if (not ede-object) | |
1021 | (error "Cannot invoke %s for %s" (symbol-name sym) | |
1022 | (buffer-name))) | |
1023 | ;; Always query a target. There should never be multiple | |
1024 | ;; projects in a single buffer. | |
1025 | (apply sym (ede-singular-object "Target: ") args)) | |
1026 | ||
1027 | (defun ede-rescan-toplevel () | |
1028 | "Rescan all project files." | |
1029 | (interactive) | |
1030 | (let ((toppath (ede-toplevel-project default-directory)) | |
1031 | (ede-deep-rescan t)) | |
1032 | (project-rescan (ede-load-project-file toppath)) | |
1033 | (ede-reset-all-buffers 1) | |
1034 | )) | |
1035 | ||
1036 | (defun ede-new-target (&rest args) | |
1037 | "Create a new target specific to this type of project file. | |
1038 | Different projects accept different arguments ARGS. | |
1039 | Typically you can specify NAME, target TYPE, and AUTOADD, where AUTOADD is | |
1040 | a string \"y\" or \"n\", which answers the y/n question done interactively." | |
1041 | (interactive) | |
1042 | (apply 'project-new-target (ede-current-project) args) | |
1043 | (setq ede-object nil) | |
1044 | (setq ede-object (ede-buffer-object (current-buffer))) | |
1045 | (ede-apply-target-options)) | |
1046 | ||
1047 | (defun ede-new-target-custom () | |
1048 | "Create a new target specific to this type of project file." | |
1049 | (interactive) | |
1050 | (project-new-target-custom (ede-current-project))) | |
1051 | ||
1052 | (defun ede-delete-target (target) | |
1053 | "Delete TARGET from the current project." | |
1054 | (interactive (list | |
1055 | (let ((ede-object (ede-current-project))) | |
1056 | (ede-invoke-method 'project-interactive-select-target | |
1057 | "Target: ")))) | |
1058 | ;; Find all sources in buffers associated with the condemned buffer. | |
1059 | (let ((condemned (ede-target-buffers target))) | |
1060 | (project-delete-target target) | |
1061 | ;; Loop over all project controlled buffers | |
1062 | (save-excursion | |
1063 | (while condemned | |
1064 | (set-buffer (car condemned)) | |
1065 | (setq ede-object nil) | |
1066 | (setq ede-object (ede-buffer-object (current-buffer))) | |
1067 | (setq condemned (cdr condemned)))) | |
1068 | (ede-apply-target-options))) | |
1069 | ||
1070 | (defun ede-add-file (target) | |
1071 | "Add the current buffer to a TARGET in the current project." | |
1072 | (interactive (list | |
1073 | (let ((ede-object (ede-current-project))) | |
1074 | (ede-invoke-method 'project-interactive-select-target | |
1075 | "Target: ")))) | |
1076 | (when (stringp target) | |
1077 | (let* ((proj (ede-current-project)) | |
1078 | (ob (object-assoc-list 'name (oref proj targets)))) | |
1079 | (setq target (cdr (assoc target ob))))) | |
1080 | ||
1081 | (when (not target) | |
1082 | (error "Could not find specified target %S" target)) | |
1083 | ||
1084 | (project-add-file target (buffer-file-name)) | |
1085 | (setq ede-object nil) | |
1086 | (setq ede-object (ede-buffer-object (current-buffer))) | |
1087 | (when (not ede-object) | |
1088 | (error "Can't add %s to target %s: Wrong file type" | |
1089 | (file-name-nondirectory (buffer-file-name)) | |
1090 | (object-name target))) | |
1091 | (ede-apply-target-options)) | |
1092 | ||
1093 | (defun ede-remove-file (&optional force) | |
1094 | "Remove the current file from targets. | |
1095 | Optional argument FORCE forces the file to be removed without asking." | |
1096 | (interactive "P") | |
1097 | (if (not ede-object) | |
1098 | (error "Cannot invoke remove-file for %s" (buffer-name))) | |
1099 | (let ((eo (if (listp ede-object) | |
1100 | (prog1 | |
1101 | ede-object | |
1102 | (setq force nil)) | |
1103 | (list ede-object)))) | |
1104 | (while eo | |
1105 | (if (or force (y-or-n-p (format "Remove from %s? " (ede-name (car eo))))) | |
1106 | (project-remove-file (car eo) (buffer-file-name))) | |
1107 | (setq eo (cdr eo))) | |
1108 | (setq ede-object nil) | |
1109 | (setq ede-object (ede-buffer-object (current-buffer))) | |
1110 | (ede-apply-target-options))) | |
1111 | ||
1112 | (defun ede-edit-file-target () | |
1113 | "Enter the project file to hand edit the current buffer's target." | |
1114 | (interactive) | |
1115 | (ede-invoke-method 'project-edit-file-target)) | |
1116 | ||
1117 | (defun ede-compile-project () | |
1118 | "Compile the current project." | |
1119 | (interactive) | |
1120 | ;; @TODO - This just wants the root. There should be a better way. | |
1121 | (let ((cp (ede-current-project))) | |
1122 | (while (ede-parent-project cp) | |
1123 | (setq cp (ede-parent-project cp))) | |
1124 | (let ((ede-object cp)) | |
1125 | (ede-invoke-method 'project-compile-project)))) | |
1126 | ||
1127 | (defun ede-compile-selected (target) | |
1128 | "Compile some TARGET from the current project." | |
1129 | (interactive (list (project-interactive-select-target (ede-current-project) | |
1130 | "Target to Build: "))) | |
1131 | (project-compile-target target)) | |
1132 | ||
1133 | (defun ede-compile-target () | |
1134 | "Compile the current buffer's associated target." | |
1135 | (interactive) | |
1136 | (ede-invoke-method 'project-compile-target)) | |
1137 | ||
1138 | (defun ede-debug-target () | |
1139 | "Debug the current buffer's assocated target." | |
1140 | (interactive) | |
1141 | (ede-invoke-method 'project-debug-target)) | |
1142 | ||
1143 | (defun ede-make-dist () | |
1144 | "Create a distribution from the current project." | |
1145 | (interactive) | |
1146 | (let ((ede-object (ede-current-project))) | |
1147 | (ede-invoke-method 'project-make-dist))) | |
1148 | ||
1149 | ;;; Customization | |
1150 | ;; | |
1151 | ;; Routines for customizing projects and targets. | |
1152 | ||
1153 | (defvar eieio-ede-old-variables nil | |
1154 | "The old variables for a project.") | |
1155 | ||
1156 | (defalias 'customize-project 'ede-customize-project) | |
1157 | (defun ede-customize-project (&optional group) | |
1158 | "Edit fields of the current project through EIEIO & Custom. | |
1159 | Optional GROUP specifies the subgroup of slots to customize." | |
1160 | (interactive "P") | |
1161 | (require 'eieio-custom) | |
1162 | (let* ((ov (oref (ede-current-project) local-variables)) | |
1163 | (cp (ede-current-project)) | |
1164 | (group (if group (eieio-read-customization-group cp)))) | |
1165 | (eieio-customize-object cp group) | |
1166 | (make-local-variable 'eieio-ede-old-variables) | |
1167 | (setq eieio-ede-old-variables ov))) | |
1168 | ||
1169 | (defalias 'customize-target 'ede-customize-current-target) | |
1170 | (defun ede-customize-current-target(&optional group) | |
1171 | "Edit fields of the current target through EIEIO & Custom. | |
1172 | Optional argument OBJ is the target object to customize. | |
1173 | Optional argument GROUP is the slot group to display." | |
1174 | (interactive "P") | |
1175 | (require 'eieio-custom) | |
1176 | (if (not (obj-of-class-p ede-object ede-target)) | |
1177 | (error "Current file is not part of a target.")) | |
1178 | (let ((group (if group (eieio-read-customization-group ede-object)))) | |
1179 | (ede-customize-target ede-object group))) | |
1180 | ||
1181 | (defun ede-customize-target (obj group) | |
1182 | "Edit fields of the current target through EIEIO & Custom. | |
1183 | Optional argument OBJ is the target object to customize. | |
1184 | Optional argument GROUP is the slot group to display." | |
1185 | (require 'eieio-custom) | |
1186 | (if (and obj (not (obj-of-class-p obj ede-target))) | |
1187 | (error "No logical target to customize")) | |
1188 | (eieio-customize-object obj (or group 'default))) | |
1189 | ;;; Target Sorting | |
1190 | ;; | |
1191 | ;; Target order can be important, but custom doesn't support a way | |
1192 | ;; to resort items in a list. This function by David Engster allows | |
1193 | ;; targets to be re-arranged. | |
1194 | ||
1195 | (defvar ede-project-sort-targets-order nil | |
1196 | "Variable for tracking target order in `ede-project-sort-targets'.") | |
1197 | ||
1198 | (defun ede-project-sort-targets () | |
1199 | "Create a custom-like buffer for sorting targets of current project." | |
1200 | (interactive) | |
1201 | (let ((proj (ede-current-project)) | |
1202 | (count 1) | |
1203 | current order) | |
1204 | (switch-to-buffer (get-buffer-create "*EDE sort targets*")) | |
1205 | (erase-buffer) | |
1206 | (setq ede-object-project proj) | |
1207 | (widget-create 'push-button | |
1208 | :notify (lambda (&rest ignore) | |
1209 | (let ((targets (oref ede-object-project targets)) | |
1210 | cur newtargets) | |
1211 | (while (setq cur (pop ede-project-sort-targets-order)) | |
1212 | (setq newtargets (append newtargets | |
1213 | (list (nth cur targets))))) | |
1214 | (oset ede-object-project targets newtargets)) | |
1215 | (ede-commit-project ede-object-project) | |
1216 | (kill-buffer)) | |
1217 | " Accept ") | |
1218 | (widget-insert " ") | |
1219 | (widget-create 'push-button | |
1220 | :notify (lambda (&rest ignore) | |
1221 | (kill-buffer)) | |
1222 | " Cancel ") | |
1223 | (widget-insert "\n\n") | |
1224 | (setq ede-project-sort-targets-order nil) | |
1225 | (mapc (lambda (x) | |
1226 | (add-to-ordered-list | |
1227 | 'ede-project-sort-targets-order | |
1228 | x x)) | |
1229 | (number-sequence 0 (1- (length (oref proj targets))))) | |
1230 | (ede-project-sort-targets-list) | |
1231 | (use-local-map widget-keymap) | |
1232 | (widget-setup) | |
1233 | (goto-char (point-min)))) | |
1234 | ||
1235 | (defun ede-project-sort-targets-list () | |
1236 | "Sort the target list while using `ede-project-sort-targets'." | |
1237 | (save-excursion | |
1238 | (let ((count 0) | |
1239 | (targets (oref ede-object-project targets)) | |
1240 | (inhibit-read-only t) | |
1241 | (inhibit-modification-hooks t)) | |
1242 | (goto-char (point-min)) | |
1243 | (forward-line 2) | |
1244 | (delete-region (point) (point-max)) | |
1245 | (while (< count (length targets)) | |
1246 | (if (> count 0) | |
1247 | (widget-create 'push-button | |
1248 | :notify `(lambda (&rest ignore) | |
1249 | (let ((cur ede-project-sort-targets-order)) | |
1250 | (add-to-ordered-list | |
1251 | 'ede-project-sort-targets-order | |
1252 | (nth ,count cur) | |
1253 | (1- ,count)) | |
1254 | (add-to-ordered-list | |
1255 | 'ede-project-sort-targets-order | |
1256 | (nth (1- ,count) cur) ,count)) | |
1257 | (ede-project-sort-targets-list)) | |
1258 | " Up ") | |
1259 | (widget-insert " ")) | |
1260 | (if (< count (1- (length targets))) | |
1261 | (widget-create 'push-button | |
1262 | :notify `(lambda (&rest ignore) | |
1263 | (let ((cur ede-project-sort-targets-order)) | |
1264 | (add-to-ordered-list | |
1265 | 'ede-project-sort-targets-order | |
1266 | (nth ,count cur) (1+ ,count)) | |
1267 | (add-to-ordered-list | |
1268 | 'ede-project-sort-targets-order | |
1269 | (nth (1+ ,count) cur) ,count)) | |
1270 | (ede-project-sort-targets-list)) | |
1271 | " Down ") | |
1272 | (widget-insert " ")) | |
1273 | (widget-insert (concat " " (number-to-string (1+ count)) ".: " | |
1274 | (oref (nth (nth count ede-project-sort-targets-order) | |
1275 | targets) name) "\n")) | |
1276 | (setq count (1+ count)))))) | |
1277 | ||
1278 | ;;; Customization hooks | |
1279 | ;; | |
1280 | ;; These hooks are used when finishing up a customization. | |
1281 | (defmethod eieio-done-customizing ((proj ede-project)) | |
1282 | "Call this when a user finishes customizing PROJ." | |
1283 | (let ((ov eieio-ede-old-variables) | |
1284 | (nv (oref proj local-variables))) | |
1285 | (setq eieio-ede-old-variables nil) | |
1286 | (while ov | |
1287 | (if (not (assoc (car (car ov)) nv)) | |
1288 | (save-excursion | |
1289 | (mapc (lambda (b) | |
1290 | (set-buffer b) | |
1291 | (kill-local-variable (car (car ov)))) | |
1292 | (ede-project-buffers proj)))) | |
1293 | (setq ov (cdr ov))) | |
1294 | (mapc (lambda (b) (ede-set-project-variables proj b)) | |
1295 | (ede-project-buffers proj)))) | |
1296 | ||
1297 | (defmethod eieio-done-customizing ((target ede-target)) | |
1298 | "Call this when a user finishes customizing TARGET." | |
1299 | nil) | |
1300 | ||
1301 | (defmethod ede-commit-project ((proj ede-project)) | |
1302 | "Commit any change to PROJ to its file." | |
1303 | nil | |
1304 | ) | |
1305 | ||
1306 | \f | |
1307 | ;;; EDE project placeholder methods | |
1308 | ;; | |
1309 | (defmethod ede-project-force-load ((this ede-project-placeholder)) | |
1310 | "Make sure the placeholder THIS is replaced with the real thing. | |
1311 | Return the new object created in its place." | |
1312 | this | |
1313 | ) | |
1314 | ||
1315 | \f | |
1316 | ;;; EDE project target baseline methods. | |
1317 | ;; | |
1318 | ;; If you are developing a new project type, you need to implement | |
1319 | ;; all of these methods, unless, of course, they do not make sense | |
1320 | ;; for your particular project. | |
1321 | ;; | |
1322 | ;; Your targets should inherit from `ede-target', and your project | |
1323 | ;; files should inherit from `ede-project'. Create the appropriate | |
1324 | ;; methods based on those below. | |
1325 | ||
1326 | (defmethod project-interactive-select-target ((this ede-project-placeholder) prompt) | |
1327 | ; checkdoc-params: (prompt) | |
1328 | "Make sure placeholder THIS is replaced with the real thing, and pass through." | |
1329 | (project-interactive-select-target (ede-project-force-load this) prompt)) | |
1330 | ||
1331 | (defmethod project-interactive-select-target ((this ede-project) prompt) | |
1332 | "Interactively query for a target that exists in project THIS. | |
1333 | Argument PROMPT is the prompt to use when querying the user for a target." | |
1334 | (let ((ob (object-assoc-list 'name (oref this targets)))) | |
1335 | (cdr (assoc (completing-read prompt ob nil t) ob)))) | |
1336 | ||
1337 | (defmethod project-add-file ((this ede-project-placeholder) file) | |
1338 | ; checkdoc-params: (file) | |
1339 | "Make sure placeholder THIS is replaced with the real thing, and pass through." | |
1340 | (project-add-file (ede-project-force-load this) file)) | |
1341 | ||
1342 | (defmethod project-add-file ((ot ede-target) file) | |
1343 | "Add the current buffer into project project target OT. | |
1344 | Argument FILE is the file to add." | |
1345 | (error "add-file not supported by %s" (object-name ot))) | |
1346 | ||
1347 | (defmethod project-remove-file ((ot ede-target) fnnd) | |
1348 | "Remove the current buffer from project target OT. | |
1349 | Argument FNND is an argument." | |
1350 | (error "remove-file not supported by %s" (object-name ot))) | |
1351 | ||
1352 | (defmethod project-edit-file-target ((ot ede-target)) | |
1353 | "Edit the target OT associated w/ this file." | |
1354 | (find-file (oref (ede-current-project) file))) | |
1355 | ||
1356 | (defmethod project-new-target ((proj ede-project) &rest args) | |
1357 | "Create a new target. It is up to the project PROJ to get the name." | |
1358 | (error "new-target not supported by %s" (object-name proj))) | |
1359 | ||
1360 | (defmethod project-new-target-custom ((proj ede-project)) | |
1361 | "Create a new target. It is up to the project PROJ to get the name." | |
1362 | (error "New-target-custom not supported by %s" (object-name proj))) | |
1363 | ||
1364 | (defmethod project-delete-target ((ot ede-target)) | |
1365 | "Delete the current target OT from it's parent project." | |
1366 | (error "add-file not supported by %s" (object-name ot))) | |
1367 | ||
1368 | (defmethod project-compile-project ((obj ede-project) &optional command) | |
1369 | "Compile the entire current project OBJ. | |
1370 | Argument COMMAND is the command to use when compiling." | |
1371 | (error "compile-project not supported by %s" (object-name obj))) | |
1372 | ||
1373 | (defmethod project-compile-target ((obj ede-target) &optional command) | |
1374 | "Compile the current target OBJ. | |
1375 | Argument COMMAND is the command to use for compiling the target." | |
1376 | (error "compile-target not supported by %s" (object-name obj))) | |
1377 | ||
1378 | (defmethod project-debug-target ((obj ede-target)) | |
1379 | "Run the current project target OBJ in a debugger." | |
1380 | (error "debug-target not supported by %s" (object-name obj))) | |
1381 | ||
1382 | (defmethod project-make-dist ((this ede-project)) | |
1383 | "Build a distribution for the project based on THIS project." | |
1384 | (error "Make-dist not supported by %s" (object-name this))) | |
1385 | ||
1386 | (defmethod project-dist-files ((this ede-project)) | |
1387 | "Return a list of files that constitutes a distribution of THIS project." | |
1388 | (error "Dist-files is not supported by %s" (object-name this))) | |
1389 | ||
1390 | (defmethod project-rescan ((this ede-project)) | |
1391 | "Rescan the EDE proj project THIS." | |
1392 | (error "Rescanning a project is not supported by %s" (object-name this))) | |
1393 | \f | |
1394 | ;;; Default methods for EDE classes | |
1395 | ;; | |
1396 | ;; These are methods which you might want to override, but there is | |
1397 | ;; no need to in most situations because they are either a) simple, or | |
1398 | ;; b) cosmetic. | |
1399 | ||
1400 | (defmethod ede-name ((this ede-target)) | |
1401 | "Return the name of THIS targt." | |
1402 | (oref this name)) | |
1403 | ||
1404 | (defmethod ede-target-name ((this ede-target)) | |
1405 | "Return the name of THIS target, suitable for make or debug style commands." | |
1406 | (oref this name)) | |
1407 | ||
1408 | (defmethod ede-name ((this ede-project)) | |
1409 | "Return a short-name for THIS project file. | |
1410 | Do this by extracting the lowest directory name." | |
1411 | (oref this name)) | |
1412 | ||
1413 | (defmethod ede-description ((this ede-project)) | |
1414 | "Return a description suitable for the minibuffer about THIS." | |
1415 | (format "Project %s: %d subprojects, %d targets." | |
1416 | (ede-name this) (length (oref this subproj)) | |
1417 | (length (oref this targets)))) | |
1418 | ||
1419 | (defmethod ede-description ((this ede-target)) | |
1420 | "Return a description suitable for the minibuffer about THIS." | |
1421 | (format "Target %s: with %d source files." | |
1422 | (ede-name this) (length (oref this source)))) | |
1423 | ||
1424 | (defmethod ede-want-file-p ((this ede-target) file) | |
1425 | "Return non-nil if THIS target wants FILE." | |
1426 | ;; By default, all targets reference the source object, and let it decide. | |
1427 | (let ((src (ede-target-sourcecode this))) | |
1428 | (while (and src (not (ede-want-file-p (car src) file))) | |
1429 | (setq src (cdr src))) | |
1430 | src)) | |
1431 | ||
1432 | (defmethod ede-want-file-source-p ((this ede-target) file) | |
1433 | "Return non-nil if THIS target wants FILE." | |
1434 | ;; By default, all targets reference the source object, and let it decide. | |
1435 | (let ((src (ede-target-sourcecode this))) | |
1436 | (while (and src (not (ede-want-file-source-p (car src) file))) | |
1437 | (setq src (cdr src))) | |
1438 | src)) | |
1439 | ||
1440 | (defun ede-header-file () | |
1441 | "Return the header file for the current buffer. | |
1442 | Not all buffers need headers, so return nil if no applicable." | |
1443 | (if ede-object | |
1444 | (ede-buffer-header-file ede-object (current-buffer)) | |
1445 | nil)) | |
1446 | ||
1447 | (defmethod ede-buffer-header-file ((this ede-project) buffer) | |
1448 | "Return nil, projects don't have header files." | |
1449 | nil) | |
1450 | ||
1451 | (defmethod ede-buffer-header-file ((this ede-target) buffer) | |
1452 | "There are no default header files in EDE. | |
1453 | Do a quick check to see if there is a Header tag in this buffer." | |
1454 | (save-excursion | |
1455 | (set-buffer buffer) | |
1456 | (if (re-search-forward "::Header:: \\([a-zA-Z0-9.]+\\)" nil t) | |
1457 | (buffer-substring-no-properties (match-beginning 1) | |
1458 | (match-end 1)) | |
1459 | (let ((src (ede-target-sourcecode this)) | |
1460 | (found nil)) | |
1461 | (while (and src (not found)) | |
1462 | (setq found (ede-buffer-header-file (car src) (buffer-file-name)) | |
1463 | src (cdr src))) | |
1464 | found)))) | |
1465 | ||
1466 | (defun ede-documentation-files () | |
1467 | "Return the documentation files for the current buffer. | |
1468 | Not all buffers need documentations, so return nil if no applicable. | |
1469 | Some projects may have multiple documentation files, so return a list." | |
1470 | (if ede-object | |
1471 | (ede-buffer-documentation-files ede-object (current-buffer)) | |
1472 | nil)) | |
1473 | ||
1474 | (defmethod ede-buffer-documentation-files ((this ede-project) buffer) | |
1475 | "Return all documentation in project THIS based on BUFFER." | |
1476 | ;; Find the info node. | |
1477 | (ede-documentation this)) | |
1478 | ||
1479 | (defmethod ede-buffer-documentation-files ((this ede-target) buffer) | |
1480 | "Check for some documentation files for THIS. | |
1481 | Also do a quick check to see if there is a Documentation tag in this BUFFER." | |
1482 | (save-excursion | |
1483 | (set-buffer buffer) | |
1484 | (if (re-search-forward "::Documentation:: \\([a-zA-Z0-9.]+\\)" nil t) | |
1485 | (buffer-substring-no-properties (match-beginning 1) | |
1486 | (match-end 1)) | |
1487 | ;; Check the master project | |
1488 | (let ((cp (ede-toplevel))) | |
1489 | (ede-buffer-documentation-files cp (current-buffer)))))) | |
1490 | ||
1491 | (defmethod ede-documentation ((this ede-project)) | |
1492 | "Return a list of files that provides documentation. | |
1493 | Documentation is not for object THIS, but is provided by THIS for other | |
1494 | files in the project." | |
1495 | (let ((targ (oref this targets)) | |
1496 | (proj (oref this subproj)) | |
1497 | (found nil)) | |
1498 | (while targ | |
1499 | (setq found (append (ede-documentation (car targ)) found) | |
1500 | targ (cdr targ))) | |
1501 | (while proj | |
1502 | (setq found (append (ede-documentation (car proj)) found) | |
1503 | proj (cdr proj))) | |
1504 | found)) | |
1505 | ||
1506 | (defmethod ede-documentation ((this ede-target)) | |
1507 | "Return a list of files that provides documentation. | |
1508 | Documentation is not for object THIS, but is provided by THIS for other | |
1509 | files in the project." | |
1510 | nil) | |
1511 | ||
1512 | (defun ede-html-documentation-files () | |
1513 | "Return a list of HTML documentation files associated with this project." | |
1514 | (ede-html-documentation (ede-toplevel)) | |
1515 | ) | |
1516 | ||
1517 | (defmethod ede-html-documentation ((this ede-project)) | |
1518 | "Return a list of HTML files provided by project THIS." | |
1519 | ||
1520 | ) | |
1521 | ||
1522 | (defun ede-ecb-project-paths () | |
1523 | "Return a list of all paths for all active EDE projects. | |
1524 | This functions is meant for use with ECB." | |
1525 | (let ((p ede-projects) | |
1526 | (d nil)) | |
1527 | (while p | |
1528 | (setq d (cons (file-name-directory (oref (car p) file)) | |
1529 | d) | |
1530 | p (cdr p))) | |
1531 | d)) | |
1532 | \f | |
1533 | ;;; EDE project-autoload methods | |
1534 | ;; | |
1535 | (defmethod ede-dir-to-projectfile ((this ede-project-autoload) dir) | |
1536 | "Return a full file name of project THIS found in DIR. | |
1537 | Return nil if the project file does not exist." | |
1538 | (let* ((d (file-name-as-directory dir)) | |
1539 | (root (ede-project-root-directory this d)) | |
1540 | (pf (oref this proj-file)) | |
1541 | (f (cond ((stringp pf) | |
1542 | (expand-file-name pf (or root d))) | |
1543 | ((and (symbolp pf) (fboundp pf)) | |
1544 | (funcall pf (or root d))))) | |
1545 | ) | |
1546 | (when (and f (file-exists-p f)) | |
1547 | f))) | |
1548 | ||
1549 | ;;; EDE basic functions | |
1550 | ;; | |
1551 | (defun ede-add-project-to-global-list (proj) | |
1552 | "Add the project PROJ to the master list of projects. | |
1553 | On success, return the added project." | |
1554 | (when (not proj) | |
1555 | (error "No project created to add to master list")) | |
1556 | (when (not (eieio-object-p proj)) | |
1557 | (error "Attempt to add Non-object to master project list")) | |
1558 | (when (not (obj-of-class-p proj ede-project-placeholder)) | |
1559 | (error "Attempt to add a non-project to the ede projects list")) | |
1560 | (add-to-list 'ede-projects proj) | |
1561 | proj) | |
1562 | ||
1563 | (defun ede-load-project-file (dir &optional rootreturn) | |
1564 | "Project file independent way to read a project in from DIR. | |
1565 | Optional ROOTRETURN will return the root project for DIR." | |
1566 | ;; Only load if something new is going on. Flush the dirhash. | |
1567 | (ede-project-directory-remove-hash dir) | |
1568 | ;; Do the load | |
1569 | ;;(message "EDE LOAD : %S" file) | |
1570 | (let* ((file dir) | |
1571 | (path (expand-file-name (file-name-directory file))) | |
1572 | (pfc (ede-directory-project-p path)) | |
1573 | (toppath nil) | |
1574 | (o nil)) | |
1575 | (cond | |
1576 | ((not pfc) | |
1577 | ;; @TODO - Do we really need to scan? Is this a waste of time? | |
1578 | ;; Scan upward for a the next project file style. | |
1579 | (let ((p path)) | |
1580 | (while (and p (not (ede-directory-project-p p))) | |
1581 | (setq p (ede-up-directory p))) | |
1582 | (if p (ede-load-project-file p) | |
1583 | nil) | |
1584 | ;; recomment as we go | |
1585 | ;nil | |
1586 | )) | |
1587 | ;; Do nothing if we are buiding an EDE project already | |
1588 | (ede-constructing | |
1589 | nil) | |
1590 | ;; Load in the project in question. | |
1591 | (t | |
1592 | (setq toppath (ede-toplevel-project path)) | |
1593 | ;; We found the top-most directory. Check to see if we already | |
1594 | ;; have an object defining it's project. | |
1595 | (setq pfc (ede-directory-project-p toppath t)) | |
1596 | ||
1597 | ;; See if it's been loaded before | |
1598 | (setq o (object-assoc (ede-dir-to-projectfile pfc toppath) 'file | |
1599 | ede-projects)) | |
1600 | (if (not o) | |
1601 | ;; If not, get it now. | |
1602 | (let ((ede-constructing t)) | |
1603 | (setq o (funcall (oref pfc load-type) toppath)) | |
1604 | (when (not o) | |
1605 | (error "Project type error: :load-type failed to create a project")) | |
1606 | (ede-add-project-to-global-list o))) | |
1607 | ||
1608 | ;; Return the found root project. | |
1609 | (when rootreturn (set rootreturn o)) | |
1610 | ||
1611 | (let (tocheck found) | |
1612 | ;; Now find the project file belonging to FILE! | |
1613 | (setq tocheck (list o)) | |
1614 | (setq file (ede-dir-to-projectfile pfc (expand-file-name path))) | |
1615 | (while (and tocheck (not found)) | |
1616 | (let ((newbits nil)) | |
1617 | (when (car tocheck) | |
1618 | (if (string= file (oref (car tocheck) file)) | |
1619 | (setq found (car tocheck))) | |
1620 | (setq newbits (oref (car tocheck) subproj))) | |
1621 | (setq tocheck | |
1622 | (append (cdr tocheck) newbits)))) | |
1623 | (if (not found) | |
1624 | (message "No project for %s, but passes project-p test" file) | |
1625 | ;; Now that the file has been reset inside the project object, do | |
1626 | ;; the cache maintenance. | |
1627 | (setq ede-project-cache-files | |
1628 | (delete (oref found file) ede-project-cache-files))) | |
1629 | found))))) | |
1630 | ||
1631 | (defun ede-parent-project (&optional obj) | |
1632 | "Return the project belonging to the parent directory. | |
1633 | nil if there is no previous directory. | |
1634 | Optional argument OBJ is an object to find the parent of." | |
1635 | (let* ((proj (or obj ede-object-project)) ;; Current project. | |
1636 | (root (if obj (ede-project-root obj) | |
1637 | ede-object-root-project))) | |
1638 | ;; This case is a SHORTCUT if the project has defined | |
1639 | ;; a way to calculate the project root. | |
1640 | (if (and root proj (eq root proj)) | |
1641 | nil ;; we are at the root. | |
1642 | ;; Else, we may have a nil proj or root. | |
1643 | (let* ((thisdir (if obj (oref obj directory) | |
1644 | default-directory)) | |
1645 | (updir (ede-up-directory thisdir))) | |
1646 | (when updir | |
1647 | ;; If there was no root, perhaps we can derive it from | |
1648 | ;; updir now. | |
1649 | (let ((root (or root (ede-directory-get-toplevel-open-project updir)))) | |
1650 | (or | |
1651 | ;; This lets us find a subproject under root based on updir. | |
1652 | (and root | |
1653 | (ede-find-subproject-for-directory root updir)) | |
1654 | ;; Try the all structure based search. | |
1655 | (ede-directory-get-open-project updir) | |
1656 | ;; Load up the project file as a last resort. | |
1657 | ;; Last resort since it uses file-truename, and other | |
1658 | ;; slow features. | |
1659 | (and (ede-directory-project-p updir) | |
1660 | (ede-load-project-file | |
1661 | (file-name-as-directory updir)))))))))) | |
1662 | ||
1663 | (defun ede-current-project (&optional dir) | |
1664 | "Return the current project file. | |
1665 | If optional DIR is provided, get the project for DIR instead." | |
1666 | (let ((ans nil)) | |
1667 | ;; If it matches the current directory, do we have a pre-existing project? | |
1668 | (when (and (or (not dir) (string= dir default-directory)) | |
1669 | ede-object-project) | |
1670 | (setq ans ede-object-project) | |
1671 | ) | |
1672 | ;; No current project. | |
1673 | (when (not ans) | |
1674 | (let* ((ldir (or dir default-directory))) | |
1675 | (setq ans (ede-directory-get-open-project ldir)) | |
1676 | (or ans | |
1677 | ;; No open project, if this dir pass project-p, then load. | |
1678 | (when (ede-directory-project-p ldir) | |
1679 | (setq ans (ede-load-project-file ldir)))))) | |
1680 | ;; Return what we found. | |
1681 | ans)) | |
1682 | ||
1683 | (defun ede-buffer-object (&optional buffer) | |
1684 | "Return the target object for BUFFER. | |
1685 | This function clears cached values and recalculates." | |
1686 | (save-excursion | |
1687 | (if (not buffer) (setq buffer (current-buffer))) | |
1688 | (set-buffer buffer) | |
1689 | (setq ede-object nil) | |
1690 | (let ((po (ede-current-project))) | |
1691 | (if po (setq ede-object (ede-find-target po buffer)))) | |
1692 | (if (= (length ede-object) 1) | |
1693 | (setq ede-object (car ede-object))) | |
1694 | ede-object)) | |
1695 | ||
1696 | (defmethod ede-target-in-project-p ((proj ede-project) target) | |
1697 | "Is PROJ the parent of TARGET? | |
1698 | If TARGET belongs to a subproject, return that project file." | |
1699 | (if (and (slot-boundp proj 'targets) | |
1700 | (memq target (oref proj targets))) | |
1701 | proj | |
1702 | (let ((s (oref proj subproj)) | |
1703 | (ans nil)) | |
1704 | (while (and s (not ans)) | |
1705 | (setq ans (ede-target-in-project-p (car s) target)) | |
1706 | (setq s (cdr s))) | |
1707 | ans))) | |
1708 | ||
1709 | (defun ede-target-parent (target) | |
1710 | "Return the project which is the parent of TARGET. | |
1711 | It is recommended you track the project a different way as this function | |
1712 | could become slow in time." | |
1713 | ;; @todo - use ede-object-project as a starting point. | |
1714 | (let ((ans nil) (projs ede-projects)) | |
1715 | (while (and (not ans) projs) | |
1716 | (setq ans (ede-target-in-project-p (car projs) target) | |
1717 | projs (cdr projs))) | |
1718 | ans)) | |
1719 | ||
1720 | (defun ede-maybe-checkout (&optional buffer) | |
1721 | "Check BUFFER out of VC if necessary." | |
1722 | (save-excursion | |
1723 | (if buffer (set-buffer buffer)) | |
1724 | (if (and buffer-read-only vc-mode | |
1725 | (y-or-n-p "Checkout Makefile.am from VC? ")) | |
1726 | (vc-toggle-read-only)))) | |
1727 | ||
1728 | (defmethod ede-find-target ((proj ede-project) buffer) | |
1729 | "Fetch the target in PROJ belonging to BUFFER or nil." | |
1730 | (save-excursion | |
1731 | (set-buffer buffer) | |
1732 | (or ede-object | |
1733 | (if (ede-buffer-mine proj buffer) | |
1734 | proj | |
1735 | (let ((targets (oref proj targets)) | |
1736 | (f nil)) | |
1737 | (while targets | |
1738 | (if (ede-buffer-mine (car targets) buffer) | |
1739 | (setq f (cons (car targets) f))) | |
1740 | (setq targets (cdr targets))) | |
1741 | f))))) | |
1742 | ||
1743 | (defmethod ede-target-buffer-in-sourcelist ((this ede-target) buffer source) | |
1744 | "Return non-nil if object THIS is in BUFFER to a SOURCE list. | |
1745 | Handles complex path issues." | |
1746 | (member (ede-convert-path this (buffer-file-name buffer)) source)) | |
1747 | ||
1748 | (defmethod ede-buffer-mine ((this ede-project) buffer) | |
1749 | "Return non-nil if object THIS lays claim to the file in BUFFER." | |
1750 | nil) | |
1751 | ||
1752 | (defmethod ede-buffer-mine ((this ede-target) buffer) | |
1753 | "Return non-nil if object THIS lays claim to the file in BUFFER." | |
1754 | (condition-case nil | |
1755 | (ede-target-buffer-in-sourcelist this buffer (oref this source)) | |
1756 | ;; An error implies a bad match. | |
1757 | (error nil))) | |
1758 | ||
1759 | \f | |
1760 | ;;; Project mapping | |
1761 | ;; | |
1762 | (defun ede-project-buffers (project) | |
1763 | "Return a list of all active buffers controlled by PROJECT. | |
1764 | This includes buffers controlled by a specific target of PROJECT." | |
1765 | (let ((bl (buffer-list)) | |
1766 | (pl nil)) | |
1767 | (while bl | |
1768 | (save-excursion | |
1769 | (set-buffer (car bl)) | |
1770 | (if (and ede-object (eq (ede-current-project) project)) | |
1771 | (setq pl (cons (car bl) pl)))) | |
1772 | (setq bl (cdr bl))) | |
1773 | pl)) | |
1774 | ||
1775 | (defun ede-target-buffers (target) | |
1776 | "Return a list of buffers that are controlled by TARGET." | |
1777 | (let ((bl (buffer-list)) | |
1778 | (pl nil)) | |
1779 | (while bl | |
1780 | (save-excursion | |
1781 | (set-buffer (car bl)) | |
1782 | (if (if (listp ede-object) | |
1783 | (memq target ede-object) | |
1784 | (eq ede-object target)) | |
1785 | (setq pl (cons (car bl) pl)))) | |
1786 | (setq bl (cdr bl))) | |
1787 | pl)) | |
1788 | ||
1789 | (defun ede-buffers () | |
1790 | "Return a list of all buffers controled by an EDE object." | |
1791 | (let ((bl (buffer-list)) | |
1792 | (pl nil)) | |
1793 | (while bl | |
1794 | (save-excursion | |
1795 | (set-buffer (car bl)) | |
1796 | (if ede-object | |
1797 | (setq pl (cons (car bl) pl)))) | |
1798 | (setq bl (cdr bl))) | |
1799 | pl)) | |
1800 | ||
1801 | (defun ede-map-buffers (proc) | |
1802 | "Execute PROC on all buffers controled by EDE." | |
1803 | (mapcar proc (ede-buffers))) | |
1804 | ||
1805 | (defmethod ede-map-project-buffers ((this ede-project) proc) | |
1806 | "For THIS, execute PROC on all buffers belonging to THIS." | |
1807 | (mapcar proc (ede-project-buffers this))) | |
1808 | ||
1809 | (defmethod ede-map-target-buffers ((this ede-target) proc) | |
1810 | "For THIS, execute PROC on all buffers belonging to THIS." | |
1811 | (mapcar proc (ede-target-buffers this))) | |
1812 | ||
1813 | ;; other types of mapping | |
1814 | (defmethod ede-map-subprojects ((this ede-project) proc) | |
1815 | "For object THIS, execute PROC on all direct subprojects. | |
1816 | This function does not apply PROC to sub-sub projects. | |
1817 | See also `ede-map-all-subprojects'." | |
1818 | (mapcar proc (oref this subproj))) | |
1819 | ||
1820 | (defmethod ede-map-all-subprojects ((this ede-project) allproc) | |
1821 | "For object THIS, execute PROC on THIS and all subprojects. | |
1822 | This function also applies PROC to sub-sub projects. | |
1823 | See also `ede-map-subprojects'." | |
1824 | (apply 'append | |
1825 | (list (funcall allproc this)) | |
1826 | (ede-map-subprojects | |
1827 | this | |
1828 | (lambda (sp) | |
1829 | (ede-map-all-subprojects sp allproc)) | |
1830 | ))) | |
1831 | ||
1832 | ;; (ede-map-all-subprojects (ede-load-project-file "../semantic/") (lambda (sp) (oref sp file))) | |
1833 | ||
1834 | (defmethod ede-map-targets ((this ede-project) proc) | |
1835 | "For object THIS, execute PROC on all targets." | |
1836 | (mapcar proc (oref this targets))) | |
1837 | ||
1838 | (defmethod ede-map-any-target-p ((this ede-project) proc) | |
1839 | "For project THIS, map PROC to all targets and return if any non-nil. | |
1840 | Return the first non-nil value returned by PROC." | |
1841 | (ede-or (ede-map-targets this proc))) | |
1842 | ||
1843 | \f | |
1844 | ;;; Some language specific methods. | |
1845 | ;; | |
1846 | ;; These items are needed by ede-cpp-root to add better support for | |
1847 | ;; configuring items for Semantic. | |
1848 | (defun ede-apply-preprocessor-map () | |
1849 | "Apply preprocessor tables onto the current buffer." | |
1850 | (when (and ede-object (boundp 'semantic-lex-spp-macro-symbol-obarray)) | |
1851 | (let ((map (ede-preprocessor-map ede-object))) | |
1852 | (when map | |
1853 | ;; We can't do a require for the below symbol. | |
1854 | (setq semantic-lex-spp-macro-symbol-obarray | |
1855 | (semantic-lex-make-spp-table map)) | |
1856 | )))) | |
1857 | ||
1858 | (defmethod ede-system-include-path ((this ede-project)) | |
1859 | "Get the system include path used by project THIS." | |
1860 | nil) | |
1861 | ||
1862 | (defmethod ede-preprocessor-map ((this ede-project)) | |
1863 | "Get the pre-processor map for project THIS." | |
1864 | nil) | |
1865 | ||
1866 | (defmethod ede-system-include-path ((this ede-target)) | |
1867 | "Get the system include path used by project THIS." | |
1868 | nil) | |
1869 | ||
1870 | (defmethod ede-preprocessor-map ((this ede-target)) | |
1871 | "Get the pre-processor map for project THIS." | |
1872 | nil) | |
1873 | ||
1874 | \f | |
1875 | ;;; Project-local variables | |
1876 | ;; | |
1877 | (defun ede-make-project-local-variable (variable &optional project) | |
1878 | "Make VARIABLE project-local to PROJECT." | |
1879 | (if (not project) (setq project (ede-current-project))) | |
1880 | (if (assoc variable (oref project local-variables)) | |
1881 | nil | |
1882 | (oset project local-variables (cons (list variable) | |
1883 | (oref project local-variables))) | |
1884 | (mapcar (lambda (b) (save-excursion | |
1885 | (set-buffer b) | |
1886 | (make-local-variable variable))) | |
1887 | (ede-project-buffers project)))) | |
1888 | ||
1889 | (defmethod ede-set-project-variables ((project ede-project) &optional buffer) | |
1890 | "Set variables local to PROJECT in BUFFER." | |
1891 | (if (not buffer) (setq buffer (current-buffer))) | |
1892 | (save-excursion | |
1893 | (set-buffer buffer) | |
1894 | (mapcar (lambda (v) | |
1895 | (make-local-variable (car v)) | |
1896 | ;; set it's value here? | |
1897 | (set (car v) (cdr v)) | |
1898 | ) | |
1899 | (oref project local-variables)))) | |
1900 | ||
1901 | (defun ede-set (variable value &optional proj) | |
1902 | "Set the project local VARIABLE to VALUE. | |
1903 | If VARIABLE is not project local, just use set." | |
1904 | (let ((p (or proj (ede-current-project))) | |
1905 | a) | |
1906 | (if (and p (setq a (assoc variable (oref p local-variables)))) | |
1907 | (progn | |
1908 | (setcdr a value) | |
1909 | (mapc (lambda (b) (save-excursion | |
1910 | (set-buffer b) | |
1911 | (set variable value))) | |
1912 | (ede-project-buffers p))) | |
1913 | (set variable value)) | |
1914 | (ede-commit-local-variables p)) | |
1915 | value) | |
1916 | ||
1917 | (defmethod ede-commit-local-variables ((proj ede-project)) | |
1918 | "Commit change to local variables in PROJ." | |
1919 | nil) | |
1920 | ||
1921 | \f | |
1922 | ;;; Accessors for more complex types where oref is inappropriate. | |
1923 | ;; | |
1924 | (defmethod ede-target-sourcecode ((this ede-target)) | |
1925 | "Return the sourcecode objects which THIS permits." | |
1926 | (let ((sc (oref this sourcetype)) | |
1927 | (rs nil)) | |
1928 | (while (and (listp sc) sc) | |
1929 | (setq rs (cons (symbol-value (car sc)) rs) | |
1930 | sc (cdr sc))) | |
1931 | rs)) | |
1932 | ||
1933 | \f | |
1934 | ;;; Lame stuff | |
1935 | ;; | |
1936 | (defun ede-or (arg) | |
1937 | "Do `or' like stuff to ARG because you can't apply `or'." | |
1938 | (while (and arg (not (car arg))) | |
1939 | (setq arg (cdr arg))) | |
1940 | arg) | |
1941 | ||
1942 | \f | |
1943 | ;;; Debugging. | |
1944 | ||
1945 | (defun ede-adebug-project () | |
1946 | "Run adebug against the current ede project. | |
1947 | Display the results as a debug list." | |
1948 | (interactive) | |
1949 | (require 'data-debug) | |
1950 | (when (ede-current-project) | |
1951 | (data-debug-new-buffer "*Analyzer ADEBUG*") | |
1952 | (data-debug-insert-object-slots (ede-current-project) "") | |
1953 | )) | |
1954 | ||
1955 | (defun ede-adebug-project-parent () | |
1956 | "Run adebug against the current ede parent project. | |
1957 | Display the results as a debug list." | |
1958 | (interactive) | |
1959 | (require 'data-debug) | |
1960 | (when (ede-parent-project) | |
1961 | (data-debug-new-buffer "*Analyzer ADEBUG*") | |
1962 | (data-debug-insert-object-slots (ede-parent-project) "") | |
1963 | )) | |
1964 | ||
1965 | (defun ede-adebug-project-root () | |
1966 | "Run adebug against the current ede parent project. | |
1967 | Display the results as a debug list." | |
1968 | (interactive) | |
1969 | (require 'data-debug) | |
1970 | (when (ede-toplevel) | |
1971 | (data-debug-new-buffer "*Analyzer ADEBUG*") | |
1972 | (data-debug-insert-object-slots (ede-toplevel) "") | |
1973 | )) | |
1974 | \f | |
1975 | ;;; Hooks & Autoloads | |
1976 | ;; | |
1977 | ;; These let us watch various activities, and respond apropriatly. | |
1978 | ||
1979 | ;; (add-hook 'edebug-setup-hook | |
1980 | ;; (lambda () | |
1981 | ;; (def-edebug-spec ede-with-projectfile | |
1982 | ;; (form def-body)))) | |
1983 | ||
acc33231 CY |
1984 | (provide 'ede) |
1985 | ||
1986 | ;; Include this last because it depends on ede. | |
1987 | (require 'ede/files) | |
1988 | ||
1989 | ;; If this does not occur after the provide, we can get a recursive | |
1990 | ;; load. Yuck! | |
1991 | (if (featurep 'speedbar) | |
1992 | (ede-speedbar-file-setup) | |
1993 | (add-hook 'speedbar-load-hook 'ede-speedbar-file-setup)) | |
1994 | ||
1995 | ;;; ede.el ends here |