abingham / prosjekt

A emacs extension for working with "projects"
22 stars 7 forks source link

Running code when a project is opened #27

Closed sohailsomani closed 12 years ago

sohailsomani commented 12 years ago

More of a question than anything but are there any prosjekt-open-hooks that would allow me to run arbitrary code when you open a prosjekt project?

That would be very helpful.

The most obvious place to do it would be right after you set curfile in prosjekt-open.

abingham commented 12 years ago

I've been thinking a bit about this, but I haven't settled on what I think is best (and I've been distracted by other stuff.) On the one hand, yes, I think it would be straightforward to add generic open- and close-hooks that run for every project, and these could be configured like normal hooks, i.e. in people .emacs setup.

On the other hand, I'd like a way to let people embed hook functions directly in their project configurations. More generally, I'd like them to be able to embed arbitrary function in their project configs, function which could be assigned to keybindings, etc. This is (obviously) still very much in the "still thinking about it" phase for me.

For what your needs, would simple prosjekt-open-hooks and prosjekt-close-hooks be enough? I bet I could cobble those together fairly quickly...I'm still relatively new at elisp coding, but it sounds pretty simple.

On Tue, Aug 7, 2012 at 5:26 PM, kingcheez notifications@github.com wrote:

More of a question than anything but are there any prosjekt-open-hooksthat would allow me to run arbitrary code when you open a prosjekt project?

That would be very helpful.

The most obvious place to do it would be right after you set curfile in prosjekt-open.

— Reply to this email directly or view it on GitHubhttps://github.com/abingham/prosjekt/issues/27.

sohailsomani commented 12 years ago

Yep, for my needs that would be enough. Actually, I cobbled it together just now:

diff --git a/prosjekt/prosjekt.el b/prosjekt/prosjekt.el
index cb5d4e6..77fbffc 100644
--- a/prosjekt/prosjekt.el
+++ b/prosjekt/prosjekt.el
@@ -74,6 +74,8 @@
 ; minor-mode-map-alist entry
 (defvar prosjekt-mode t)

+(defvar prsj-open-hooks '())
+
 (defun prosjekt-startup ()
   "Initialize the global configuration information."
   (prsj-load-config))
@@ -123,6 +125,8 @@
       (if curfile
          (find-file
           (expand-file-name curfile prsj-proj-dir))))
+    (dolist (hook prsj-open-hooks)
+      (funcall hook))
     ))

This was sufficient for my purpose which was to run TAGS over everything.

abingham commented 12 years ago

OK, excellent. I just committed your change, with the minor difference that I called the hooked "prosjekt-open-hooks" rather than "prsj-open-hooks". I have a distinction in the code between "public" things (which start with 'prosjekt') and "implementation" things (which start with prsj.) I'm not sure if that's normal or even a good idea, and sometimes the boundary is fuzzy.

In any event, thanks! Let me know if it doesn't work or whatever.

sohailsomani commented 12 years ago

Works fine. Thanks for the hookup :)

For what it's worth, this is what I did in my .emacs:


(defun prosjekt-redo-tags ()
  (interactive)
  (let ((cwd default-directory))
    (unwind-protect
        (progn
          (cd prsj-proj-dir)
          (shell-command "del /s /q TAGS && dir /s /b *.h* *.c* | etags --append -")
          (setf tags-file-name (concat prsj-proj-dir "/TAGS"))
          (message "Re-generated tags file for %s" prsj-proj-dir))
      (cd cwd))))

(add-to-list 'prosjekt-open-hooks 'prosjekt-redo-tags)
sohailsomani commented 12 years ago

Oh and I had to use shell-command and not prsj-run-tool or whatever because I needed it to be synchronous.

abingham commented 12 years ago

Yeah, that's the right thing to do. prsj-run-tool isn't really intended for public consumption, but rather for managing keybindings.

If you have any more ideas, criticisms, or whatever regarding prosjekt, by all means let me know. As far as I know, you're the only person using it besides me! I'm sure it's got rough edges or missing functionality to which I'm just blind.

Austin

On Tue, Aug 7, 2012 at 7:34 PM, kingcheez notifications@github.com wrote:

Oh and I had to use shell-command and not prsj-run-tool or whatever because I needed it to be synchronous.

— Reply to this email directly or view it on GitHubhttps://github.com/abingham/prosjekt/issues/27#issuecomment-7560726.

sohailsomani commented 12 years ago

Sure, I have some ideas. I'll write them up when I get a chance.

abingham commented 12 years ago

Yes, the changes for prosjekt-open-hooks are in. Take a look at these commits:

https://github.com/abingham/prosjekt/commit/ea6ae9662973d317601bdcf4b49f0bf5fe794cf1

https://github.com/abingham/prosjekt/commit/95e08699a79a8d63942a0dd7f22e93dc3c1a8e54

(I think those links are public...let me know if they point to nothing for you.)

Are they not showing up when you pull?

On Sun, Aug 12, 2012 at 9:25 PM, kingcheez notifications@github.com wrote:

Hey, I don't see this change in the repo, did you push?

— Reply to this email directly or view it on GitHubhttps://github.com/abingham/prosjekt/issues/27#issuecomment-7678962.

sohailsomani commented 12 years ago

Sorry man, I am not sure why but I had to re-clone the repo to get the changes... Pulling didn't help!

On 13/08/2012 12:50 AM, abingham wrote:

Yes, the changes for prosjekt-open-hooks are in. Take a look at these commits:

https://github.com/abingham/prosjekt/commit/ea6ae9662973d317601bdcf4b49f0bf5fe794cf1

https://github.com/abingham/prosjekt/commit/95e08699a79a8d63942a0dd7f22e93dc3c1a8e54

(I think those links are public...let me know if they point to nothing for you.)

Are they not showing up when you pull?

On Sun, Aug 12, 2012 at 9:25 PM, kingcheez notifications@github.com wrote:

Hey, I don't see this change in the repo, did you push?

— Reply to this email directly or view it on GitHubhttps://github.com/abingham/prosjekt/issues/27#issuecomment-7678962.

— Reply to this email directly or view it on GitHub https://github.com/abingham/prosjekt/issues/27#issuecomment-7683461.

abingham commented 12 years ago

Weird, but no problem. Is it possible that you had checked out a different branch or something?

Austin

On Mon, Aug 13, 2012 at 10:50 AM, kingcheez notifications@github.comwrote:

Sorry man, I am not sure why but I had to re-clone the repo to get the changes... Pulling didn't help!

On 13/08/2012 12:50 AM, abingham wrote:

Yes, the changes for prosjekt-open-hooks are in. Take a look at these commits:

https://github.com/abingham/prosjekt/commit/ea6ae9662973d317601bdcf4b49f0bf5fe794cf1

https://github.com/abingham/prosjekt/commit/95e08699a79a8d63942a0dd7f22e93dc3c1a8e54

(I think those links are public...let me know if they point to nothing for you.)

Are they not showing up when you pull?

On Sun, Aug 12, 2012 at 9:25 PM, kingcheez notifications@github.com wrote:

Hey, I don't see this change in the repo, did you push?

— Reply to this email directly or view it on GitHub< https://github.com/abingham/prosjekt/issues/27#issuecomment-7678962>.

— Reply to this email directly or view it on GitHub https://github.com/abingham/prosjekt/issues/27#issuecomment-7683461.

— Reply to this email directly or view it on GitHubhttps://github.com/abingham/prosjekt/issues/27#issuecomment-7686319.

sohailsomani commented 12 years ago

Nope, it was master. I must have done something wrong.

On 13/08/2012 4:52 AM, abingham wrote:

Weird, but no problem. Is it possible that you had checked out a different branch or something?

Austin

On Mon, Aug 13, 2012 at 10:50 AM, kingcheez notifications@github.comwrote:

Sorry man, I am not sure why but I had to re-clone the repo to get the changes... Pulling didn't help!

On 13/08/2012 12:50 AM, abingham wrote:

Yes, the changes for prosjekt-open-hooks are in. Take a look at these commits:

https://github.com/abingham/prosjekt/commit/ea6ae9662973d317601bdcf4b49f0bf5fe794cf1

https://github.com/abingham/prosjekt/commit/95e08699a79a8d63942a0dd7f22e93dc3c1a8e54

(I think those links are public...let me know if they point to nothing for you.)

Are they not showing up when you pull?

On Sun, Aug 12, 2012 at 9:25 PM, kingcheez notifications@github.com wrote:

Hey, I don't see this change in the repo, did you push?

— Reply to this email directly or view it on GitHub< https://github.com/abingham/prosjekt/issues/27#issuecomment-7678962>.

— Reply to this email directly or view it on GitHub https://github.com/abingham/prosjekt/issues/27#issuecomment-7683461.

— Reply to this email directly or view it on GitHubhttps://github.com/abingham/prosjekt/issues/27#issuecomment-7686319.

— Reply to this email directly or view it on GitHub https://github.com/abingham/prosjekt/issues/27#issuecomment-7686358.