From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Politz Newsgroups: gmane.emacs.help Subject: Re: Convenient way to set "root of my project"? Date: Wed, 28 Jan 2009 10:03:12 +0100 Organization: FH-Trier Message-ID: <1233133455.246089@arno.fh-trier.de> References: <43f72653-1412-4402-8074-ef5302ab07a0@35g2000pry.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1233135783 17273 80.91.229.12 (28 Jan 2009 09:43:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Jan 2009 09:43:03 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jan 28 10:44:17 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LS6xs-0007b6-CE for geh-help-gnu-emacs@m.gmane.org; Wed, 28 Jan 2009 10:44:09 +0100 Original-Received: from localhost ([127.0.0.1]:47601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LS6wa-0005Yg-A8 for geh-help-gnu-emacs@m.gmane.org; Wed, 28 Jan 2009 04:42:48 -0500 Original-Path: news.stanford.edu!headwall.stanford.edu!news.glorb.com!news2.glorb.com!news2.arglkargh.de!news.n-ix.net!news.belwue.de!news.uni-kl.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 96 Original-NNTP-Posting-Host: 143-93-54-11.arno.fh-trier.de Original-X-Trace: news.uni-kl.de 1233133523 16560 143.93.54.11 (28 Jan 2009 09:05:23 GMT) Original-X-Complaints-To: usenet@news.uni-kl.de Original-NNTP-Posting-Date: Wed, 28 Jan 2009 09:05:23 +0000 (UTC) User-Agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018) In-Reply-To: <43f72653-1412-4402-8074-ef5302ab07a0@35g2000pry.googlegroups.com> Cache-Post-Path: arno.fh-trier.de!unknown@dslb-084-059-200-161.pools.arcor-ip.net X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) Original-Xref: news.stanford.edu gnu.emacs.help:166401 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:61721 Archived-At: 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) ------------%<---------------------