aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorKarl Heuer1997-02-20 05:44:24 +0000
committerKarl Heuer1997-02-20 05:44:24 +0000
commit82d0954a232bda18d96a5b878cd80bef5ce610b6 (patch)
tree35c7cb0c8731e5dab45a0a1d6a6931993e258498 /lisp
parent9a06295dcf86dc9e1171020e92406fbcd2f9b632 (diff)
downloademacs-82d0954a232bda18d96a5b878cd80bef5ce610b6.tar.gz
emacs-82d0954a232bda18d96a5b878cd80bef5ce610b6.zip
(find-file, find-file-other-window,
find-file-read-only, find-file-read-only-other-window, find-file-read-only-other-frame, find-alternate-file-other-window, find-alternate-file): With a prefix argument, enable users to specify a coding system interactively. (find-file-noselect): Describe optional arguments NOWARN and RAWFILE in the doc-string. (write-file, insert-file, append-to-file): Accept a prefix argument to enable users to specify a coding system interactively. (revert-buffer): Read an auto-saved file without any code conversion.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/files.el130
1 files changed, 88 insertions, 42 deletions
diff --git a/lisp/files.el b/lisp/files.el
index ad5fa847813..d554005b8fa 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -506,57 +506,73 @@ do not put this buffer at the front of the list of recently selected ones."
506 (pop-to-buffer buffer t norecord) 506 (pop-to-buffer buffer t norecord)
507 (raise-frame (window-frame (selected-window))))) 507 (raise-frame (window-frame (selected-window)))))
508 508
509(defun find-file (filename) 509(defun find-file (filename &optional coding-system)
510 "Edit file FILENAME. 510 "Edit file FILENAME.
511Switch to a buffer visiting file FILENAME, 511Switch to a buffer visiting file FILENAME,
512creating one if none already exists." 512creating one if none already exists.
513 (interactive "FFind file: ") 513A prefix argument enables user to specify the coding-system interactively."
514 (switch-to-buffer (find-file-noselect filename))) 514 (interactive "FFind file: \nZCoding-system: ")
515 515 (if coding-system
516(defun find-file-other-window (filename) 516 (let ((coding-system-for-read coding-system))
517 (switch-to-buffer (find-file-noselect filename)))
518 (switch-to-buffer (find-file-noselect filename))))
519
520(defun find-file-other-window (filename &optional coding-system)
517 "Edit file FILENAME, in another window. 521 "Edit file FILENAME, in another window.
518May create a new window, or reuse an existing one. 522May create a new window, or reuse an existing one.
523A prefix argument enables user to specify the coding-system interactively.
519See the function `display-buffer'." 524See the function `display-buffer'."
520 (interactive "FFind file in other window: ") 525 (interactive "FFind file in other window: \nZCoding-system: ")
521 (switch-to-buffer-other-window (find-file-noselect filename))) 526 (if coding-system
527 (let ((coding-system-for-read coding-system))
528 (switch-to-buffer-other-window (find-file-noselect filename)))
529 (switch-to-buffer-other-window (find-file-noselect filename))))
522 530
523(defun find-file-other-frame (filename) 531(defun find-file-other-frame (filename &optional coding-system)
524 "Edit file FILENAME, in another frame. 532 "Edit file FILENAME, in another frame.
525May create a new frame, or reuse an existing one. 533May create a new frame, or reuse an existing one.
534A prefix argument enables user to specify the coding-system interactively.
526See the function `display-buffer'." 535See the function `display-buffer'."
527 (interactive "FFind file in other frame: ") 536 (interactive "FFind file in other frame: \nZCoding-system: ")
528 (switch-to-buffer-other-frame (find-file-noselect filename))) 537 (if coding-system
538 (let ((coding-system-for-read coding-system))
539 (switch-to-buffer-other-frame (find-file-noselect filename)))
540 (switch-to-buffer-other-frame (find-file-noselect filename))))
529 541
530(defun find-file-read-only (filename) 542(defun find-file-read-only (filename &optional coding-system)
531 "Edit file FILENAME but don't allow changes. 543 "Edit file FILENAME but don't allow changes.
532Like \\[find-file] but marks buffer as read-only. 544Like \\[find-file] but marks buffer as read-only.
545A prefix argument enables user to specify the coding-system interactively.
533Use \\[toggle-read-only] to permit editing." 546Use \\[toggle-read-only] to permit editing."
534 (interactive "fFind file read-only: ") 547 (interactive "fFind file read-only: \nZCoding-system: ")
535 (find-file filename) 548 (find-file filename coding-system)
536 (setq buffer-read-only t) 549 (setq buffer-read-only t)
537 (current-buffer)) 550 (current-buffer))
538 551
539(defun find-file-read-only-other-window (filename) 552(defun find-file-read-only-other-window (filename &optional coding-system)
540 "Edit file FILENAME in another window but don't allow changes. 553 "Edit file FILENAME in another window but don't allow changes.
541Like \\[find-file-other-window] but marks buffer as read-only. 554Like \\[find-file-other-window] but marks buffer as read-only.
555A prefix argument enables user to specify the coding-system interactively.
542Use \\[toggle-read-only] to permit editing." 556Use \\[toggle-read-only] to permit editing."
543 (interactive "fFind file read-only other window: ") 557 (interactive "fFind file read-only other window: \nZCoding-system: ")
544 (find-file-other-window filename) 558 (find-file-other-window filename coding-system)
545 (setq buffer-read-only t) 559 (setq buffer-read-only t)
546 (current-buffer)) 560 (current-buffer))
547 561
548(defun find-file-read-only-other-frame (filename) 562(defun find-file-read-only-other-frame (filename &optional coding-system)
549 "Edit file FILENAME in another frame but don't allow changes. 563 "Edit file FILENAME in another frame but don't allow changes.
550Like \\[find-file-other-frame] but marks buffer as read-only. 564Like \\[find-file-other-frame] but marks buffer as read-only.
565A prefix argument enables user to specify the coding-system interactively.
551Use \\[toggle-read-only] to permit editing." 566Use \\[toggle-read-only] to permit editing."
552 (interactive "fFind file read-only other frame: ") 567 (interactive "fFind file read-only other frame: \nZCoding-system: ")
553 (find-file-other-frame filename) 568 (find-file-other-frame filename coding-system)
554 (setq buffer-read-only t) 569 (setq buffer-read-only t)
555 (current-buffer)) 570 (current-buffer))
556 571
557(defun find-alternate-file-other-window (filename) 572(defun find-alternate-file-other-window (filename &optional coding-system)
558 "Find file FILENAME as a replacement for the file in the next window. 573 "Find file FILENAME as a replacement for the file in the next window.
559This command does not select that window." 574This command does not select that window.
575A prefix argument enables user to specify the coding-system interactively."
560 (interactive 576 (interactive
561 (save-selected-window 577 (save-selected-window
562 (other-window 1) 578 (other-window 1)
@@ -567,17 +583,20 @@ This command does not select that window."
567 (setq file-name (file-name-nondirectory file) 583 (setq file-name (file-name-nondirectory file)
568 file-dir (file-name-directory file))) 584 file-dir (file-name-directory file)))
569 (list (read-file-name 585 (list (read-file-name
570 "Find alternate file: " file-dir nil nil file-name))))) 586 "Find alternate file: " file-dir nil nil file-name)
587 (if current-prefix-arg
588 (read-coding-system "Coding-system: "))))))
571 (if (one-window-p) 589 (if (one-window-p)
572 (find-file-other-window filename) 590 (find-file-other-window filename coding-system)
573 (save-selected-window 591 (save-selected-window
574 (other-window 1) 592 (other-window 1)
575 (find-alternate-file filename)))) 593 (find-alternate-file filename coding-system))))
576 594
577(defun find-alternate-file (filename) 595(defun find-alternate-file (filename &optional coding-system)
578 "Find file FILENAME, select its buffer, kill previous buffer. 596 "Find file FILENAME, select its buffer, kill previous buffer.
579If the current buffer now contains an empty file that you just visited 597If the current buffer now contains an empty file that you just visited
580\(presumably by mistake), use this command to visit the file you really want." 598\(presumably by mistake), use this command to visit the file you really want.
599A prefix argument enables user to specify the coding-system interactively."
581 (interactive 600 (interactive
582 (let ((file buffer-file-name) 601 (let ((file buffer-file-name)
583 (file-name nil) 602 (file-name nil)
@@ -586,7 +605,9 @@ If the current buffer now contains an empty file that you just visited
586 (setq file-name (file-name-nondirectory file) 605 (setq file-name (file-name-nondirectory file)
587 file-dir (file-name-directory file))) 606 file-dir (file-name-directory file)))
588 (list (read-file-name 607 (list (read-file-name
589 "Find alternate file: " file-dir nil nil file-name)))) 608 "Find alternate file: " file-dir nil nil file-name)
609 (if current-prefix-arg
610 (read-coding-system "Coding-system: ")))))
590 (and (buffer-modified-p) (buffer-file-name) 611 (and (buffer-modified-p) (buffer-file-name)
591 ;; (not buffer-read-only) 612 ;; (not buffer-read-only)
592 (not (yes-or-no-p (format "Buffer %s is modified; kill anyway? " 613 (not (yes-or-no-p (format "Buffer %s is modified; kill anyway? "
@@ -606,7 +627,7 @@ If the current buffer now contains an empty file that you just visited
606 (setq buffer-file-name nil) 627 (setq buffer-file-name nil)
607 (setq buffer-file-number nil) 628 (setq buffer-file-number nil)
608 (setq buffer-file-truename nil) 629 (setq buffer-file-truename nil)
609 (find-file filename)) 630 (find-file filename coding-system))
610 (cond ((eq obuf (current-buffer)) 631 (cond ((eq obuf (current-buffer))
611 (setq buffer-file-name ofile) 632 (setq buffer-file-name ofile)
612 (setq buffer-file-number onum) 633 (setq buffer-file-number onum)
@@ -753,7 +774,9 @@ file name handlers and remote file access uses a file name handler."
753 "Read file FILENAME into a buffer and return the buffer. 774 "Read file FILENAME into a buffer and return the buffer.
754If a buffer exists visiting FILENAME, return that one, but 775If a buffer exists visiting FILENAME, return that one, but
755verify that the file has not changed since visited or saved. 776verify that the file has not changed since visited or saved.
756The buffer is not selected, just returned to the caller." 777The buffer is not selected, just returned to the caller.
778Optional first arg NOWARN non-nil means suppress any warning messages.
779Optional second arg RAWFILE non-nil means the file is read literally"
757 (setq filename 780 (setq filename
758 (abbreviate-file-name 781 (abbreviate-file-name
759 (expand-file-name filename))) 782 (expand-file-name filename)))
@@ -1554,7 +1577,7 @@ the old visited file has been renamed to the new name FILENAME."
1554 (not along-with-file) 1577 (not along-with-file)
1555 (set-buffer-modified-p t))) 1578 (set-buffer-modified-p t)))
1556 1579
1557(defun write-file (filename &optional confirm) 1580(defun write-file (filename &optional confirm coding-system)
1558 "Write current buffer into file FILENAME. 1581 "Write current buffer into file FILENAME.
1559Makes buffer visit that file, and marks it not modified. 1582Makes buffer visit that file, and marks it not modified.
1560If the buffer is already visiting a file, you can specify 1583If the buffer is already visiting a file, you can specify
@@ -1563,7 +1586,10 @@ old name in that directory.
1563 1586
1564If optional second arg CONFIRM is non-nil, 1587If optional second arg CONFIRM is non-nil,
1565ask for confirmation for overwriting an existing file. 1588ask for confirmation for overwriting an existing file.
1566Interactively, confirmation is required unless you supply a prefix argument." 1589Interactively, confirmation is required unless you supply a prefix argument.
1590
1591A prefix argument also enables user to interactively specify a
1592coding-system for encoding the file."
1567;; (interactive "FWrite file: ") 1593;; (interactive "FWrite file: ")
1568 (interactive 1594 (interactive
1569 (list (if buffer-file-name 1595 (list (if buffer-file-name
@@ -1573,7 +1599,10 @@ Interactively, confirmation is required unless you supply a prefix argument."
1573 (cdr (assq 'default-directory 1599 (cdr (assq 'default-directory
1574 (buffer-local-variables))) 1600 (buffer-local-variables)))
1575 nil nil (buffer-name))) 1601 nil nil (buffer-name)))
1576 (not current-prefix-arg))) 1602 (not current-prefix-arg)
1603 (if current-prefix-arg
1604 (read-coding-system "Coding-system: "))
1605 ))
1577 (or (null filename) (string-equal filename "") 1606 (or (null filename) (string-equal filename "")
1578 (progn 1607 (progn
1579 ;; If arg is just a directory, 1608 ;; If arg is just a directory,
@@ -1587,7 +1616,13 @@ Interactively, confirmation is required unless you supply a prefix argument."
1587 (error "Canceled"))) 1616 (error "Canceled")))
1588 (set-visited-file-name filename (not confirm)))) 1617 (set-visited-file-name filename (not confirm))))
1589 (set-buffer-modified-p t) 1618 (set-buffer-modified-p t)
1590 (save-buffer)) 1619 (if coding-system
1620 (let ((coding-system-for-write coding-system))
1621 ;; It is convenient to change buffer-file-coding-system to the
1622 ;; specified one.
1623 (set-buffer-file-coding-system coding-system)
1624 (save-buffer))
1625 (save-buffer)))
1591 1626
1592(defun backup-buffer () 1627(defun backup-buffer ()
1593 "Make a backup of the disk file visited by the current buffer, if appropriate. 1628 "Make a backup of the disk file visited by the current buffer, if appropriate.
@@ -2116,27 +2151,36 @@ With arg, set read-only iff arg is positive."
2116 (> (prefix-numeric-value arg) 0))) 2151 (> (prefix-numeric-value arg) 0)))
2117 (force-mode-line-update)) 2152 (force-mode-line-update))
2118 2153
2119(defun insert-file (filename) 2154(defun insert-file (filename &optional coding-system)
2120 "Insert contents of file FILENAME into buffer after point. 2155 "Insert contents of file FILENAME into buffer after point.
2121Set mark after the inserted text. 2156Set mark after the inserted text.
2157A prefix argument enables user to specify the coding-system interactively.
2122 2158
2123This function is meant for the user to run interactively. 2159This function is meant for the user to run interactively.
2124Don't call it from programs! Use `insert-file-contents' instead. 2160Don't call it from programs! Use `insert-file-contents' instead.
2125\(Its calling sequence is different; see its documentation)." 2161\(Its calling sequence is different; see its documentation)."
2126 (interactive "*fInsert file: ") 2162 (interactive "*fInsert file: \nZCoding-system: ")
2127 (if (file-directory-p filename) 2163 (if (file-directory-p filename)
2128 (signal 'file-error (list "Opening input file" "file is a directory" 2164 (signal 'file-error (list "Opening input file" "file is a directory"
2129 filename))) 2165 filename)))
2130 (let ((tem (insert-file-contents filename))) 2166 (let ((tem
2167 (if coding-system
2168 (let ((coding-system-for-read coding-system))
2169 (insert-file-contents filename))
2170 (insert-file-contents filename))))
2131 (push-mark (+ (point) (car (cdr tem)))))) 2171 (push-mark (+ (point) (car (cdr tem))))))
2132 2172
2133(defun append-to-file (start end filename) 2173(defun append-to-file (start end filename &optional coding-system)
2134 "Append the contents of the region to the end of file FILENAME. 2174 "Append the contents of the region to the end of file FILENAME.
2135When called from a function, expects three arguments, 2175When called from a function, expects three arguments,
2136START, END and FILENAME. START and END are buffer positions 2176START, END and FILENAME. START and END are buffer positions
2137saying what text to write." 2177saying what text to write.
2138 (interactive "r\nFAppend to file: ") 2178A prefix argument enables user to specify the coding-system interactively."
2139 (write-region start end filename t)) 2179 (interactive "r\nFAppend to file: \nZCoding-system: ")
2180 (if coding-system
2181 (let ((coding-system-for-write coding-system))
2182 (write-region start end filename t))
2183 (write-region start end filename t)))
2140 2184
2141(defun file-newest-backup (filename) 2185(defun file-newest-backup (filename)
2142 "Return most recent backup file for FILENAME or nil if no backups exist." 2186 "Return most recent backup file for FILENAME or nil if no backups exist."
@@ -2355,7 +2399,9 @@ non-nil, it is called instead of rereading visited file contents."
2355 file file-name))) 2399 file file-name)))
2356 (yes-or-no-p (format "Recover auto save file %s? " file-name))) 2400 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
2357 (switch-to-buffer (find-file-noselect file t)) 2401 (switch-to-buffer (find-file-noselect file t))
2358 (let ((buffer-read-only nil)) 2402 (let ((buffer-read-only nil)
2403 ;; Auto-saved file shoule be read without any code conversion.
2404 (coding-system-for-read 'no-conversion))
2359 (erase-buffer) 2405 (erase-buffer)
2360 (insert-file-contents file-name nil)) 2406 (insert-file-contents file-name nil))
2361 (after-find-file nil nil t)) 2407 (after-find-file nil nil t))