unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* rename-file
@ 2009-08-26 16:05 Sam Steingold
  2009-08-26 18:58 ` rename-file Stephen Berman
                   ` (3 more replies)
  0 siblings, 4 replies; 24+ messages in thread
From: Sam Steingold @ 2009-08-26 16:05 UTC (permalink / raw)
  To: emacs-devel

Why isn't the buffer, which is visiting a file, renamed
when I rename the underlying file with rename-file?





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

* Re: rename-file
  2009-08-26 16:05 rename-file Sam Steingold
@ 2009-08-26 18:58 ` Stephen Berman
  2009-08-27  3:16   ` rename-file Stefan Monnier
  2009-08-26 19:21 ` rename-file Stefan Monnier
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 24+ messages in thread
From: Stephen Berman @ 2009-08-26 18:58 UTC (permalink / raw)
  To: emacs-devel

On Wed, 26 Aug 2009 12:05:06 -0400 Sam Steingold <sds@gnu.org> wrote:

> Why isn't the buffer, which is visiting a file, renamed
> when I rename the underlying file with rename-file?

Not only that, but subsequently doing `C-h v buffer-file-name' on that
buffer returns the previous name, though that file(name) no longer
exists.

Steve Berman





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

* Re: rename-file
  2009-08-26 16:05 rename-file Sam Steingold
  2009-08-26 18:58 ` rename-file Stephen Berman
@ 2009-08-26 19:21 ` Stefan Monnier
  2009-08-26 20:20   ` rename-file Lennart Borgman
  2009-08-26 20:35   ` rename-file Sam Steingold
  2009-08-26 20:42 ` rename-file martin rudalics
  2009-08-27 13:49 ` rename-file Daniel Colascione
  3 siblings, 2 replies; 24+ messages in thread
From: Stefan Monnier @ 2009-08-26 19:21 UTC (permalink / raw)
  To: Sam Steingold; +Cc: emacs-devel

> Why isn't the buffer, which is visiting a file, renamed
> when I rename the underlying file with rename-file?

Because rename-file is a low-level function.  Maybe we should introduce
a new command rename-file-buffer which automatically applies to the
current buffer's file.


        Stefan





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

* Re: rename-file
  2009-08-26 19:21 ` rename-file Stefan Monnier
@ 2009-08-26 20:20   ` Lennart Borgman
  2009-08-26 20:35   ` rename-file Sam Steingold
  1 sibling, 0 replies; 24+ messages in thread
From: Lennart Borgman @ 2009-08-26 20:20 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Sam Steingold, emacs-devel

On Wed, Aug 26, 2009 at 9:21 PM, Stefan Monnier<monnier@iro.umontreal.ca> wrote:
>> Why isn't the buffer, which is visiting a file, renamed
>> when I rename the underlying file with rename-file?
>
> Because rename-file is a low-level function.  Maybe we should introduce
> a new command rename-file-buffer which automatically applies to the
> current buffer's file.

Yes, that would be good because it would be less confusing.




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

* Re: rename-file
  2009-08-26 19:21 ` rename-file Stefan Monnier
  2009-08-26 20:20   ` rename-file Lennart Borgman
@ 2009-08-26 20:35   ` Sam Steingold
  2009-08-27  3:15     ` rename-file Eli Zaretskii
                       ` (2 more replies)
  1 sibling, 3 replies; 24+ messages in thread
From: Sam Steingold @ 2009-08-26 20:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On Wed, Aug 26, 2009 at 3:21 PM, Stefan Monnier<monnier@iro.umontreal.ca> wrote:
>> Why isn't the buffer, which is visiting a file, renamed
>> when I rename the underlying file with rename-file?
>
> Because rename-file is a low-level function.  Maybe we should introduce
> a new command rename-file-buffer which automatically applies to the
> current buffer's file.

OK to commit?

(defun rename-buffer-file (new-name)
  "Rename the current buffer and the file it is visiting to NEW-NAME."
  (interactive "FRename current file and buffer to: ")
  (let ((filename (or buffer-file-name
                      (error "This buffer is not visiting a file")))
        (oldbuf (find-buffer-visiting new-name)))
    (when (or (null oldbuf)
              (y-or-n-p "Buffer %s is already visiting %s, proceed? "
                        oldbuf new-name))
      (rename-file filename new-name 1)
      (set-visited-file-name new-name nil t))))

-- 
Sam Steingold <http://sds.podval.org>




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

* Re: rename-file
  2009-08-26 16:05 rename-file Sam Steingold
  2009-08-26 18:58 ` rename-file Stephen Berman
  2009-08-26 19:21 ` rename-file Stefan Monnier
@ 2009-08-26 20:42 ` martin rudalics
  2009-08-27 13:49 ` rename-file Daniel Colascione
  3 siblings, 0 replies; 24+ messages in thread
From: martin rudalics @ 2009-08-26 20:42 UTC (permalink / raw)
  To: Sam Steingold; +Cc: emacs-devel

 > Why isn't the buffer, which is visiting a file, renamed
 > when I rename the underlying file with rename-file?

Personally, I do the following when renaming a file or a directory:
First I do a `bookmark-set-filename' on every involved buffer.  Next I
do (the precise reasons I don't remember) for any BUFFER whose filename
is set to NEW

         (with-current-buffer buffer
           (let ((buffer-modified-p (buffer-modified-p)))
             ;; make buffer visit new
             (set-visited-file-name new nil t)
             (clear-visited-file-modtime)
             (set-buffer-modified-p buffer-modified-p)))))

`dired-rename-file' does something similar, but I never looked into
that.

Finally, I do a redisplay to assure that modelines and frame titles get
updated correctly.  When renaming directories I also set the default
directory, if necessary.

All these are sufficient for my personal needs and have not caused any
problems over the past five years.  But I'm afraid there's a number of
more hairy issues involved when a package has stored away some buffers'
names in a local list.

martin




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

* Re: rename-file
  2009-08-26 20:35   ` rename-file Sam Steingold
@ 2009-08-27  3:15     ` Eli Zaretskii
  2009-08-27  3:25     ` rename-file Richard Stallman
  2009-08-27 14:47     ` rename-file Sam Steingold
  2 siblings, 0 replies; 24+ messages in thread
From: Eli Zaretskii @ 2009-08-27  3:15 UTC (permalink / raw)
  To: Sam Steingold; +Cc: monnier, emacs-devel

> Date: Wed, 26 Aug 2009 16:35:31 -0400
> From: Sam Steingold <sds@gnu.org>
> Cc: emacs-devel@gnu.org
> 
> > Because rename-file is a low-level function.  Maybe we should introduce
> > a new command rename-file-buffer which automatically applies to the
> > current buffer's file.
> 
> OK to commit?
> 
> (defun rename-buffer-file (new-name)
>   "Rename the current buffer and the file it is visiting to NEW-NAME."
>   (interactive "FRename current file and buffer to: ")
>   (let ((filename (or buffer-file-name
>                       (error "This buffer is not visiting a file")))
>         (oldbuf (find-buffer-visiting new-name)))
>     (when (or (null oldbuf)
>               (y-or-n-p "Buffer %s is already visiting %s, proceed? "
>                         oldbuf new-name))
>       (rename-file filename new-name 1)
>       (set-visited-file-name new-name nil t))))

Will this work in a Dired buffer, especially if there are files in
that directory visited by other buffers?

What about other buffers visiting the same file?





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

* Re: rename-file
  2009-08-26 18:58 ` rename-file Stephen Berman
@ 2009-08-27  3:16   ` Stefan Monnier
  2009-08-27  8:38     ` rename-file Stephen Berman
  0 siblings, 1 reply; 24+ messages in thread
From: Stefan Monnier @ 2009-08-27  3:16 UTC (permalink / raw)
  To: Stephen Berman; +Cc: emacs-devel

>> Why isn't the buffer, which is visiting a file, renamed
>> when I rename the underlying file with rename-file?

> Not only that, but subsequently doing `C-h v buffer-file-name' on that
> buffer returns the previous name, though that file(name) no longer
> exists.

That's perfectly OK.  It's exactly as if someone had done "mv" from
outside Emacs (or from a M-x shell buffer).  There's nothing wrong with
such a situation.  C-x C-s will (re)create the file.


        Stefan




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

* Re: rename-file
  2009-08-26 20:35   ` rename-file Sam Steingold
  2009-08-27  3:15     ` rename-file Eli Zaretskii
@ 2009-08-27  3:25     ` Richard Stallman
  2009-08-27  3:41       ` rename-file Sam Steingold
  2009-08-27 14:47     ` rename-file Sam Steingold
  2 siblings, 1 reply; 24+ messages in thread
From: Richard Stallman @ 2009-08-27  3:25 UTC (permalink / raw)
  To: Sam Steingold; +Cc: monnier, emacs-devel

    (defun rename-buffer-file (new-name)
      "Rename the current buffer and the file it is visiting to NEW-NAME."
      (interactive "FRename current file and buffer to: ")

Given the existence of the command `rename-buffer',
this name will cause confusion.

Does it rename the buffer, or does it just set the visited file name?
The code seems to do the latter.  If so, the doc string is inaccurate.





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

* Re: rename-file
  2009-08-27  3:25     ` rename-file Richard Stallman
@ 2009-08-27  3:41       ` Sam Steingold
  2009-08-27 17:11         ` rename-file Stefan Monnier
  2009-08-29  0:46         ` rename-file Richard Stallman
  0 siblings, 2 replies; 24+ messages in thread
From: Sam Steingold @ 2009-08-27  3:41 UTC (permalink / raw)
  To: rms; +Cc: monnier, emacs-devel

On Wed, Aug 26, 2009 at 11:25 PM, Richard Stallman<rms@gnu.org> wrote:
>    (defun rename-buffer-file (new-name)
>      "Rename the current buffer and the file it is visiting to NEW-NAME."
>      (interactive "FRename current file and buffer to: ")
>
> Given the existence of the command `rename-buffer',
> this name will cause confusion.

please suggest a better name.

> Does it rename the buffer, or does it just set the visited file name?
> The code seems to do the latter.  If so, the doc string is inaccurate.

doc string says:

rename the _BUFFER_ and the _FILE_.
it renames the file and keeps the buffer associated with it.

-- 
Sam Steingold <http://sds.podval.org>




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

* Re: rename-file
  2009-08-27  3:16   ` rename-file Stefan Monnier
@ 2009-08-27  8:38     ` Stephen Berman
  2009-08-27  9:09       ` rename-file Andreas Schwab
  2009-08-27 17:08       ` rename-file Stefan Monnier
  0 siblings, 2 replies; 24+ messages in thread
From: Stephen Berman @ 2009-08-27  8:38 UTC (permalink / raw)
  To: emacs-devel

On Wed, 26 Aug 2009 23:16:08 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote:

>>> Why isn't the buffer, which is visiting a file, renamed
>>> when I rename the underlying file with rename-file?
>
>> Not only that, but subsequently doing `C-h v buffer-file-name' on that
>> buffer returns the previous name, though that file(name) no longer
>> exists.
>
> That's perfectly OK.  It's exactly as if someone had done "mv" from
> outside Emacs (or from a M-x shell buffer).  There's nothing wrong with
> such a situation.  C-x C-s will (re)create the file.

I should have left out the though-clause above, it was a misguided
afterthought.  What's problematic is that returning the previous name
contradicts the doc string of buffer-file-name: "Name of file visited in
current buffer, or nil if not visiting a file."

Steve Berman





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

* Re: rename-file
  2009-08-27  8:38     ` rename-file Stephen Berman
@ 2009-08-27  9:09       ` Andreas Schwab
  2009-08-27 10:01         ` rename-file Stephen Berman
  2009-08-27 17:08       ` rename-file Stefan Monnier
  1 sibling, 1 reply; 24+ messages in thread
From: Andreas Schwab @ 2009-08-27  9:09 UTC (permalink / raw)
  To: Stephen Berman; +Cc: emacs-devel

Stephen Berman <stephen.berman@gmx.net> writes:

> What's problematic is that returning the previous name contradicts the
> doc string of buffer-file-name: "Name of file visited in current
> buffer, or nil if not visiting a file."

That's not a contradiction.  All that buffer-file-name defines is a
relationship between a buffer and a file name, independent of the
current meaning of that name.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




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

* Re: rename-file
  2009-08-27  9:09       ` rename-file Andreas Schwab
@ 2009-08-27 10:01         ` Stephen Berman
  2009-08-27 10:21           ` rename-file Andreas Schwab
  0 siblings, 1 reply; 24+ messages in thread
From: Stephen Berman @ 2009-08-27 10:01 UTC (permalink / raw)
  To: emacs-devel

On Thu, 27 Aug 2009 11:09:45 +0200 Andreas Schwab <schwab@linux-m68k.org> wrote:

> Stephen Berman <stephen.berman@gmx.net> writes:
>
>> What's problematic is that returning the previous name contradicts the
>> doc string of buffer-file-name: "Name of file visited in current
>> buffer, or nil if not visiting a file."
>
> That's not a contradiction.  All that buffer-file-name defines is
> a relationship between a buffer and a file name, independent of the
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> current meaning of that name.

If that is so, then the doc string should be changed to "A name of the
file visited in the current buffer...", to avoid confusion.  As it is, I
understand it to be equivalent to "The name of the file visited in the
current buffer..." (and indeed, "the name" is used in the comment above
the filename field of the buffer struct declaration in buffer.h), and
the name shown (after changing it with rename-file), i.e. the value of
buffer-file-name, is incorrect.  More explicitly:

1. C-x C-f bla
2. C-h v buffer-file-name => bla
3. M-x rename-file RET blabla
4. C-h v buffer-file-name => bla

Surely the return value in step 4 is unwanted, isn't it?

Steve Berman





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

* Re: rename-file
  2009-08-27 10:01         ` rename-file Stephen Berman
@ 2009-08-27 10:21           ` Andreas Schwab
  2009-08-27 11:28             ` rename-file Stephen Berman
  0 siblings, 1 reply; 24+ messages in thread
From: Andreas Schwab @ 2009-08-27 10:21 UTC (permalink / raw)
  To: Stephen Berman; +Cc: emacs-devel

Stephen Berman <stephen.berman@gmx.net> writes:

> If that is so, then the doc string should be changed to "A name of the
> file visited in the current buffer...", to avoid confusion.

No, that's very wrong.  There can be only at most one name associated
with any buffer.

> 1. C-x C-f bla
> 2. C-h v buffer-file-name => bla
> 3. M-x rename-file RET blabla
> 4. C-h v buffer-file-name => bla
>
> Surely the return value in step 4 is unwanted, isn't it?

The visited name of the buffer didn't change in any way whatsoever.
Only set-visited-file-name can do that.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




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

* Re: rename-file
  2009-08-27 10:21           ` rename-file Andreas Schwab
@ 2009-08-27 11:28             ` Stephen Berman
  2009-08-27 11:50               ` rename-file Miles Bader
  2009-08-27 12:18               ` rename-file Andreas Schwab
  0 siblings, 2 replies; 24+ messages in thread
From: Stephen Berman @ 2009-08-27 11:28 UTC (permalink / raw)
  To: emacs-devel

On Thu, 27 Aug 2009 12:21:36 +0200 Andreas Schwab <schwab@linux-m68k.org> wrote:

>                         There can be only at most one name associated
> with any buffer.

Isn't it rather "exactly one file name"?  Or is it possible to have
nameless buffers?

>
>> 1. C-x C-f bla
>> 2. C-h v buffer-file-name => bla
>> 3. M-x rename-file RET blabla
>> 4. C-h v buffer-file-name => bla
>>
>> Surely the return value in step 4 is unwanted, isn't it?
>
> The visited name of the buffer didn't change in any way whatsoever.

But that's precisely the problem!

> Only set-visited-file-name can do that.

Then it should be made to take effect between steps 3 and 4 above.

I don't understand how anyone can deny that evaluating the variable
whose value is documented as the "Name of file visited in current
buffer, or nil if not visiting a file" should return the correct current
name of the visited file.

Steve Berman





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

* Re: rename-file
  2009-08-27 11:28             ` rename-file Stephen Berman
@ 2009-08-27 11:50               ` Miles Bader
  2009-08-27 14:59                 ` rename-file Stephen Berman
  2009-08-27 12:18               ` rename-file Andreas Schwab
  1 sibling, 1 reply; 24+ messages in thread
From: Miles Bader @ 2009-08-27 11:50 UTC (permalink / raw)
  To: Stephen Berman; +Cc: emacs-devel

Stephen Berman <stephen.berman@gmx.net> writes:
> I don't understand how anyone can deny that evaluating the variable
> whose value is documented as the "Name of file visited in current
> buffer, or nil if not visiting a file" should return the correct current
> name of the visited file.

Because "rename-file" is a relatively low-level command, which just
tells the OS to rename the file.

If you want "smart" renaming, use dired to rename files ("R" command).
It will update buffer filenames (and buffer names) accordingly.

While the latter behavior is convenient, there's certainly nothing
_wrong_ with the former -- there's no guarantee that a buffer's filename
variable refers an existing file at all (and really there can't be,
since in the general case, emacs can't keep track of what goes on in the
filesystem behind its back).

-Miles

-- 
"An atheist doesn't have to be someone who thinks he has a proof that
there can't be a god.  He only has to be someone who believes that the
evidence on the God question is at a similar level to the evidence on
the werewolf question."  [John McCarthy]




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

* Re: rename-file
  2009-08-27 11:28             ` rename-file Stephen Berman
  2009-08-27 11:50               ` rename-file Miles Bader
@ 2009-08-27 12:18               ` Andreas Schwab
  1 sibling, 0 replies; 24+ messages in thread
From: Andreas Schwab @ 2009-08-27 12:18 UTC (permalink / raw)
  To: Stephen Berman; +Cc: emacs-devel

Stephen Berman <stephen.berman@gmx.net> writes:

> On Thu, 27 Aug 2009 12:21:36 +0200 Andreas Schwab <schwab@linux-m68k.org> wrote:
>
>>                         There can be only at most one name associated
>> with any buffer.
>
> Isn't it rather "exactly one file name"?  Or is it possible to have
> nameless buffers?

Sure.  See the docstring of buffer-file-name.

>>> 1. C-x C-f bla
>>> 2. C-h v buffer-file-name => bla
>>> 3. M-x rename-file RET blabla
>>> 4. C-h v buffer-file-name => bla
>>>
>>> Surely the return value in step 4 is unwanted, isn't it?
>>
>> The visited name of the buffer didn't change in any way whatsoever.
>
> But that's precisely the problem!

There is no assotiation between a buffer and a file, only between a
buffer and file name.

>> Only set-visited-file-name can do that.
>
> Then it should be made to take effect between steps 3 and 4 above.

No.  That the filesystem changes does not in any way change the
association of a buffer to a file name, just like deleting a file does
not magically kill a buffer.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




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

* Re: rename-file
  2009-08-26 16:05 rename-file Sam Steingold
                   ` (2 preceding siblings ...)
  2009-08-26 20:42 ` rename-file martin rudalics
@ 2009-08-27 13:49 ` Daniel Colascione
  3 siblings, 0 replies; 24+ messages in thread
From: Daniel Colascione @ 2009-08-27 13:49 UTC (permalink / raw)
  To: Emacs-Devel devel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Aug 26, 2009, at 12:05 PM, Sam Steingold wrote:
> Why isn't the buffer, which is visiting a file, renamed
> when I rename the underlying file with rename-file?

Here's what I use. It's DTRT for years. (I have it bound to C-x m.)
Something like this, IMHO, should be the user-level rename-file.


(defun qtmstr-rename-file (new)
  "Rename file OLD to NEW, renaming the buffer as well.

If the file is under version control, act like vc-rename-file."

  (interactive "FRename to: ")

  (let ((oldbuf (current-buffer))
        (oldbufname (buffer-name))
        (old (buffer-file-name))
        vc)

    (if (and oldbuf (buffer-modified-p oldbuf))
	(error "Please save files before moving them"))
    (if (get-file-buffer new)
	(error "Already editing new file name"))
    (if (file-exists-p new)
	(error "New file already exists"))

    (let ((state (vc-state old)))
      (cond ((memq state '(up-to-date edited))
             (setq vc t)
             (vc-call rename-file old new)
             (vc-file-clearprops old))

            (state
             (error "Please %s files before moving them"
                    (if (stringp state) "check in" "update")))))

    (if (file-exists-p old) (rename-file old new))

    (with-current-buffer oldbuf
      (let ((buffer-read-only buffer-read-only))
        (set-visited-file-name new))
      (when vc
        (vc-backend new)
        (vc-mode-line new))
      (set-buffer-modified-p nil))
    (message "Renamed %s to %s%s"
             oldbufname new (if vc " [with VC]" ""))))
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iEYEARECAAYFAkqWjswACgkQ17c2LVA10VtOywCgxhjjfavlB0qDDKMKgR1D1llN
o3IAoIICnOzZbDqP+RBpT3m2tPyXg935
=4l7w
-----END PGP SIGNATURE-----




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

* Re: rename-file
  2009-08-26 20:35   ` rename-file Sam Steingold
  2009-08-27  3:15     ` rename-file Eli Zaretskii
  2009-08-27  3:25     ` rename-file Richard Stallman
@ 2009-08-27 14:47     ` Sam Steingold
  2 siblings, 0 replies; 24+ messages in thread
From: Sam Steingold @ 2009-08-27 14:47 UTC (permalink / raw)
  To: emacs-devel; +Cc: Stefan Monnier

Sam Steingold wrote:
> On Wed, Aug 26, 2009 at 3:21 PM, Stefan Monnier<monnier@iro.umontreal.ca> wrote:
>>> Why isn't the buffer, which is visiting a file, renamed
>>> when I rename the underlying file with rename-file?
>> Because rename-file is a low-level function.  Maybe we should introduce
>> a new command rename-file-buffer which automatically applies to the
>> current buffer's file.
> 
> OK to commit?
> 
> (defun rename-buffer-file (new-name)
>   "Rename the current buffer and the file it is visiting to NEW-NAME."
>   (interactive "FRename current file and buffer to: ")
>   (let ((filename (or buffer-file-name
>                       (error "This buffer is not visiting a file")))
>         (oldbuf (find-buffer-visiting new-name)))
>     (when (or (null oldbuf)
>               (y-or-n-p "Buffer %s is already visiting %s, proceed? "
>                         oldbuf new-name))
>       (rename-file filename new-name 1)
>       (set-visited-file-name new-name nil t))))
> 

on a second thought I decided that R in dired + M-x vc-rename-file are already
sufficient. sorry about the noise.






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

* Re: rename-file
  2009-08-27 11:50               ` rename-file Miles Bader
@ 2009-08-27 14:59                 ` Stephen Berman
  0 siblings, 0 replies; 24+ messages in thread
From: Stephen Berman @ 2009-08-27 14:59 UTC (permalink / raw)
  To: emacs-devel

On Thu, 27 Aug 2009 20:50:24 +0900 Miles Bader <miles@gnu.org> wrote:

> Stephen Berman <stephen.berman@gmx.net> writes:
>> I don't understand how anyone can deny that evaluating the variable
>> whose value is documented as the "Name of file visited in current
>> buffer, or nil if not visiting a file" should return the correct current
>> name of the visited file.
>
> Because "rename-file" is a relatively low-level command, which just
> tells the OS to rename the file.
>
> If you want "smart" renaming, use dired to rename files ("R" command).
> It will update buffer filenames (and buffer names) accordingly.
>
> While the latter behavior is convenient, there's certainly nothing
> _wrong_ with the former -- there's no guarantee that a buffer's filename
> variable refers an existing file at all (and really there can't be,
> since in the general case, emacs can't keep track of what goes on in the
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> filesystem behind its back).
  ^^^^^^^^^^^^^^^^^^^^^^^^^^

I understand the Emacs can't be expected to track filesystem changes
that happen outside its purview (but sometimes it does anyway,
e.g. auto-revert-mode), but my concern is about changes due to a
sequence of Emacs commands (steps 1-4 below), which result in a value
for buffer-file-name that to my understanding is not consistent with its
doc string.  I wouldn't have complained if the doc string had noted this
possibility, e.g.:

"Name of file visited in current buffer, or nil if not visiting a file.
Note that a non-nil value of this variable does not change if the file
name changed after visiting the file."

On Thu, 27 Aug 2009 14:18:03 +0200 Andreas Schwab <schwab@linux-m68k.org> wrote:

> Stephen Berman <stephen.berman@gmx.net> writes:
>
>>>> 1. C-x C-f bla
>>>> 2. C-h v buffer-file-name => bla
>>>> 3. M-x rename-file RET blabla
>>>> 4. C-h v buffer-file-name => bla
>>>>
>>>> Surely the return value in step 4 is unwanted, isn't it?
>>>
>>> The visited name of the buffer didn't change in any way whatsoever.
>>
>> But that's precisely the problem!
>
> There is no assotiation between a buffer and a file, only between a
> buffer and file name.
>
>>> Only set-visited-file-name can do that.
>>
>> Then it should be made to take effect between steps 3 and 4 above.
>
> No.  That the filesystem changes does not in any way change the
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> association of a buffer to a file name, just like deleting a file does
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> not magically kill a buffer.

That appears to depend on the command or function that brings about the
filesystem change, e.g. write-file does change the association of a
buffer to a file name:

5. C-h v buffer-file-name => blip
6. C-x C-w blap (i.e. at the prompt type "blap" after default-directory)
7. C-h v buffer-file-name => "/<default-directory>/blap"
8. There is no longer a buffer visiting "/<default-directory>/blip"

If write-file does it, there's no reason in principle why rename-file
cannot do it, so if (or since) it (currently) does not change the
association, the doc string should note this.  Or is there a convention
that an Emacs command does not track file system changes unless its doc
string explicitly says it does?  If so, is this convention documented or
assumed as common lore?

Steve Berman




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

* Re: rename-file
  2009-08-27  8:38     ` rename-file Stephen Berman
  2009-08-27  9:09       ` rename-file Andreas Schwab
@ 2009-08-27 17:08       ` Stefan Monnier
  1 sibling, 0 replies; 24+ messages in thread
From: Stefan Monnier @ 2009-08-27 17:08 UTC (permalink / raw)
  To: Stephen Berman; +Cc: emacs-devel

> I should have left out the though-clause above, it was a misguided
> afterthought.  What's problematic is that returning the previous name
> contradicts the doc string of buffer-file-name: "Name of file visited in
> current buffer, or nil if not visiting a file."

The docstring sounds correct to me.  If you rename the underlying file,
it means the buffer's file name will refer to some other file (or no
file at all).


        Stefan




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

* Re: rename-file
  2009-08-27  3:41       ` rename-file Sam Steingold
@ 2009-08-27 17:11         ` Stefan Monnier
  2009-08-29  0:46         ` rename-file Richard Stallman
  1 sibling, 0 replies; 24+ messages in thread
From: Stefan Monnier @ 2009-08-27 17:11 UTC (permalink / raw)
  To: Sam Steingold; +Cc: rms, emacs-devel

> doc string says:

> rename the _BUFFER_ and the _FILE_.
> it renames the file and keeps the buffer associated with it.

BTW, the issue is not whether it renames the buffer, but wether it
renames the buffer's buffer-file-name.


        Stefan


PS: I hear dired's R does such a thing, so we should consolidate
that code.




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

* Re: rename-file
  2009-08-27  3:41       ` rename-file Sam Steingold
  2009-08-27 17:11         ` rename-file Stefan Monnier
@ 2009-08-29  0:46         ` Richard Stallman
  2009-08-31 22:09           ` rename-file Sam Steingold
  1 sibling, 1 reply; 24+ messages in thread
From: Richard Stallman @ 2009-08-29  0:46 UTC (permalink / raw)
  To: Sam Steingold; +Cc: monnier, emacs-devel

    > Given the existence of the command `rename-buffer',
    > this name will cause confusion.

    please suggest a better name.

I can't suggest one, since I am not sure what this function really
does.

    > Does it rename the buffer, or does it just set the visited file name?
    > The code seems to do the latter.  If so, the doc string is inaccurate.

    doc string says:

    rename the _BUFFER_ and the _FILE_.
    it renames the file and keeps the buffer associated with it.

Then the code could use some more comments.  Where does the buffer
name get changed?




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

* Re: rename-file
  2009-08-29  0:46         ` rename-file Richard Stallman
@ 2009-08-31 22:09           ` Sam Steingold
  0 siblings, 0 replies; 24+ messages in thread
From: Sam Steingold @ 2009-08-31 22:09 UTC (permalink / raw)
  To: emacs-devel

Richard Stallman wrote:
> 
>     rename the _BUFFER_ and the _FILE_.
>     it renames the file and keeps the buffer associated with it.
> 
> Where does the buffer
> name get changed?

in set-visited-file-name





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

end of thread, other threads:[~2009-08-31 22:09 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-26 16:05 rename-file Sam Steingold
2009-08-26 18:58 ` rename-file Stephen Berman
2009-08-27  3:16   ` rename-file Stefan Monnier
2009-08-27  8:38     ` rename-file Stephen Berman
2009-08-27  9:09       ` rename-file Andreas Schwab
2009-08-27 10:01         ` rename-file Stephen Berman
2009-08-27 10:21           ` rename-file Andreas Schwab
2009-08-27 11:28             ` rename-file Stephen Berman
2009-08-27 11:50               ` rename-file Miles Bader
2009-08-27 14:59                 ` rename-file Stephen Berman
2009-08-27 12:18               ` rename-file Andreas Schwab
2009-08-27 17:08       ` rename-file Stefan Monnier
2009-08-26 19:21 ` rename-file Stefan Monnier
2009-08-26 20:20   ` rename-file Lennart Borgman
2009-08-26 20:35   ` rename-file Sam Steingold
2009-08-27  3:15     ` rename-file Eli Zaretskii
2009-08-27  3:25     ` rename-file Richard Stallman
2009-08-27  3:41       ` rename-file Sam Steingold
2009-08-27 17:11         ` rename-file Stefan Monnier
2009-08-29  0:46         ` rename-file Richard Stallman
2009-08-31 22:09           ` rename-file Sam Steingold
2009-08-27 14:47     ` rename-file Sam Steingold
2009-08-26 20:42 ` rename-file martin rudalics
2009-08-27 13:49 ` rename-file Daniel Colascione

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