all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* renaming current file and buffer
@ 2006-01-02 22:29 Dieter Wilhelm
  2006-01-03  3:37 ` Ian Zimmerman
  0 siblings, 1 reply; 13+ messages in thread
From: Dieter Wilhelm @ 2006-01-02 22:29 UTC (permalink / raw)


Hi

Every so often I'm working on a file whose name I've not chosen
appropriately.  So far I couldn't find an elegant way in Emacs to
rename the file and the buffer at the same time.  I found the function
definitions below in the net, which serve my needs perfectly, but I'm
wondering whether I've overlooked something equally fitting from standard
emacs packages? What are you doing in this situation? Yes I know:
Thinking in advance, but ...

(defun rename-file-and-buffer (new-name)
  "Renames both current buffer and file it's visiting to NEW-NAME."
  (interactive "sNew name: ")
  (let ((name (buffer-name))
	(filename (buffer-file-name)))
    (if (not filename)
	(message "Buffer '%s' is not visiting a file!" name)
      (if (get-buffer new-name)
	  (message "A buffer named '%s' already exists!" new-name)
	(progn
	  (rename-file name new-name 1)
	  (rename-buffer new-name)
	  (set-visited-file-name new-name)
	  (set-buffer-modified-p nil))))))

(defun move-file-and-buffer (dir)
  "Moves both current buffer and file it's visiting to DIR."
  (interactive "DNew directory: ")
  (let* ((name (buffer-name))
	 (filename (buffer-file-name))
	 (dir
	  (if (string-match dir "\\(?:/\\|\\\\)$")
	      (substring dir 0 -1) dir))
	 (newname (concat dir "/" name)))

    (if (not filename)
	(message "Buffer '%s' is not visiting a file!" name)
      (progn
	(copy-file filename newname 1)
	(delete-file filename)
	(set-visited-file-name newname)
	(set-buffer-modified-p nil)
	t))))

-- 
Best wishes

     Dieter Wilhelm

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

* Re: renaming current file and buffer
  2006-01-02 22:29 renaming current file and buffer Dieter Wilhelm
@ 2006-01-03  3:37 ` Ian Zimmerman
  2006-01-03 10:16   ` Dieter Wilhelm
  0 siblings, 1 reply; 13+ messages in thread
From: Ian Zimmerman @ 2006-01-03  3:37 UTC (permalink / raw)
  Cc: help-gnu-emacs


Dieter> Every so often I'm working on a file whose name I've not chosen
Dieter> appropriately.  So far I couldn't find an elegant way in Emacs to
Dieter> rename the file and the buffer at the same time.  I found the function
Dieter> definitions below in the net, which serve my needs perfectly, but I'm
Dieter> wondering whether I've overlooked something equally fitting from standard
Dieter> emacs packages? What are you doing in this situation? Yes I know:
Dieter> Thinking in advance, but ...

Doesn't C-x C-w (`write-file') work for you?
It does have the side effect of saving the buffer at that time, sorry if
that's not what you want.

-- 
A true pessimist won't be discouraged by a little success.

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

* Re: renaming current file and buffer
  2006-01-03  3:37 ` Ian Zimmerman
@ 2006-01-03 10:16   ` Dieter Wilhelm
  2006-01-03 20:39     ` Peter Dyballa
  2006-01-04  0:03     ` Ian Zimmerman
  0 siblings, 2 replies; 13+ messages in thread
From: Dieter Wilhelm @ 2006-01-03 10:16 UTC (permalink / raw)
  Cc: help-gnu-emacs

Ian Zimmerman <nobrowser@gmail.com> writes:

> Dieter> Every so often I'm working on a file whose name I've not chosen
> Dieter> appropriately.  So far I couldn't find an elegant way in Emacs to
> Dieter> rename the file and the buffer at the same time.  I found the function
> Dieter> definitions below in the net, which serve my needs perfectly, but I'm
> Dieter> wondering whether I've overlooked something equally fitting from standard
> Dieter> emacs packages? What are you doing in this situation? Yes I know:
> Dieter> Thinking in advance, but ...
>
> Doesn't C-x C-w (`write-file') work for you?

Agreed, write-file gives me the opportunity for choosing another name
(with the corresponding buffer name).  But then I'd have to kill the badly
named file in a second step (e.g. in a dired buffer) since the old,
now redundant file remains on the file system.

> It does have the side effect of saving the buffer at that time, sorry if
> that's not what you want.

Thank you for your reply.  I'm new to newsgroups, may I ask why you've
written to my email address directly and copied your message to
`help-gnu-emacs@gnu.org', isn't it usual posting directly (and solely)
to the newsgroup?
-- 
Best wishes

     Dieter Wilhelm

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

* Re: renaming current file and buffer
  2006-01-03 10:16   ` Dieter Wilhelm
@ 2006-01-03 20:39     ` Peter Dyballa
  2006-01-03 23:51       ` Dieter Wilhelm
  2006-01-04  0:03     ` Ian Zimmerman
  1 sibling, 1 reply; 13+ messages in thread
From: Peter Dyballa @ 2006-01-03 20:39 UTC (permalink / raw)
  Cc: help-gnu-emacs


Am 03.01.2006 um 11:16 schrieb Dieter Wilhelm:

>> Doesn't C-x C-w (`write-file') work for you?
>
> Agreed, write-file gives me the opportunity for choosing another name
> (with the corresponding buffer name).  But then I'd have to kill  
> the badly
> named file in a second step (e.g. in a dired buffer) since the old,
> now redundant file remains on the file system.

I now remember how I handle this: I rename in dired-mode the file I  
am editing (having it saved before). The buffer name follows this  
change after some time.

--
Mit friedvollen Grüßen

   Pete

Der Unterschied zwischen Theorie und Praxis ist in
Praxis meist größer als in der Theorie

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

* Re: renaming current file and buffer
  2006-01-03 20:39     ` Peter Dyballa
@ 2006-01-03 23:51       ` Dieter Wilhelm
  2006-01-03 23:58         ` Peter Dyballa
  0 siblings, 1 reply; 13+ messages in thread
From: Dieter Wilhelm @ 2006-01-03 23:51 UTC (permalink / raw)


Peter Dyballa <Peter_Dyballa@Web.DE> writes:

> Am 03.01.2006 um 11:16 schrieb Dieter Wilhelm:
>
>>> Doesn't C-x C-w (`write-file') work for you?
>>
>> Agreed, write-file gives me the opportunity for choosing another name
>> (with the corresponding buffer name).  But then I'd have to kill
>> the badly
>> named file in a second step (e.g. in a dired buffer) since the old,
>> now redundant file remains on the file system.
>
> I now remember how I handle this: I rename in dired-mode the file I
> am editing (having it saved before). The buffer name follows this
> change after some time.

Knowing the behaviour of `rename-file' (not changing the buffer name)
I was somehow prejudiced against testing this possibility with
dired. But it actually works, thanks a lot for this hint!

With the standard dired it's a tad slow albeit.  It means getting into
dired (C-x 4 d, lest I don't forget the filename), then looking for
the file (possibly searching with C-s).  This might, just might
justify the hassle of using a home-made function.  But with the
dired-x package - I just discovered - its working like a charm.  Just
typing C-x C-j in the respective buffer is getting one into a dired
buffer with point already at the corresponding file! Then R NEW-NAME
RET RET and here we are again.

Great stuff

-- 
Best wishes

     Dieter Wilhelm

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

* Re: renaming current file and buffer
  2006-01-03 23:51       ` Dieter Wilhelm
@ 2006-01-03 23:58         ` Peter Dyballa
  2006-01-04  1:03           ` Dieter Wilhelm
  0 siblings, 1 reply; 13+ messages in thread
From: Peter Dyballa @ 2006-01-03 23:58 UTC (permalink / raw)
  Cc: help-gnu-emacs


Am 04.01.2006 um 00:51 schrieb Dieter Wilhelm:

> With the standard dired it's a tad slow albeit.  It means getting into
> dired (C-x 4 d, lest I don't forget the filename), then looking for
> the file (possibly searching with C-s).

Just type C-x d in the buffer whose file name you want to rename. It  
will position the cursor in dired on that file!

--
Mit friedvollen Grüßen

   Pete

Die Zeit wird kommen, da unsere Nachkommen sich wundern werden, wie  
wir so wunderbare Dinge einfach gewusst haben konnten. (Ein Optimist  
nach Lucius Annæus Seneca)

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

* Re: renaming current file and buffer
  2006-01-03 10:16   ` Dieter Wilhelm
  2006-01-03 20:39     ` Peter Dyballa
@ 2006-01-04  0:03     ` Ian Zimmerman
  1 sibling, 0 replies; 13+ messages in thread
From: Ian Zimmerman @ 2006-01-04  0:03 UTC (permalink / raw)
  Cc: help-gnu-emacs


Dieter> Thank you for your reply.  I'm new to newsgroups, may I ask why
Dieter> you've written to my email address directly and copied your
Dieter> message to `help-gnu-emacs@gnu.org', isn't it usual posting
Dieter> directly (and solely) to the newsgroup?

1/ The list has a bidirectional gateway with the newsgroup, or so I
assumed.  Has my reply not appeared in the newsgroup?  I have stopped
using newsgroups at all because I can't find a quality free server in my
area.  My ISP has just stopped offering NNTP access altogether (not that
I used it because it was crappy like most of them).

2/ http://www.newsreaders.com/misc/mail-copies-to.html

-- 
A true pessimist won't be discouraged by a little success.

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

* Re: renaming current file and buffer
  2006-01-03 23:58         ` Peter Dyballa
@ 2006-01-04  1:03           ` Dieter Wilhelm
  2006-01-04 11:23             ` Peter Dyballa
       [not found]             ` <mailman.21367.1136381051.20277.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 13+ messages in thread
From: Dieter Wilhelm @ 2006-01-04  1:03 UTC (permalink / raw)


Peter Dyballa <Peter_Dyballa@Web.DE> writes:

> Am 04.01.2006 um 00:51 schrieb Dieter Wilhelm:
>
>> With the standard dired it's a tad slow albeit.  It means getting into
>> dired (C-x 4 d, lest I don't forget the filename), then looking for
>> the file (possibly searching with C-s).
>
> Just type C-x d in the buffer whose file name you want to rename. It
> will position the cursor in dired on that file!

It's not working for me when I previously have opened the file with
C-x C-f.  Only when the file at some stage have had the focus in dired


-- 
Best wishes

     Dieter Wilhelm

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

* Re: renaming current file and buffer
  2006-01-04  1:03           ` Dieter Wilhelm
@ 2006-01-04 11:23             ` Peter Dyballa
       [not found]             ` <mailman.21367.1136381051.20277.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 13+ messages in thread
From: Peter Dyballa @ 2006-01-04 11:23 UTC (permalink / raw)
  Cc: help-gnu-emacs


Am 04.01.2006 um 02:03 schrieb Dieter Wilhelm:

>> Just type C-x d in the buffer whose file name you want to rename. It
>> will position the cursor in dired on that file!
>
> It's not working for me when I previously have opened the file with
> C-x C-f.  Only when the file at some stage have had the focus in dired

Could be this customisation helps:

'(dired-dwim-target t)

--
Mit friedvollen Grüßen

   Pete

Es geht nix über eine elektrische Klobürste!

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

* Re: renaming current file and buffer
       [not found]             ` <mailman.21367.1136381051.20277.help-gnu-emacs@gnu.org>
@ 2006-02-01  1:11               ` David Combs
  2006-02-01  9:20                 ` Peter Dyballa
       [not found]                 ` <mailman.488.1138786073.3044.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 13+ messages in thread
From: David Combs @ 2006-02-01  1:11 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 763 bytes --]

In article <mailman.21367.1136381051.20277.help-gnu-emacs@gnu.org>,
Peter Dyballa  <Peter_Dyballa@Web.DE> wrote:
>
>Am 04.01.2006 um 02:03 schrieb Dieter Wilhelm:
>
>>> Just type C-x d in the buffer whose file name you want to rename. It
>>> will position the cursor in dired on that file!
>>
>> It's not working for me when I previously have opened the file with
>> C-x C-f.  Only when the file at some stage have had the focus in dired
>
>Could be this customisation helps:
>
>'(dired-dwim-target t)
>
>--
>Mit friedvollen Grüßen
>
>   Pete
>
>Es geht nix über eine elektrische Klobürste!
>
>
>

What does that do?


dired-dwim-target-directory is a compiled Lisp function in `dired-aux'.
(dired-dwim-target-directory)

Not documented.

[back]


Thanks,

David

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

* Re: renaming current file and buffer
  2006-02-01  1:11               ` David Combs
@ 2006-02-01  9:20                 ` Peter Dyballa
  2006-02-11 12:32                   ` Dieter Wilhelm
       [not found]                 ` <mailman.488.1138786073.3044.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 13+ messages in thread
From: Peter Dyballa @ 2006-02-01  9:20 UTC (permalink / raw)
  Cc: help-gnu-emacs


Am 01.02.2006 um 02:11 schrieb David Combs:

> In article <mailman.21367.1136381051.20277.help-gnu-emacs@gnu.org>,
> Peter Dyballa  <Peter_Dyballa@Web.DE> wrote:
>>
>> Am 04.01.2006 um 02:03 schrieb Dieter Wilhelm:
>>
>>>> Just type C-x d in the buffer whose file name you want to  
>>>> rename. It
>>>> will position the cursor in dired on that file!
>>>
>>> It's not working for me when I previously have opened the file with
>>> C-x C-f.  Only when the file at some stage have had the focus in  
>>> dired
>>
>> Could be this customisation helps:
>>
>> '(dired-dwim-target t)
>>
>> --
>> Mit friedvollen Grüßen
>>
>>   Pete
>>
>> Es geht nix über eine elektrische Klobürste!
>>
>>
>>
>
> What does that do?
>
>
> dired-dwim-target-directory is a compiled Lisp function in `dired- 
> aux'.
> (dired-dwim-target-directory)
>
> Not documented.
>
> [back]
>
>

Is this better?

	dired-dwim-target is a variable defined in `dired.el'.
	Its value is t
	
	Documentation:
	*If non-nil, Dired tries to guess a default target directory.
	This means: if there is a dired buffer displayed in the next window,
	use its current subdir, instead of the current subdir of this dired  
buffer.
	
	The target is used in the prompt for file copy, rename etc.
	
	You can customize this variable.


'dwim' stands for 'do what I mean.'

--
Greetings

   Pete

Eat the rich -- the poor are tough and stringy.

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

* Re: renaming current file and buffer
       [not found]                 ` <mailman.488.1138786073.3044.help-gnu-emacs@gnu.org>
@ 2006-02-09  6:40                   ` David Combs
  0 siblings, 0 replies; 13+ messages in thread
From: David Combs @ 2006-02-09  6:40 UTC (permalink / raw)


In article <mailman.488.1138786073.3044.help-gnu-emacs@gnu.org>,
Peter Dyballa  <Peter_Dyballa@Web.DE> wrote:


>Is this better?
>
>	dired-dwim-target is a variable defined in `dired.el'.
>	Its value is t
>	
>	Documentation:
>	*If non-nil, Dired tries to guess a default target directory.
>	This means: if there is a dired buffer displayed in the next window,
>	use its current subdir, instead of the current subdir of this dired  
>buffer.
>	
>	The target is used in the prompt for file copy, rename etc.
>	
>	You can customize this variable.
>
>
>'dwim' stands for 'do what I mean.'
>
>--
>Greetings
>
>   Pete
>
>Eat the rich -- the poor are tough and stringy.


Thanks much

David

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

* Re: renaming current file and buffer
  2006-02-01  9:20                 ` Peter Dyballa
@ 2006-02-11 12:32                   ` Dieter Wilhelm
  0 siblings, 0 replies; 13+ messages in thread
From: Dieter Wilhelm @ 2006-02-11 12:32 UTC (permalink / raw)


Peter Dyballa <Peter_Dyballa@Web.DE> writes:

> Am 01.02.2006 um 02:11 schrieb David Combs:
>> Peter Dyballa  <Peter_Dyballa@Web.DE> wrote:
>>> Am 04.01.2006 um 02:03 schrieb Dieter Wilhelm:
>>>
>>>>> Just type C-x d in the buffer whose file name you want to
>>>>> rename. It
>>>>> will position the cursor in dired on that file!

>>>> C-x C-f.  Only when the file at some stage have had the focus in
>>>> dired
>>>
>>> Could be this customisation helps:
>>>
>>> '(dired-dwim-target t)

No, unfortunately not.
the only way I got the intended effect is with this extension from dired-x
     (define-key global-map "\C-x\C-j" 'dired-jump)

> 	*If non-nil, Dired tries to guess a default target directory.
> 	This means: if there is a dired buffer displayed in the next window,
> 	use its current subdir, instead of the current subdir of this
> 	dired  buffer.
> 'dwim' stands for 'do what I mean.'

But this is also a great alleviation, reminds me a bit of the midnight
commander!

Thanks a lot

       Dieter
-- 
Best wishes

     Dieter Wilhelm

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

end of thread, other threads:[~2006-02-11 12:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-02 22:29 renaming current file and buffer Dieter Wilhelm
2006-01-03  3:37 ` Ian Zimmerman
2006-01-03 10:16   ` Dieter Wilhelm
2006-01-03 20:39     ` Peter Dyballa
2006-01-03 23:51       ` Dieter Wilhelm
2006-01-03 23:58         ` Peter Dyballa
2006-01-04  1:03           ` Dieter Wilhelm
2006-01-04 11:23             ` Peter Dyballa
     [not found]             ` <mailman.21367.1136381051.20277.help-gnu-emacs@gnu.org>
2006-02-01  1:11               ` David Combs
2006-02-01  9:20                 ` Peter Dyballa
2006-02-11 12:32                   ` Dieter Wilhelm
     [not found]                 ` <mailman.488.1138786073.3044.help-gnu-emacs@gnu.org>
2006-02-09  6:40                   ` David Combs
2006-01-04  0:03     ` Ian Zimmerman

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.