1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; eproject.el --- project workspaces for emacs
5 ;; Copyright (C) 2008-2010 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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;; User-configurable items:
26 (defvar prj-default-config
'(
28 ("Clean" "make clean" "C-f9")
29 ("Run" "echo run what" "f8")
30 ("Stop" "-e eproject-killtool" "C-f8")
32 ("Configure" "./configure")
34 ("Explore Project" "nautilus --browser `pwd` &")
35 ("XTerm In Project" "xterm &")
37 "*The default tools menu for new projects in eproject."
40 (defvar prj-set-default-directory nil
41 "*Should eproject set the project directory as default-directory
42 for all project files (nil/t).")
44 (defvar prj-set-framepos nil
45 "*Should eproject restore the last frame position/size (nil/t).")
47 (defvar prj-set-compilation-frame nil
48 "*Should eproject show compilation output in the other frame (nil/t).")
50 (defvar prj-set-multi-isearch nil
51 "*Should eproject setup multi-isearch in the project files (nil/t).")
53 ;; End of user-configurable items
54 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56 ;; There is a global file (~/.emacs.d/eproject.lst)
57 (defun prj-globalfile ()
58 (expand-file-name "eproject.lst"
59 (if (boundp 'user-emacs-directory
)
64 ;; with the list of all projects
67 ;; and the project that was open in the last session (if any)
68 (defvar prj-last-open nil
)
70 ;; and the frame coords from last session
71 (defvar prj-frame-pos nil
)
73 ;; eproject version that created the config file
74 (defvar prj-version nil
)
76 ;; Here is a function to reset these
78 (setq prj-version nil
)
80 (setq prj-last-open nil
)
81 (setq prj-frame-pos nil
)
84 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85 ;; Each project has a directory
87 (defvar prj-directory
)
89 ;; with a configuration files in it
90 (defvar prj-default-cfg
"eproject.cfg")
100 ;; an alist of settings
106 ;; a list of utility functions (feature incomplete)
107 (defvar prj-functions nil
)
109 ;; directory to run commands, default to prj-directory
110 (defvar prj-exec-directory
)
112 ;; The current project
115 ;; A list with generated functions for each tool
116 (defvar prj-tools-fns
)
118 ;; A list with files removed from the project
119 (defvar prj-removed-files
)
121 ;; Here is a function to reset/close the project
123 (setq prj-version nil
)
124 (setq prj-current nil
)
125 (setq prj-directory nil
)
126 (setq prj-exec-directory nil
)
128 (setq prj-removed-files nil
)
129 (setq prj-curfile nil
)
130 (setq prj-config nil
)
131 (setq prj-tools-fns nil
)
132 (setq prj-tools
(copy-tree prj-default-config
))
133 (prj-reset-functions)
136 (defun prj-reset-functions ()
137 (dolist (l prj-functions
)
138 (if (eq (car l
) 'setq
)
139 (makunbound (cadr l
))
140 (fmakunbound (cadr l
))
142 (setq prj-functions nil
)
145 (defun prj-set-functions (s)
146 (prj-reset-functions)
147 (setq prj-functions s
)
148 (dolist (l s
) (eval l
))
151 ;; Some more variables:
153 ;; the frame that exists on startup
154 (defvar prj-initial-frame nil
)
156 ;; this is put into minor-mode-alist
157 (defvar eproject-mode t
)
159 ;; where this file is in
160 (defvar eproject-directory
)
162 ;; eproject version that created the files
163 (defvar eproject-version
"0.4")
167 (defun eproject-setup-toggle () (interactive))
168 (defun eproject-setup-quit () (interactive))
169 (defun prj-config-get-result (s))
170 (defun prj-config-reset ())
171 (defun prj-config-print ())
172 (defun prj-config-parse ())
175 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
178 (defun caddr (l) (car (cddr l
)))
180 (defun prj-del-list (l e
)
181 (let ((a (assoc (car e
) l
)))
186 (defun prj-add-list (l e
)
187 (nconc (prj-del-list l e
) (list e
))
190 (defun prj-next-file (l e
)
191 (and (setq e
(assoc (car e
) l
))
195 (defun prj-prev-file (l e
)
196 (prj-next-file (reverse l
) e
)
199 ; replace a closed file, either by the previous or the next.
200 (defun prj-otherfile (l f
)
201 (or (prj-prev-file l f
)
205 ;; make relative path, but only up to the second level of ..
206 (defun prj-relative-path (f)
207 (let ((r (file-relative-name f prj-directory
)))
208 (if (string-match "^\\.\\.[/\\]\\.\\.[/\\]\\.\\.[/\\]" r
)
213 ;; friendly truncate filename
214 (defun prj-shortname (s)
215 (let ((l (length s
)) (x 30) n
)
219 (setq n
(length (file-name-nondirectory s
)))
220 (if (< n l
) (setq n
(1+ n
)))
223 (concat (substring s
0 (- x n
)) "..." (substring s
(- n
)))
226 (concat (substring s
0 x
) "...")
229 (concat "..." (substring s
(- n
) (- (- x
3) n
)) "...")
232 (defun prj-settitle ()
233 (modify-frame-parameters
237 (format "emacs - %s" (car prj-current
))
240 (defun eproject-addon (f)
241 (concat eproject-directory f
)
244 (defun prj-goto-line (n)
246 (beginning-of-line n
)
249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
250 ;; Write configuration to file
252 (defun prj-print-list (s fp
)
254 (setq v
(list 'setq s
255 (if (and (atom v
) (null (and (symbolp v
) v
)))
260 (pp v fp
) (princ "\n" fp
)
263 (defun prj-create-file (filename)
264 (let ((fp (generate-new-buffer filename
)))
265 (princ ";; -*- mode: Lisp; -*-\n\n" fp
)
268 (defun prj-close-file (fp)
269 (with-current-buffer fp
271 (and t
(write-region nil nil
(buffer-name fp
) nil
0))
277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
278 ;; Load/Save global project list and initial frame sizes
280 (defun prj-loadlist ()
282 (load (prj-globalfile) t t
)
283 (setq prj-version eproject-version
)
286 (defun prj-get-frame-pos (f)
288 (lambda (parm) (cons parm
(frame-parameter f parm
)))
289 '(top left width height
)
292 (defun prj-savelist ()
293 (let ((g (prj-globalfile)) fp
)
294 (unless (file-exists-p g
)
295 (make-directory (file-name-directory g
) t
)
297 (setq prj-last-open
(car prj-current
))
298 (when (frame-live-p prj-initial-frame
)
299 (setq prj-frame-pos
(prj-get-frame-pos prj-initial-frame
))
301 (setq fp
(prj-create-file g
))
303 (prj-print-list 'prj-version fp
)
304 (prj-print-list 'prj-list fp
)
305 (prj-print-list 'prj-last-open fp
)
306 (prj-print-list 'prj-frame-pos fp
)
310 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
311 ;; Load/Save local per-project configuration file
313 (defun prj-update-config ()
314 (let ((d (prj-get-directory prj-current
))
315 (e (prj-getconfig "exec-root"))
317 (if e
(setq d
(expand-file-name e d
)))
318 (setq prj-exec-directory
(file-name-as-directory d
))
321 (defun prj-get-directory (a)
322 (file-name-as-directory (expand-file-name (cadr a
)))
325 (defun prj-get-cfg ()
326 (expand-file-name (or (caddr prj-current
) prj-default-cfg
) prj-directory
)
329 (defun prj-loadconfig (a)
333 (setq prj-directory
(prj-get-directory a
))
334 (when (file-regular-p (setq lf
(prj-get-cfg)))
337 (or (assoc prj-curfile prj-files
)
341 (if (setq e
(prj-getconfig "project-name"))
343 (prj-setconfig "project-name" (car a
))
346 (prj-set-functions prj-functions
)
347 (setq prj-version eproject-version
)
350 (defun prj-saveconfig ()
354 (setq w
(selected-window))
355 (setq c
(window-buffer w
))
356 (dolist (f prj-files
)
357 (cond ((setq b
(get-buffer (car f
)))
358 (set-window-buffer w b t
)
359 (with-current-buffer b
360 (let ((s (line-number-at-pos (window-start w
)))
361 (p (line-number-at-pos (window-point w
)))
363 (push (list (car f
) s p
) files
)
368 (set-window-buffer w c t
)
370 (let ((fp (prj-create-file (prj-get-cfg)))
371 (prj-curfile (car prj-curfile
))
372 (prj-files (nreverse files
))
375 (prj-print-list 'prj-version fp
)
376 (prj-print-list 'prj-config fp
)
377 (prj-print-list 'prj-tools fp
)
378 (prj-print-list 'prj-files fp
)
379 (prj-print-list 'prj-curfile fp
)
380 (prj-print-list 'prj-functions fp
)
385 (defun prj-saveall ()
390 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
391 ;; The core functions: Open / Close / Add / Remove Project
393 (defun eproject-open (a)
394 "Open another project."
397 (or (prj-config-get-result 'p
)
398 (completing-read "Open Project: " (mapcar 'car prj-list
))
401 (let ((b (assoc a prj-list
)))
403 (error "No such project: %s" a
)
407 (setq a
(or (car (member a prj-list
)) a
))
408 (unless (eq a prj-current
)
409 (unless (file-directory-p (prj-get-directory a
))
410 (error "No such directory: %s" (cadr a
))
412 (setq prj-list
(cons a
(delq a prj-list
)))
419 (unless (prj-edit-file prj-curfile
)
423 (defun eproject-close ()
424 "Close the current project."
432 (save-some-buffers nil
)
433 (eproject-killbuffers t
)
436 (or f
(prj-addhooks))
444 (defun eproject-killbuffers (&optional from-project
)
445 "If called interactively kills all buffers that
446 do not belong to project files"
449 (dolist (f prj-files
)
450 (setq b
(get-buffer (car f
)))
452 (setq a
(cons (list b
) a
))
454 (dolist (b (buffer-list))
455 (when (eq (consp (assoc b a
)) from-project
)
459 (defun eproject-add (dir &optional name cfg
)
460 "Add a new or existing project to the list."
463 (setq d
(read-directory-name "Add project in directory: " prj-directory nil t
))
464 (setq n
(file-name-nondirectory (directory-file-name d
)))
465 (setq n
(read-string "Project name: " n
))
466 (setq f
(read-string "Project file: " prj-default-cfg
))
470 (setq dir
(directory-file-name dir
))
472 (setq name
(file-name-nondirectory dir
))
474 (when (and cfg
(string-equal cfg prj-default-cfg
))
477 (let ((a (if cfg
(list name dir cfg
) (list name dir
))))
482 (defun eproject-remove (a)
483 "Remove a project from the list."
486 (or (prj-config-get-result 'p
)
487 (completing-read "Remove project: " (mapcar 'car prj-list
))
490 (let ((b (assoc a prj-list
)))
492 (error "No such project: %s" a
)
498 (prog1 (y-or-n-p (format "Remove \"%s\"? " (car a
)))
501 (setq prj-list
(prj-del-list prj-list a
))
505 (defun eproject-save ()
506 "Save the project configuration to file."
513 (defun eproject-revert ()
514 "Reload the project configuration from file."
518 (prj-loadconfig prj-current
)
523 (defun eproject-addfile (f)
524 "Add a file to the current project."
528 (read-file-name "Add file to project: " nil nil t nil
)
530 (unless prj-current
(error "No project open"))
531 (let ((a (prj-insert-file f
(prj-config-get-result 'f
))))
533 (message "Added to project: %s" (car a
))
539 (defun eproject-removefile (a)
540 "Remove a file from the current project."
541 (interactive (prj-get-existing-file-1 "Remove file from project: "))
542 (setq a
(prj-get-existing-file-2 a
))
546 (defun eproject-visitfile (a)
547 "Visit a file from the current project."
548 (interactive (prj-get-existing-file-1 "Visit file: "))
549 (setq a
(prj-get-existing-file-2 a
))
553 (defun prj-get-existing-file-1 (msg)
556 (or (prj-config-get-result 'f
)
557 (completing-read msg
(mapcar 'car prj-files
))
560 (defun prj-get-existing-file-2 (a)
561 (unless prj-current
(error "No project open"))
564 (let ((b (assoc (prj-relative-path a
) prj-files
)))
565 (unless b
(error "No such file in project: %s" a
))
569 (defun eproject-help ()
570 "Show the eproject README."
572 (view-file (eproject-addon "eproject.txt"))
575 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
576 ;; Hook functions to track opening/closing files from emacs
578 (defun prj-addhooks ()
579 (add-hook 'kill-buffer-hook
'prj-kill-buffer-hook
)
580 (add-hook 'find-file-hook
'prj-find-file-hook
)
581 (add-hook 'window-configuration-change-hook
'prj-wcc-hook
)
584 (defun prj-removehooks ()
585 (remove-hook 'window-configuration-change-hook
'prj-wcc-hook
)
586 (remove-hook 'find-file-hook
'prj-find-file-hook
)
587 (remove-hook 'kill-buffer-hook
'prj-kill-buffer-hook
)
590 (defun prj-wcc-hook ()
591 (dolist (w (window-list))
592 (prj-register-buffer (window-buffer w
))
595 (defun prj-find-file-hook ()
596 (run-with-idle-timer 0.2 nil
'prj-wcc-hook
)
599 (defun prj-kill-buffer-hook ()
600 (let ((b (current-buffer)) a
)
601 (if (setq a
(rassq b prj-files
))
602 (prj-remove-file a t
)
603 (if (setq a
(rassq b prj-removed-files
))
604 (setq prj-removed-files
(delq a prj-removed-files
))
607 (defun prj-register-buffer (b)
609 (setq f
(buffer-file-name b
))
610 (when (and f t
) ;;(not (string-match "^\\." (file-name-nondirectory f))))
611 (setq a
(rassq b prj-files
))
613 (setq a
(prj-insert-file f nil t
))
616 (message "Added to project: %s" (car a
))
618 (prj-init-buffer a b
)
620 (when (and a
(null (eq a prj-curfile
)))
626 (defun prj-insert-file (f &optional after on-the-fly
)
627 (let ((r (prj-relative-path f
)) a m
)
628 (setq a
(assoc r prj-files
))
629 (unless (or a
(and on-the-fly
(assoc r prj-removed-files
)))
631 (setq m
(memq (or after prj-curfile
) prj-files
))
633 (setcdr m
(cons a
(cdr m
)))
634 (setq prj-files
(prj-add-list prj-files a
))
636 (setq prj-removed-files
(prj-del-list prj-removed-files a
))
640 (defun prj-remove-file (a &optional on-the-fly
)
641 (let ((n (prj-otherfile prj-files a
)) b
)
642 (setq prj-files
(prj-del-list prj-files a
))
643 (when (eq prj-curfile a
)
647 (setq prj-removed-files
(prj-add-list prj-removed-files a
))
649 (unless (prj-config-print)
650 (prj-edit-file prj-curfile
)
653 (message "Removed from project: %s" (car a
))
656 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
659 (defun prj-init-buffer (a b
)
660 (with-current-buffer b
661 (rename-buffer (car a
) t
)
662 (when prj-set-default-directory
668 (defun prj-find-file (a)
672 (setq f
(expand-file-name (car a
) prj-directory
))
673 (setq b
(get-file-buffer f
))
676 (setq b
(find-file-noselect f
))
678 (when (and b
(consp (cdr a
)))
682 (prj-init-buffer a b
)
686 (defun prj-edit-file (a)
687 (let ((f (prj-find-file a
)))
689 (eproject-setup-quit)
690 (switch-to-buffer (car f
))
691 (prj-restore-edit-pos (cdr f
) (selected-window))
693 ;;(message "dir: %s" default-directory)
698 (defun prj-restore-edit-pos (pos w
)
699 (let ((top (car pos
)) (line (cadr pos
)))
700 (when (and (numberp top
) (numberp line
))
702 (set-window-start w
(point))
706 (defun prj-select-window (w)
707 (let (focus-follows-mouse)
709 (select-frame-set-input-focus (window-frame w
))
712 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
713 ;; choose next/previous file
715 (defun eproject-nextfile ()
716 "Switch to the next file that belongs to the current project."
718 (prj-switch-file 'prj-next-file
'next-buffer
)
721 (defun eproject-prevfile ()
722 "Switch to the previous file that belongs to the current project."
724 (prj-switch-file 'prj-prev-file
'previous-buffer
)
727 (defun prj-switch-file (fn1 fn2
)
728 (let ((a (rassoc (current-buffer) prj-files
)))
730 (prj-edit-file (or (funcall fn1 prj-files a
) a
))
733 (prj-edit-file prj-curfile
)
739 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
742 (defun prj-setkeys ()
743 (let ((f (consp prj-current
))
744 (a (assoc 'eproject-mode minor-mode-map-alist
))
745 (map (make-sparse-keymap))
749 (push (cons 'eproject-mode map
) minor-mode-map-alist
)
752 (define-key map
[M-right
] 'eproject-nextfile
)
753 (define-key map
[M-left
] 'eproject-prevfile
)
754 (define-key map
[C-f5
] 'eproject-dired
)
756 (dolist (a prj-tools
)
757 (unless (setq fn
(nth n prj-tools-fns
))
758 (setq fn
(list 'lambda
))
759 (setq prj-tools-fns
(nconc prj-tools-fns
(list fn
)))
761 (setcdr fn
`(() (interactive) (prj-run-tool ',a
)))
763 (when (setq s
(caddr a
))
764 (define-key map
(prj-parse-key s
) (and f fn
))
766 (define-key map
[f5] 'eproject-setup-toggle)
769 (defun prj-parse-key (s)
771 (if (string-match "[a-z][a-z0-9]+$" s)
773 (concat "\"\\" s "\""))))
775 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
778 (defun prj-list-sorted ()
779 (sort (append prj-list nil)
780 '(lambda (a b) (string-lessp (car a) (car b)))
783 (defun prj-setmenu ()
784 (let ((f (consp prj-current)) m1 m2 m3)
787 `(("Open" open ,@(prj-menulist-maker prj-list prj-current 'prj-menu-open))
789 ("Add ..." "Add new or existing project to the list" . eproject-add)
790 ("Remove ..." "Remove project from the list" . eproject-remove)
791 ,@(and f '(("Close" "Close current project" . eproject-close)))
793 ("Setup" "Enter the project setup area." . eproject-setup-toggle)
794 ("Help" "View eproject.txt" . eproject-help)
798 (nconc m1 (cons '("--") (prj-menulist-maker prj-tools nil prj-tools-fns)))
800 `(("Dired" "Browse project directory in Dired - Use 'a' to add file(s) to the project" . eproject-dired)
802 ,@(prj-menulist-maker prj-files prj-curfile 'prj-menu-edit)
807 `((buffer "Project" project ,@m1)
808 (file "List" list ,@m2)
813 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
815 (defun prj-menu-edit ()
817 (let ((a (nth last-command-event prj-files)))
818 (if a (prj-edit-file a))
821 (defun prj-menu-open ()
823 (let ((a (nth last-command-event prj-list)))
824 (if a (eproject-open (car a)))
827 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
829 (defun prj-menu-maker (map l v)
830 (let ((e (list nil)))
831 (setq v (append v e))
832 (dolist (k (reverse l))
834 (when (symbolp (car k))
841 ((and (consp (cdr k)) (symbolp (cadr k)))
844 (setq k (and s (cons (car k) (make-sparse-keymap (car k)))))
847 (setcar e (intern (downcase (car k))))
850 (define-key-after map (vconcat v) k a)
851 (define-key map (vconcat v) k)
853 (if s (prj-menu-maker map s v))
856 (defun prj-copy-head (l n)
858 (while (and l (> n 0))
865 (defun prj-split-list (l n)
868 (push (prj-copy-head l n) r)
869 (setq l (nthcdr n l))
874 (defun prj-menulist-maker (l act fns)
875 (let (r (w 30) s (m 0) (n 0) k)
878 (prj-menulist-maker-1 (list l fns n) act)
881 ;; menu too long; split into submenus
882 (setq s (prj-split-list l w))
883 (setq k (prj-menulist-maker-1 (list (append (pop s) '(("--"))) fns n) act))
884 (setq r (nreverse k))
887 (setq fns (nthcdr w fns))
890 (setq k (prj-menulist-maker-1 (list l fns n) act))
891 (push (cons (concat (prj-shortname (caar l)) " ...")
892 (cons (intern (format "m_%d" (setq m (1+ m))))
898 (defun prj-menulist-maker-1 (l act)
904 (setcar (cddr l) (1+ n))
905 (setq f (if (consp (cadr l))
906 (prog1 (car (cadr l)) (setcar (cdr l) (cdr (cadr l))))
910 (unless (string-match "^ *#" i)
911 (setq s (if (and (consp (cdr a)) (stringp (cadr a))) (cadr a) i))
913 (setq e (cons s (cons (intern s) (prj-menulist-maker-1 l act))))
920 (setq i (prj-shortname i))
921 (setq e (cons n (if (eq a act)
922 `(menu-item ,i ,f :button (:toggle . t) :help ,s)
923 (cons i (cons s f)))))
930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
931 ;; Run make and other commands
933 (defun prj-compilation-in-frame (cmd)
934 (let ((bn "*compilation*") w h b c f)
935 (unless (get-buffer-window bn t)
936 (setq b (get-buffer-create bn))
937 (setq f (frame-list))
939 (setq w (frame-first-window (car f)))
940 (delete-other-windows w)
943 (setq h (/ (* 70 (frame-height)) 100))
944 (delete-other-windows w)
945 (setq w (split-window w h))
947 (set-window-buffer w b)
949 (let ((display-buffer-reuse-frames t) (f (selected-frame)))
951 (select-frame-set-input-focus f)
955 (cond ((string-match "^-e +" cmd)
956 (setq cmd (read (substring cmd (match-end 0))))
957 (unless (commandp cmd)
958 (setq cmd `(lambda () (interactive) ,cmd))
960 (command-execute cmd)
962 ((let ((b (current-buffer))
963 (old-dir default-directory)
966 (when (string-match "^-in +\\([^[:space:]]+\\) +" cmd)
967 (setq new-dir (match-string-no-properties 1 cmd))
968 (setq cmd (substring cmd (match-end 0)))
970 (when prj-exec-directory
971 (setq new-dir (expand-file-name new-dir prj-exec-directory))
974 (cond ((string-match "\\(.+\\)& *$" cmd)
975 (start-process-shell-command
976 "eproject-async" nil (match-string 1 cmd))
977 (message (match-string 1 cmd))
979 (prj-set-compilation-frame
980 (prj-compilation-in-frame cmd)
985 (with-current-buffer b (cd old-dir))
988 (defun prj-run-tool (a)
989 (unless (string-match "^--+$" (car a))
990 (prj-run (or (cadr a) (car a)))
993 (defun eproject-killtool ()
995 (let ((bn "*compilation*") w0 w1)
996 (when (setq w1 (get-buffer-window bn t))
997 (when (fboundp 'kill-compilation)
998 (setq w0 (selected-window))
1004 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1005 ;; run grep on project files
1007 (defun eproject-grep (command-args)
1008 "Run the grep command on all the project files."
1012 (grep-compute-defaults)
1013 (let ((default (grep-default-command)))
1014 (list (read-from-minibuffer
1015 "Run grep on project files: "
1016 (if current-prefix-arg default grep-command)
1020 (if current-prefix-arg nil default)
1022 (let ((b (current-buffer)) (old-dir default-directory))
1023 (dolist (f (mapcar 'car prj-files))
1024 (setq command-args (concat command-args " " f))
1026 (when prj-directory (cd prj-directory))
1028 (with-current-buffer b (cd old-dir))
1031 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1032 ;; add files to the project with dired
1036 (defun prj-dired-addfiles ()
1040 (dolist (f (dired-get-marked-files))
1041 (setq a (prj-insert-file f))
1044 (setq prj-curfile a)
1046 (message "Added to project: %d file(s)" n)
1050 (defun prj-dired-run ()
1052 (let ((f (dired-get-marked-files)) c)
1053 (and (setq c (pop f))
1055 (let ((prj-directory (file-name-directory c)))
1058 (defun eproject-dired ()
1059 "Start a dired window with the project directory."
1062 (eproject-setup-quit)
1063 ;;(message "Use 'a' to add marked or single files to the project.")
1064 (dired prj-directory)
1065 (let ((map dired-mode-map))
1066 (define-key map [mouse-2] 'dired-find-file)
1067 (define-key map "a" 'prj-dired-addfiles)
1068 (define-key map "r" 'prj-dired-run)
1069 (define-key map [menu-bar operate command] '("Add to Project"
1070 "Add current or marked file(s) to project" . prj-dired-addfiles))
1073 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1075 (defun prj-setup-all ()
1082 (defun prj-getconfig (n)
1083 (let ((a (cdr (assoc n prj-config))))
1087 (defun prj-setconfig (n v)
1088 (let ((a (assoc n prj-config)))
1091 (setq prj-config (nconc prj-config (list a)))
1096 (defun prj-on-kill ()
1100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1101 ;; isearch in all project files
1103 (defun prj-isearch-function (b wrap)
1105 (or b (setq b (current-buffer)))
1108 (setq a (car prj-files))
1109 (setq a (car (last prj-files)))
1111 ((setq a (rassoc b prj-files))
1113 (setq a (prj-next-file prj-files a))
1114 (setq a (prj-prev-file prj-files a))
1118 (if (buffer-live-p (cdr a))
1120 (setq d (car (prj-find-file a)))
1122 ;; (print `(prj-isearch (wrap . ,wrap) ,b ,d) (get-buffer "*Messages*"))
1126 (defun prj-isearch-setup ()
1127 (cond ((and prj-set-multi-isearch prj-current)
1128 (setq multi-isearch-next-buffer-function 'prj-isearch-function)
1129 (setq multi-isearch-pause 'initial)
1130 (add-hook 'isearch-mode-hook 'multi-isearch-setup)
1133 (remove-hook 'isearch-mode-hook 'multi-isearch-setup)
1136 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1139 (defun prj-startup-delayed ()
1141 (load (eproject-addon "eproject-config") nil t)
1143 ;; When no projects are specified yet, load the eproject project itself.
1145 (load (eproject-addon prj-default-cfg))
1148 ;; no project so far
1151 (add-hook 'kill-emacs-hook 'prj-on-kill)
1153 ;; inhibit open last project when a file was on the commandline
1154 (unless (buffer-file-name (window-buffer))
1157 ;; open last project
1158 (eproject-open prj-last-open)
1160 ;; restore frame position
1161 (when (and prj-set-framepos prj-frame-pos prj-initial-frame)
1162 (modify-frame-parameters prj-initial-frame prj-frame-pos)
1163 ;; emacs bug: when it's too busy it doesn't set frames correctly.
1167 (defun prj-command-line-switch (option)
1168 (setq prj-last-open (pop argv))
1169 (setq inhibit-startup-screen t)
1172 (defun eproject-startup ()
1173 ;; where is this file
1175 (setq eproject-directory (file-name-directory load-file-name)))
1176 (if (boundp 'prj-list)
1178 (load (eproject-addon "eproject-config"))
1182 (when prj-last-open (setq inhibit-startup-screen t))
1183 (when (display-graphic-p) (setq prj-initial-frame (selected-frame)))
1184 (push '("project" . prj-command-line-switch) command-switch-alist)
1185 (run-with-idle-timer 0.1 nil 'prj-startup-delayed)
1188 ;;;###autoload(require 'eproject)
1192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1193 ;; eproject.el ends here