help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Setting mark in minibuffer prompt


From: Drew Adams
Subject: RE: Setting mark in minibuffer prompt
Date: Sun, 8 Jul 2012 10:06:16 -0700

> 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...




reply via email to

[Prev in Thread] Current Thread [Next in Thread]