21.5.27: file-coding-system-alist fails when dired loaded

tbennett at nvidia.com tbennett at nvidia.com
Sat Mar 3 20:10:25 EST 2007


[RESEND- orig has not shown up in xemacs.org archives after 48 hours..]

I tried to set file-coding-alist to have all files under a certain
directory be raw-text-dos.  It worked at first, but then consistently
failed and set all the files to raw-text-unix instead.

Eventually realized that it worked until dired was loaded.  When dired
is loaded insert-file-contents recurses on itself (via
insert-file-contents-internal and dired-handler-fn).  Something about
this recursion messes up coding-system detection.

Repros for me using 21.5.27 on unix, osx, and cygwin.

Place the following lisp into a file called "bug.el", then:

    $ cat /etc/termcap > data

    $ xemacs -q -l bug.el -f with-dired        -- bad
    $ xemacs -q -l bug.el -f without-dired     -- good

coding system in *Message-Log* should be raw-text-dos at end.  In
'with-dired' case it is raw-text-unix.

---cut--here---
;; causes "insert-file-contents" to be called 2x via recursion 
;; insert-file-contents calls insert-file-contents-internal calls
;; (somehow) dired-handler-fn which calls insert-file-contents
(defun with-dired ()
  (message "TEST-WITH-DIRED-LOADED")
  (require 'dired)
  (find-file ".")
  (find-file "./data")
  (message "CODING SYSTEM: %s" buffer-file-coding-system)
  (switch-to-buffer-other-window " *Message-Log*")
)

(defun without-dired ()
  (message "TEST-WITHOUT-DIRED")
  (find-file "./data")
  (message "CODING SYSTEM: %s" buffer-file-coding-system)
  (switch-to-buffer-other-window " *Message-Log*")
)

(add-to-list 'file-coding-system-alist '("data" raw-text-dos) t)

---cut--here---

In without-dired case, the calling sequence looks like:

    insert-file-contents 
       insert-file-contents-internal

But in with-dired case it looks like this:

    insert-file-contents 
       insert-file-contents-internal             (rtns nil **)
           insert-file-contents
               insert-file-contents-internal     (rtns 'raw-text-dos)

Somehow dired-handler-fn is involved in the recursion, but I don't quite
understand it.

The innermost call to insert-file-contents seems to do the right
thing, but the outer one returns nil which is used to overwrite
coding-system in this line:

      (setq coding-system used-codesys)

Changing it to:

    (if used-codesys)
      (setq coding-system used-codesys))

Seems to fix it...

Also, I was concerned that the file was actually being read 2 times, but
strace seems to indicate that is not happening.

Attaching a version of insert-file-contents with lots of message's
added.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: bug.el
Type: application/emacs-lisp
Size: 7064 bytes
Desc: bug.el
Url : http://lists.xemacs.org/pipermail/xemacs-beta/attachments/20070303/d95a6a9c/bug.bin
-------------- next part --------------

-- 
--tony


More information about the XEmacs-Beta mailing list