diff options
| author | Richard M. Stallman | 1995-08-14 16:05:46 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-08-14 16:05:46 +0000 |
| commit | 40dfe94dc57b25c7dc144d8ba88f09778b53a348 (patch) | |
| tree | f28b45bddbe2580fd49a0896abde508a8e0d1833 | |
| parent | e6b75e30dc80863bde42c0b50797719846470f06 (diff) | |
| download | emacs-40dfe94dc57b25c7dc144d8ba88f09778b53a348.tar.gz emacs-40dfe94dc57b25c7dc144d8ba88f09778b53a348.zip | |
(insert-file-contents-literally): New function.
(find-file-noselect): Use it if new optional argument `rawfile' is non-nil.
| -rw-r--r-- | lisp/files.el | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/lisp/files.el b/lisp/files.el index 7c2b5b64e97..773de12eec9 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -657,7 +657,28 @@ If there is no such live buffer, return nil." | |||
| 657 | (setq list (cdr list)))) | 657 | (setq list (cdr list)))) |
| 658 | found)))) | 658 | found)))) |
| 659 | 659 | ||
| 660 | (defun find-file-noselect (filename &optional nowarn) | 660 | (defun insert-file-contents-literally (filename &optional visit beg end replace) |
| 661 | "Like `insert-file-contents', q.v., but only reads in the file. | ||
| 662 | A buffer may be modified in several ways after reading into the buffer due | ||
| 663 | to advanced Emacs features, such as file-name-handlers, format decoding, | ||
| 664 | find-file-hooks, etc. | ||
| 665 | This function ensures that none of these modifications will take place." | ||
| 666 | (let ((file-name-handler-alist nil) | ||
| 667 | (format-alist nil) | ||
| 668 | (after-insert-file-functions nil) | ||
| 669 | (find-buffer-file-type-function | ||
| 670 | (if (fboundp 'find-buffer-file-type) | ||
| 671 | (symbol-function 'find-buffer-file-type) | ||
| 672 | nil))) | ||
| 673 | (unwind-protect | ||
| 674 | (progn | ||
| 675 | (fset 'find-buffer-file-type (lambda (filename) t)) | ||
| 676 | (insert-file-contents filename visit beg end replace)) | ||
| 677 | (if find-buffer-file-type-function | ||
| 678 | (fset 'find-buffer-file-type find-buffer-file-type-function) | ||
| 679 | (fmakunbound 'find-buffer-file-type))))) | ||
| 680 | |||
| 681 | (defun find-file-noselect (filename &optional nowarn rawfile) | ||
| 661 | "Read file FILENAME into a buffer and return the buffer. | 682 | "Read file FILENAME into a buffer and return the buffer. |
| 662 | If a buffer exists visiting FILENAME, return that one, but | 683 | If a buffer exists visiting FILENAME, return that one, but |
| 663 | verify that the file has not changed since visited or saved. | 684 | verify that the file has not changed since visited or saved. |
| @@ -719,13 +740,19 @@ The buffer is not selected, just returned to the caller." | |||
| 719 | (set-buffer-major-mode buf) | 740 | (set-buffer-major-mode buf) |
| 720 | (set-buffer buf) | 741 | (set-buffer buf) |
| 721 | (erase-buffer) | 742 | (erase-buffer) |
| 722 | (condition-case () | 743 | (if rawfile |
| 723 | (insert-file-contents filename t) | 744 | (condition-case () |
| 724 | (file-error | 745 | (insert-file-contents-literally filename t) |
| 725 | ;; Run find-file-not-found-hooks until one returns non-nil. | 746 | (file-error |
| 726 | (or (run-hook-with-args-until-success 'find-file-not-found-hooks) | 747 | ;; Unconditionally set error |
| 727 | ;; If they fail too, set error. | 748 | (setq error t))) |
| 728 | (setq error t)))) | 749 | (condition-case () |
| 750 | (insert-file-contents filename t) | ||
| 751 | (file-error | ||
| 752 | ;; Run find-file-not-found-hooks until one returns non-nil. | ||
| 753 | (or (run-hook-with-args-until-success 'find-file-not-found-hooks) | ||
| 754 | ;; If they fail too, set error. | ||
| 755 | (setq error t))))) | ||
| 729 | ;; Find the file's truename, and maybe use that as visited name. | 756 | ;; Find the file's truename, and maybe use that as visited name. |
| 730 | (setq buffer-file-truename truename) | 757 | (setq buffer-file-truename truename) |
| 731 | (setq buffer-file-number number) | 758 | (setq buffer-file-number number) |
| @@ -750,7 +777,9 @@ The buffer is not selected, just returned to the caller." | |||
| 750 | (progn | 777 | (progn |
| 751 | (make-local-variable 'backup-inhibited) | 778 | (make-local-variable 'backup-inhibited) |
| 752 | (setq backup-inhibited t))) | 779 | (setq backup-inhibited t))) |
| 753 | (after-find-file error (not nowarn)))) | 780 | (if rawfile |
| 781 | nil | ||
| 782 | (after-find-file error (not nowarn))))) | ||
| 754 | buf))) | 783 | buf))) |
| 755 | 784 | ||
| 756 | (defvar after-find-file-from-revert-buffer nil) | 785 | (defvar after-find-file-from-revert-buffer nil) |