unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Eli Zaretskii'" <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: RE: search files with conversion but fundamental mode, no handlers, no file-local vars
Date: Thu, 20 Dec 2012 11:42:55 -0800	[thread overview]
Message-ID: <C5EC56169DD142598B33AA38A64E2BF7@us.oracle.com> (raw)
In-Reply-To: <83txrgmtof.fsf@gnu.org>

> 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	other threads:[~2012-12-20 19:42 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-20 18:57 search files with conversion but fundamental mode, no handlers, no file-local vars Drew Adams
2012-12-20 19:04 ` Eli Zaretskii
2012-12-20 19:42   ` Drew Adams [this message]
2012-12-20 21:35     ` Eli Zaretskii
2012-12-20 22:01       ` Drew Adams
2012-12-21  8:51         ` Eli Zaretskii
2012-12-20 21:42     ` Stefan Monnier
2012-12-20 22:01       ` Drew Adams
2012-12-20 22:22         ` Stefan Monnier
2012-12-20 22:47           ` Drew Adams
2012-12-21  3:47             ` Stefan Monnier
2012-12-21  4:02               ` Drew Adams
2012-12-21  4:52                 ` Stefan Monnier
2012-12-21 11:53                 ` Eli Zaretskii
2012-12-21 16:13                   ` Drew Adams
2012-12-21  8:54             ` Eli Zaretskii
2012-12-21 14:44               ` Stefan Monnier
2012-12-21 15:09                 ` Eli Zaretskii
2012-12-22 16:00                   ` Stefan Monnier
2012-12-21 16:12                 ` Drew Adams
2012-12-21  8:39         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=C5EC56169DD142598B33AA38A64E2BF7@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).