From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: Setting mark in minibuffer prompt Date: Sun, 8 Jul 2012 10:06:16 -0700 Message-ID: <7A0C0DE9B626433FB3A172ACCC2E10E9@us.oracle.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1341767207 6012 80.91.229.3 (8 Jul 2012 17:06:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 8 Jul 2012 17:06:47 +0000 (UTC) To: "'Whitfield Diffie'" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jul 08 19:06:47 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SnuwV-0000ks-O1 for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Jul 2012 19:06:43 +0200 Original-Received: from localhost ([::1]:54336 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SnuwU-0003yE-JH for geh-help-gnu-emacs@m.gmane.org; Sun, 08 Jul 2012 13:06:42 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:43578) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SnuwP-0003y4-MT for help-gnu-emacs@gnu.org; Sun, 08 Jul 2012 13:06:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SnuwN-0006fP-Rl for help-gnu-emacs@gnu.org; Sun, 08 Jul 2012 13:06:37 -0400 Original-Received: from acsinet15.oracle.com ([141.146.126.227]:22652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SnuwN-0006ew-Lv for help-gnu-emacs@gnu.org; Sun, 08 Jul 2012 13:06:35 -0400 Original-Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by acsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q68H6Umf005834 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 8 Jul 2012 17:06:31 GMT Original-Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q68H6T2O017600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 8 Jul 2012 17:06:30 GMT Original-Received: from abhmt106.oracle.com (abhmt106.oracle.com [141.146.116.58]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q68H6TrR026860; Sun, 8 Jul 2012 12:06:29 -0500 Original-Received: from dradamslap1 (/10.159.186.64) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 08 Jul 2012 10:06:29 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: Thread-Index: Ac1dH4RiNCuhUNGuQveCxzA7WnLFpwAA+SOw X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Source-IP: ucsinet21.oracle.com [156.151.31.93] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 141.146.126.227 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:85729 Archived-At: > I am trying to write an interactive function that prompts for a > filename, placing point at the end of the prompt and mark somewhere > earlier in the path. IIUC, you want point to remain after the inserted `default-directory', and you want mark at some position to the left of that. And you (your program) knows what that earlier position is. Is it, perhaps, always the parent directory as in your example? The code below assumes that - adjust as needed. > For example, I would like to be prompted: > ~/notes-directory/2012.05.17/ > ^ ^ > | | > mark point I moved your mark & point indicators to where I think you mean, since they seem to have been messed up in the mail (perhaps you use non-nil `indent-tabs-mode'?). > so that if I type a I get today's notes directory but if I type > , I get the overall notes directory. ... > I can type and get the prompt > Find file: ~/notes-directory/2012.05.17/ > if I now move the cursor back to just before 2012, set the mark and > move the cursor to the end of the line, I am in the right state. Note: The directory you see in the minibuffer is NOT part of the prompt. It is actually text - the value of variable `default-directory' - that is automatically inserted in the minibuffer. This is because your value of option `insert-default-directory' is no doubt non-nil. Maybe something like this is what you want: (defadvice read-file-name-default (around select-child-directory activate) "Put mark at start of child dir name; leave point at eob." (unwind-protect (progn (add-hook 'minibuffer-setup-hook 'select-child-dir) ad-do-it) (remove-hook 'minibuffer-setup-hook 'select-child-dir))))) (defun select-child-dir () "Select last subdir of `default-directory' in minibuffer." (goto-char (1- (point-max))) (let ((bob (minibuffer-prompt-end))) (while (and (> (point) bob) (not (equal ?/ (char-before)))) (backward-char)) (set-mark (point))) (goto-char (point-max))) No guarantees, of course...