all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#70806: [PATCH] Add rename-file-and-open function
@ 2024-05-06 18:43 Charalampos Mitrodimas
  2024-05-06 18:59 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Charalampos Mitrodimas @ 2024-05-06 18:43 UTC (permalink / raw)
  To: 70806

[-- Attachment #1: Type: text/plain, Size: 796 bytes --]

Tags: patch

Hi,

The new function is similar to "rename-file", but it automatically opens
the file once it's renamed (or throws a relevant error).

I'm not sure if this addition is necessary, but I've had it for so many
years that I thought it might be useful to have it in Emacs by
default. I'm also not sure if it's in the correct position within
lisp/files.el. In any case, I'm submitting this patch for consideration.

--
C. Mitrodimas


In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.16.0) of 2024-05-06 built on
 Debian-bookworm-latest-amd64-base
Repository revision: 71395b7888f4d7b64be36a8cedb5b2b8c4819259
Repository branch: master
System Description: Debian GNU/Linux 12 (bookworm)

Configured using:
 'configure --with-native-compilation'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-rename-file-and-open-function.patch --]
[-- Type: text/patch, Size: 2452 bytes --]

From 6c91170beb549240325e04ed1f08de833c6bfd88 Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas <charmitro@posteo.net>
Date: Mon, 6 May 2024 21:31:08 +0300
Subject: [PATCH] Add rename-file-and-open function

Introduce rename-file-and-open, a new function that renames a file and
opens the renamed file immediately. This function was developed to
make the renaming of a file more automated: when using rename-file, the
renamed file is not automatically opened, requiring an additional
step to open it manually.

The rename-file-and-open function takes two required arguments:
    - file: the source file name (a string)
    - newname: the destination file name (a string)
    - ok-if-already-exists: control the behavior when the destination
      file already exists

It calls rename-file to perform the actual renaming, handling any
file-error that may occur by signaling a user-error with an appropriate
error message.

* lisp/files.el (rename-file-and-open): New function to rename a file
  and open it, since `rename-file' doesn't open the renamed file.
---
 lisp/files.el | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lisp/files.el b/lisp/files.el
index c24e48e3db2..ded6e1b130f 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -7380,6 +7380,25 @@ rename-auto-save-file
 	     (recent-auto-save-p))
 	(rename-file osave buffer-auto-save-file-name t))))
 
+(defun rename-file-and-open (file newname &optional ok-if-already-exists)
+  "Rename FILE as NEWNAME and open the renamed file.
+Both args must be strings.
+
+If file has names other than FILE, it continues to have those names.
+If NEWNAME is a directory name, rename FILE to a like-named file under
+NEWNAME.  For NEWNAME to be recognized as a directory name, it should
+end in a slash.
+
+Signal a `file-already-exists' error if a file NEWNAME already exists
+unless optional third argument OK-IF-ALREADY-EXISTS is non-nil.
+An integer third arg means request confirmation if NEWNAME already exists."
+  (interactive "fRename file: \nGRename to file: \np")
+  (condition-case err
+      (rename-file file newname ok-if-already-exists)
+    (file-error
+     (user-error "Failed to rename file: %s" (error-message-string err))))
+  (find-file newname))
+
 (defun make-auto-save-file-name ()
   "Return file name to use for auto-saves of current buffer.
 Does not consider `auto-save-visited-file-name' as that variable is checked
-- 
2.39.3 (Apple Git-146)


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

* bug#70806: [PATCH] Add rename-file-and-open function
  2024-05-06 18:43 bug#70806: [PATCH] Add rename-file-and-open function Charalampos Mitrodimas
@ 2024-05-06 18:59 ` Eli Zaretskii
  2024-05-06 23:48   ` Charalampos Mitrodimas
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2024-05-06 18:59 UTC (permalink / raw)
  To: Charalampos Mitrodimas; +Cc: 70806

> From: Charalampos Mitrodimas <charmitro@posteo.net>
> Date: Mon, 06 May 2024 18:43:40 +0000
> 
> The new function is similar to "rename-file", but it automatically opens
> the file once it's renamed (or throws a relevant error).
> 
> I'm not sure if this addition is necessary, but I've had it for so many
> years that I thought it might be useful to have it in Emacs by
> default. I'm also not sure if it's in the correct position within
> lisp/files.el. In any case, I'm submitting this patch for consideration.

I think we have "C-x C-w" for those scenarios.  It works the other way
around: first you visit the file under the original name, then change
its name when you save it.





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

* bug#70806: [PATCH] Add rename-file-and-open function
  2024-05-06 18:59 ` Eli Zaretskii
@ 2024-05-06 23:48   ` Charalampos Mitrodimas
  2024-05-18  8:39     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Charalampos Mitrodimas @ 2024-05-06 23:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 70806


On 6/5/24 9:59 PM, Eli Zaretskii wrote:
>> From: Charalampos Mitrodimas <charmitro@posteo.net>
>> Date: Mon, 06 May 2024 18:43:40 +0000
>>
>> The new function is similar to "rename-file", but it automatically opens
>> the file once it's renamed (or throws a relevant error).
>>
>> I'm not sure if this addition is necessary, but I've had it for so many
>> years that I thought it might be useful to have it in Emacs by
>> default. I'm also not sure if it's in the correct position within
>> lisp/files.el. In any case, I'm submitting this patch for consideration.
> I think we have "C-x C-w" for those scenarios.  It works the other way
> around: first you visit the file under the original name, then change
> its name when you save it.
That is indeed better than my function. Thanks!





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

* bug#70806: [PATCH] Add rename-file-and-open function
  2024-05-06 23:48   ` Charalampos Mitrodimas
@ 2024-05-18  8:39     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-05-18  8:39 UTC (permalink / raw)
  To: Charalampos Mitrodimas; +Cc: 70806-done

> Date: Mon,  6 May 2024 23:48:30 +0000
> Cc: 70806@debbugs.gnu.org
> From: Charalampos Mitrodimas <charmitro@posteo.net>
> 
> 
> On 6/5/24 9:59 PM, Eli Zaretskii wrote:
> >> From: Charalampos Mitrodimas <charmitro@posteo.net>
> >> Date: Mon, 06 May 2024 18:43:40 +0000
> >>
> >> The new function is similar to "rename-file", but it automatically opens
> >> the file once it's renamed (or throws a relevant error).
> >>
> >> I'm not sure if this addition is necessary, but I've had it for so many
> >> years that I thought it might be useful to have it in Emacs by
> >> default. I'm also not sure if it's in the correct position within
> >> lisp/files.el. In any case, I'm submitting this patch for consideration.
> > I think we have "C-x C-w" for those scenarios.  It works the other way
> > around: first you visit the file under the original name, then change
> > its name when you save it.
> That is indeed better than my function. Thanks!

No further comments within 12 days, so I conclude this issue can be
closed now.





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

end of thread, other threads:[~2024-05-18  8:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-06 18:43 bug#70806: [PATCH] Add rename-file-and-open function Charalampos Mitrodimas
2024-05-06 18:59 ` Eli Zaretskii
2024-05-06 23:48   ` Charalampos Mitrodimas
2024-05-18  8:39     ` Eli Zaretskii

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.