emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: search files with conversion but fundamental mode, no handlers, no f


From: Drew Adams
Subject: RE: search files with conversion but fundamental mode, no handlers, no file-local vars
Date: Thu, 20 Dec 2012 11:42:55 -0800

> What's wrong with insert-file-contents?

I'm not sure, now that I try it again!  Thanks for asking.

I tried it earlier, but I was no doubt seeing problems from something else that
I was doing at the same time.

When I finally came across `mm-insert-file-contents' its code looked like TRT
and its doc string seemed to indicate that it was different from
`insert-file-contents' precisely in preventing some of the things I think I want
to prevent.

Brief testing with `insert-file-contents' now seems not to show some of the
problems I encountered before.  But I have not tried cases where file handlers
might kick in etc.  At least I can see that fundamental mode is used, which is
good (one of the main things).

What is the use case for `mm-insert-file-contents'?  I can see that it is
intended only for "low-level" use etc., but it still seems to skip some stuff
that I do not need/want to be done.

Here is the doc string:

"Like `insert-file-contents', but only reads in the file.
A buffer may be modified in several ways after reading into the buffer due
to advanced Emacs features, such as file-name-handlers, format decoding,
`find-file-hooks', etc.
If INHIBIT is non-nil, inhibit `mm-inhibit-file-name-handlers'.
  This function ensures that none of these modifications will take place."

I don't have the C code defining `insert-file-contents', to compare.  but that
doc string does seem to suggest that, _unlike_ `insert-file-contents', it
inhibits the use of "`file-name-handlers,..., `find-file-hooks', etc."  I do not
need/want handlers, hooks, etc. to kick in here.

Here are the bindings made in the function, to inhibit such stuff:

(letf* ((format-alist nil)
         (auto-mode-alist (if inhibit nil (mm-auto-mode-alist)))
         ((default-value 'major-mode) 'fundamental-mode)
         (enable-local-variables nil)
         (after-insert-file-functions nil)
         (enable-local-eval nil)
         (inhibit-file-name-operation (if inhibit
                                          'insert-file-contents
                                        inhibit-file-name-operation))
         (inhibit-file-name-handlers
          (if inhibit
              (append mm-inhibit-file-name-handlers
                      inhibit-file-name-handlers)
            inhibit-file-name-handlers))
         (ffh (if (boundp 'find-file-hook)
                  'find-file-hook
                'find-file-hooks))
         (val (symbol-value ffh)))
    (set ffh nil)
    (unwind-protect
        (insert-file-contents filename visit beg end replace)
      (set ffh val))))

So `mm-insert-file-contents' still seems, from looking at the code, to be my
best option.

It would seem to be the case that `insert-file-contents' does not nullify
`auto-mode-alist' or set the default mode to fundamental or disable local
variables or...  If not, why is all that done explicitly here, in a wrapper for
`insert-file-contents'?

Still a bit confused...




reply via email to

[Prev in Thread] Current Thread [Next in Thread]