all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Convenient way to set "root of my project"?
@ 2009-01-27 22:13 Brett Hoerner
  2009-01-28  7:11 ` Drew Adams
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Brett Hoerner @ 2009-01-27 22:13 UTC (permalink / raw)
  To: help-gnu-emacs

I'd like for commands like "grep" and "find file" to open at the root
of my "project" (I know emacs has no knowledge of projects).  Does
anyone do / use something similar?

For example, I'm in /foo/bar/blah/doo/woo/file and I M-x grep, it's
based in /foo/bar/blah/doo/woo/ and I don't want to take the time to
change the path every time - 99% of the time I want to search my
current project (let's say /foo) for something.  Ditto for find-file,
changes are the file I want isn't in /foo/bar/blah/doo/woo/, but
somewhere further up the tree (and down another branch), I'd love to
start at /foo.

Ideas?  Or maybe I'm using both of these wrong and someone can tell me
the proper emacs-foo?

Thanks,
Brett


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: Convenient way to set "root of my project"?
  2009-01-27 22:13 Convenient way to set "root of my project"? Brett Hoerner
@ 2009-01-28  7:11 ` Drew Adams
  2009-01-28  7:49 ` Thierry Volpiatto
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Drew Adams @ 2009-01-28  7:11 UTC (permalink / raw)
  To: 'Brett Hoerner', help-gnu-emacs

> I'd like for commands like "grep" and "find file" to open at the root
> of my "project" (I know emacs has no knowledge of projects).  Does
> anyone do / use something similar?
> 
> For example, I'm in /foo/bar/blah/doo/woo/file and I M-x grep, it's
> based in /foo/bar/blah/doo/woo/ and I don't want to take the time to
> change the path every time - 99% of the time I want to search my
> current project (let's say /foo) for something.  Ditto for find-file,
> changes are the file I want isn't in /foo/bar/blah/doo/woo/, but
> somewhere further up the tree (and down another branch), I'd love to
> start at /foo.
> 
> Ideas?  Or maybe I'm using both of these wrong and someone can tell me
> the proper emacs-foo?

Sounds similar to the recent thread "build a macro that opens a directory and
prompts for file name" - see that for suggestions. In particular, see Emacs
command `cd' and variable `default-directory'. 

Also, in `grep', without using `cd' to change the `default-directory', you can
change the target files using prefix `../' - that's a quick way to do a one-off
search in the parent directory. You can do things like `grep foo ../../*.el
../*.el *.el */*.el', etc. Same thing applies for `find-file': you can type
`../' etc. after the default directory shown in the minibuffer.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Convenient way to set "root of my project"?
  2009-01-27 22:13 Convenient way to set "root of my project"? Brett Hoerner
  2009-01-28  7:11 ` Drew Adams
@ 2009-01-28  7:49 ` Thierry Volpiatto
  2009-01-28  7:57 ` Kevin Rodgers
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Thierry Volpiatto @ 2009-01-28  7:49 UTC (permalink / raw)
  To: help-gnu-emacs

Brett Hoerner <bretthoerner@gmail.com> writes:

> I'd like for commands like "grep" and "find file" to open at the root
> of my "project" (I know emacs has no knowledge of projects).  Does
> anyone do / use something similar?
>
> For example, I'm in /foo/bar/blah/doo/woo/file and I M-x grep, it's
> based in /foo/bar/blah/doo/woo/ and I don't want to take the time to
> change the path every time - 99% of the time I want to search my
> current project (let's say /foo) for something.  Ditto for find-file,
> changes are the file I want isn't in /foo/bar/blah/doo/woo/, but
> somewhere further up the tree (and down another branch), I'd love to
> start at /foo.
>
> Ideas?  Or maybe I'm using both of these wrong and someone can tell me
> the proper emacs-foo?

You have to use the appropriate tool to do a recursive search
For grep it's the -r option.

Search the word "defun" in all my elisp dirs and subdirs:
,----
| (diredp-do-grep "grep -nHr -e defun   /home/thierry/elisp/icicles")
`----

==> 2 mn 11

But you can use more convenient tool like traverselisp.el.

M-x traverse-deep-rfind RET /home/thierry/elisp/icicles RET defun RET .el

==> 37 s

Faster but traverse is set to ignore all .hg, .svn etc...
You can set that as you want. (for files also)
Here it search only on .el files.

traverselisp is on emacswiki at:

http://www.emacswiki.org/cgi-bin/emacs/traverselisp.el
or
hg clone http://freehg.org/u/thiedlecques/traverselisp/ 

-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Convenient way to set "root of my project"?
  2009-01-27 22:13 Convenient way to set "root of my project"? Brett Hoerner
  2009-01-28  7:11 ` Drew Adams
  2009-01-28  7:49 ` Thierry Volpiatto
@ 2009-01-28  7:57 ` Kevin Rodgers
  2009-01-28  9:03 ` Andreas Politz
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2009-01-28  7:57 UTC (permalink / raw)
  To: help-gnu-emacs

Brett Hoerner wrote:
> I'd like for commands like "grep" and "find file" to open at the root
> of my "project" (I know emacs has no knowledge of projects).  Does
> anyone do / use something similar?
> 
> For example, I'm in /foo/bar/blah/doo/woo/file and I M-x grep, it's
> based in /foo/bar/blah/doo/woo/ and I don't want to take the time to
> change the path every time - 99% of the time I want to search my
> current project (let's say /foo) for something.  Ditto for find-file,
> changes are the file I want isn't in /foo/bar/blah/doo/woo/, but
> somewhere further up the tree (and down another branch), I'd love to
> start at /foo.

How should `M-x grep' or `C-x C-f' know to start at /foo instead of
/foo/bar or /foo/bar/blah or /foo/bar/blah/doo (instead of / or
/foo/bar/flah/doo/woo)?

I.e. what do you mean by "project"?

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Convenient way to set "root of my project"?
  2009-01-27 22:13 Convenient way to set "root of my project"? Brett Hoerner
                   ` (2 preceding siblings ...)
  2009-01-28  7:57 ` Kevin Rodgers
@ 2009-01-28  9:03 ` Andreas Politz
  2009-01-28 10:57 ` Peter Dyballa
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Andreas Politz @ 2009-01-28  9:03 UTC (permalink / raw)
  To: help-gnu-emacs

Brett Hoerner wrote:
> I'd like for commands like "grep" and "find file" to open at the root
> of my "project" (I know emacs has no knowledge of projects).  Does
> anyone do / use something similar?
> 
> For example, I'm in /foo/bar/blah/doo/woo/file and I M-x grep, it's
> based in /foo/bar/blah/doo/woo/ and I don't want to take the time to
> change the path every time - 99% of the time I want to search my
> current project (let's say /foo) for something.  Ditto for find-file,
> changes are the file I want isn't in /foo/bar/blah/doo/woo/, but
> somewhere further up the tree (and down another branch), I'd love to
> start at /foo.
> 
> Ideas?  Or maybe I'm using both of these wrong and someone can tell me
> the proper emacs-foo?
> 
> Thanks,
> Brett


Here is some code to play around with. The problem I thinks is,
there is no hook into the post process of M-x commands. By
the time you know which command is running, it is to late to
set up a directory.
The solution I've made is to rebind M-x and artifically trigger
post/pre-command-hooks. I don't know exactly what sideeffects
this has, but I also don't see any other convenient solution.
(For the problem of setting up a special directory for certain
commands, regardless of how (M-x or keys) they where invoked.)

-ap

------------%<---------------------
(defvar project-directory-commands-hash nil)
(defvar project-directory-temp nil)
(make-variable-buffer-local 'project-directory-temp)

(defvar project-directory-commands '(rgrep))

(define-minor-mode project-directory-commands-mode
   "Use `project-directory' instead of `default-directory' for
certain commands"
   nil nil nil
   :global t
   (cond
    (project-directory-commands-mode
     (add-hook 'pre-command-hook 'project-directory-pre-command)
     (add-hook 'post-command-hook 'project-directory-post-command)
     (setq project-directory-commands-hash (make-hash-table))
     (global-set-key (kbd "M-x") 'extended-execute-extended-command)
     (dolist (c project-directory-commands)
       (puthash c t project-directory-commands-hash)))

    (t
     (global-set-key (kbd "M-x") 'execute-extended-command)
     (remove-hook 'pre-command-hook 'project-directory-pre-command)
     (remove-hook 'post-command-hook 'project-directory-post-command)
     (clrhash project-directory-commands-hash))))

(defun project-directory-pre-command ()
   (when (and (gethash this-command project-directory-commands-hash)
              (boundp 'project-directory)
              project-directory)
     (setq project-directory-temp default-directory)
     (setq default-directory project-directory)))

(defun project-directory-post-command ()
   (when project-directory-temp
     (setq default-directory project-directory-temp)
     (setq project-directory-temp nil)))



(defun extended-execute-extended-command (command)
   (interactive (list
                 (intern
                  (completing-read
                   (concat
                    (cond
                     ((eq '- current-prefix-arg) "- ")
                     ((equal current-prefix-arg '(4)) "C-u ")
                     (current-prefix-arg (format "%d " (prefix-numeric-value current-prefix-arg))))
                    "M-x ")
                   obarray 'commandp t nil 'extended-command-history))))
   (let ((this-command command))
     (run-hooks 'pre-command-hook))
   (condition-case nil
       (command-execute command)
     (error nil))
   (let ((this-command command))
     (run-hooks 'post-command-hook)))


;;(set (make-local-variable 'project-directory) "/")
(provide 'project-directory-commands)
------------%<---------------------


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Convenient way to set "root of my project"?
  2009-01-27 22:13 Convenient way to set "root of my project"? Brett Hoerner
                   ` (3 preceding siblings ...)
  2009-01-28  9:03 ` Andreas Politz
@ 2009-01-28 10:57 ` Peter Dyballa
       [not found] ` <mailman.6052.1233129460.26697.help-gnu-emacs@gnu.org>
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 11+ messages in thread
From: Peter Dyballa @ 2009-01-28 10:57 UTC (permalink / raw)
  To: Brett Hoerner; +Cc: help-gnu-emacs


Am 27.01.2009 um 23:13 schrieb Brett Hoerner:

> I'd like for commands like "grep" and "find file" to open at the root
> of my "project" (I know emacs has no knowledge of projects).  Does
> anyone do / use something similar?


Why aren't you using find-grep? It's defined as <find . files and  
grep for something in them>. Changing the "." to another directory,  
for example an environment variable set before you launch GNU Emacs,  
the search will start there. You can restrict the search to certain  
file name(type)s (-name "*.[chm]" or \( -name <sort 1> -o -name <sort  
2> -o -name <sort 3> \)). The output can be found in a buffer with  
hypertext feature: clicking on a line like

	./src/nsterm.m:4634:      [self keyDown: theEvent];

opens that buffer read-write on the given line. The cursor is  
positioned at the word you were looking for.

--
Greetings

   Pete

When confronted with actual numbers, a mathematician is at a loss.
				– Steffen Hokland







^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Convenient way to set "root of my project"?
       [not found] ` <mailman.6052.1233129460.26697.help-gnu-emacs@gnu.org>
@ 2009-01-28 15:22   ` Brett Hoerner
  0 siblings, 0 replies; 11+ messages in thread
From: Brett Hoerner @ 2009-01-28 15:22 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 28, 1:57 am, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
> How should `M-x grep' or `C-x C-f' know to start at /foo instead of
> /foo/bar or /foo/bar/blah or /foo/bar/blah/doo (instead of / or
> /foo/bar/flah/doo/woo)?
>
> I.e. what do you mean by "project"?

I expect to have to do define that, I just want to do it in an
automatic-ish way.

For example, most of my "projects" (read: applications I work on) I
keep inside of /a/PROJECT-NAME/src/, so it would be nice to set
default-directory to /a/foo/src/ when I open /a/foo/src/bar/bash/woo/
hello/file, so I can simply run 'ack' or 'find-grep' or 'find-file' or
whatever without having to type out a full path every time.

Brett


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Convenient way to set "root of my project"?
       [not found] ` <mailman.6072.1233140265.26697.help-gnu-emacs@gnu.org>
@ 2009-01-28 15:24   ` Brett Hoerner
  0 siblings, 0 replies; 11+ messages in thread
From: Brett Hoerner @ 2009-01-28 15:24 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 28, 4:57 am, Peter Dyballa <Peter_Dyba...@Web.DE> wrote:
> Why aren't you using find-grep? It's defined as <find . files and  
> grep for something in them>.

I think I wasn't clear.  The problem isn't the command itself (I'm
actually using ack, which is more or less the same as find-grep), it's
the fact that I don't want to specify the full path every time.  It's
pretty exhausting.  And I don't think an ENV variable would work
because I have multiple "projects" - I'd like to set a buffer-local
value so it just "knows" to start at the base of the project's src/
rather than the current folder (kind of pointless in a large project).

Brett


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Convenient way to set "root of my project"?
       [not found] ` <mailman.6047.1233126709.26697.help-gnu-emacs@gnu.org>
@ 2009-01-28 15:25   ` Brett Hoerner
  2009-01-28 21:24     ` Scott Frazer
  2009-01-29 17:00     ` Drew Adams
  0 siblings, 2 replies; 11+ messages in thread
From: Brett Hoerner @ 2009-01-28 15:25 UTC (permalink / raw)
  To: help-gnu-emacs

On Jan 28, 1:11 am, "Drew Adams" <drew.ad...@oracle.com> wrote:
> Sounds similar to the recent thread "build a macro that opens a directory and
> prompts for file name" - see that for suggestions. In particular, see Emacs
> command `cd' and variable `default-directory'.

Thanks!

I had used 'cd' by hand in the past, but 'default-directory' looks
like what I want.  I'm very new to all of this, I just need to find a
way now to hook the opening of a file, detect if it matches a path
like '/a/NAME/src/.*' and set the default directory of that buffer to
'/a/NAME/src/'

Brett


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Convenient way to set "root of my project"?
  2009-01-28 15:25   ` Brett Hoerner
@ 2009-01-28 21:24     ` Scott Frazer
  2009-01-29 17:00     ` Drew Adams
  1 sibling, 0 replies; 11+ messages in thread
From: Scott Frazer @ 2009-01-28 21:24 UTC (permalink / raw)
  To: help-gnu-emacs

Brett Hoerner wrote:
> On Jan 28, 1:11 am, "Drew Adams" <drew.ad...@oracle.com> wrote:
>> Sounds similar to the recent thread "build a macro that opens a directory and
>> prompts for file name" - see that for suggestions. In particular, see Emacs
>> command `cd' and variable `default-directory'.
> 
> Thanks!
> 
> I had used 'cd' by hand in the past, but 'default-directory' looks
> like what I want.  I'm very new to all of this, I just need to find a
> way now to hook the opening of a file, detect if it matches a path
> like '/a/NAME/src/.*' and set the default directory of that buffer to
> '/a/NAME/src/'

This might be close:

(defvar my-default-directory-roots (list "/foo/bar"
                                          "/baz/quux")
   "Default directory roots")

(defun my-set-default-directory-hook ()
   (mapc (lambda (root)
           (when (string-match (concat "^" root) (buffer-file-name))
             (setq default-directory root)))
         my-default-directory-roots))

(add-hook 'find-file-hook 'my-set-default-directory-hook)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: Convenient way to set "root of my project"?
  2009-01-28 15:25   ` Brett Hoerner
  2009-01-28 21:24     ` Scott Frazer
@ 2009-01-29 17:00     ` Drew Adams
  1 sibling, 0 replies; 11+ messages in thread
From: Drew Adams @ 2009-01-29 17:00 UTC (permalink / raw)
  To: 'Brett Hoerner', help-gnu-emacs

> > Sounds similar to the recent thread "build a macro that 
> > opens a directory and prompts for file name" - see that
> > for suggestions. In particular, see Emacs
> > command `cd' and variable `default-directory'.
> 
> Thanks!
> 
> I had used 'cd' by hand in the past, but 'default-directory' looks
> like what I want.

`cd' just sets the value of `default-directory'.

But from your other mail, it sounds like you want to set `default-directory'
_automatically_ to some "project" directory, whenever you visit a file that is
under that directory.

> I just need to find a way now to hook the opening of a file, detect
> if it matches a path like '/a/NAME/src/.*' and set the default
> directory of that buffer to '/a/NAME/src/'

Perhaps take a look at `find-file-hooks'. You could add a function there that
checks the current `default-directory' value (for the visited file), and, if it
is underneath your "project" directory, then set `default-directory' to the
"project" directory instead. Not sure if the timing of running the hook will be
right - you'll have to check.

But watch out. If you do that, then the directory associated with that file
buffer will be the project directory, not the file's own directory (underneath
the proj dir). I don't think that's what you want - it will affect saving the
buffer etc.

It's not clear to me exactly what you want/need. My guess is that it would be
better to just have a Dired buffer open for your project directory. Perhaps
someone else has a better understanding of what you want, and can help.





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2009-01-29 17:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-27 22:13 Convenient way to set "root of my project"? Brett Hoerner
2009-01-28  7:11 ` Drew Adams
2009-01-28  7:49 ` Thierry Volpiatto
2009-01-28  7:57 ` Kevin Rodgers
2009-01-28  9:03 ` Andreas Politz
2009-01-28 10:57 ` Peter Dyballa
     [not found] ` <mailman.6052.1233129460.26697.help-gnu-emacs@gnu.org>
2009-01-28 15:22   ` Brett Hoerner
     [not found] ` <mailman.6072.1233140265.26697.help-gnu-emacs@gnu.org>
2009-01-28 15:24   ` Brett Hoerner
     [not found] ` <mailman.6047.1233126709.26697.help-gnu-emacs@gnu.org>
2009-01-28 15:25   ` Brett Hoerner
2009-01-28 21:24     ` Scott Frazer
2009-01-29 17:00     ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.