unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Setting mark in minibuffer prompt
@ 2012-05-17 15:25 Whitfield Diffie
  2012-07-08 15:36 ` Fwd: " Whitfield Diffie
  0 siblings, 1 reply; 5+ messages in thread
From: Whitfield Diffie @ 2012-05-17 15:25 UTC (permalink / raw)
  To: help-gnu-emacs

    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.  For example, I would like to be prompted:

        ~/notes-directory/2012.05.17/
                                      ^                  ^
                                      |                   |
                                 mark             point

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.

    It is certainly possible to get to this state by hand.  From
today's 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.

    I can also manage to set the arguments to read-file-name in such a
way that the point is somewhere in the middle of the prompt but what I
want is to have the point at the end and the mark in the middle.


    I hope I am writing to the right place.  I have received some
wonderful help on some occasions in the past and silence on others.

                          Many thanks,

                                                Whit



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Setting mark in minibuffer prompt
       [not found] <mailman.1294.1337271903.855.help-gnu-emacs@gnu.org>
@ 2012-05-18 10:57 ` José A. Romero L.
  2012-05-18 20:12 ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: José A. Romero L. @ 2012-05-18 10:57 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: help-gnu-emacs

W dniu czwartek, 17 maja 2012 17:25:30 UTC+2 użytkownik Whitfield Diffie napisał:
> 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.  For example, I would like to be prompted:
(...)

Probably not what you're looking for, but have you tried using ido
with (setq ido-everywhere t) ?

Best Regards,
--
José A. Romero L.
escherdragon at gmail
"We who cut mere stones must always be envisioning cathedrals."
(Quarry worker's creed)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Setting mark in minibuffer prompt
       [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
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2012-05-18 20:12 UTC (permalink / raw)
  To: help-gnu-emacs

>     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.  For example, I would like to be prompted:

>         ~/notes-directory/2012.05.17/
>                                       ^                  ^
>                                       |                   |
>                                  mark             point

You could wrap the call to read-file-name in something like:

   (minibuffer-with-setup-hook
      (lambda ()
        (place-mark-where-I-like-it))
    (read-file-name ...))

Also, instead of placing the mark, you could place point where you say
mark should go, using the same minibuffer-with-setup-hook trick as above.


        Stefan


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Setting mark in minibuffer prompt
  2012-07-08 15:36 ` Fwd: " Whitfield Diffie
@ 2012-07-08 17:06   ` Drew Adams
  2012-07-08 17:54     ` Whitfield Diffie
  0 siblings, 1 reply; 5+ messages in thread
From: Drew Adams @ 2012-07-08 17:06 UTC (permalink / raw)
  To: 'Whitfield Diffie', help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Setting mark in minibuffer prompt
  2012-07-08 17:06   ` Drew Adams
@ 2012-07-08 17:54     ` Whitfield Diffie
  0 siblings, 0 replies; 5+ messages in thread
From: Whitfield Diffie @ 2012-07-08 17:54 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1365 bytes --]

> IIUC, you want point to remain after the inserted `default-directory', and you
> want mark at some position to the left of that.  ...

    You did understand correctly and the code you sent seems to solve
the problem.  The essential point I didn't understand was the need to
use the minibuffer-setup-hook.  Many thanks.

    Virtue being its own punishment, I am enclosing a related question
I asked almost exactly two years ago in case the answer is equally
simple

   If I type (read-string "Prompt: ") I can line edit the typein with
<crtl-a>, <ctrl-b>, <ctrl-k>, etc.  If I type (read-passwd "Prompt: ")
the only characters that are not merely absorbed into the string are
<ctrl-u> and either of the delete-backwards characters.  Does anyone
know how to get the cursor to come out in the right place as I back up
down the row of dots that read-passwd echoes?

    I realize it is not obvious what use this would be.  Don't trust
me; I have something up my sleeve.

            Many thanks,

                            Whit


    I have attached the code I wrote to do this but I am not happy
with the technique because I had to insert the cursor ``by hand.''
Unfortunately what is attached is rather long because it is not an
example; it implements a line editor.


                     Very gratefully,

                                                Whit

[-- Attachment #2: read-keyphrase.el --]
[-- Type: application/octet-stream, Size: 5861 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-07-08 17:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [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
2012-05-17 15:25 Whitfield Diffie
2012-07-08 15:36 ` Fwd: " Whitfield Diffie
2012-07-08 17:06   ` Drew Adams
2012-07-08 17:54     ` Whitfield Diffie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).