From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Luc Teirlinck Newsgroups: gmane.emacs.devel Subject: format.el Date: Wed, 17 Mar 2004 20:11:06 -0600 (CST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200403180211.i2I2B6703529@raven.dms.auburn.edu> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1079576137 22556 80.91.224.253 (18 Mar 2004 02:15:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 18 Mar 2004 02:15:37 +0000 (UTC) Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Thu Mar 18 03:15:28 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1B3n4C-0004oG-00 for ; Thu, 18 Mar 2004 03:15:28 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1B3n4B-0001F2-00 for ; Thu, 18 Mar 2004 03:15:27 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B3n2g-0007Gh-59 for emacs-devel@quimby.gnus.org; Wed, 17 Mar 2004 21:13:54 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1B3n28-0007GG-L0 for emacs-devel@gnu.org; Wed, 17 Mar 2004 21:13:20 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1B3n1a-0007AV-Vu for emacs-devel@gnu.org; Wed, 17 Mar 2004 21:13:19 -0500 Original-Received: from [131.204.53.104] (helo=manatee.dms.auburn.edu) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B3n1a-0007AS-MY for emacs-devel@gnu.org; Wed, 17 Mar 2004 21:12:46 -0500 Original-Received: from raven.dms.auburn.edu (raven.dms.auburn.edu [131.204.53.29]) by manatee.dms.auburn.edu (8.12.10/8.12.10) with ESMTP id i2I2CfKt009940 for ; Wed, 17 Mar 2004 20:12:41 -0600 (CST) Original-Received: (from teirllm@localhost) by raven.dms.auburn.edu (8.11.6+Sun/8.11.6) id i2I2B6703529; Wed, 17 Mar 2004 20:11:06 -0600 (CST) X-Authentication-Warning: raven.dms.auburn.edu: teirllm set sender to teirllm@dms.auburn.edu using -f Original-To: emacs-devel@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:20566 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:20566 What about the following patch to format.el, which would make `format-write-file' ask interactively for confirmation before overwriting an existing file, in exactly the same way `write-file' does? I believe most users would expect `format-write-file' to behave exactly like the more familiar and analogous `write-file' and asking for confirmation does seem a lot safer. The patch would also make `format-insert-file' always return a list of two elements, just like `insert-file-contents' does, instead of returning such a list if the FORMAT argument is nil and a non-list cons cell otherwise. There seems to be no reason whatsoever for the subtle difference and I checked that the `insert-file-contents' change does not produce any incompatibilities in the Emacs source code, because the format argument is `nil' in all involved uses. That is exactly the case that would not change. Those subtle differences can confuse the user and they would have to be carefully documented at all appropriate places, including the Elisp manual (currently that is not the case). It seems a lot easier to make the behavior uniform. I could install if desired. ===File ~/format.el-diff==================================== *** format.el.~1.43.~ Mon Feb 9 13:59:35 2004 --- format.el Mon Mar 8 20:07:30 2004 *************** *** 366,376 **** (funcall to-fn beg end (current-buffer))))) (setq format (cdr format))))))) ! (defun format-write-file (filename format) "Write current buffer into file FILENAME using some FORMAT. ! Makes buffer visit that file and sets the format as the default for future saves. If the buffer is already visiting a file, you can specify a directory ! name as FILENAME, to write a file of the same old name in that directory." (interactive ;; Same interactive spec as write-file, plus format question. (let* ((file (if buffer-file-name --- 366,380 ---- (funcall to-fn beg end (current-buffer))))) (setq format (cdr format))))))) ! (defun format-write-file (filename format &optional confirm) "Write current buffer into file FILENAME using some FORMAT. ! Make buffer visit that file and set the format as the default for future saves. If the buffer is already visiting a file, you can specify a directory ! name as FILENAME, to write a file of the same old name in that directory. ! ! If optional third 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 ;; Same interactive spec as write-file, plus format question. (let* ((file (if buffer-file-name *************** *** 382,388 **** nil nil (buffer-name)))) (fmt (format-read (format "Write file `%s' in format: " (file-name-nondirectory file))))) ! (list file fmt))) (let ((old-formats buffer-file-format) preserve-formats) (dolist (fmt old-formats) --- 386,392 ---- nil nil (buffer-name)))) (fmt (format-read (format "Write file `%s' in format: " (file-name-nondirectory file))))) ! (list file fmt (not current-prefix-arg)))) (let ((old-formats buffer-file-format) preserve-formats) (dolist (fmt old-formats) *************** *** 393,399 **** (dolist (fmt preserve-formats) (unless (memq fmt buffer-file-format) (setq buffer-file-format (append buffer-file-format (list fmt)))))) ! (write-file filename)) (defun format-find-file (filename format) "Find the file FILENAME using data format FORMAT. --- 397,403 ---- (dolist (fmt preserve-formats) (unless (memq fmt buffer-file-format) (setq buffer-file-format (append buffer-file-format (list fmt)))))) ! (write-file filename confirm)) (defun format-find-file (filename format) "Find the file FILENAME using data format FORMAT. *************** *** 416,422 **** the part of the file to read. The return value is like the value of `insert-file-contents': ! a list (ABSOLUTE-FILE-NAME . SIZE)." (interactive ;; Same interactive spec as write-file, plus format question. (let* ((file (read-file-name "Find file: ")) --- 420,426 ---- the part of the file to read. The return value is like the value of `insert-file-contents': ! a list (ABSOLUTE-FILE-NAME SIZE)." (interactive ;; Same interactive spec as write-file, plus format question. (let* ((file (read-file-name "Find file: ")) *************** *** 429,435 **** (setq size (nth 1 value))) (if format (setq size (format-decode format size) ! value (cons (car value) size))) value)) (defun format-read (&optional prompt) --- 433,439 ---- (setq size (nth 1 value))) (if format (setq size (format-decode format size) ! value (list (car value) size))) value)) (defun format-read (&optional prompt) ============================================================