/[emacs]/emacs/lisp/international/mule-cmds.el
ViewVC logotype

Diff of /emacs/lisp/international/mule-cmds.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.277 by handa, Thu Jul 7 06:20:13 2005 UTC revision 1.278 by handa, Tue Jul 19 02:29:58 2005 UTC
# Line 820  returned without any user interaction. Line 820  returned without any user interaction.
820  `prefer-coding-system'.  `prefer-coding-system'.
821    
822  However, the user is queried if the chosen coding system is  However, the user is queried if the chosen coding system is
823  inconsistent with what would be selected by `set-auto-coding' from  inconsistent with what would be selected by `find-auto-coding' from
824  coding cookies &c. if the contents of the region were read from a  coding cookies &c. if the contents of the region were read from a
825  file.  (That could lead to data corruption in a file subsequently  file.  (That could lead to data corruption in a file subsequently
826  re-visited and edited.)  re-visited and edited.)
# Line 850  and TO is ignored." Line 850  and TO is ignored."
850             (not (listp default-coding-system)))             (not (listp default-coding-system)))
851        (setq default-coding-system (list default-coding-system)))        (setq default-coding-system (list default-coding-system)))
852    
853    (let ((no-other-defaults nil))    (let ((no-other-defaults nil)
854            auto-cs)
855        (unless (or (stringp from) find-file-literally)    
856          ;; Find an auto-coding that is specified for the the current
857          ;; buffer and file from the region FROM and TO.
858          (save-excursion
859            (save-restriction
860              (widen)
861              (goto-char from)
862              (setq auto-cs (find-auto-coding (or file buffer-file-name "")
863                                              (- to from)))
864              (if auto-cs
865                  (if (coding-system-p (car auto-cs))
866                      (setq auto-cs (car auto-cs))
867                    (display-warning
868                     :warning
869                     (format "\
870    Invalid coding system `%s' is specified
871    for the current buffer/file by the %s.
872    It is highly recommended to fix it before writing to a file."
873                             (car auto-cs)
874                             (if (eq (cdr auto-cs) :coding) ":coding tag"
875                               (format "variable `%s'" (cdr auto-cs)))))
876                    (or (yes-or-no-p "Really proceed with writing? ")
877                        (error "Save aborted"))
878                    (setq auto-cs nil))))))
879    
880      (if (eq (car default-coding-system) t)      (if (eq (car default-coding-system) t)
881          (setq no-other-defaults t          (setq no-other-defaults t
882                default-coding-system (cdr default-coding-system)))                default-coding-system (cdr default-coding-system)))
# Line 860  and TO is ignored." Line 886  and TO is ignored."
886            (mapcar (function (lambda (x) (cons x (coding-system-base x))))            (mapcar (function (lambda (x) (cons x (coding-system-base x))))
887                    default-coding-system))                    default-coding-system))
888    
889        (if (and auto-cs (not no-other-defaults))
890            ;; If the file has a coding cookie, try to use it before anything
891            ;; else (i.e. before default-coding-system which will typically come
892            ;; from file-coding-system-alist).
893            (let ((base (coding-system-base auto-cs)))
894              (or (memq base '(nil undecided))
895                  (rassq base default-coding-system)
896                  (push (cons auto-cs base) default-coding-system))))
897    
898      ;; From now on, the list of defaults is reversed.      ;; From now on, the list of defaults is reversed.
899      (setq default-coding-system (nreverse default-coding-system))      (setq default-coding-system (nreverse default-coding-system))
900    
# Line 893  and TO is ignored." Line 928  and TO is ignored."
928               (coding-system-get preferred 'mime-charset)               (coding-system-get preferred 'mime-charset)
929               (not (rassq base default-coding-system))               (not (rassq base default-coding-system))
930               (push (cons preferred base)               (push (cons preferred base)
931                     default-coding-system)))))                     default-coding-system))))
932    
933    (if select-safe-coding-system-accept-default-p      (if select-safe-coding-system-accept-default-p
934        (setq accept-default-p select-safe-coding-system-accept-default-p))          (setq accept-default-p select-safe-coding-system-accept-default-p))
935    
936    (let ((codings (find-coding-systems-region from to))      (let ((codings (find-coding-systems-region from to))
937          (coding-system nil)            (coding-system nil)
938          safe rejected unsafe)            safe rejected unsafe)
939      (if (eq (car codings) 'undecided)        (if (eq (car codings) 'undecided)
940          ;; Any coding system is ok.            ;; Any coding system is ok.
941          (setq coding-system t)            (setq coding-system t)
942        ;; Classify the defaults into safe, rejected, and unsafe.          ;; Classify the defaults into safe, rejected, and unsafe.
943        (dolist (elt default-coding-system)          (dolist (elt default-coding-system)
944          (if (memq (cdr elt) codings)            (if (memq (cdr elt) codings)
945              (if (and (functionp accept-default-p)                (if (and (functionp accept-default-p)
946                       (not (funcall accept-default-p (cdr elt))))                         (not (funcall accept-default-p (cdr elt))))
947                  (push (car elt) rejected)                    (push (car elt) rejected)
948                (push (car elt) safe))                  (push (car elt) safe))
949            (push (car elt) unsafe)))              (push (car elt) unsafe)))
950        (if safe          (if safe
951            (setq coding-system (car safe))))              (setq coding-system (car safe))))
952    
953      ;; If all the defaults failed, ask a user.        ;; If all the defaults failed, ask a user.
954      (when (not coding-system)        (when (not coding-system)
955        (setq coding-system (select-safe-coding-system-interactively          (setq coding-system (select-safe-coding-system-interactively
956                             from to codings unsafe rejected (car codings))))                               from to codings unsafe rejected (car codings))))
957    
958      (if (vectorp (coding-system-eol-type coding-system))        (if (vectorp (coding-system-eol-type coding-system))
959          (let ((eol (coding-system-eol-type buffer-file-coding-system)))            (let ((eol (coding-system-eol-type buffer-file-coding-system)))
960            (if (numberp eol)              (if (numberp eol)
961                (setq coding-system                  (setq coding-system
962                      (coding-system-change-eol-conversion coding-system eol)))))                        (coding-system-change-eol-conversion coding-system eol)))))
963    
964      (if (eq coding-system t)        (if (eq coding-system t)
965          (setq coding-system buffer-file-coding-system))            (setq coding-system buffer-file-coding-system))
966      ;; Check we're not inconsistent with what `coding:' spec &c would        ;; Check we're not inconsistent with what `coding:' spec &c would
967      ;; give when file is re-read.        ;; give when file is re-read.
968      ;; But don't do this if we explicitly ignored the cookie        ;; But don't do this if we explicitly ignored the cookie
969      ;; by using `find-file-literally'.        ;; by using `find-file-literally'.
970      (unless (or (stringp from)        (when (and auto-cs
971                  find-file-literally                   (not (and
972                  (and coding-system                         coding-system
973                       (memq (coding-system-type coding-system) '(0 5))))                         (memq (coding-system-type coding-system) '(0 5)))))
       (let ((auto-cs (save-excursion  
                        (save-restriction  
                          (widen)  
                          (narrow-to-region from to)  
                          (goto-char (point-min))  
                          (set-auto-coding (or file buffer-file-name "")  
                                           (buffer-size))))))  
974          ;; Merge coding-system and auto-cs as far as possible.          ;; Merge coding-system and auto-cs as far as possible.
975          (if (not coding-system)          (if (not coding-system)
976              (setq coding-system auto-cs)              (setq coding-system auto-cs)
# Line 974  and TO is ignored." Line 1002  and TO is ignored."
1002                       (format "Selected encoding %s disagrees with \                       (format "Selected encoding %s disagrees with \
1003  %s specified by file contents.  Really save (else edit coding cookies \  %s specified by file contents.  Really save (else edit coding cookies \
1004  and try again)? " coding-system auto-cs))  and try again)? " coding-system auto-cs))
1005                (error "Save aborted")))))                (error "Save aborted"))))
1006      coding-system))        coding-system)))
1007    
1008  (setq select-safe-coding-system-function 'select-safe-coding-system)  (setq select-safe-coding-system-function 'select-safe-coding-system)
1009    

Legend:
Removed from v.1.277  
changed lines
  Added in v.1.278

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26