From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jeremy Bryant via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#67313: [PATCH] New command write-file-no-switch Date: Mon, 20 Nov 2023 23:33:27 +0000 Message-ID: <87zfz8dmk5.fsf@jeremybryant.net> Reply-To: Jeremy Bryant Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28735"; mail-complaints-to="usenet@ciao.gmane.io" To: 67313@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 21 00:38:14 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r5DqH-0007GV-Oj for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 21 Nov 2023 00:38:14 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5Dq5-0003OF-NE; Mon, 20 Nov 2023 18:38:02 -0500 Original-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 1r5Dq4-0003NP-53 for bug-gnu-emacs@gnu.org; Mon, 20 Nov 2023 18:38:00 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r5Dq3-00052j-Sc for bug-gnu-emacs@gnu.org; Mon, 20 Nov 2023 18:37:59 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r5Dq5-0002v7-Sl for bug-gnu-emacs@gnu.org; Mon, 20 Nov 2023 18:38:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jeremy Bryant Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 20 Nov 2023 23:38:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 67313 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.170052342611156 (code B ref -1); Mon, 20 Nov 2023 23:38:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Nov 2023 23:37:06 +0000 Original-Received: from localhost ([127.0.0.1]:54829 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r5DpC-0002tr-55 for submit@debbugs.gnu.org; Mon, 20 Nov 2023 18:37:06 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:59802) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r5Dp7-0002tG-Jf for submit@debbugs.gnu.org; Mon, 20 Nov 2023 18:37:05 -0500 Original-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 1r5Doz-0003H1-KX for bug-gnu-emacs@gnu.org; Mon, 20 Nov 2023 18:36:53 -0500 Original-Received: from out-170.mta1.migadu.com ([2001:41d0:203:375::aa]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5Dow-0004vs-4C for bug-gnu-emacs@gnu.org; Mon, 20 Nov 2023 18:36:52 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jeremybryant.net; s=key1; t=1700523406; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=VzaNRZHtYlSRDXlB/8G0pfk9zfO6QlktLgnqk57wbJg=; b=o+KluJG6EiGD828brDLU3eIXuZSJst3pOUHyD1K6O1hRH++WbzJZ+yL0yfS17HLqJWiCjt IgI5r5NZX1pna5jqEi/wOnYb2PXCXGuP/pFbT6jH7zU2XbTj51zBcY3TpmkmbA0SCCUrUc 6tj+kdrilMS10L9X1DXvYySDpjGRkKVuNQkoDg+4w/15siWjthsBzEAZAnSLVrc97hcICH pfJD/4gd+cSBZ/FY2W2ndpEl01X0hfJv4Ftb+ow5b8rqp4Ammt68YLetGZyDACvXlX8Fxu olrr1+m6pVsJhHaF5WdFDOYnJst124gk+V+Btw0uXt79uw8WjNetPQAX3o7m0g== X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:203:375::aa; envelope-from=jb@jeremybryant.net; helo=out-170.mta1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:274694 Archived-At: --=-=-= Content-Type: text/plain Tags: patch By default write-file changes the buffer to point to the new filename, but a user may wish to simply do the equivalent of write-file without switching, as a sort of backup file. The attached is a patch concept to introduce the idea. Please let me know if this makes sense to introduce a new command rather than modifying the existing one (which may be less convenient). I understand there would be additional things to do for new commands, but would like to propose the idea first. Any suggestions welcome. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-New-command-write-file-no-switch.patch >From d6eec95e5a5bd31c10f4031b4febd65021938973 Mon Sep 17 00:00:00 2001 From: Jeremy Bryant Date: Mon, 20 Nov 2023 23:30:49 +0000 Subject: [PATCH] New command write-file-no-switch * lisp/files.el (write-file-no-switch): New command like write-file but without switching to the new filename. --- lisp/files.el | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/lisp/files.el b/lisp/files.el index 1cdcec23b11..bc314b8fb95 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -4949,6 +4949,78 @@ write-file ;; the one at the old location. (vc-refresh-state))) +(defun write-file-no-switch (filename &optional confirm) + "Like write-file but without switching to the new filename. +... +Write current buffer into file FILENAME. +This makes the buffer visit that file, and marks it as not modified. + +Interactively, prompt for FILENAME. +If you specify just a directory name as FILENAME, that means to write +to a file in that directory. In this case, the base name of the file +is the same as that of the file visited in the buffer, or the buffer +name sans leading directories, if any, if the buffer is not already +visiting a file. + +You can also yank the file name into the minibuffer to edit it, +using \\\\[next-history-element]. + +If optional second arg CONFIRM is non-nil, this function +asks for confirmation before overwriting an existing file. +Interactively, confirmation is required unless you supply a prefix argument." + (interactive + (list (if buffer-file-name + (read-file-name "Write file: " + nil nil nil nil) + (read-file-name "Write file: " default-directory + (expand-file-name + (file-name-nondirectory (buffer-name)) + default-directory) + nil nil)) + (not current-prefix-arg))) + + (copy-file buffer-file-name filename) + ;; (let ((old-modes + ;; (and buffer-file-name + ;; ;; File may have gone away; ignore errors in that case. + ;; (ignore-errors (file-modes buffer-file-name))))) + ;; (or (null filename) (string-equal filename "") + ;; (progn + ;; ;; If arg is a directory name, + ;; ;; use the default file name, but in that directory. + ;; (if (directory-name-p filename) + ;; (setq filename (concat filename + ;; (file-name-nondirectory + ;; (or buffer-file-name (buffer-name)))))) + ;; (and confirm + ;; (file-exists-p filename) + ;; ;; NS does its own confirm dialog. + ;; (not (and (eq (framep-on-display) 'ns) + ;; (listp last-nonmenu-event) + ;; use-dialog-box)) + ;; (or (y-or-n-p (format-message + ;; "File `%s' exists; overwrite? " filename)) + ;; (user-error "Canceled"))) + ;; (set-visited-file-name filename (not confirm)))) + ;; (set-buffer-modified-p t) + ;; ;; Make buffer writable if file is writable. + ;; (and buffer-file-name + ;; (file-writable-p buffer-file-name) + ;; (setq buffer-read-only nil)) + ;; (save-buffer) + ;; ;; If the old file was executable, then make the new file + ;; ;; executable, too. + ;; (when (and old-modes + ;; (not (zerop (logand #o111 old-modes)))) + ;; (set-file-modes buffer-file-name + ;; (logior (logand #o111 old-modes) + ;; (file-modes buffer-file-name)))) + ;; ;; It's likely that the VC status at the new location is different from + ;; ;; the one at the old location. + ;; (vc-refresh-state) + ;; ) + ) + (defun rename-visited-file (new-location) "Rename the file visited by the current buffer to NEW-LOCATION. This command also sets the visited file name. If the buffer -- 2.40.1 --=-=-=--