unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: bug#15329: saveplace restores dired positions to random places
       [not found] <87r4cwjy50.fsf@mail.jurta.org>
@ 2013-09-11 20:45 ` Juri Linkov
  2013-09-12 16:12   ` Karl Fogel
  0 siblings, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2013-09-11 20:45 UTC (permalink / raw)
  To: 15329; +Cc: emacs-devel

> Remembering dired positions is a good feature, but
> unfortunately in its current implementation is useless.
>
> The problem is that often the position of point in Dired
> is restored to random places because in Dired buffers
> it depends on many irrelevant ever-changing factors
> such as the total size of all files in the directory
> and available space (thus the line with this information
> changes its length), sizes of each file above the restored
> file in the Dired buffer also accounts to the incorrect position
> of point, also added/deleted files in Dired change the restored
> position to random places, different sorting order, etc.
>
> An obvious solution to this problem is to save the
> current file name in Dired instead of its point.
>
> It seems saving information other than point doesn't contradict
> the purpose of saveplace.el that automatically saves places where
> visiting them later automatically moves point to the saved position.
> Also elements of `save-place-alist' are (FILENAME . POSITION),
> not more limited (FILENAME . POINT).  So saving a string to
> POSITION would be consistent with the design of saveplace.el.

I realized this is not backward-compatible change, i.e.
older Emacs versions won't be able to read saved places
in the new format.  Unfortunately, Dired filename positions
can't be added to the current format that uses an alist
with cons pair cells.  I mean (FILENAME . POINT)
can't be changed to (FILENAME POINT DIRED-FILENAME-POSITION)
because older Emacs versions will fail to read them.

The only solution that I see is to save two alists to the places file:

((FILENAME1 . POINT1)
 (FILENAME2 . POINT2)
 ...)
((FILENAME1 DIRED-FILENAME-POSITION1)
 (FILENAME2 DIRED-FILENAME-POSITION2)
 ...)

Then the current code:

  (with-demoted-errors
    (car (read-from-string
      (buffer-substring (point-min) (point-max)))))

will read the first alist without problems,
and additional code in newer versions like

  (with-demoted-errors
    (cadr (read-from-string
      (buffer-substring (point-min) (point-max)))))

will read the second alist with more information
about the context of saved places (like bookmarks).



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

* Re: bug#15329: saveplace restores dired positions to random places
  2013-09-11 20:45 ` bug#15329: saveplace restores dired positions to random places Juri Linkov
@ 2013-09-12 16:12   ` Karl Fogel
  2013-09-12 19:13     ` Stefan Monnier
  2013-09-12 20:52     ` Juri Linkov
  0 siblings, 2 replies; 5+ messages in thread
From: Karl Fogel @ 2013-09-12 16:12 UTC (permalink / raw)
  To: emacs-devel; +Cc: 15329

Juri Linkov wrote:
>> An obvious solution to this problem is to save the
>> current file name in Dired instead of its point.
>>
>> It seems saving information other than point doesn't contradict
>> the purpose of saveplace.el that automatically saves places where
>> visiting them later automatically moves point to the saved position.
>> Also elements of `save-place-alist' are (FILENAME . POSITION),
>> not more limited (FILENAME . POINT).  So saving a string to
>> POSITION would be consistent with the design of saveplace.el.
>
>I realized this is not backward-compatible change, i.e.
>older Emacs versions won't be able to read saved places
>in the new format.  Unfortunately, Dired filename positions
>can't be added to the current format that uses an alist
>with cons pair cells.  I mean (FILENAME . POINT)
>can't be changed to (FILENAME POINT DIRED-FILENAME-POSITION)
>because older Emacs versions will fail to read them.
>
>The only solution that I see is to save two alists to the places file:
>
>((FILENAME1 . POINT1)
> (FILENAME2 . POINT2)
> ...)
>((FILENAME1 DIRED-FILENAME-POSITION1)
> (FILENAME2 DIRED-FILENAME-POSITION2)
> ...)
>
>Then the current code:
>
>  (with-demoted-errors
>    (car (read-from-string
>      (buffer-substring (point-min) (point-max)))))
>
>will read the first alist without problems,
>and additional code in newer versions like
>
>  (with-demoted-errors
>    (cadr (read-from-string
>      (buffer-substring (point-min) (point-max)))))
>
>will read the second alist with more information
>about the context of saved places (like bookmarks).

Well, rather, we could use that as an upgrade strategy for the saveplace
format as a whole.  In other words, starting now and for a few versions
of Emacs into the future, write the old format to the first part of the
file, and then a more flexible new format to the second part.  The
modern format would have a more extensible structure, similarly to how
bookmark.el does it.  Say, a sublist whose first element is the type of
the record, and the rest of which is the data for that record.  Like:

  ((FILE_OR_DIR_NAME_1 ('position (position information goes here)))
   (FILE_OR_DIR_NAME_2 ('dired-position (different kind of information)))
   ...)

etc.

Thoughts?

-Karl



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

* Re: bug#15329: saveplace restores dired positions to random places
  2013-09-12 16:12   ` Karl Fogel
@ 2013-09-12 19:13     ` Stefan Monnier
  2013-09-12 20:52     ` Juri Linkov
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2013-09-12 19:13 UTC (permalink / raw)
  To: Karl Fogel; +Cc: 15329, emacs-devel

>   ((FILE_OR_DIR_NAME_1 ('position (position information goes here)))
>    (FILE_OR_DIR_NAME_2 ('dired-position (different kind of information)))
>    ...)

Re-using as much as possible of bookmarks's format would make sense.


        Stefan



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

* Re: bug#15329: saveplace restores dired positions to random places
  2013-09-12 16:12   ` Karl Fogel
  2013-09-12 19:13     ` Stefan Monnier
@ 2013-09-12 20:52     ` Juri Linkov
  2013-10-03 21:37       ` Karl Fogel
  1 sibling, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2013-09-12 20:52 UTC (permalink / raw)
  To: Karl Fogel; +Cc: 15329, emacs-devel

> The modern format would have a more extensible structure, similarly to how
> bookmark.el does it.  Say, a sublist whose first element is the type of
> the record, and the rest of which is the data for that record.

Do you think it would be possible to use the existing
infrastructure of bookmark.el, so for instance, to save
a place in an Info manual, saveplace.el could call
`Info-bookmark-make-record' and to restore it with
`Info-bookmark-jump'.  This would be better than adding
a third hook for saveplace (the second existing hook
is desktop-specific like `Info-desktop-buffer-misc-data'
and `Info-restore-desktop-buffer').



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

* Re: bug#15329: saveplace restores dired positions to random places
  2013-09-12 20:52     ` Juri Linkov
@ 2013-10-03 21:37       ` Karl Fogel
  0 siblings, 0 replies; 5+ messages in thread
From: Karl Fogel @ 2013-10-03 21:37 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 15329, emacs-devel

Juri Linkov <juri@jurta.org> writes:
>> The modern format would have a more extensible structure, similarly to how
>> bookmark.el does it.  Say, a sublist whose first element is the type of
>> the record, and the rest of which is the data for that record.
>
>Do you think it would be possible to use the existing
>infrastructure of bookmark.el, so for instance, to save
>a place in an Info manual, saveplace.el could call
>`Info-bookmark-make-record' and to restore it with
>`Info-bookmark-jump'.  This would be better than adding
>a third hook for saveplace (the second existing hook
>is desktop-specific like `Info-desktop-buffer-misc-data'
>and `Info-restore-desktop-buffer').

Yes; since both saveplace and bookmark are in the standard Emacs dist,
it's fine for them to share code, and would improve maintainability.

I'm not sure when I'll get a chance to work on this, though.  The
original bug here is about saving/restoring position in dired buffers.
While the current rather random behavior in dired is obviously a bug,
and fixing it would be a Good Thing, I'm not sure it rises to the level
where I drop other things to work on it :-).  However, if someone were
to write a patch (along the lines described in this bug report), I'd
certainly commit to reviewing it.

Best,
-Karl



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

end of thread, other threads:[~2013-10-03 21:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <87r4cwjy50.fsf@mail.jurta.org>
2013-09-11 20:45 ` bug#15329: saveplace restores dired positions to random places Juri Linkov
2013-09-12 16:12   ` Karl Fogel
2013-09-12 19:13     ` Stefan Monnier
2013-09-12 20:52     ` Juri Linkov
2013-10-03 21:37       ` Karl Fogel

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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