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

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

Re: elisp: Text-based file-chooser


From: Larry Kohlman
Subject: Re: elisp: Text-based file-chooser
Date: Wed, 05 Jan 2011 16:16:35 -0600

On Wed, 05 Jan 2011 11:06:59 -0800, Drew Adams wrote:

>> > So I guess you're saying that you do not want (necessarily) to visit
>> > the file, you just want to read a file name.
>> 
>> Exactly.
>> 
>> > But you do not want to use the
>> > "GUI file selector", by which I suppose you mean a file-selection
>> > dialog box.  Is that it?
>> 
>> I want a file-browsing dialog box, but I want it to be text-mode so it
>> can be used on a raw terminal or inside an xterm.
> 
> Dunno what such an animal is or how you get it.  By "dialog box" I meant
> a graphic dialog box, not available from a terminal.

Dialog boxes don't have to be graphical. In fact Linux has an old
utility called "dialog" that's used by scripts to put up different kinds
of dialog boxes on a purely text console. Dialog's file selection would
be perfect for what I want except that it lacks emacs keybindings and
its UI is nonstandard in some rather annoying ways. I've already looked
at the many dialog knockoffs but most lack a file-selector and the few
that do have the same odd UI.

> 
>> Something roughly like dired but that lets the user browse files and
>> directories
> 
> So far, that sounds like Dired.

> 
>> and only returns the path with a selected or entered filename and does
>> absolutely nothing else.
> 
> In Dired, you have the path in the buffer header. You can also get the
> path as a string from variable `default-directory'.
> 
> If you are trying to get the absolute name of the file where the cursor
> is, as a string, you can use `(dired-get-filename)'.

That's an interesting feature that I'm sure to find a good use for, but
it's not what I'm trying to do right now.

> 
>> I know it's out there because I've seen it before, but I just can't
>> find the magic command or plugin.
> 
> Well it's not clear to me what you want.  And I'm probably not familiar
> with the magic command or plugin anyway.  Perhaps someone else can help
> you.
> 
>> > If all you want is to read a file name without using a dialog box,
>> > then just use `read-file-name' with `use-file-dialog' bound to `t'.
>> > (let ((use-file-dialog  t))
>> >   (read-file-name ...)...)
> 
> (All that does is ensure that you don't get a graphic dialog box.)

There are actually two flags that control that, use-file-dialog and
use-dialog box. To get the GUI selector to pop up both have to be t,
window-system must be t, AND read-file-name has to have been triggered
by a mouse event. For anyone trying to go the opposite direction from
mine who WANTS the GUI file-selector, here is how you persuade
read-file-name to produce a graphical dialog:

(defadvice read-file-name (around read-file-name act)
  "Substitute a GUI file picker-outer in read-file-name."
  (let ((last-nonmenu-event last-nonmenu-event))
  (when (and use-file-dialog use-dialog-box window-system) 
    (setq last-nonmenu-event nil))
    ad-do-it
   )) 

> 
>> All I get when I do that is a one-line prompt for a filename. It gives
>> me completion
> 
> Which should show you a list of files that match your input.  With empty
> input, TAB TAB should show you all files and subdirs in the directory.

Thanks, I didn't know that was there. It's rather clumsy if you don't
have a mouse available but it's sufficient if nothing better comes
along.

> 
>> but I don't get a file list to browse.
> 
> You get a file list, but not to browse, depending on what you mean by
> browse. You can explore the entire file system from `read-file-name',
> showing the contents of any directory, and reading any file name.  I
> would call that browsing, but you might not.

"Browsing", to me, means one can see a list of files and directories and
navigate through the list to select what they want. Seeing just one name
at a time isn't what I'd consider browsing. Imagine "browsing" a web
page by seeing only one line each time you press a key.

> 
>> The manual is vague on whether read-file-name even has a text dialog.
> 
> I don't know what a text dialog is, so I wouldn't know if the manual is
> vague about it.  If you think it is, consider `M-x report-emacs-bug' to
> get it cleared up.

Might have been clearer if I'd said "a text-mode dialog". 

>> If it's bringing up a text dialog on some installations then either
>> there's some well-hidden secret to triggering one, or read-file-name
>> may be redirecting the request to the function I need via
>> read-file-name-function.
> 
> `read-file-name' just reads a file name with completion.  It brings up a
> graphic dialog box only in certain situations, and you are anyway not
> interested in that.  Other than that it does just what you saw - on all
> installations (AFAIK).

Thanks. I was wondering if it was just my installation or of they all
did that. The documentation isn't real clear about how that's supposed
to work.



reply via email to

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