all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / 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; 10+ 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] 10+ messages in thread

* Fwd: Setting mark in minibuffer prompt
  2012-05-17 15:25 Setting mark in minibuffer prompt Whitfield Diffie
@ 2012-07-08 15:36 ` Whitfield Diffie
  2012-07-08 16:15   ` Laurent Hoeltgen
                     ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Whitfield Diffie @ 2012-07-08 15:36 UTC (permalink / raw)
  To: help-gnu-emacs

    I haven't had any response to this message.  Is this simply that
no one knew the answer or that I am sending it to the wrong place.
Would someone please acknowledge receipt?

                   Whit

---------- Forwarded message ----------
From: Whitfield Diffie <the.whitfield.diffie@gmail.com>
Date: Thu, May 17, 2012 at 8:25 AM
Subject: Setting mark in minibuffer prompt
To: help-gnu-emacs@gnu.org


    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] 10+ messages in thread

* Re: Fwd: Setting mark in minibuffer prompt
  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:06   ` Drew Adams
  2 siblings, 0 replies; 10+ messages in thread
From: Laurent Hoeltgen @ 2012-07-08 16:15 UTC (permalink / raw)
  To: help-gnu-emacs

On 07/08/2012 05:36 PM, Whitfield Diffie wrote:
>     I haven't had any response to this message.  Is this simply that
> no one knew the answer or that I am sending it to the wrong place.
> Would someone please acknowledge receipt?
> 
>                    Whit
> 
> ---------- Forwarded message ----------
> From: Whitfield Diffie <the.whitfield.diffie@gmail.com>
> Date: Thu, May 17, 2012 at 8:25 AM
> Subject: Setting mark in minibuffer prompt
> To: help-gnu-emacs@gnu.org
> 
> 
>     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
> 

Hi,

Your message has arrived. Unfortunately, I can't really help you. Maybe
somebody else can.

Regards,
Laurent




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

* Re: Fwd: Setting mark in minibuffer prompt
  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 17:06   ` Drew Adams
  2 siblings, 1 reply; 10+ messages in thread
From: Thien-Thi Nguyen @ 2012-07-08 16:22 UTC (permalink / raw)
  To: Whitfield Diffie; +Cc: help-gnu-emacs

() Whitfield Diffie <the.whitfield.diffie@gmail.com>
() Sun, 8 Jul 2012 08:36:49 -0700

   Would someone please acknowledge receipt?

   ---------- Forwarded message ----------
   From: Whitfield Diffie <the.whitfield.diffie@gmail.com>
   Date: Thu, May 17, 2012 at 8:25 AM
   Subject: Setting mark in minibuffer prompt
   To: help-gnu-emacs@gnu.org


       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.

   [desired behavior]

Well, it's most polite to wait until the message is complete
before acknowledging receipt.  You can complete it by asking a
specific question or posting code that demonstrates your efforts
to date (along with a specific question).  Until then, you are
tempting the crass to respond with their own (possibly incomplete)
messages, which might be fun, too, i suppose.

Does that make sense?



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

* RE: Setting mark in minibuffer prompt
  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:06   ` Drew Adams
  2012-07-08 17:54     ` Whitfield Diffie
  2 siblings, 1 reply; 10+ 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] 10+ messages in thread

* Re: Fwd: Setting mark in minibuffer prompt
  2012-07-08 16:22   ` Thien-Thi Nguyen
@ 2012-07-08 17:18     ` Whitfield Diffie
  2012-07-08 20:21       ` Thien-Thi Nguyen
  0 siblings, 1 reply; 10+ messages in thread
From: Whitfield Diffie @ 2012-07-08 17:18 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: help-gnu-emacs

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

> You can complete [the message] by asking a
> specific question or posting code that demonstrates your efforts
> to date (along with a specific question). ...
> Does that make sense?

    I makes sens but I thought that was what I had done.
Rather than writing

       I am trying to write an interactive function
       that prompts for a file name, placing point at
       the end of the prompt and mark somewhere
       earlier in the path.

I had written

       How do I write an interactive function
       that prompts for a file name, placing point at
       the end of the prompt and mark somewhere
       earlier in the path?

    I described what I could do; code that does that is now attached.

    Certainly, I do not want to be impolite and would like to
understand the list's sense of courtesy.

                                  Thanks,

                                                 Whit

P.S. I finished this note only because it was almost done when I got
Drew Adams message, which offers an answer; I will not have a look at
that.

[-- Attachment #2: visit-notes.el --]
[-- Type: application/octet-stream, Size: 502 bytes --]

(defun visit-notes nil

  "   Notes prompts for a filename of the form ``~/notes/<date>'', placing
   point in the prompt before the date, for example:

                              location of point  
                                       |
                                       V
                    Directory: ~/notes/2012.07.08/"

  (interactive)
  (read-filename "Directory: "
		 "~/notes/"
		 nil
		 nil
		 (filename-as-directory (format-time-string "%Y.%m.%d"
							    (current-time)))))



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

* Re: Setting mark in minibuffer prompt
  2012-07-08 17:06   ` Drew Adams
@ 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
  0 siblings, 1 reply; 10+ 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] 10+ messages in thread

* how to customize `read-passwd' [was: Setting mark in minibuffer prompt]
  2012-07-08 17:54     ` Whitfield Diffie
@ 2012-07-08 18:07       ` Drew Adams
  2012-07-11  4:44         ` Whitfield Diffie
  0 siblings, 1 reply; 10+ messages in thread
From: Drew Adams @ 2012-07-08 18:07 UTC (permalink / raw)
  To: 'Whitfield Diffie'; +Cc: help-gnu-emacs

> I am enclosing a related question I asked almost exactly
> two years ago in case the answer is equally simple

Please, in general, start a new thread for a new question.

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

What I advise is to look at the code defining `read-passwd', and define your
function similarly.

What you see there is that `read-key' is called and each key that is read is
handled with a case analysis.  What you want is to add another case (or cases).
See how that code currently handles special lists of keys: `stop-keys' and
`rubout-keys'.  More pertinent perhaps is the treatment of `C-y'.

HTH.




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

* Re: Fwd: Setting mark in minibuffer prompt
  2012-07-08 17:18     ` Whitfield Diffie
@ 2012-07-08 20:21       ` Thien-Thi Nguyen
  0 siblings, 0 replies; 10+ messages in thread
From: Thien-Thi Nguyen @ 2012-07-08 20:21 UTC (permalink / raw)
  To: Whitfield Diffie; +Cc: help-gnu-emacs

() Whitfield Diffie <the.whitfield.diffie@gmail.com>
() Sun, 8 Jul 2012 10:18:56 -0700

   Rather than writing

          I am trying to write an interactive function
          that prompts for a file name, placing point at
          the end of the prompt and mark somewhere
          earlier in the path.

   I had written

          How do I write an interactive function
          that prompts for a file name, placing point at
          the end of the prompt and mark somewhere
          earlier in the path?

       I described what I could do; code that does that is now attached.

OK, that's the spirit!



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

* Re: how to customize `read-passwd' [was: Setting mark in minibuffer prompt]
  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
  0 siblings, 0 replies; 10+ messages in thread
From: Whitfield Diffie @ 2012-07-11  4:44 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs

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

> Please, in general, start a new thread for a new question.

    Will do.  For now, I have accepted yours.

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


> What I advise is to look at the code defining `read-passwd', and define your
> function similarly.

    That is of course exactly what I did.  A simplified version that
merely accepts C-f and C-b and moves forward and backward through the
echoed dots is attached.  I have had, however, to insert my own cursor
by hand.  The problem is that the echo of the password is produced by
message and message doesn't seem to call the minibuffer-setup-hook you
taught me about.  (If you enable cursor-in-echo-area, the cursor
appears but sits at the end of the line.)

> What you see there is that `read-key' is called and each key that is read is
> handled with a case analysis.  What you want is to add another case (or cases).

    This is what I did, along with changing the nested ifs to a cond
for readability.


> See how that code currently handles special lists of keys: `stop-keys' and
> `rubout-keys'.  More pertinent perhaps is the treatment of `C-y'.

    Read password doesn't do anything with C-y; it just goes in as an
element of the password.


                                   Whit

[-- Attachment #2: line-edit-passwd.el --]
[-- Type: application/octet-stream, Size: 1805 bytes --]

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

end of thread, other threads:[~2012-07-11  4:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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.