views:

517

answers:

6

I say "project file" in the loosest sense. I have a few python projects that I work on with ropemacs using emacs W32 for Windows. What would be ideal is if I could have an icon I could click on on my desktop to open up emacs, open up the rope project, and set the speed bar in the top-level directory of that project. Then I could also maybe have a way to open up the next project in its own emacs set up the same way (but for that project). Of course, it's also acceptable if there were an emacs command or a shell command I could use to achieve the same effect instead of an icon on my desktop.

Is there any way to do this? I have absolutely no elisp-fu. :-(

+1  A: 

You can roll your own in bash/cmd.exe. The windows emacs distribution comes with a .bat file called runemacs.bat which accepts files to open as arguments. Write a small script and it should be able to open everything up from one icon.

meunierd
+2  A: 

I use the following "solution" for myself: A project root is defined by a directory that contains a Makefile. I've bound F12 to the mode specific elisp function that "compiles" the project by makeing the first target of the corresponding Makefile. This is found by recursively going upwards from the directory of the current file.

It is a little bit of setup, but you will never have to reconstruct your .metadata directory as was frequently the case with Eclipse before. And once set up, you just have to place the proper Makefiles around and you have your projects.

(defun get-makefile-recursively-higher ()
  (loop for i below 100 for cwd = (expand-file-name default-directory)
      then next for next = (expand-file-name (concat cwd "/..")) for file =
      (concat cwd "/" "Makefile") do (cond ((and (file-exists-p file))
                                            (return file))) until (equal cwd next))
)

This is then used e.g. by the LaTeX and Python mode as follows:

(defun py-execute-prog (&optional target) 
  "Invoke python on the file being edited in the current buffer using
   arguments obtained from the minibuffer.  It will save all of the modified
   buffers before trying to execute the file."
  (interactive)
  (let* (makefile file cmd)
    (setq makefile (get-makefile-recursively-higher))
    (setq file (buffer-file-name (current-buffer)))
    (setq cmd (concat "make -f " makefile))
    (setq default-directory (file-name-directory makefile))

    (save-some-buffers (not py-ask-about-save) nil)
    (setq py-pdbtrack-do-tracking-p t)
    (if (get-buffer py-output-buffer)
     (kill-buffer py-output-buffer)) ; Get rid of buffer if it exists.
    (global-unset-key "\C-x\C-l" )
    (global-unset-key  "\C-x\C-p" )
    (global-unset-key  "\C-x\C-e" )
    (global-unset-key  "\C-x\C-n" )
    (global-set-key  "\C-x\C-l" 'py-last-exception)
    (global-set-key  "\C-x\C-p" 'py-previous-exception)
    (global-set-key  "\C-x\C-e" 'py-current-line-exception)
    (global-set-key  "\C-x\C-n" 'py-next-exception) 
    (define-key comint-mode-map [mouse-3] 'py-current-line-exception)
    (make-comint "Python Output" "make" nil "-f" makefile)
    (if (not (get-buffer py-output-buffer)) 
        (message "No output.")
      (setq py-exception-buffer (current-buffer))
      (pop-to-buffer py-output-buffer)  
      )))


(defun make-tex (&optional target)
  (interactive)
  (let (makefile cmd)
    (setq makefile (get-makefile-recursively-higher))
    (save-buffer)
    (TeX-save-document (TeX-master-file))

    (setq cmd (concat "make -j4 -f " makefile " LATEXPARAM=\"-halt-on-error -file-line-error\""
                      " TEXMASTER=" (expand-file-name (TeX-master-file)) ".tex"
                      " TEXMASTERDIR=" (file-name-directory makefile) "/"))

    (when (stringp target)
      (setq cmd (concat cmd " " target))
      )
    (ad-activate-regexp "auto-compile-yes-or-no-p-always-yes")
    (compile cmd)
    (ad-deactivate-regexp "auto-compile-yes-or-no-p-always-yes")
    )
  )
wr
+3  A: 

You could get everything set up the way you want for a project, then use the answer I posted about using desktop.el and named sessions:

http://stackoverflow.com/questions/847962/what-alternate-session-managers-are-available-for-emacs/849180#849180

scottfrazer
+1  A: 

There's eproject, but it seems to be very sparsely documented.

Jouni K. Seppänen
+4  A: 

I'm actually working on a solution to this very problem. I always had a group of files I wanted to open/close at the same time, plus do things like open a magit-status window, a dired buffer, etc. I've started on my own project mode called metaproject. It's in the very early stages, but is functional enough that I'm using it for project groups at work now.

Check it out here: http://nafai77.github.com/metaproject/

What's in git is pretty stable, though sparsely documented. I'm going to start working on it again here soon. I currently have the basics of a small plug-in architecture, so you can register custom actions that can be done on project open.

Travis B. Hartwell
Good that people are working on that!I am used to a commercial code editor and very new to emacs, I'd love to have a search limited to project files, auto-completion, preview of function prototypes depending on what is under the cursor... These exist already I guess, but having them limited to the content of a project I don't think so.
Gauthier
A: 

See http://www.emacswiki.org/emacs/CategoryProgrammerUtils#ProjectSupport. There are several packages which manage "projects". I favor mk-project, but then again, I wrote it. ;-)

Matt Keller