all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Whitfield Diffie'" <the.whitfield.diffie@gmail.com>,
	<help-gnu-emacs@gnu.org>
Subject: RE: Setting mark in minibuffer prompt
Date: Sun, 8 Jul 2012 10:06:16 -0700	[thread overview]
Message-ID: <7A0C0DE9B626433FB3A172ACCC2E10E9@us.oracle.com> (raw)
In-Reply-To: <CAOgUEJLRpnA9g+k4rAArvUG=kmot0eqB8fW_q=4rc7m_jpJrXw@mail.gmail.com>

> 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 <cr> I get today's notes directory but if I type
> <c-x><c-x><c-k><cr>, I get the overall notes directory.
...
> I can type <c-x><c-f> 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...




  parent reply	other threads:[~2012-07-08 17:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-17 15:25 Setting mark in minibuffer prompt Whitfield Diffie
2012-07-08 15:36 ` Fwd: " Whitfield Diffie
2012-07-08 16:15   ` Laurent Hoeltgen
2012-07-08 16:22   ` Thien-Thi Nguyen
2012-07-08 17:18     ` Whitfield Diffie
2012-07-08 20:21       ` Thien-Thi Nguyen
2012-07-08 17:06   ` Drew Adams [this message]
2012-07-08 17:54     ` Whitfield Diffie
2012-07-08 18:07       ` how to customize `read-passwd' [was: Setting mark in minibuffer prompt] Drew Adams
2012-07-11  4:44         ` Whitfield Diffie
     [not found] <mailman.1294.1337271903.855.help-gnu-emacs@gnu.org>
2012-05-18 10:57 ` Setting mark in minibuffer prompt José A. Romero L.
2012-05-18 20:12 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7A0C0DE9B626433FB3A172ACCC2E10E9@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=the.whitfield.diffie@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.