1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; eproject.el --- project workspaces for emacs
5 ;; Copyright (C) 2008 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 (expand-file-name (concat user-emacs-directory
"eproject.lst"))
28 ;; with the list of all projects
31 ;; and the project that was open in the last session (if any)
32 (defvar prj-last-open nil
)
34 ;; and the frame coords from last session
35 (defvar prj-frame-pos nil
)
37 ;; eproject version that created the config file
38 (defvar prj-version nil
)
40 ;; Here is a function to reset these
42 (setq prj-version nil
)
44 (setq prj-last-open nil
)
45 (setq prj-frame-pos nil
)
48 ;; Each project has a directory
49 (defvar prj-directory
)
51 ;; with a configuration files in it
52 (defun prj-localfile ()
53 (expand-file-name "eproject.cfg" prj-directory
)
64 ;; an alist of settings
70 ;; a list of utility functions (feature incomplete)
71 (defvar prj-functions nil
)
73 ;; directory to run commands, default to prj-directory
74 (defvar prj-directory-run
)
76 ;; Here are some default tools for new projects,
77 ;; (which you might want to adjust to your needs)
79 (defun prj-default-config ()
80 (setq prj-tools
(copy-tree '(
82 ("Clean" "make clean" "C-f9")
83 ("Run" "echo run what" "f8")
84 ("Stop" "-e eproject-killtool" "C-f8")
86 ("Configure" "./configure")
88 ("Explore Project" "nautilus --browser `pwd` &")
89 ("XTerm In Project" "xterm &")
93 ;; This defines the current project
96 ;; There is an internal list with generated functions
98 (defvar prj-tools-fns
)
100 ;; and a list with files removed from the project
101 (defvar prj-removed-files
)
103 ;; Here is a function to reset/close the project
105 (setq prj-version nil
)
106 (setq prj-current nil
)
107 (setq prj-directory nil
)
108 (setq prj-directory-run nil
)
110 (setq prj-removed-files nil
)
111 (setq prj-curfile nil
)
112 (setq prj-config nil
)
114 (setq prj-tools-fns nil
)
115 (prj-reset-functions)
119 (defun prj-reset-functions ()
120 (dolist (l prj-functions
)
121 (if (eq (car l
) 'setq
)
122 (makunbound (cadr l
))
123 (fmakunbound (cadr l
))
125 (setq prj-functions nil
)
128 (defun prj-set-functions (s)
129 (prj-reset-functions)
130 (setq prj-functions s
)
131 (dolist (l s
) (eval l
))
134 ;; Some more variables
136 ;; the frame that exists on startup
137 (defvar prj-initial-frame nil
)
139 ;; this is put into minor-mode-alist
140 (defvar eproject-mode t
)
142 ;; where this file is in
143 (defvar eproject-directory
)
145 ;; eproject version that created the files
146 (defvar eproject-version
"0.2")
150 (defun eproject-setup-toggle () (interactive))
151 (defun eproject-setup-quit () (interactive))
152 (defun prj-config-get-result (s))
153 (defun prj-config-reset ())
154 (defun prj-config-print ())
155 (defun prj-config-parse ())
158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
161 (defun prj-del-list (l e
)
162 (let ((a (assoc (car e
) l
)))
167 (defun prj-add-list (l e
)
168 (nconc (prj-del-list l e
) (list e
))
171 (defun prj-next-file (l e
)
172 (let ((a (assoc (car e
) l
)))
175 (if (cdr l
) (cadr l
) a
)
178 (defun prj-prev-file (l e
)
179 (let ((a (assoc (car e
) l
)) (p l
))
181 (while (and l
(null (eq (car l
) a
)))
187 ;; replace a closed file, either by the previous or the next.
188 (defun prj-otherfile (l f
)
189 (let ((n (prj-prev-file l f
)))
191 (setq n
(prj-next-file l f
))
197 (defun caddr (l) (car (cddr l
)))
199 ;; make relative path, but only up to the second level of ..
200 (defun prj-relative-path (f)
201 (let ((r (file-relative-name f prj-directory
)))
202 (if (string-match "^\\.\\.[/\\]\\.\\.[/\\]\\.\\.[/\\]" r
)
207 ;; friendly truncate filename
208 (defun prj-shortname (s)
209 (let ((l (length s
)) (x 30) n
)
213 (setq n
(length (file-name-nondirectory s
)))
214 (if (< n l
) (setq n
(1+ n
)))
217 (concat (substring s
0 (- x n
)) "..." (substring s
(- n
)))
220 (concat (substring s
0 x
) "...")
223 (concat "..." (substring s
(- n
) (- (- x
3) n
)) "...")
226 (defun prj-settitle ()
227 (modify-frame-parameters
231 (format "emacs - %s" (car prj-current
))
234 (defun eproject-addon (f)
235 (concat eproject-directory f
)
238 (defun prj-goto-line (n)
240 (beginning-of-line n
)
243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
244 ;; Write configuration to file
246 (defun prj-print-list (s fp
)
248 (setq v
(list 'setq s
249 (if (and (atom v
) (null (and (symbolp v
) v
)))
254 (pp v fp
) (princ "\n" fp
)
257 (defun prj-create-file (filename)
258 (let ((fp (generate-new-buffer filename
)))
259 (princ ";; -*- mode: Lisp; -*-\n\n" fp
)
262 (defun prj-close-file (fp)
263 (with-current-buffer fp
265 (write-region 1 (point-max) (buffer-name fp
) nil
0)
271 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
272 ;; Load/Save global project list and initial frame sizes
274 (defun prj-loadlist ()
276 (load (prj-globalfile) t t
)
277 (setq prj-version eproject-version
)
280 (defun prj-get-frame-pos (f)
283 (lambda (parm) (cons parm
(frame-parameter f parm
)))
284 '(top left width height
)
287 (defun prj-savelist ()
288 (let ((g (prj-globalfile))
291 (unless (file-exists-p g
)
292 (make-directory (file-name-directory g
) t
)
294 (setq prj-last-open
(car prj-current
))
295 (when (frame-live-p prj-initial-frame
)
296 (setq prj-frame-pos
(prj-get-frame-pos prj-initial-frame
))
298 (setq fp
(prj-create-file g
))
300 (prj-print-list 'prj-version fp
)
301 (prj-print-list 'prj-list fp
)
302 (prj-print-list 'prj-last-open fp
)
303 (prj-print-list 'prj-frame-pos fp
)
307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
308 ;; Load/Save local per-project configuration file
310 (defun prj-update-config ()
311 (setq prj-directory-run
312 (file-name-as-directory
314 (or (prj-getconfig "run-directory") ".")
319 (defun prj-loadconfig (a)
324 (file-name-as-directory
325 (expand-file-name (cadr a
))
328 (when (file-exists-p (setq lf
(prj-localfile)))
331 (or (assoc prj-curfile prj-files
)
335 (if (setq e
(prj-getconfig "project-name"))
337 (prj-setconfig "project-name" (car a
))
340 (prj-set-functions prj-functions
)
341 (setq prj-version eproject-version
)
344 (defun prj-saveconfig ()
348 (setq w
(selected-window))
349 (setq c
(window-buffer w
))
350 (dolist (f prj-files
)
351 (cond ((setq b
(get-buffer (car f
)))
352 (set-window-buffer w b t
)
353 (with-current-buffer b
354 (let ((s (line-number-at-pos (window-start w
)))
355 (p (line-number-at-pos (window-point w
)))
357 (push (list (car f
) s p
) files
)
362 (set-window-buffer w c t
)
364 (let ((fp (prj-create-file (prj-localfile)))
365 (prj-curfile (car prj-curfile
))
366 (prj-files (nreverse files
))
369 (prj-print-list 'prj-version fp
)
370 (prj-print-list 'prj-config fp
)
371 (prj-print-list 'prj-tools fp
)
372 (prj-print-list 'prj-files fp
)
373 (prj-print-list 'prj-curfile fp
)
374 (prj-print-list 'prj-functions fp
)
379 (defun prj-saveall ()
384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
385 ;; The core functions: Open / Close / Add / Remove Project
387 (defun eproject-open (a)
388 "Open another project."
391 (or (prj-config-get-result 'p
)
392 (completing-read "Open Project: " (mapcar 'car prj-list
))
395 (let ((b (assoc a prj-list
)))
397 (error "No such project: %s" a
)
401 (setq a
(or (car (member a prj-list
)) a
))
402 (unless (eq a prj-current
)
403 (unless (file-directory-p (cadr a
))
404 (error "Error: No such directory: %s" (cadr a
))
406 (setq prj-list
(cons a
(delq a prj-list
)))
413 (unless (prj-edit-file prj-curfile
)
417 (defun eproject-close ()
418 "Close the current project."
426 (save-some-buffers nil
)
427 (eproject-killbuffers t
)
430 (or f
(prj-addhooks))
437 (defun eproject-killbuffers (&optional from-project
)
438 "If called interactively kills all buffers that
439 do not belong to project files"
442 (dolist (f prj-files
)
443 (setq b
(get-buffer (car f
)))
445 (setq a
(cons (list b
) a
))
447 (dolist (b (buffer-list))
448 (when (eq (consp (assoc b a
)) from-project
)
452 (defun eproject-add (d)
453 "Add a new or existing project to the list."
456 (read-directory-name "Add project in directory: " prj-directory nil t
)
459 (setq d
(directory-file-name d
))
461 (when (= 0 (length d
))
462 (error "Error: Empty directory name.")
465 (setq n
(file-name-nondirectory d
))
471 (defun eproject-remove (a)
472 "Remove a project from the list."
475 (or (prj-config-get-result 'p
)
476 (completing-read "Remove project: " (mapcar 'car prj-list
))
479 (let ((b (assoc a prj-list
)))
481 (error "No such project: %s" a
)
487 (prog1 (y-or-n-p (format "Remove \"%s\"? " (car a
)))
490 (setq prj-list
(prj-del-list prj-list a
))
494 (defun eproject-save ()
495 "Save the project configuration to file."
502 (defun eproject-revert ()
503 "Reload the project configuration from file."
507 (prj-loadconfig prj-current
)
512 (defun eproject-addfile (f)
513 "Add a file to the current project."
517 (read-file-name "Add file to project: " nil nil t nil
)
519 (unless prj-current
(error "No project open"))
520 (let ((a (prj-insert-file f
(prj-config-get-result 'f
))))
522 (message "Added to project: %s" (car a
))
528 (defun eproject-removefile (a)
529 "Remove a file from the current project."
530 (interactive (prj-get-existing-file-1 "Remove file from project: "))
531 (setq a
(prj-get-existing-file-2 a
))
535 (defun eproject-visitfile (a)
536 "Visit a file from the current project."
537 (interactive (prj-get-existing-file-1 "Visit file: "))
538 (setq a
(prj-get-existing-file-2 a
))
542 (defun prj-get-existing-file-1 (msg)
545 (or (prj-config-get-result 'f
)
546 (completing-read msg
(mapcar 'car prj-files
))
549 (defun prj-get-existing-file-2 (a)
550 (unless prj-current
(error "No project open"))
553 (let ((b (assoc (prj-relative-path a
) prj-files
)))
554 (unless b
(error "No such file in project: %s" a
))
558 (defun eproject-help ()
559 "Show the eproject README."
561 (view-file (eproject-addon "eproject.txt"))
564 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
565 ;; Hook functions to track opening/closing files from emacs
567 (defun prj-addhooks ()
568 (add-hook 'kill-buffer-hook
'prj-kill-buffer-hook
)
569 (add-hook 'find-file-hook
'prj-find-file-hook
)
570 (add-hook 'window-configuration-change-hook
'prj-wcc-hook
)
573 (defun prj-removehooks ()
574 (remove-hook 'window-configuration-change-hook
'prj-wcc-hook
)
575 (remove-hook 'find-file-hook
'prj-find-file-hook
)
576 (remove-hook 'kill-buffer-hook
'prj-kill-buffer-hook
)
579 (defun prj-wcc-hook ()
580 (let ((w (selected-window)) (b (window-buffer (selected-window))))
581 ;; (message "wcc-hook: %s" (prin1-to-string (list wcc-count w b n)))
582 (prj-register-buffer b
)
585 (defun prj-find-file-hook ()
589 `(lambda () (prj-register-buffer ,(current-buffer)))
592 (defun prj-kill-buffer-hook ()
593 (let ((b (current-buffer)) a
)
594 (if (setq a
(rassq b prj-files
))
595 (prj-remove-file a t
)
596 (if (setq a
(rassq b prj-removed-files
))
597 (setq prj-removed-files
(delq a prj-removed-files
))
600 (defun prj-register-buffer (b)
602 (setq f
(buffer-file-name b
))
604 (setq a
(rassq b prj-files
))
606 (setq a
(prj-insert-file f nil t
))
609 (message "Added to project: %s" (car a
))
612 (with-current-buffer b
613 (rename-buffer (car a
) t
)
615 (when (and a
(null (eq a prj-curfile
)))
621 (defun prj-insert-file (f &optional after on-the-fly
)
622 (let ((r (prj-relative-path f
)) a m
)
623 (setq a
(assoc r prj-files
))
624 (unless (or a
(and on-the-fly
(assoc r prj-removed-files
)))
626 (setq m
(memq (or after prj-curfile
) prj-files
))
628 (setcdr m
(cons a
(cdr m
)))
629 (setq prj-files
(prj-add-list prj-files a
))
631 (setq prj-removed-files
(prj-del-list prj-removed-files a
))
635 (defun prj-remove-file (a &optional on-the-fly
)
636 (let ((n (prj-otherfile prj-files a
)) b
)
637 (setq prj-files
(prj-del-list prj-files a
))
638 (when (eq prj-curfile a
)
642 (setq prj-removed-files
(prj-add-list prj-removed-files a
))
644 (unless (prj-config-print)
645 (prj-edit-file prj-curfile
)
648 (message "Removed from project: %s" (car a
))
651 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
654 (defun prj-edit-file (a)
656 (let ((n (car a
)) f b pos
)
657 (setq f
(expand-file-name n prj-directory
))
658 (setq b
(get-file-buffer f
))
661 (setq b
(find-file-noselect f
))
664 (with-current-buffer b
671 (eproject-setup-quit)
673 (prj-restore-edit-pos pos
(selected-window))
679 (defun prj-restore-edit-pos (pos w
)
681 (let ((b (current-buffer)) (top (car pos
)) (line (cadr pos
)))
682 (when (and (numberp top
) (numberp line
))
684 (set-window-start w
(point))
688 (defun prj-select-window (w)
689 (let (focus-follows-mouse)
691 (select-frame-set-input-focus (window-frame w
))
694 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
695 ;; choose next/previous file
697 (defun eproject-nextfile ()
698 "Switch to the next file that belongs to the current project."
700 (prj-switch-file 'prj-next-file
'next-buffer
)
703 (defun eproject-prevfile ()
704 "Switch to the previous file that belongs to the current project."
706 (prj-switch-file 'prj-prev-file
'previous-buffer
)
709 (defun prj-switch-file (fn1 fn2
)
710 (let ((a (rassoc (current-buffer) prj-files
)))
712 (prj-edit-file (funcall fn1 prj-files a
))
715 (prj-edit-file prj-curfile
)
721 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
724 (defun prj-setkeys ()
725 (let ((f (consp prj-current
))
726 (a (assoc 'eproject-mode minor-mode-map-alist
))
727 (map (make-sparse-keymap))
731 (push (cons 'eproject-mode map
) minor-mode-map-alist
)
734 (define-key map
[M-right
] 'eproject-nextfile
)
735 (define-key map
[M-left
] 'eproject-prevfile
)
736 (define-key map
[C-f5
] 'eproject-dired
)
738 (dolist (a prj-tools
)
739 (unless (setq fn
(nth n prj-tools-fns
))
740 (setq fn
(list 'lambda
))
741 (setq prj-tools-fns
(nconc prj-tools-fns
(list fn
)))
743 (setcdr fn
`(() (interactive) (prj-run-tool ',a
)))
745 (when (setq s
(caddr a
))
746 (define-key map
(prj-parse-key s
) (and f fn
))
748 (define-key map
[f5] 'eproject-setup-toggle)
751 (defun prj-parse-key (s)
753 (if (string-match "[a-z][a-z0-9]+$" s)
755 (concat "\"\\" s "\""))))
757 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
760 (defun prj-list-sorted ()
761 (sort (append prj-list nil)
762 '(lambda (a b) (string-lessp (car a) (car b)))
765 (defun prj-setmenu ()
766 (let ((f (consp prj-current)) m1 m2 m3)
771 ,@(prj-menulist-maker prj-list prj-current 'prj-menu-open)
773 ("Add ..." "Add new or existing project to the list" . eproject-add)
774 ("Remove ..." "Remove project from the list" . eproject-remove)
775 ,@(and f '(("Close" "Close current project" . eproject-close)))
777 '("Setup" "Enter the project setup area." . eproject-setup-toggle)
780 (nconc m1 (cons '("--") (prj-menulist-maker prj-tools nil prj-tools-fns)))
782 `(("Dired" "Browse project directory in Dired - Use 'a' to add file(s) to the project" . eproject-dired)
784 ,@(prj-menulist-maker prj-files prj-curfile 'prj-menu-edit)
789 `((buffer "Project" project ,@m1)
790 (file "List" list ,@m2)
795 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
797 (defun prj-menu-edit ()
799 (let ((a (nth last-command-event prj-files)))
800 (if a (prj-edit-file a))
803 (defun prj-menu-open ()
805 (let ((a (nth last-command-event prj-list)))
806 (if a (eproject-open (car a)))
809 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
811 (defun prj-menu-maker (map l v)
812 (let ((e (list nil)))
813 (setq v (append v e))
814 (dolist (k (reverse l))
816 (when (symbolp (car k))
823 ((and (consp (cdr k)) (symbolp (cadr k)))
826 (setq k (and s (cons (car k) (make-sparse-keymap (car k)))))
829 (setcar e (intern (downcase (car k))))
832 (define-key-after map (vconcat v) k a)
833 (define-key map (vconcat v) k)
835 (if s (prj-menu-maker map s v))
838 (defun prj-copy-head (l n)
840 (while (and l (> n 0))
847 (defun prj-split-list (l n)
850 (push (prj-copy-head l n) r)
851 (setq l (nthcdr n l))
856 (defun prj-menulist-maker (l act fns)
857 (let (r (w 30) s (m 0) (n 0) k)
860 (prj-menulist-maker-1 (list l fns n) act)
863 ;; menu too long; split into submenus
864 (setq s (prj-split-list l w))
865 (setq k (prj-menulist-maker-1 (list (append (pop s) '(("--"))) fns n) act))
866 (setq r (nreverse k))
869 (setq fns (nthcdr w fns))
872 (setq k (prj-menulist-maker-1 (list l fns n) act))
873 (push (cons (concat (prj-shortname (caar l)) " ...")
874 (cons (intern (format "m_%d" (setq m (1+ m))))
880 (defun prj-menulist-maker-1 (l act)
886 (setcar (cddr l) (1+ n))
887 (setq f (if (consp (cadr l))
888 (prog1 (car (cadr l)) (setcar (cdr l) (cdr (cadr l))))
892 (unless (string-match "^ *#" i)
893 (setq s (if (and (consp (cdr a)) (stringp (cadr a))) (cadr a) i))
895 (setq e (cons s (cons (intern s) (prj-menulist-maker-1 l act))))
902 (setq i (prj-shortname i))
903 (setq e (cons n (if (eq a act)
904 `(menu-item ,i ,f :button (:toggle . t) :help ,s)
905 (cons i (cons s f)))))
912 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
913 ;; Run make and other commands
915 (defun prj-setup-tool-window ()
916 (let ((bn "*compilation*") w h b c f)
917 (unless (get-buffer-window bn t)
918 (setq b (get-buffer-create bn))
919 (setq f (frame-list))
921 (setq w (frame-first-window (car f)))
922 (delete-other-windows w)
925 (setq h (/ (* 70 (frame-height)) 100))
926 (delete-other-windows w)
927 (setq w (split-window w h))
929 (set-window-buffer w b)
934 (when (string-match "^-in +\\([^[:space:]]+\\) +" cmd)
935 (setq dir (match-string-no-properties 1 cmd))
936 (setq cmd (substring cmd (match-end 0)))
938 (when prj-directory-run
939 (setq dir (expand-file-name (or dir ".") prj-directory-run))
942 (cond ((string-match "^-e +" cmd)
943 (setq cmd (read (substring cmd (match-end 0))))
944 (unless (commandp cmd)
945 (setq cmd `(lambda () (interactive) ,cmd))
947 (command-execute cmd)
949 ((string-match "\\(.+\\)& *$" cmd)
950 (start-process-shell-command "eproject-async" nil (match-string 1 cmd))
951 (message (match-string 1 cmd))
954 (unless (or (fboundp 'ecb-activate) (fboundp 'ewm-init))
955 (prj-setup-tool-window)
957 (let ((display-buffer-reuse-frames t))
961 (defun prj-run-tool (a)
962 (unless (string-match "^--+$" (car a))
963 (prj-run (or (cadr a) (car a)))
966 (defun eproject-killtool ()
968 (let ((bn "*compilation*") w0 w1)
969 (when (setq w1 (get-buffer-window bn t))
970 (when (fboundp 'kill-compilation)
971 (setq w0 (selected-window))
977 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
978 ;; run grep on project files
982 (defun eproject-grep (command-args)
983 "Run the grep command on all the project files."
986 (grep-compute-defaults)
987 (let ((default (grep-default-command)))
988 (list (read-from-minibuffer
989 "Run grep on project files: "
990 (if current-prefix-arg default grep-command)
994 (if current-prefix-arg nil default)
996 (let ((default-directory prj-directory))
997 (dolist (f (mapcar 'car prj-files))
998 (setq command-args (concat command-args " " f))
1003 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1004 ;; add files to the project with dired
1008 (defun prj-dired-addfiles ()
1012 (dolist (f (dired-get-marked-files))
1013 (setq a (prj-insert-file f))
1016 (setq prj-curfile a)
1018 (message "Added to project: %d file(s)" n)
1022 (defun prj-dired-run ()
1024 (let ((f (dired-get-marked-files)) c)
1025 (and (setq c (pop f))
1027 (let ((prj-directory (file-name-directory c)))
1030 (defun eproject-dired ()
1031 "Start a dired window with the project directory."
1033 (when prj-directory-run
1034 (eproject-setup-quit)
1035 ;;(message "Use 'a' to add marked or single files to the project.")
1036 (dired prj-directory-run)
1037 (let ((map dired-mode-map))
1038 (define-key map [mouse-2] 'dired-find-file)
1039 (define-key map "a" 'prj-dired-addfiles)
1040 (define-key map "r" 'prj-dired-run)
1041 (define-key map [menu-bar operate command] '("Add to Project"
1042 "Add current or marked file(s) to project" . prj-dired-addfiles))
1045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1047 (defun prj-setup-all ()
1054 (defun prj-getconfig (n)
1055 (let ((a (cdr (assoc n prj-config))))
1059 (defun prj-setconfig (n v)
1060 (let ((a (assoc n prj-config)))
1063 (setq prj-config (nconc prj-config (list a)))
1068 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1071 (defun prj-startup-delayed ()
1072 ;; where is this file
1073 (setq eproject-directory
1074 (file-name-directory (symbol-file 'eproject-startup)))
1077 (load (eproject-addon "eproject-config") nil t)
1079 ;; When no projects are specified yet, load the eproject project itself.
1081 (load (eproject-addon "eproject.cfg"))
1084 ;; no project so far
1087 (add-hook 'kill-emacs-hook 'prj-saveall)
1089 ;; inhibit open last project when a file was on the commandline
1090 (unless (buffer-file-name (window-buffer))
1093 ;; open last project
1094 (eproject-open prj-last-open)
1096 ;; restore frame position
1097 (unless (fboundp 'ewm-init)
1099 (modify-frame-parameters prj-initial-frame prj-frame-pos)
1100 ;; emacs bug: when it's too busy it doesn't set frames correctly.
1104 (when (fboundp 'ecb-activate)
1109 (defun prj-command-line-switch (option)
1110 (setq prj-last-open (pop argv))
1111 (setq inhibit-startup-screen t)
1114 (defun eproject-startup ()
1115 (if (boundp 'prj-list)
1117 (load (eproject-addon "eproject-config"))
1121 (when prj-last-open (setq inhibit-startup-screen t))
1122 (setq prj-initial-frame (selected-frame))
1123 (push '("project" . prj-command-line-switch) command-switch-alist)
1124 (run-with-idle-timer 0.1 nil 'prj-startup-delayed)
1127 ;;;###autoload(require 'eproject)
1131 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1132 ;; eproject.el ends here