From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Le Wang Newsgroups: gmane.emacs.help Subject: Re: Looking for CDPATH functionality in emacs. Date: Tue, 4 Jan 2011 17:43:07 +0800 Message-ID: References: <4D221B85.5040702@syslang.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=20cf302d4c928e3add04990218f8 X-Trace: dough.gmane.org 1294134250 32685 80.91.229.12 (4 Jan 2011 09:44:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 4 Jan 2011 09:44:10 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: "Steven W. Orr" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 04 10:44:04 2011 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.69) (envelope-from ) id 1Pa3Qw-0003Pg-Uf for geh-help-gnu-emacs@m.gmane.org; Tue, 04 Jan 2011 10:44:03 +0100 Original-Received: from localhost ([127.0.0.1]:59247 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pa3Qw-0002jm-B4 for geh-help-gnu-emacs@m.gmane.org; Tue, 04 Jan 2011 04:44:02 -0500 Original-Received: from [140.186.70.92] (port=53931 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pa3Q7-0002gq-K6 for help-gnu-emacs@gnu.org; Tue, 04 Jan 2011 04:43:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pa3Q6-00067n-8N for help-gnu-emacs@gnu.org; Tue, 04 Jan 2011 04:43:11 -0500 Original-Received: from mail-ey0-f169.google.com ([209.85.215.169]:46682) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pa3Q5-00067S-UA for help-gnu-emacs@gnu.org; Tue, 04 Jan 2011 04:43:10 -0500 Original-Received: by eyh6 with SMTP id 6so3164583eyh.0 for ; Tue, 04 Jan 2011 01:43:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=Qdjogax8ECNI6+Xiur2gaN9AdAUwxnlbFAel9xZah/s=; b=eN53g2/mFBlE3+EAyT8aKIAxFt5N3Igt/jdJptVRkS8QeVw4OiQGSSSqdIinmq6TSg 5VGREHLKaWcKpce1hyOg/HxrHg0TAzpPDc6c6vRQpj5zLj76X9xsBidC55ZN4I1Py/Ix stI5cxwK8qh1YaWANPevmsrda8wLUlt5GLS1Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=pny4oVSlof5MsYWNYlAt1puIAhFlMH1/+ELol+SrhdMbTa8DHfAbd6JtsOZzia5hCo oS8h7ND2KhXKdZK4MmYaMHAs4OHMRZnFNttieIyLGV+k1j6FVvJ84gX9hIeY6UIL5Y0n 7rdzdjuRkuQbuD+e3vEUH06aAzISYET0NdHfA= Original-Received: by 10.14.133.16 with SMTP id p16mr7111619eei.31.1294134187801; Tue, 04 Jan 2011 01:43:07 -0800 (PST) Original-Received: by 10.14.119.11 with HTTP; Tue, 4 Jan 2011 01:43:07 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) 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:78157 Archived-At: --20cf302d4c928e3add04990218f8 Content-Type: text/plain; charset=ISO-8859-1 Sorry, I'm trying out yasnippet, and it expanded something in the code accidentally. Here is the right bits: (defun my-visit-file (arg) "Visit a file using completion. If there is only one window with nothing in it, then do not split the current window. " (interactive "P") (let ((insert-default-directory t) my-file) (when (equal arg '(4)) (setq insert-default-directory nil)) (setq my-file (read-file-name "my-visit-file: ")) (if (and (one-window-p) (zerop (buffer-size))) (find-file my-file) (find-file-ther-window my-file)))) (define-abbrev-table 'global-abbrev-table '(("spec" "/path/to/special/dir" nil 0))) On Tue, Jan 4, 2011 at 12:42 PM, Le Wang wrote: > On Tue, Jan 4, 2011 at 2:55 AM, Steven W. Orr wrote: > >> So, if you made it this far, here's the recap: >> >> 1. Does anything already exist that smells like what I want? >> > > Yes, abbrev (see below). I don't use them heavily myself, but here is a > tutorial: http://xahlee.org/emacs/emacs_abbrev_mode.html > > >> 2. Can I fix my-visit-file so that a C-u will prevent the default prompt >> from >> being the current directory of the file I'm starting from? (But I do still >> want filename completion.) >> > > Read the filename yourself, so you can have control: > > (defun my-visit-file (arg) > "Visit a file using completion. If there is only one window with > nothing in it, then do not split the current window. " > (interactive "P") > (let ((insert-default-directory t) > my-file) > (when (equal arg '(4)) > (setq insert-default-directory nil)) > (setq my-file (read-file-name "my-visit-file: ")) > (if (and (one-window-p) (zerop (buffer-size))) > (find-file my-file) > (find-file-(or )ther-window my-file)))) > > (define-abbrev-table 'global-abbrev-table > '(("spec" "/path/to/special/dir" nil 0))) > > > You can read the doc on `read-file-name' and `insert-default-directory' for > yourself. I've also added an abbrev table entry for "spec". So, if you > my-find-file, "spec", ae, it should expand do what you want. > > You can bind expansion to a shorter chord if you like. > > -- > Le > -- Le --20cf302d4c928e3add04990218f8 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Sorry, I'm trying out yasnippet, and it expanded something in the code = accidentally. =A0Here is the right bits:

(defun my-visit-file (arg)
=A0"Visit a = file using completion. If there is only one window with
nothing in it, then do not split the current window. "
=A0(interactive "P")
=A0(let ((ins= ert-default-directory t)
=A0=A0 =A0 =A0 my-file)
=
=A0=A0 (when (equal arg '(4))
=A0= =A0 =A0 (setq insert-default-directory nil))
=A0=A0 (setq my-file (read-file-name "my-visit-file: &= quot;))
=A0=A0 (if (and (one-window-p) (zerop (buffer-= size)))
=A0=A0 =A0 =A0 (find-file my-file)
=
=A0=A0 =A0 (find-file-ther-window my-file))))

(define-abbrev-table 'global-= abbrev-table
=A0=A0'(("spec" "/path= /to/special/dir" nil 0)))


On Tue, Jan 4, 2011 at 12:42 PM, Le Wang <l26wang@gmail.com> wrote:
On Tue, Jan 4, 2011 at 2:55 AM= , Steven W. Orr <steveo@syslang.net> wrote:
So, if you made it this far, here's the recap:

1. Does anything already exist that smells like what I want?

Yes, abbrev (see below). =A0I don't use the= m heavily myself, but here is a tutorial:=A0http://xahlee.org/emacs/emacs= _abbrev_mode.html
=A0
2. Can I fix my-visit-file so that a C-u will prevent the default prompt fr= om
being the current directory of the file I'm starting from? (But I do st= ill
want filename completion.)
=A0
Read th= e filename yourself, so you can have control:

(defun my-visit-file (arg)
=
=A0"Visit a file using comp= letion. If there is only one window with
nothing in it, then do not split the current window. "
=
=A0(interactive &quo= t;P")
=A0(let ((= insert-default-directory t)
=A0=A0 =A0 =A0 my-file)
=A0=A0 (when (equal arg= '(4))
=A0=A0 =A0= (setq insert-default-directory nil))
=A0=A0 (setq my-file (read= -file-name "my-visit-file: "))
=A0=A0 (if (and (one-window-p) (zerop= (buffer-size)))
=A0=A0 =A0 =A0 (find-file = my-file)
=A0=A0 =A0 (= find-file-(or =A0)ther-window my-file))))

(define-abbrev-table= 'global-abbrev-table
=
=A0=A0'(("spec" "/path/to/special/dir" nil 0))= )

You= can read the doc on `read-file-name' and `insert-default-directory'= ; for yourself. =A0I've also added an abbrev table entry for "spec= ". =A0So, if you <C-u>my-find-file, "spec", <C-x>= ;ae, it should expand do what you want.

You can bind expansion to a shorter chord if you like.<= /div>

--
Le



--
Le
--20cf302d4c928e3add04990218f8--