emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

format.el


From: Luc Teirlinck
Subject: format.el
Date: Wed, 17 Mar 2004 20:11:06 -0600 (CST)

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)
============================================================




reply via email to

[Prev in Thread] Current Thread [Next in Thread]