1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; eproject.el --- project workspaces for emacs
5 ;; Copyright (C) 2008,2009 grischka
7 ;; Author: grischka -- grischka@users.sourceforge.net
8 ;; Created: 24 Jan 2008
11 ;; This program is free software, released under the GNU General
12 ;; Public License (GPL, version 2). For details see:
14 ;; http://www.fsf.org/licenses/gpl.html
16 ;; This program 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 GNU
19 ;; General Public License for more details.
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23 ;; There is a global file (~/.emacs.d/eproject.lst)
24 (defun prj-globalfile ()
25 (expand-file-name "eproject.lst"
26 (if (boundp 'user-emacs-directory
) user-emacs-directory
30 ;; with the list of all projects
33 ;; and the project that was open in the last session (if any)
34 (defvar prj-last-open nil
)
36 ;; and the frame coords from last session
37 (defvar prj-frame-pos nil
)
39 ;; eproject version that created the config file
40 (defvar prj-version nil
)
42 ;; Here is a function to reset these
44 (setq prj-version nil
)
46 (setq prj-last-open nil
)
47 (setq prj-frame-pos nil
)
50 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
51 ;; Each project has a directory
53 (defvar prj-directory
)
55 ;; with a configuration files in it
56 (defvar prj-default-cfg
"eproject.cfg")
66 ;; an alist of settings
72 ;; a list of utility functions (feature incomplete)
73 (defvar prj-functions nil
)
75 ;; directory to run commands, default to prj-directory
76 (defvar prj-exec-directory
)
78 ;; Here are some default tools for new projects,
79 ;; (which you might want to adjust to your needs)
81 (defun prj-default-config ()
82 (setq prj-tools
(copy-tree '(
84 ("Clean" "make clean" "C-f9")
85 ("Run" "echo run what" "f8")
86 ("Stop" "-e eproject-killtool" "C-f8")
88 ("Configure" "./configure")
90 ("Explore Project" "nautilus --browser `pwd` &")
91 ("XTerm In Project" "xterm &")
95 ;; The current project
98 ;; A list with generated functions for each tool
99 (defvar prj-tools-fns
)
101 ;; A list with files removed from the project
102 (defvar prj-removed-files
)
104 ;; Here is a function to reset/close the project
106 (setq prj-version nil
)
107 (setq prj-current nil
)
108 (setq prj-directory nil
)
109 (setq prj-exec-directory nil
)
111 (setq prj-removed-files nil
)
112 (setq prj-curfile nil
)
113 (setq prj-config nil
)
115 (setq prj-tools-fns nil
)
116 (prj-reset-functions)
120 (defun prj-reset-functions ()
121 (dolist (l prj-functions
)
122 (if (eq (car l
) 'setq
)
123 (makunbound (cadr l
))
124 (fmakunbound (cadr l
))
126 (setq prj-functions nil
)
129 (defun prj-set-functions (s)
130 (prj-reset-functions)
131 (setq prj-functions s
)
132 (dolist (l s
) (eval l
))
135 ;; Some more variables:
137 ;; the frame that exists on startup
138 (defvar prj-initial-frame nil
)
140 ;; this is put into minor-mode-alist
141 (defvar eproject-mode t
)
143 ;; where this file is in
144 (defvar eproject-directory
)
146 ;; eproject version that created the files
147 (defvar eproject-version
"0.3")
151 (defun eproject-setup-toggle () (interactive))
152 (defun eproject-setup-quit () (interactive))
153 (defun prj-config-get-result (s))
154 (defun prj-config-reset ())
155 (defun prj-config-print ())
156 (defun prj-config-parse ())
159 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
162 (defun caddr (l) (car (cddr l
)))
164 (defun prj-del-list (l e
)
165 (let ((a (assoc (car e
) l
)))
170 (defun prj-add-list (l e
)
171 (nconc (prj-del-list l e
) (list e
))
174 (defun prj-next-file (l e
)
175 (and (setq e
(assoc (car e
) l
))
179 (defun prj-prev-file (l e
)
180 (prj-next-file (reverse l
) e
)
183 ; replace a closed file, either by the previous or the next.
184 (defun prj-otherfile (l f
)
185 (or (prj-prev-file l f
)
189 ;; make relative path, but only up to the second level of ..
190 (defun prj-relative-path (f)
191 (let ((r (file-relative-name f prj-directory
)))
192 (if (string-match "^\\.\\.[/\\]\\.\\.[/\\]\\.\\.[/\\]" r
)
197 ;; friendly truncate filename
198 (defun prj-shortname (s)
199 (let ((l (length s
)) (x 30) n
)
203 (setq n
(length (file-name-nondirectory s
)))
204 (if (< n l
) (setq n
(1+ n
)))
207 (concat (substring s
0 (- x n
)) "..." (substring s
(- n
)))
210 (concat (substring s
0 x
) "...")
213 (concat "..." (substring s
(- n
) (- (- x
3) n
)) "...")
216 (defun prj-settitle ()
217 (modify-frame-parameters
221 (format "emacs - %s" (car prj-current
))
224 (defun eproject-addon (f)
225 (concat eproject-directory f
)
228 (defun prj-goto-line (n)
230 (beginning-of-line n
)
233 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
234 ;; Write configuration to file
236 (defun prj-print-list (s fp
)
238 (setq v
(list 'setq s
239 (if (and (atom v
) (null (and (symbolp v
) v
)))
244 (pp v fp
) (princ "\n" fp
)
247 (defun prj-create-file (filename)
248 (let ((fp (generate-new-buffer filename
)))
249 (princ ";; -*- mode: Lisp; -*-\n\n" fp
)
252 (defun prj-close-file (fp)
253 (with-current-buffer fp
255 (and t
(write-region nil nil
(buffer-name fp
) nil
0))
261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
262 ;; Load/Save global project list and initial frame sizes
264 (defun prj-loadlist ()
266 (load (prj-globalfile) t t
)
267 (setq prj-version eproject-version
)
270 (defun prj-get-frame-pos (f)
272 (lambda (parm) (cons parm
(frame-parameter f parm
)))
273 '(top left width height
)
276 (defun prj-savelist ()
277 (let ((g (prj-globalfile)) fp
)
278 (unless (file-exists-p g
)
279 (make-directory (file-name-directory g
) t
)
281 (setq prj-last-open
(car prj-current
))
282 (when (frame-live-p prj-initial-frame
)
283 (setq prj-frame-pos
(prj-get-frame-pos prj-initial-frame
))
285 (setq fp
(prj-create-file g
))
287 (prj-print-list 'prj-version fp
)
288 (prj-print-list 'prj-list fp
)
289 (prj-print-list 'prj-last-open fp
)
290 (prj-print-list 'prj-frame-pos fp
)
294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
295 ;; Load/Save local per-project configuration file
297 (defun prj-update-config ()
298 (let ((d (prj-get-directory prj-current
))
299 (e (prj-getconfig "exec-root"))
301 (if e
(setq d
(expand-file-name e d
)))
302 (setq prj-exec-directory
(file-name-as-directory d
))
305 (defun prj-get-directory (a)
306 (file-name-as-directory (expand-file-name (cadr a
)))
309 (defun prj-get-cfg ()
310 (expand-file-name (or (caddr prj-current
) prj-default-cfg
) prj-directory
)
313 (defun prj-loadconfig (a)
317 (setq prj-directory
(prj-get-directory a
))
318 (when (file-regular-p (setq lf
(prj-get-cfg)))
321 (or (assoc prj-curfile prj-files
)
325 (if (setq e
(prj-getconfig "project-name"))
327 (prj-setconfig "project-name" (car a
))
330 (prj-set-functions prj-functions
)
331 (setq prj-version eproject-version
)
334 (defun prj-saveconfig ()
338 (setq w
(selected-window))
339 (setq c
(window-buffer w
))
340 (dolist (f prj-files
)
341 (cond ((setq b
(get-buffer (car f
)))
342 (set-window-buffer w b t
)
343 (with-current-buffer b
344 (let ((s (line-number-at-pos (window-start w
)))
345 (p (line-number-at-pos (window-point w
)))
347 (push (list (car f
) s p
) files
)
352 (set-window-buffer w c t
)
354 (let ((fp (prj-create-file (prj-get-cfg)))
355 (prj-curfile (car prj-curfile
))
356 (prj-files (nreverse files
))
359 (prj-print-list 'prj-version fp
)
360 (prj-print-list 'prj-config fp
)
361 (prj-print-list 'prj-tools fp
)
362 (prj-print-list 'prj-files fp
)
363 (prj-print-list 'prj-curfile fp
)
364 (prj-print-list 'prj-functions fp
)
369 (defun prj-saveall ()
374 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
375 ;; The core functions: Open / Close / Add / Remove Project
377 (defun eproject-open (a)
378 "Open another project."
381 (or (prj-config-get-result 'p
)
382 (completing-read "Open Project: " (mapcar 'car prj-list
))
385 (let ((b (assoc a prj-list
)))
387 (error "No such project: %s" a
)
391 (setq a
(or (car (member a prj-list
)) a
))
392 (unless (eq a prj-current
)
393 (unless (file-directory-p (prj-get-directory a
))
394 (error "No such directory: %s" (cadr a
))
396 (setq prj-list
(cons a
(delq a prj-list
)))
404 (unless (prj-edit-file prj-curfile
)
408 (defun eproject-close ()
409 "Close the current project."
417 (save-some-buffers nil
)
418 (eproject-killbuffers t
)
421 (or f
(prj-addhooks))
429 (defun eproject-killbuffers (&optional from-project
)
430 "If called interactively kills all buffers that
431 do not belong to project files"
434 (dolist (f prj-files
)
435 (setq b
(get-buffer (car f
)))
437 (setq a
(cons (list b
) a
))
439 (dolist (b (buffer-list))
440 (when (eq (consp (assoc b a
)) from-project
)
444 (defun eproject-add (dir &optional name cfg
)
445 "Add a new or existing project to the list."
448 (setq d
(read-directory-name "Add project in directory: " prj-directory nil t
))
449 (setq n
(file-name-nondirectory (directory-file-name d
)))
450 (setq n
(read-string "Project name: " n
))
451 (setq f
(read-string "Project file: " prj-default-cfg
))
455 (setq dir
(directory-file-name dir
))
456 (setq name
(file-name-nondirectory dir
))
457 (when (and cfg
(string-equal cfg prj-default-cfg
))
460 (let ((a (if cfg
(list name dir cfg
) (list name dir
))))
465 (defun eproject-remove (a)
466 "Remove a project from the list."
469 (or (prj-config-get-result 'p
)
470 (completing-read "Remove project: " (mapcar 'car prj-list
))
473 (let ((b (assoc a prj-list
)))
475 (error "No such project: %s" a
)
481 (prog1 (y-or-n-p (format "Remove \"%s\"? " (car a
)))
484 (setq prj-list
(prj-del-list prj-list a
))
488 (defun eproject-save ()
489 "Save the project configuration to file."
496 (defun eproject-revert ()
497 "Reload the project configuration from file."
501 (prj-loadconfig prj-current
)
506 (defun eproject-addfile (f)
507 "Add a file to the current project."
511 (read-file-name "Add file to project: " nil nil t nil
)
513 (unless prj-current
(error "No project open"))
514 (let ((a (prj-insert-file f
(prj-config-get-result 'f
))))
516 (message "Added to project: %s" (car a
))
522 (defun eproject-removefile (a)
523 "Remove a file from the current project."
524 (interactive (prj-get-existing-file-1 "Remove file from project: "))
525 (setq a
(prj-get-existing-file-2 a
))
529 (defun eproject-visitfile (a)
530 "Visit a file from the current project."
531 (interactive (prj-get-existing-file-1 "Visit file: "))
532 (setq a
(prj-get-existing-file-2 a
))
536 (defun prj-get-existing-file-1 (msg)
539 (or (prj-config-get-result 'f
)
540 (completing-read msg
(mapcar 'car prj-files
))
543 (defun prj-get-existing-file-2 (a)
544 (unless prj-current
(error "No project open"))
547 (let ((b (assoc (prj-relative-path a
) prj-files
)))
548 (unless b
(error "No such file in project: %s" a
))
552 (defun eproject-help ()
553 "Show the eproject README."
555 (view-file (eproject-addon "eproject.txt"))
558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
559 ;; Hook functions to track opening/closing files from emacs
561 (defun prj-addhooks ()
562 (add-hook 'kill-buffer-hook
'prj-kill-buffer-hook
)
563 (add-hook 'find-file-hook
'prj-find-file-hook
)
564 (add-hook 'window-configuration-change-hook
'prj-wcc-hook
)
567 (defun prj-removehooks ()
568 (remove-hook 'window-configuration-change-hook
'prj-wcc-hook
)
569 (remove-hook 'find-file-hook
'prj-find-file-hook
)
570 (remove-hook 'kill-buffer-hook
'prj-kill-buffer-hook
)
573 (defun prj-wcc-hook ()
574 (let ((w (selected-window)) (b (window-buffer (selected-window))))
575 ;;(message "wcc-hook: %s" (prin1-to-string (list w b)))
576 (prj-register-buffer b
)
579 (defun prj-find-file-hook ()
580 (run-with-idle-timer 0.2 nil
'prj-wcc-hook
)
583 (defun prj-kill-buffer-hook ()
584 (let ((b (current-buffer)) a
)
585 (if (setq a
(rassq b prj-files
))
586 (prj-remove-file a t
)
587 (if (setq a
(rassq b prj-removed-files
))
588 (setq prj-removed-files
(delq a prj-removed-files
))
591 (defun prj-register-buffer (b)
593 (setq f
(buffer-file-name b
))
594 (when (and f t
) ;;(not (string-match "^\\." (file-name-nondirectory f))))
595 (setq a
(rassq b prj-files
))
597 (setq a
(prj-insert-file f nil t
))
600 (message "Added to project: %s" (car a
))
603 (with-current-buffer b
604 (rename-buffer (car a
) t
)
606 (when (and a
(null (eq a prj-curfile
)))
612 (defun prj-insert-file (f &optional after on-the-fly
)
613 (let ((r (prj-relative-path f
)) a m
)
614 (setq a
(assoc r prj-files
))
615 (unless (or a
(and on-the-fly
(assoc r prj-removed-files
)))
617 (setq m
(memq (or after prj-curfile
) prj-files
))
619 (setcdr m
(cons a
(cdr m
)))
620 (setq prj-files
(prj-add-list prj-files a
))
622 (setq prj-removed-files
(prj-del-list prj-removed-files a
))
626 (defun prj-remove-file (a &optional on-the-fly
)
627 (let ((n (prj-otherfile prj-files a
)) b
)
628 (setq prj-files
(prj-del-list prj-files a
))
629 (when (eq prj-curfile a
)
633 (setq prj-removed-files
(prj-add-list prj-removed-files a
))
635 (unless (prj-config-print)
636 (prj-edit-file prj-curfile
)
639 (message "Removed from project: %s" (car a
))
642 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
645 (defun prj-find-file (a)
648 (setq f
(expand-file-name (car a
) prj-directory
))
649 (setq b
(get-file-buffer f
))
652 (setq b
(find-file-noselect f
))
655 (with-current-buffer b
656 (rename-buffer (car a
) t
)
658 (when (consp (cdr a
))
666 (defun prj-edit-file (a)
667 (let ((f (prj-find-file a
)))
669 (eproject-setup-quit)
670 (switch-to-buffer (car f
))
671 (prj-restore-edit-pos (cdr f
) (selected-window))
677 (defun prj-restore-edit-pos (pos w
)
678 (let ((top (car pos
)) (line (cadr pos
)))
679 (when (and (numberp top
) (numberp line
))
681 (set-window-start w
(point))
685 (defun prj-select-window (w)
686 (let (focus-follows-mouse)
688 (select-frame-set-input-focus (window-frame w
))
691 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
692 ;; choose next/previous file
694 (defun eproject-nextfile ()
695 "Switch to the next file that belongs to the current project."
697 (prj-switch-file 'prj-next-file
'next-buffer
)
700 (defun eproject-prevfile ()
701 "Switch to the previous file that belongs to the current project."
703 (prj-switch-file 'prj-prev-file
'previous-buffer
)
706 (defun prj-switch-file (fn1 fn2
)
707 (let ((a (rassoc (current-buffer) prj-files
)))
709 (prj-edit-file (or (funcall fn1 prj-files a
) a
))
712 (prj-edit-file prj-curfile
)
718 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
721 (defun prj-setkeys ()
722 (let ((f (consp prj-current
))
723 (a (assoc 'eproject-mode minor-mode-map-alist
))
724 (map (make-sparse-keymap))
728 (push (cons 'eproject-mode map
) minor-mode-map-alist
)
731 (define-key map
[M-right
] 'eproject-nextfile
)
732 (define-key map
[M-left
] 'eproject-prevfile
)
733 (define-key map
[C-f5
] 'eproject-dired
)
735 (dolist (a prj-tools
)
736 (unless (setq fn
(nth n prj-tools-fns
))
737 (setq fn
(list 'lambda
))
738 (setq prj-tools-fns
(nconc prj-tools-fns
(list fn
)))
740 (setcdr fn
`(() (interactive) (prj-run-tool ',a
)))
742 (when (setq s
(caddr a
))
743 (define-key map
(prj-parse-key s
) (and f fn
))
745 (define-key map
[f5] 'eproject-setup-toggle)
748 (defun prj-parse-key (s)
750 (if (string-match "[a-z][a-z0-9]+$" s)
752 (concat "\"\\" s "\""))))
754 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
757 (defun prj-list-sorted ()
758 (sort (append prj-list nil)
759 '(lambda (a b) (string-lessp (car a) (car b)))
762 (defun prj-setmenu ()
763 (let ((f (consp prj-current)) m1 m2 m3)
766 `(("Open" open ,@(prj-menulist-maker prj-list prj-current 'prj-menu-open))
768 ("Add ..." "Add new or existing project to the list" . eproject-add)
769 ("Remove ..." "Remove project from the list" . eproject-remove)
770 ,@(and f '(("Close" "Close current project" . eproject-close)))
772 ("Setup" "Enter the project setup area." . eproject-setup-toggle)
773 ("Help" "View eproject.txt" . eproject-help)
777 (nconc m1 (cons '("--") (prj-menulist-maker prj-tools nil prj-tools-fns)))
779 `(("Dired" "Browse project directory in Dired - Use 'a' to add file(s) to the project" . eproject-dired)
781 ,@(prj-menulist-maker prj-files prj-curfile 'prj-menu-edit)
786 `((buffer "Project" project ,@m1)
787 (file "List" list ,@m2)
792 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
794 (defun prj-menu-edit ()
796 (let ((a (nth last-command-event prj-files)))
797 (if a (prj-edit-file a))
800 (defun prj-menu-open ()
802 (let ((a (nth last-command-event prj-list)))
803 (if a (eproject-open (car a)))
806 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
808 (defun prj-menu-maker (map l v)
809 (let ((e (list nil)))
810 (setq v (append v e))
811 (dolist (k (reverse l))
813 (when (symbolp (car k))
820 ((and (consp (cdr k)) (symbolp (cadr k)))
823 (setq k (and s (cons (car k) (make-sparse-keymap (car k)))))
826 (setcar e (intern (downcase (car k))))
829 (define-key-after map (vconcat v) k a)
830 (define-key map (vconcat v) k)
832 (if s (prj-menu-maker map s v))
835 (defun prj-copy-head (l n)
837 (while (and l (> n 0))
844 (defun prj-split-list (l n)
847 (push (prj-copy-head l n) r)
848 (setq l (nthcdr n l))
853 (defun prj-menulist-maker (l act fns)
854 (let (r (w 30) s (m 0) (n 0) k)
857 (prj-menulist-maker-1 (list l fns n) act)
860 ;; menu too long; split into submenus
861 (setq s (prj-split-list l w))
862 (setq k (prj-menulist-maker-1 (list (append (pop s) '(("--"))) fns n) act))
863 (setq r (nreverse k))
866 (setq fns (nthcdr w fns))
869 (setq k (prj-menulist-maker-1 (list l fns n) act))
870 (push (cons (concat (prj-shortname (caar l)) " ...")
871 (cons (intern (format "m_%d" (setq m (1+ m))))
877 (defun prj-menulist-maker-1 (l act)
883 (setcar (cddr l) (1+ n))
884 (setq f (if (consp (cadr l))
885 (prog1 (car (cadr l)) (setcar (cdr l) (cdr (cadr l))))
889 (unless (string-match "^ *#" i)
890 (setq s (if (and (consp (cdr a)) (stringp (cadr a))) (cadr a) i))
892 (setq e (cons s (cons (intern s) (prj-menulist-maker-1 l act))))
899 (setq i (prj-shortname i))
900 (setq e (cons n (if (eq a act)
901 `(menu-item ,i ,f :button (:toggle . t) :help ,s)
902 (cons i (cons s f)))))
909 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
910 ;; Run make and other commands
912 (defun prj-setup-tool-window ()
913 (let ((bn "*compilation*") w h b c f)
914 (unless (get-buffer-window bn t)
915 (setq b (get-buffer-create bn))
916 (setq f (frame-list))
918 (setq w (frame-first-window (car f)))
919 (delete-other-windows w)
922 (setq h (/ (* 70 (frame-height)) 100))
923 (delete-other-windows w)
924 (setq w (split-window w h))
926 (set-window-buffer w b)
930 (cond ((string-match "^-e +" cmd)
931 (setq cmd (read (substring cmd (match-end 0))))
932 (unless (commandp cmd)
933 (setq cmd `(lambda () (interactive) ,cmd))
935 (command-execute cmd)
938 (when (string-match "^-in +\\([^[:space:]]+\\) +" cmd)
939 (setq dir (match-string-no-properties 1 cmd))
940 (setq cmd (substring cmd (match-end 0)))
942 (when prj-exec-directory
943 (setq dir (expand-file-name (or dir ".") prj-exec-directory))
946 (cond ((string-match "\\(.+\\)& *$" cmd)
947 (start-process-shell-command "eproject-async" nil (match-string 1 cmd))
948 (message (match-string 1 cmd))
951 (unless (or (fboundp 'ecb-activate) (fboundp 'ewm-init))
952 (prj-setup-tool-window)
954 (let ((display-buffer-reuse-frames t) (f (selected-frame)))
956 (select-frame-set-input-focus f)
959 (defun prj-run-tool (a)
960 (unless (string-match "^--+$" (car a))
961 (prj-run (or (cadr a) (car a)))
964 (defun eproject-killtool ()
966 (let ((bn "*compilation*") w0 w1)
967 (when (setq w1 (get-buffer-window bn t))
968 (when (fboundp 'kill-compilation)
969 (setq w0 (selected-window))
975 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
976 ;; run grep on project files
978 (defun eproject-grep (command-args)
979 "Run the grep command on all the project files."
983 (grep-compute-defaults)
984 (let ((default (grep-default-command)))
985 (list (read-from-minibuffer
986 "Run grep on project files: "
987 (if current-prefix-arg default grep-command)
991 (if current-prefix-arg nil default)
993 (let ((default-directory prj-directory))
994 (dolist (f (mapcar 'car prj-files))
995 (setq command-args (concat command-args " " f))
1000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1001 ;; add files to the project with dired
1005 (defun prj-dired-addfiles ()
1009 (dolist (f (dired-get-marked-files))
1010 (setq a (prj-insert-file f))
1013 (setq prj-curfile a)
1015 (message "Added to project: %d file(s)" n)
1019 (defun prj-dired-run ()
1021 (let ((f (dired-get-marked-files)) c)
1022 (and (setq c (pop f))
1024 (let ((prj-directory (file-name-directory c)))
1027 (defun eproject-dired ()
1028 "Start a dired window with the project directory."
1031 (eproject-setup-quit)
1032 ;;(message "Use 'a' to add marked or single files to the project.")
1033 (dired prj-directory)
1034 (let ((map dired-mode-map))
1035 (define-key map [mouse-2] 'dired-find-file)
1036 (define-key map "a" 'prj-dired-addfiles)
1037 (define-key map "r" 'prj-dired-run)
1038 (define-key map [menu-bar operate command] '("Add to Project"
1039 "Add current or marked file(s) to project" . prj-dired-addfiles))
1042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1044 (defun prj-setup-all ()
1051 (defun prj-getconfig (n)
1052 (let ((a (cdr (assoc n prj-config))))
1056 (defun prj-setconfig (n v)
1057 (let ((a (assoc n prj-config)))
1060 (setq prj-config (nconc prj-config (list a)))
1065 (defun prj-on-kill ()
1069 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1070 ;; isearch in all project files
1072 (defun prj-isearch-function (b wrap)
1074 (or b (setq b (current-buffer)))
1077 (setq a (car prj-files))
1078 (setq a (car (last prj-files)))
1080 ((setq a (rassoc b prj-files))
1082 (setq a (prj-next-file prj-files a))
1083 (setq a (prj-prev-file prj-files a))
1087 (if (buffer-live-p (cdr a))
1089 (setq d (car (prj-find-file a)))
1091 ;; (print `(prj-isearch (wrap . ,wrap) ,b ,d) (get-buffer "*Messages*"))
1095 (defun prj-isearch-setup ()
1097 (setq multi-isearch-next-buffer-function 'prj-isearch-function)
1098 (setq multi-isearch-pause 'initial)
1099 (add-hook 'isearch-mode-hook 'multi-isearch-setup)
1102 (remove-hook 'isearch-mode-hook 'multi-isearch-setup)
1105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1108 (defun prj-startup-delayed ()
1110 (load (eproject-addon "eproject-config") nil t)
1112 ;; When no projects are specified yet, load the eproject project itself.
1114 (load (eproject-addon prj-default-cfg))
1117 ;; no project so far
1120 (add-hook 'kill-emacs-hook 'prj-on-kill)
1122 ;; inhibit open last project when a file was on the commandline
1123 (unless (buffer-file-name (window-buffer))
1126 ;; open last project
1127 (eproject-open prj-last-open)
1129 ;; restore frame position
1130 (unless (fboundp 'ewm-init)
1131 (when (and prj-frame-pos prj-initial-frame)
1132 (modify-frame-parameters prj-initial-frame prj-frame-pos)
1133 ;; emacs bug: when it's too busy it doesn't set frames correctly.
1137 (when (fboundp 'ecb-activate)
1142 (defun prj-command-line-switch (option)
1143 (setq prj-last-open (pop argv))
1144 (setq inhibit-startup-screen t)
1147 (defun eproject-startup ()
1148 ;; where is this file
1150 (setq eproject-directory (file-name-directory load-file-name)))
1151 (if (boundp 'prj-list)
1153 (load (eproject-addon "eproject-config"))
1157 (when prj-last-open (setq inhibit-startup-screen t))
1158 (when (display-graphic-p) (setq prj-initial-frame (selected-frame)))
1159 (push '("project" . prj-command-line-switch) command-switch-alist)
1160 (run-with-idle-timer 0.1 nil 'prj-startup-delayed)
1163 ;;;###autoload(require 'eproject)
1167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1168 ;; eproject.el ends here