- (set-buffer-major-mode buf)
- (set-buffer buf)
- (erase-buffer)
- (condition-case ()
- (if rawfile
- (insert-file-contents-literally filename t)
- (insert-file-contents filename t))
- (file-error
- (when (and (file-exists-p filename)
- (not (file-readable-p filename)))
- (signal 'file-error (list "File is not readable" filename)))
- (if rawfile
- ;; Unconditionally set error
- (setq error t)
- (or
- ;; Run find-file-not-found-hooks until one returns non-nil.
- (run-hook-with-args-until-success 'find-file-not-found-hooks)
- ;; If they fail too, set error.
- (setq error t)))))
- ;; Find the file's truename, and maybe use that as visited name.
- ;; automatically computed in XEmacs, unless jka-compr was used!
- (unless buffer-file-truename
- (setq buffer-file-truename truename))
- (setq buffer-file-number number)
- (and find-file-use-truenames
- ;; This should be in C. Put pathname
- ;; abbreviations that have been explicitly
- ;; requested back into the pathname. Most
- ;; importantly, strip out automounter /tmp_mnt
- ;; directories so that auto-save will work
- (setq buffer-file-name (abbreviate-file-name buffer-file-name)))
- ;; Set buffer's default directory to that of the file.
- (setq default-directory (file-name-directory buffer-file-name))
- ;; Turn off backup files for certain file names. Since
- ;; this is a permanent local, the major mode won't eliminate it.
- (and (not (funcall backup-enable-predicate buffer-file-name))
- (progn
- (make-local-variable 'backup-inhibited)
- (setq backup-inhibited t)))
- (if rawfile
- ;; #### FSF 20.3 sets buffer-file-coding-system to
- ;; `no-conversion' here. Should we copy? It also
- ;; makes `find-file-literally' a local variable
- ;; and sets it to t.
- nil
- (after-find-file error (not nowarn))
- (setq buf (current-buffer))))
- (t
- (kill-buffer buf)
- (signal (car data) (cdr data))))
- ))
- buf))))
-\f
-;; FSF has `insert-file-literally' and `find-file-literally' here.
+ (or nowarn
+ (verify-visited-file-modtime buf)
+ (cond ((not (file-exists-p filename))
+ (error "File %s no longer exists!" filename))
+ ;; Certain files should be reverted automatically
+ ;; if they have changed on disk and not in the buffer.
+ ((and (not (buffer-modified-p buf))
+ (dolist (rx revert-without-query nil)
+ (when (string-match rx filename)
+ (return t))))
+ (with-current-buffer buf
+ (message "Reverting file %s..." filename)
+ (revert-buffer t t)
+ (message "Reverting file %s... done" filename)))
+ ((yes-or-no-p
+ (if (string= (file-name-nondirectory filename)
+ (buffer-name buf))
+ (format
+ (if (buffer-modified-p buf)
+ (gettext "File %s changed on disk. Discard your edits? ")
+ (gettext "File %s changed on disk. Reread from disk? "))
+ (file-name-nondirectory filename))
+ (format
+ (if (buffer-modified-p buf)
+ (gettext "File %s changed on disk. Discard your edits in %s? ")
+ (gettext "File %s changed on disk. Reread from disk into %s? "))
+ (file-name-nondirectory filename)
+ (buffer-name buf))))
+ (with-current-buffer buf
+ (revert-buffer t t)))))
+ (when (not (eq rawfile (not (null find-file-literally))))
+ (with-current-buffer buf
+ (if (buffer-modified-p)
+ (if (y-or-n-p (if rawfile
+ "Save file and revisit literally? "
+ "Save file and revisit non-literally? "))
+ (progn
+ (save-buffer)
+ (find-file-noselect-1 buf filename nowarn
+ rawfile truename number))
+ (if (y-or-n-p (if rawfile
+ "Discard your edits and revisit file literally? "
+ "Discard your edits and revisit file non-literally? "))
+ (find-file-noselect-1 buf filename nowarn
+ rawfile truename number)
+ (error (if rawfile "File already visited non-literally"
+ "File already visited literally"))))
+ (if (y-or-n-p (if rawfile
+ "Revisit file literally? "
+ "Revisit file non-literally? "))
+ (find-file-noselect-1 buf filename nowarn
+ rawfile truename number)
+ (error (if rawfile "File already visited non-literally"
+ "File already visited literally"))))))
+ ;; Return the buffer we are using.
+ buf)
+ ;; Create a new buffer.
+ (setq buf (create-file-buffer filename))
+ ;; Catch various signals, such as QUIT, and kill the buffer
+ ;; in that case.
+ (condition-case data
+ (progn
+ (set-buffer-major-mode buf)
+ ;; find-file-noselect-1 may use a different buffer.
+ (find-file-noselect-1 buf filename nowarn
+ rawfile truename number))
+ (t
+ (kill-buffer buf)
+ (signal (car data) (cdr data)))))))))))
+
+(defun find-file-noselect-1 (buf filename nowarn rawfile truename number)
+ (let ((inhibit-read-only t)
+ error)
+ (with-current-buffer buf
+ (kill-local-variable 'find-file-literally)
+ ;; Needed in case we are re-visiting the file with a different
+ ;; text representation.
+ (kill-local-variable 'buffer-file-coding-system)
+ (erase-buffer)
+; (and (default-value 'enable-multibyte-characters)
+; (not rawfile)
+; (set-buffer-multibyte t))
+ (condition-case ()
+ (if rawfile
+ (insert-file-contents-literally filename t)
+ (insert-file-contents filename t))
+ (file-error
+ (when (and (file-exists-p filename)
+ (not (file-readable-p filename)))
+ (signal 'file-error (list "File is not readable" filename)))
+ (if rawfile
+ ;; Unconditionally set error
+ (setq error t)
+ (or
+ ;; Run find-file-not-found-hooks until one returns non-nil.
+ (run-hook-with-args-until-success 'find-file-not-found-hooks)
+ ;; If they fail too, set error.
+ (setq error t)))))
+ ;; Find the file's truename, and maybe use that as visited name.
+ ;; automatically computed in XEmacs, unless jka-compr was used!
+ (unless buffer-file-truename
+ (setq buffer-file-truename truename))
+ (setq buffer-file-number number)
+ (and find-file-use-truenames
+ ;; This should be in C. Put pathname
+ ;; abbreviations that have been explicitly
+ ;; requested back into the pathname. Most
+ ;; importantly, strip out automounter /tmp_mnt
+ ;; directories so that auto-save will work
+ (setq buffer-file-name (abbreviate-file-name buffer-file-name)))
+ ;; Set buffer's default directory to that of the file.
+ (setq default-directory (file-name-directory buffer-file-name))
+ ;; Turn off backup files for certain file names. Since
+ ;; this is a permanent local, the major mode won't eliminate it.
+ (and (not (funcall backup-enable-predicate buffer-file-name))
+ (progn
+ (make-local-variable 'backup-inhibited)
+ (setq backup-inhibited t)))
+ (if rawfile
+ (progn
+ (setq buffer-file-coding-system 'no-conversion)
+ (make-local-variable 'find-file-literally)
+ (setq find-file-literally t))
+ (after-find-file error (not nowarn))
+ (setq buf (current-buffer)))
+ (current-buffer))))
+
+(defun insert-file-literally (filename)
+ "Insert contents of file FILENAME into buffer after point with no conversion.
+
+This function is meant for the user to run interactively.
+Don't call it from programs! Use `insert-file-contents-literally' instead.
+\(Its calling sequence is different; see its documentation)."
+ (interactive "*fInsert file literally: ")
+ (if (file-directory-p filename)
+ (signal 'file-error (list "Opening input file" "file is a directory"
+ filename)))
+ (let ((tem (insert-file-contents-literally filename)))
+ (push-mark (+ (point) (car (cdr tem))))))
+
+(defvar find-file-literally nil
+ "Non-nil if this buffer was made by `find-file-literally' or equivalent.
+This is a permanent local.")
+(put 'find-file-literally 'permanent-local t)
+
+(defun find-file-literally (filename)
+ "Visit file FILENAME with no conversion of any kind.
+Format conversion and character code conversion are both disabled,
+and multibyte characters are disabled in the resulting buffer.
+The major mode used is Fundamental mode regardless of the file name,
+and local variable specifications in the file are ignored.
+Automatic uncompression and adding a newline at the end of the
+file due to `require-final-newline' is also disabled.
+
+You cannot absolutely rely on this function to result in
+visiting the file literally. If Emacs already has a buffer
+which is visiting the file, you get the existing buffer,
+regardless of whether it was created literally or not.
+
+In a Lisp program, if you want to be sure of accessing a file's
+contents literally, you should create a temporary buffer and then read
+the file contents into it using `insert-file-contents-literally'."
+ (interactive "FFind file literally: ")
+ (switch-to-buffer (find-file-noselect filename nil t)))
+;;; End Sync: XEmacs 21.5 (cb65bfaf7110 tip) 2015-07-03 --SY