Re: Update filename history after several actions

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Update filename history after several actions

Richard Stallman
I asked

    Would you like it if we changed find-file-noselect to put its argument
    into the history if it is not present?

You responded:

    There should be all functions in the file-name-history that were edited
    in emacs, i.e. there were intentionally loaded t be edited or viewed by
    the user. So adding all file names at the level you suggest is not the
    right way, cause find-file-noselect can't decide whether the file was
    loaded to be edited or e.g. to be processed automatically.

    I suggest to add the file-name-history inclusion of file names at a more
    "upper" level in the call stack, as a result of a user oriented task.

Doing this at a higher level would work, but it would be an ugly
approach, requiring changes in many places.

find-file-noselect has an argument NOWARN that probably ought to
be--but isn't actually--provided as t by Lisp programs that visit
files for their own reasons that users don't know about.  It occurs to
me that if we change these programs to pass t for this arg, which they
should anyway, then if find-file-noselect adds the file name to the
history if NOWARN is nil, it might give just the right results.

What do others think of this idea?


_______________________________________________
Emacs-devel mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-devel
Reply | Threaded
Open this post in threaded view
|

Re: Update filename history after several actions

Tomas Zerolo
On Tue, Oct 04, 2005 at 01:02:26AM -0400, Richard M. Stallman wrote:
[...]
> find-file-noselect has an argument NOWARN that probably ought to
> be--but isn't actually--provided as t by Lisp programs that visit
> files for their own reasons [...]

Sorry for the random and semi-offtopic nitpick -- but wouldn't be NOUSER
or NONINTERACTIVE or something along these lines be a less misleading
name? NOWARN suggests a (related but) different purpose to me.

Regards
-- tomás

_______________________________________________
Emacs-devel mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-devel

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Update filename history after several actions

Juri Linkov
>> find-file-noselect has an argument NOWARN that probably ought to
>> be--but isn't actually--provided as t by Lisp programs that visit
>> files for their own reasons [...]
>
> Sorry for the random and semi-offtopic nitpick -- but wouldn't be NOUSER
> or NONINTERACTIVE or something along these lines be a less misleading
> name? NOWARN suggests a (related but) different purpose to me.

What about adding a new option with a list of command names compared
in `find-file-noselect' with `this-command' before adding a file name
to the history?  Every package (e.g. dired.el, recentf.el) could add
their own user-level command names to such a variable.

--
Juri Linkov
http://www.jurta.org/emacs/



_______________________________________________
Emacs-devel mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-devel
Reply | Threaded
Open this post in threaded view
|

Re: Update filename history after several actions

Richard Stallman
    What about adding a new option with a list of command names compared
    in `find-file-noselect' with `this-command' before adding a file name
    to the history?  Every package (e.g. dired.el, recentf.el) could add
    their own user-level command names to such a variable.

That would be more cumbersome that any of the other alternatives
we are considering.  So I don't like it.


_______________________________________________
Emacs-devel mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-devel
Reply | Threaded
Open this post in threaded view
|

Re: Update filename history after several actions

Juri Linkov
The simplest solution is to use the same method as employed by
Recentf mode.  It maintains the list of recently opened files,
no matter what user-level command visited them, and doesn't include
automatically processed files.  It seems that users of Recentf
mode are satisfied with its file list.  So the same method could be
used to add recently opened files to the file name history.

To update the list of recently opened files, Recentf mode puts
the function `recentf-track-opened-file' in `find-file-hook'.
The following code does the same to add recently opened files
to the history:

(add-hook 'find-file-hook 'add-file-name-to-history)

(defun add-file-name-to-history ()
  "Add the name of the file just opened to the history."
  (when (and buffer-file-name
             (or (null file-name-history)
                 (not (equal buffer-file-name (car file-name-history)))))
    (if history-delete-duplicates (delete buffer-file-name file-name-history))
    (setq file-name-history (cons buffer-file-name file-name-history))))

--
Juri Linkov
http://www.jurta.org/emacs/



_______________________________________________
Emacs-devel mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-devel
Reply | Threaded
Open this post in threaded view
|

Re: Update filename history after several actions

Richard Stallman
    The simplest solution is to use the same method as employed by
    Recentf mode.  It maintains the list of recently opened files,
    no matter what user-level command visited them, and doesn't include
    automatically processed files.

    To update the list of recently opened files, Recentf mode puts
    the function `recentf-track-opened-file' in `find-file-hook'.

How does that avoid recording files that are processed by Lisp
programs that the user doesn't know about?  If those programs use
find-file-noselect, that would run find-file-hook, which would
record the file name thus being processed.


_______________________________________________
Emacs-devel mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-devel
Reply | Threaded
Open this post in threaded view
|

Re: Update filename history after several actions

Juri Linkov
>     The simplest solution is to use the same method as employed by
>     Recentf mode.  It maintains the list of recently opened files,
>     no matter what user-level command visited them, and doesn't include
>     automatically processed files.
>
>     To update the list of recently opened files, Recentf mode puts
>     the function `recentf-track-opened-file' in `find-file-hook'.
>
> How does that avoid recording files that are processed by Lisp
> programs that the user doesn't know about?  If those programs use
> find-file-noselect, that would run find-file-hook, which would
> record the file name thus being processed.

Recentf is quite an old package, and it seems its users are happy with
the way it records recently opened files.  Perhaps this means there
are not many places where find-file-noselect is used for internal file
processing (i.e. not intended for the users to know).  In those places
where such processing is required, a more preferable way is to insert
the contents of a file into a temporary buffer.

While I tried to run the code which uses find-file-hook I sent earlier,
I noticed that often it adds too many file names to the history, even
the files opened for editing (there were no file names left from internal
file processing at all in my test).  For example, I don't like that
`next-error' adds every file it opens from the grep buffer.  Also I
don't like adding files visited in read-only mode by dired's "v" key.

All this means that the question what file names to add to the history
is rather a matter of personal preferences.  A simple hook for
`find-file-hook' is easy to put in .emacs.

But even if this functionality will get into Emacs, I think it's
better to leave the current default behavior (with only adding user
input to the history) unchanged.

--
Juri Linkov
http://www.jurta.org/emacs/



_______________________________________________
Emacs-devel mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-devel
Reply | Threaded
Open this post in threaded view
|

Re: Update filename history after several actions

Richard Stallman
    Recentf is quite an old package, and it seems its users are happy with
    the way it records recently opened files.  Perhaps this means there
    are not many places where find-file-noselect is used for internal file
    processing (i.e. not intended for the users to know).

There are lots of them!  Just search the Lisp sources
for find-file-noselect.  There are about 230 occurrences,
and I think around 200 of them do something like this.
Custom does it, bookmark.el does it, desktop.el does it,
to list but a few.

How does recentf interact with those packages?

                                                           In those places
    where such processing is required, a more preferable way is to insert
    the contents of a file into a temporary buffer.

That is definitely true.  However, there are a lot of places to
change--and it could be a difficult change, in places that alter the
file and want to be careful not to lose it (places that use
file-precious-flag).  So I don't think that is a possible solution
in the short term.


_______________________________________________
Emacs-devel mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-devel
Reply | Threaded
Open this post in threaded view
|

Re: Update filename history after several actions

Stefan Monnier
>   In those places
>     where such processing is required, a more preferable way is to insert
>     the contents of a file into a temporary buffer.

> That is definitely true.  However, there are a lot of places to
> change--and it could be a difficult change, in places that alter the
> file and want to be careful not to lose it (places that use
> file-precious-flag).  So I don't think that is a possible solution
> in the short term.

There's also the risk that the user has opened the file by hand with
find-file in which case Emacs shouldn't modify the file without also
updating the corresponding buffer.  find-file-noselect takes care of that.


        Stefan


_______________________________________________
Emacs-devel mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/emacs-devel