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
24 (defun prj-globalfile ()
25 (unless (boundp 'user-emacs-directory
)
26 (setq user-emacs-directory
"~/.emacs.d/")
28 (let ((d (expand-file-name user-emacs-directory
)))
30 (concat d
"eproject.lst")
33 ;; with the list of all projects
36 ;; and the project that was open in the last session (if any)
37 (defvar prj-last-open nil
)
39 ;; and the frame coords from last session
40 (defvar prj-frame-pos nil
)
42 ;; eproject version that created the config file
43 (defvar prj-version nil
)
45 ;; Here is a function to reset these
47 (setq prj-version nil
)
49 (setq prj-last-open nil
)
50 (setq prj-frame-pos nil
)
53 ;; Each project has a directory
54 (defvar prj-directory
)
56 ;; with a configuration files in it
57 (defun prj-localfile ()
58 (expand-file-name "eproject.cfg" prj-directory
)
69 ;; an alist of settings
75 ;; a list of utility functions (feature incomplete)
76 (defvar prj-functions nil
)
78 ;; directory to run commands, default to prj-directory
79 (defvar prj-directory-run
)
81 ;; Here are some default tools for new projects,
82 ;; (which you might want to adjust to your needs)
84 (defun prj-default-config ()
85 (setq prj-tools
(copy-tree '(
87 ("Clean" "make clean" "C-f9")
88 ("Run" "echo run what" "f8")
89 ("Stop" "-e eproject-killtool" "C-f8")
91 ("Configure" "./configure")
93 ("Explore Project" "nautilus --browser `pwd` &")
94 ("XTerm In Project" "xterm &")
98 ;; This defines the current project
101 ;; There is an internal list with generated functions
103 (defvar prj-tools-fns
)
105 ;; and a list with files removed from the project
106 (defvar prj-removed-files
)
108 ;; Here is a function to reset/close the project
110 (setq prj-version nil
)
111 (setq prj-current nil
)
112 (setq prj-directory nil
)
113 (setq prj-directory-run nil
)
115 (setq prj-removed-files nil
)
116 (setq prj-curfile nil
)
117 (setq prj-config nil
)
119 (setq prj-tools-fns nil
)
120 (prj-reset-functions)
124 (defun prj-reset-functions ()
125 (dolist (l prj-functions
)
126 (if (eq (car l
) 'setq
)
127 (makunbound (cadr l
))
128 (fmakunbound (cadr l
))
130 (setq prj-functions nil
)
133 (defun prj-set-functions (s)
134 (prj-reset-functions)
135 (setq prj-functions s
)
136 (dolist (l s
) (eval l
))
139 ;; Some more variables
141 ;; the frame that exists on startup
142 (defvar prj-initial-frame nil
)
144 ;; this is put into minor-mode-alist
145 (defvar eproject-mode t
)
147 ;; where this file is in
148 (defvar eproject-directory
)
150 ;; eproject version that created the files
151 (defvar eproject-version
"0.3")
155 (defun eproject-setup-toggle () (interactive))
156 (defun eproject-setup-quit () (interactive))
157 (defun prj-config-get-result (s))
158 (defun prj-config-reset ())
159 (defun prj-config-print ())
160 (defun prj-config-parse ())
163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
166 (defun caddr (l) (car (cddr l
)))
168 (defun prj-del-list (l e
)
169 (let ((a (assoc (car e
) l
)))
174 (defun prj-add-list (l e
)
175 (nconc (prj-del-list l e
) (list e
))
178 (defun prj-next-file (l e
)
179 (and (setq e
(assoc (car e
) l
))
183 (defun prj-prev-file (l e
)
184 (prj-next-file (reverse l
) e
)
187 ; replace a closed file, either by the previous or the next.
188 (defun prj-otherfile (l f
)
189 (or (prj-prev-file l f
)
193 ;; make relative path, but only up to the second level of ..
194 (defun prj-relative-path (f)
195 (let ((r (file-relative-name f prj-directory
)))
196 (if (string-match "^\\.\\.[/\\]\\.\\.[/\\]\\.\\.[/\\]" r
)
201 ;; friendly truncate filename
202 (defun prj-shortname (s)
203 (let ((l (length s
)) (x 30) n
)
207 (setq n
(length (file-name-nondirectory s
)))
208 (if (< n l
) (setq n
(1+ n
)))
211 (concat (substring s
0 (- x n
)) "..." (substring s
(- n
)))
214 (concat (substring s
0 x
) "...")
217 (concat "..." (substring s
(- n
) (- (- x
3) n
)) "...")
220 (defun prj-settitle ()
221 (modify-frame-parameters
225 (format "emacs - %s" (car prj-current
))
228 (defun eproject-addon (f)
229 (concat eproject-directory f
)
232 (defun prj-goto-line (n)
234 (beginning-of-line n
)
237 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
238 ;; Write configuration to file
240 (defun prj-print-list (s fp
)
242 (setq v
(list 'setq s
243 (if (and (atom v
) (null (and (symbolp v
) v
)))
248 (pp v fp
) (princ "\n" fp
)
251 (defun prj-create-file (filename)
252 (let ((fp (generate-new-buffer filename
)))
253 (princ ";; -*- mode: Lisp; -*-\n\n" fp
)
256 (defun prj-close-file (fp)
257 (with-current-buffer fp
259 (write-region nil nil
(buffer-name fp
) nil
0)
265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
266 ;; Load/Save global project list and initial frame sizes
268 (defun prj-loadlist ()
270 (load (prj-globalfile) t t
)
271 (setq prj-version eproject-version
)
274 (defun prj-get-frame-pos (f)
276 (lambda (parm) (cons parm
(frame-parameter f parm
)))
277 '(top left width height
)
280 (defun prj-savelist ()
281 (let ((g (prj-globalfile))
284 (unless (file-exists-p g
)
285 (make-directory (file-name-directory g
) t
)
287 (setq prj-last-open
(car prj-current
))
288 (when (frame-live-p prj-initial-frame
)
289 (setq prj-frame-pos
(prj-get-frame-pos prj-initial-frame
))
291 (setq fp
(prj-create-file g
))
293 (prj-print-list 'prj-version fp
)
294 (prj-print-list 'prj-list fp
)
295 (prj-print-list 'prj-last-open fp
)
296 (prj-print-list 'prj-frame-pos fp
)
300 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
301 ;; Load/Save local per-project configuration file
303 (defun prj-update-config ()
304 (setq prj-directory-run
305 (file-name-as-directory
307 (or (prj-getconfig "run-directory") ".")
312 (defun prj-loadconfig (a)
317 (file-name-as-directory
318 (expand-file-name (cadr a
))
321 (when (file-exists-p (setq lf
(prj-localfile)))
324 (or (assoc prj-curfile prj-files
)
328 (if (setq e
(prj-getconfig "project-name"))
330 (prj-setconfig "project-name" (car a
))
333 (prj-set-functions prj-functions
)
334 (setq prj-version eproject-version
)
337 (defun prj-saveconfig ()
341 (setq w
(selected-window))
342 (setq c
(window-buffer w
))
343 (dolist (f prj-files
)
344 (cond ((setq b
(get-buffer (car f
)))
345 (set-window-buffer w b t
)
346 (with-current-buffer b
347 (let ((s (line-number-at-pos (window-start w
)))
348 (p (line-number-at-pos (window-point w
)))
350 (push (list (car f
) s p
) files
)
355 (set-window-buffer w c t
)
357 (let ((fp (prj-create-file (prj-localfile)))
358 (prj-curfile (car prj-curfile
))
359 (prj-files (nreverse files
))
362 (prj-print-list 'prj-version fp
)
363 (prj-print-list 'prj-config fp
)
364 (prj-print-list 'prj-tools fp
)
365 (prj-print-list 'prj-files fp
)
366 (prj-print-list 'prj-curfile fp
)
367 (prj-print-list 'prj-functions fp
)
372 (defun prj-saveall ()
377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
378 ;; The core functions: Open / Close / Add / Remove Project
380 (defun eproject-open (a)
381 "Open another project."
384 (or (prj-config-get-result 'p
)
385 (completing-read "Open Project: " (mapcar 'car prj-list
))
388 (let ((b (assoc a prj-list
)))
390 (error "No such project: %s" a
)
394 (setq a
(or (car (member a prj-list
)) a
))
395 (unless (eq a prj-current
)
396 (unless (file-directory-p (cadr a
))
397 (error "Error: No such directory: %s" (cadr a
))
399 (setq prj-list
(cons a
(delq a prj-list
)))
407 (unless (prj-edit-file prj-curfile
)
411 (defun eproject-close ()
412 "Close the current project."
420 (save-some-buffers nil
)
421 (eproject-killbuffers t
)
424 (or f
(prj-addhooks))
432 (defun eproject-killbuffers (&optional from-project
)
433 "If called interactively kills all buffers that
434 do not belong to project files"
437 (dolist (f prj-files
)
438 (setq b
(get-buffer (car f
)))
440 (setq a
(cons (list b
) a
))
442 (dolist (b (buffer-list))
443 (when (eq (consp (assoc b a
)) from-project
)
447 (defun eproject-add (d)
448 "Add a new or existing project to the list."
451 (read-directory-name "Add project in directory: " prj-directory nil t
)
454 (setq d
(directory-file-name d
))
456 (when (= 0 (length d
))
457 (error "Error: Empty directory name.")
460 (setq n
(file-name-nondirectory d
))
466 (defun eproject-remove (a)
467 "Remove a project from the list."
470 (or (prj-config-get-result 'p
)
471 (completing-read "Remove project: " (mapcar 'car prj-list
))
474 (let ((b (assoc a prj-list
)))
476 (error "No such project: %s" a
)
482 (prog1 (y-or-n-p (format "Remove \"%s\"? " (car a
)))
485 (setq prj-list
(prj-del-list prj-list a
))
489 (defun eproject-save ()
490 "Save the project configuration to file."
497 (defun eproject-revert ()
498 "Reload the project configuration from file."
502 (prj-loadconfig prj-current
)
507 (defun eproject-addfile (f)
508 "Add a file to the current project."
512 (read-file-name "Add file to project: " nil nil t nil
)
514 (unless prj-current
(error "No project open"))
515 (let ((a (prj-insert-file f
(prj-config-get-result 'f
))))
517 (message "Added to project: %s" (car a
))
523 (defun eproject-removefile (a)
524 "Remove a file from the current project."
525 (interactive (prj-get-existing-file-1 "Remove file from project: "))
526 (setq a
(prj-get-existing-file-2 a
))
530 (defun eproject-visitfile (a)
531 "Visit a file from the current project."
532 (interactive (prj-get-existing-file-1 "Visit file: "))
533 (setq a
(prj-get-existing-file-2 a
))
537 (defun prj-get-existing-file-1 (msg)
540 (or (prj-config-get-result 'f
)
541 (completing-read msg
(mapcar 'car prj-files
))
544 (defun prj-get-existing-file-2 (a)
545 (unless prj-current
(error "No project open"))
548 (let ((b (assoc (prj-relative-path a
) prj-files
)))
549 (unless b
(error "No such file in project: %s" a
))
553 (defun eproject-help ()
554 "Show the eproject README."
556 (view-file (eproject-addon "eproject.txt"))
559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
560 ;; Hook functions to track opening/closing files from emacs
562 (defun prj-addhooks ()
563 (add-hook 'kill-buffer-hook
'prj-kill-buffer-hook
)
564 (add-hook 'find-file-hook
'prj-find-file-hook
)
565 (add-hook 'window-configuration-change-hook
'prj-wcc-hook
)
568 (defun prj-removehooks ()
569 (remove-hook 'window-configuration-change-hook
'prj-wcc-hook
)
570 (remove-hook 'find-file-hook
'prj-find-file-hook
)
571 (remove-hook 'kill-buffer-hook
'prj-kill-buffer-hook
)
574 (defun prj-wcc-hook ()
575 (let ((w (selected-window)) (b (window-buffer (selected-window))))
576 ;; (message "wcc-hook: %s" (prin1-to-string (list wcc-count w b n)))
577 (prj-register-buffer b
)
580 (defun prj-find-file-hook ()
584 `(lambda () (prj-register-buffer ,(current-buffer)))
587 (defun prj-kill-buffer-hook ()
588 (let ((b (current-buffer)) a
)
589 (if (setq a
(rassq b prj-files
))
590 (prj-remove-file a t
)
591 (if (setq a
(rassq b prj-removed-files
))
592 (setq prj-removed-files
(delq a prj-removed-files
))
595 (defun prj-register-buffer (b)
597 (setq f
(buffer-file-name b
))
599 (setq a
(rassq b prj-files
))
601 (setq a
(prj-insert-file f nil t
))
604 (message "Added to project: %s" (car a
))
607 (with-current-buffer b
608 (rename-buffer (car a
) t
)
610 (when (and a
(null (eq a prj-curfile
)))
616 (defun prj-insert-file (f &optional after on-the-fly
)
617 (let ((r (prj-relative-path f
)) a m
)
618 (setq a
(assoc r prj-files
))
619 (unless (or a
(and on-the-fly
(assoc r prj-removed-files
)))
621 (setq m
(memq (or after prj-curfile
) prj-files
))
623 (setcdr m
(cons a
(cdr m
)))
624 (setq prj-files
(prj-add-list prj-files a
))
626 (setq prj-removed-files
(prj-del-list prj-removed-files a
))
630 (defun prj-remove-file (a &optional on-the-fly
)
631 (let ((n (prj-otherfile prj-files a
)) b
)
632 (setq prj-files
(prj-del-list prj-files a
))
633 (when (eq prj-curfile a
)
637 (setq prj-removed-files
(prj-add-list prj-removed-files a
))
639 (unless (prj-config-print)
640 (prj-edit-file prj-curfile
)
643 (message "Removed from project: %s" (car a
))
646 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
649 (defun prj-find-file (a)
651 (let ((n (car a
)) f b pos
)
652 (setq f
(expand-file-name n prj-directory
))
653 (setq b
(get-file-buffer f
))
656 (setq b
(find-file-noselect f
))
659 (with-current-buffer b
669 (defun prj-edit-file (a)
670 (let ((f (prj-find-file a
)))
672 (eproject-setup-quit)
673 (switch-to-buffer (car f
))
674 (prj-restore-edit-pos (cdr f
) (selected-window))
680 (defun prj-restore-edit-pos (pos w
)
682 (let ((top (car pos
)) (line (cadr pos
)))
683 (when (and (numberp top
) (numberp line
))
685 (set-window-start w
(point))
689 (defun prj-select-window (w)
690 (let (focus-follows-mouse)
692 (select-frame-set-input-focus (window-frame w
))
695 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
696 ;; choose next/previous file
698 (defun eproject-nextfile ()
699 "Switch to the next file that belongs to the current project."
701 (prj-switch-file 'prj-next-file
'next-buffer
)
704 (defun eproject-prevfile ()
705 "Switch to the previous file that belongs to the current project."
707 (prj-switch-file 'prj-prev-file
'previous-buffer
)
710 (defun prj-switch-file (fn1 fn2
)
711 (let ((a (rassoc (current-buffer) prj-files
)))
713 (prj-edit-file (or (funcall fn1 prj-files a
) a
))
716 (prj-edit-file prj-curfile
)
722 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
725 (defun prj-setkeys ()
726 (let ((f (consp prj-current
))
727 (a (assoc 'eproject-mode minor-mode-map-alist
))
728 (map (make-sparse-keymap))
732 (push (cons 'eproject-mode map
) minor-mode-map-alist
)
735 (define-key map
[M-right
] 'eproject-nextfile
)
736 (define-key map
[M-left
] 'eproject-prevfile
)
737 (define-key map
[C-f5
] 'eproject-dired
)
739 (dolist (a prj-tools
)
740 (unless (setq fn
(nth n prj-tools-fns
))
741 (setq fn
(list 'lambda
))
742 (setq prj-tools-fns
(nconc prj-tools-fns
(list fn
)))
744 (setcdr fn
`(() (interactive) (prj-run-tool ',a
)))
746 (when (setq s
(caddr a
))
747 (define-key map
(prj-parse-key s
) (and f fn
))
749 (define-key map
[f5] 'eproject-setup-toggle)
752 (defun prj-parse-key (s)
754 (if (string-match "[a-z][a-z0-9]+$" s)
756 (concat "\"\\" s "\""))))
758 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
761 (defun prj-list-sorted ()
762 (sort (append prj-list nil)
763 '(lambda (a b) (string-lessp (car a) (car b)))
766 (defun prj-setmenu ()
767 (let ((f (consp prj-current)) m1 m2 m3)
770 `(("Open" open ,@(prj-menulist-maker prj-list prj-current 'prj-menu-open))
772 ("Add ..." "Add new or existing project to the list" . eproject-add)
773 ("Remove ..." "Remove project from the list" . eproject-remove)
774 ,@(and f '(("Close" "Close current project" . eproject-close)))
776 ("Setup" "Enter the project setup area." . eproject-setup-toggle)
777 ("Help" "View eproject.txt" . eproject-help)
781 (nconc m1 (cons '("--") (prj-menulist-maker prj-tools nil prj-tools-fns)))
783 `(("Dired" "Browse project directory in Dired - Use 'a' to add file(s) to the project" . eproject-dired)
785 ,@(prj-menulist-maker prj-files prj-curfile 'prj-menu-edit)
790 `((buffer "Project" project ,@m1)
791 (file "List" list ,@m2)
796 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
798 (defun prj-menu-edit ()
800 (let ((a (nth last-command-event prj-files)))
801 (if a (prj-edit-file a))
804 (defun prj-menu-open ()
806 (let ((a (nth last-command-event prj-list)))
807 (if a (eproject-open (car a)))
810 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
812 (defun prj-menu-maker (map l v)
813 (let ((e (list nil)))
814 (setq v (append v e))
815 (dolist (k (reverse l))
817 (when (symbolp (car k))
824 ((and (consp (cdr k)) (symbolp (cadr k)))
827 (setq k (and s (cons (car k) (make-sparse-keymap (car k)))))
830 (setcar e (intern (downcase (car k))))
833 (define-key-after map (vconcat v) k a)
834 (define-key map (vconcat v) k)
836 (if s (prj-menu-maker map s v))
839 (defun prj-copy-head (l n)
841 (while (and l (> n 0))
848 (defun prj-split-list (l n)
851 (push (prj-copy-head l n) r)
852 (setq l (nthcdr n l))
857 (defun prj-menulist-maker (l act fns)
858 (let (r (w 30) s (m 0) (n 0) k)
861 (prj-menulist-maker-1 (list l fns n) act)
864 ;; menu too long; split into submenus
865 (setq s (prj-split-list l w))
866 (setq k (prj-menulist-maker-1 (list (append (pop s) '(("--"))) fns n) act))
867 (setq r (nreverse k))
870 (setq fns (nthcdr w fns))
873 (setq k (prj-menulist-maker-1 (list l fns n) act))
874 (push (cons (concat (prj-shortname (caar l)) " ...")
875 (cons (intern (format "m_%d" (setq m (1+ m))))
881 (defun prj-menulist-maker-1 (l act)
887 (setcar (cddr l) (1+ n))
888 (setq f (if (consp (cadr l))
889 (prog1 (car (cadr l)) (setcar (cdr l) (cdr (cadr l))))
893 (unless (string-match "^ *#" i)
894 (setq s (if (and (consp (cdr a)) (stringp (cadr a))) (cadr a) i))
896 (setq e (cons s (cons (intern s) (prj-menulist-maker-1 l act))))
903 (setq i (prj-shortname i))
904 (setq e (cons n (if (eq a act)
905 `(menu-item ,i ,f :button (:toggle . t) :help ,s)
906 (cons i (cons s f)))))
913 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
914 ;; Run make and other commands
916 (defun prj-setup-tool-window ()
917 (let ((bn "*compilation*") w h b c f)
918 (unless (get-buffer-window bn t)
919 (setq b (get-buffer-create bn))
920 (setq f (frame-list))
922 (setq w (frame-first-window (car f)))
923 (delete-other-windows w)
926 (setq h (/ (* 70 (frame-height)) 100))
927 (delete-other-windows w)
928 (setq w (split-window w h))
930 (set-window-buffer w b)
935 (when (string-match "^-in +\\([^[:space:]]+\\) +" cmd)
936 (setq dir (match-string-no-properties 1 cmd))
937 (setq cmd (substring cmd (match-end 0)))
939 (when prj-directory-run
940 (setq dir (expand-file-name (or dir ".") prj-directory-run))
943 (cond ((string-match "^-e +" cmd)
944 (setq cmd (read (substring cmd (match-end 0))))
945 (unless (commandp cmd)
946 (setq cmd `(lambda () (interactive) ,cmd))
948 (command-execute cmd)
950 ((string-match "\\(.+\\)& *$" cmd)
951 (start-process-shell-command "eproject-async" nil (match-string 1 cmd))
952 (message (match-string 1 cmd))
955 (unless (or (fboundp 'ecb-activate) (fboundp 'ewm-init))
956 (prj-setup-tool-window)
958 (let ((display-buffer-reuse-frames t))
962 (defun prj-run-tool (a)
963 (unless (string-match "^--+$" (car a))
964 (prj-run (or (cadr a) (car a)))
967 (defun eproject-killtool ()
969 (let ((bn "*compilation*") w0 w1)
970 (when (setq w1 (get-buffer-window bn t))
971 (when (fboundp 'kill-compilation)
972 (setq w0 (selected-window))
978 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
979 ;; run grep on project files
983 (defun eproject-grep (command-args)
984 "Run the grep command on all the project files."
987 (grep-compute-defaults)
988 (let ((default (grep-default-command)))
989 (list (read-from-minibuffer
990 "Run grep on project files: "
991 (if current-prefix-arg default grep-command)
995 (if current-prefix-arg nil default)
997 (let ((default-directory prj-directory))
998 (dolist (f (mapcar 'car prj-files))
999 (setq command-args (concat command-args " " f))
1004 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1005 ;; add files to the project with dired
1009 (defun prj-dired-addfiles ()
1013 (dolist (f (dired-get-marked-files))
1014 (setq a (prj-insert-file f))
1017 (setq prj-curfile a)
1019 (message "Added to project: %d file(s)" n)
1023 (defun prj-dired-run ()
1025 (let ((f (dired-get-marked-files)) c)
1026 (and (setq c (pop f))
1028 (let ((prj-directory (file-name-directory c)))
1031 (defun eproject-dired ()
1032 "Start a dired window with the project directory."
1034 (when prj-directory-run
1035 (eproject-setup-quit)
1036 ;;(message "Use 'a' to add marked or single files to the project.")
1037 (dired prj-directory-run)
1038 (let ((map dired-mode-map))
1039 (define-key map [mouse-2] 'dired-find-file)
1040 (define-key map "a" 'prj-dired-addfiles)
1041 (define-key map "r" 'prj-dired-run)
1042 (define-key map [menu-bar operate command] '("Add to Project"
1043 "Add current or marked file(s) to project" . prj-dired-addfiles))
1046 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1048 (defun prj-setup-all ()
1055 (defun prj-getconfig (n)
1056 (let ((a (cdr (assoc n prj-config))))
1060 (defun prj-setconfig (n v)
1061 (let ((a (assoc n prj-config)))
1064 (setq prj-config (nconc prj-config (list a)))
1069 (defun prj-on-kill ()
1070 (save-some-buffers t)
1074 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1075 ;; isearch in all project files
1077 (defun prj-isearch-function (b wrap)
1079 (or b (setq b (current-buffer)))
1082 (setq a (car prj-files))
1083 (setq a (car (last prj-files)))
1085 ((setq a (rassoc b prj-files))
1087 (setq a (prj-next-file prj-files a))
1088 (setq a (prj-prev-file prj-files a))
1092 (if (buffer-live-p (cdr a))
1094 (setq d (car (prj-find-file a)))
1096 ;; (print `(prj-isearch (wrap . ,wrap) ,b ,d) (get-buffer "*Messages*"))
1100 (defun prj-isearch-setup ()
1102 (setq multi-isearch-next-buffer-function 'prj-isearch-function)
1103 (setq multi-isearch-pause 'initial)
1104 (add-hook 'isearch-mode-hook 'multi-isearch-setup)
1107 (remove-hook 'isearch-mode-hook 'multi-isearch-setup)
1110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1113 (defun prj-startup-delayed ()
1114 ;; where is this file
1115 (setq eproject-directory
1116 (file-name-directory (symbol-file 'eproject-startup)))
1119 (load (eproject-addon "eproject-config") nil t)
1121 ;; When no projects are specified yet, load the eproject project itself.
1123 (load (eproject-addon "eproject.cfg"))
1126 ;; no project so far
1129 (add-hook 'kill-emacs-hook 'prj-on-kill)
1131 ;; inhibit open last project when a file was on the commandline
1132 (unless (buffer-file-name (window-buffer))
1135 ;; open last project
1136 (eproject-open prj-last-open)
1138 ;; restore frame position
1139 (unless (fboundp 'ewm-init)
1140 (when (and prj-frame-pos prj-initial-frame)
1141 (modify-frame-parameters prj-initial-frame prj-frame-pos)
1142 ;; emacs bug: when it's too busy it doesn't set frames correctly.
1146 (when (fboundp 'ecb-activate)
1151 (defun prj-command-line-switch (option)
1152 (setq prj-last-open (pop argv))
1153 (setq inhibit-startup-screen t)
1156 (defun eproject-startup ()
1157 (if (boundp 'prj-list)
1159 (load (eproject-addon "eproject-config"))
1163 (when prj-last-open (setq inhibit-startup-screen t))
1164 (when (display-graphic-p) (setq prj-initial-frame (selected-frame)))
1165 (push '("project" . prj-command-line-switch) command-switch-alist)
1166 (run-with-idle-timer 0.1 nil 'prj-startup-delayed)
1169 ;;;###autoload(require 'eproject)
1173 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1174 ;; eproject.el ends here