From unknown Sat Aug 09 13:20:05 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#70806 <70806@debbugs.gnu.org> To: bug#70806 <70806@debbugs.gnu.org> Subject: Status: [PATCH] Add rename-file-and-open function Reply-To: bug#70806 <70806@debbugs.gnu.org> Date: Sat, 09 Aug 2025 20:20:05 +0000 retitle 70806 [PATCH] Add rename-file-and-open function reassign 70806 emacs submitter 70806 Charalampos Mitrodimas severity 70806 normal tag 70806 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Mon May 06 14:44:23 2024 Received: (at submit) by debbugs.gnu.org; 6 May 2024 18:44:23 +0000 Received: from localhost ([127.0.0.1]:39601 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s43K2-0005hq-N6 for submit@debbugs.gnu.org; Mon, 06 May 2024 14:44:23 -0400 Received: from lists.gnu.org ([2001:470:142::17]:54580) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s43Jz-0005hh-Lf for submit@debbugs.gnu.org; Mon, 06 May 2024 14:44:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s43JV-0006qU-K7 for bug-gnu-emacs@gnu.org; Mon, 06 May 2024 14:43:49 -0400 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s43JR-0003jn-S2 for bug-gnu-emacs@gnu.org; Mon, 06 May 2024 14:43:48 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 9195B240027 for ; Mon, 6 May 2024 20:43:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1715021021; bh=RRwDT7sowPUqD56B5yoZ5+oRvYCKgi3+Ew5MLlrJpnU=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=GUJgyvxlVybkAKAVUtOXWCXnEuJeydYXeo3BQizsOwi7vH9iXkqmRVtWIzLuGoOD4 5yk3djgBC7aAu0NnX2KlFXfZQpDS0RcNBBYMu9mHVm0JtGhysn43ENnbrP681VaYmA IjVQ3f21gRP5GkUyLrHzaroSH3B5RSs3uhnbwAyD/b+FupjaGu+mmnwI/6n3RllIXR S09hW3lIhd8RPJnDFTIJveW7RgpEVK6GX6kCLbItdR0zOE22e5hddS04oCVRUAIt2p aiJahpOaSjzP2IJYA3PHpKB86n537hZ1Jzr1Ok+w+4ILMTfsOXyNOC2Z80zyTEUG1W ePG4G1+JMZeoQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4VY9KS6zMtz6tw4 for ; Mon, 6 May 2024 20:43:40 +0200 (CEST) From: Charalampos Mitrodimas To: bug-gnu-emacs@gnu.org Subject: [PATCH] Add rename-file-and-open function Date: Mon, 06 May 2024 18:43:40 +0000 Message-ID: <87cypyn5lv.fsf@posteo.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=charmitro@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --=-=-= Content-Type: text/plain 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' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Add-rename-file-and-open-function.patch >From 6c91170beb549240325e04ed1f08de833c6bfd88 Mon Sep 17 00:00:00 2001 From: Charalampos Mitrodimas 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) --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon May 06 15:00:02 2024 Received: (at 70806) by debbugs.gnu.org; 6 May 2024 19:00:02 +0000 Received: from localhost ([127.0.0.1]:39697 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s43Z9-0005ya-TI for submit@debbugs.gnu.org; Mon, 06 May 2024 15:00:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59092) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s43Yv-0005yH-Jq for 70806@debbugs.gnu.org; Mon, 06 May 2024 14:59:57 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s43YQ-00054P-C3; Mon, 06 May 2024 14:59:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=hkZqW+xUPVsNeIpuxtF/t1Y+8ZhjDp5mWCFMSGTnRf8=; b=ePWc/tWJ4TTi 5hHrKv9Tge3xQ4qBh6WQ+jGAEoIPzGMdPrrfDE8ugkCze6/TigGYnRWiIHgR/QMJm6Cg3AriUmZ4L wbzzr5oSlCKa/+dutqXbjFIQrYVc6ymR52cBoOCWsJRh+hujqcdaW8ha+hzt0Y2dkMozTtHSQBcU+ q8EMlWXB4n+O1PU36b7mRQc+0QSl2MzbCrsP6EJrmxlbU6oJDEypSxcYqR0yCHA7kD7LB6SJe8fak ImvASbd44iUnWV2R9tLuljEYRYMF4iEVCxe8/pbK26lcARv1N4PFFS1vWOI6kun6XjGPK1rZzkvuU vsOs6hLaOj1+pSBQ+vgK7A==; Date: Mon, 06 May 2024 21:59:07 +0300 Message-Id: <86bk5ibwck.fsf@gnu.org> From: Eli Zaretskii To: Charalampos Mitrodimas In-Reply-To: <87cypyn5lv.fsf@posteo.net> (message from Charalampos Mitrodimas on Mon, 06 May 2024 18:43:40 +0000) Subject: Re: bug#70806: [PATCH] Add rename-file-and-open function References: <87cypyn5lv.fsf@posteo.net> X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 70806 Cc: 70806@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Charalampos Mitrodimas > 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. From debbugs-submit-bounces@debbugs.gnu.org Mon May 06 19:49:05 2024 Received: (at 70806) by debbugs.gnu.org; 6 May 2024 23:49:05 +0000 Received: from localhost ([127.0.0.1]:40904 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s484v-0000ko-A5 for submit@debbugs.gnu.org; Mon, 06 May 2024 19:49:05 -0400 Received: from mout02.posteo.de ([185.67.36.66]:46267) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s484s-0000kE-Mj for 70806@debbugs.gnu.org; Mon, 06 May 2024 19:49:04 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 3A8A9240101 for <70806@debbugs.gnu.org>; Tue, 7 May 2024 01:48:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1715039312; bh=DaSYN3PZwW0FTG/8EgfUL2crZtKO7BQSJuy2iUlF4EE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:From:Content-Type: Content-Transfer-Encoding:From; b=Ec1rapZdtG7S/8FW2K87diatlGyY2Z0+k/EKvXz8cb+mfJBHCSYteYq8iVkX7LSxn XxygZp7/yZlU5dPYZCIYFzi6YqWgAYnVoS1k2K2SNbaSv9equyS4Z14KHUFov9Jj4q 0nDqcf9W8XqZu7S0tBobW2n6cO1m+w0EzbHVIDWejMIiN7cx8O8EW7wdjXgxngzUvA SqouZfSHkKMGTLN+LC/e5VRJJMjkbNFEvdpTic/m8lue1V7/IXKYEUKwxVUEHV/s+F a00OW35DaT3F6WxgB/n/sMhKmd9k8QZhLQNwszF2QiJAiVkX8jFNLzNaNdfy6PvCsb RRiMc7erVSm1g== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4VYJ5C2CwKz9rxB; Tue, 7 May 2024 01:48:31 +0200 (CEST) Message-ID: Date: Mon, 6 May 2024 23:48:30 +0000 MIME-Version: 1.0 Subject: Re: bug#70806: [PATCH] Add rename-file-and-open function To: Eli Zaretskii References: <87cypyn5lv.fsf@posteo.net> <86bk5ibwck.fsf@gnu.org> Content-Language: en-US From: Charalampos Mitrodimas In-Reply-To: <86bk5ibwck.fsf@gnu.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 70806 Cc: 70806@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 6/5/24 9:59 PM, Eli Zaretskii wrote: >> From: Charalampos Mitrodimas >> 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! From debbugs-submit-bounces@debbugs.gnu.org Sat May 18 04:40:01 2024 Received: (at 70806-done) by debbugs.gnu.org; 18 May 2024 08:40:01 +0000 Received: from localhost ([127.0.0.1]:60347 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s8Fbl-0007cx-5n for submit@debbugs.gnu.org; Sat, 18 May 2024 04:40:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46014) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s8Fbk-0007cn-0X for 70806-done@debbugs.gnu.org; Sat, 18 May 2024 04:40:00 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s8Fba-0004jO-HG; Sat, 18 May 2024 04:39:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=/FmAtx80HqwkCVJlg4O6Pbao2Zowbk6FGBe/N4kBuJc=; b=pW/vLcDfleXA vEYLWPuED/lhbA4K+b8VcGGsnoMs+065CA/IWyTzUwuSOjZBuU/X6PHPN6+NHeVVLgKkMWeTVaK7c PRB/m6l7DKwxLrY1VMa632PSAs6J3uYtyvbMvIoU04Nke07q7dcx2ktwyhSXQDz5E84bhx2gr1ArP wzIo+odzvAygTbhSVFazgtJceWlV6NHv+aYRt3ofbAEwd5bpv+4jDAhIdHndEGC/qcw4/Uh5ZVkbP tGh07gb45WlYB1rMEOaeI9e9KstlGLKp7CHMloY+G9ggechm942rKhlb6I7/WAalnbQyTDPFAGJV+ 6Uzr+0PNDFYBp/q6pDnu/Q==; Date: Sat, 18 May 2024 11:39:47 +0300 Message-Id: <86v83becoc.fsf@gnu.org> From: Eli Zaretskii To: Charalampos Mitrodimas In-Reply-To: (message from Charalampos Mitrodimas on Mon, 6 May 2024 23:48:30 +0000) Subject: Re: bug#70806: [PATCH] Add rename-file-and-open function References: <87cypyn5lv.fsf@posteo.net> <86bk5ibwck.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 70806-done Cc: 70806-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Mon, 6 May 2024 23:48:30 +0000 > Cc: 70806@debbugs.gnu.org > From: Charalampos Mitrodimas > > > On 6/5/24 9:59 PM, Eli Zaretskii wrote: > >> From: Charalampos Mitrodimas > >> 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. From unknown Sat Aug 09 13:20:05 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 15 Jun 2024 11:24:07 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator