help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: "Text is read-only"... except it isn't... or shouldn't be


From: Kevin Rodgers
Subject: Re: "Text is read-only"... except it isn't... or shouldn't be
Date: Thu, 16 May 2013 00:27:16 -0600
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20

On 5/15/13 5:48 AM, ken wrote:
On 05/15/2013 01:17 AM Kevin Rodgers wrote:
On 5/14/13 2:39 PM, ken wrote:
On 05/14/2013 09:39 AM Eli Zaretskii wrote:
Emacs does look at the magic signature, see magic-mode-alist.

They why didn't it see that my file was (obviously) a text file and
not an image
file?

1. Because the default value of magic-mode-alist is nil.

If you mean this functionality was turned off in this version I recently
installed, then, yes, that agrees with what I said earlier in this thread: emacs
no longer determines a file's magic upon visiting a file.

No, you misunderstand. After file local variables and
interpreter-mode-alist, magic-mode-alist is merely the first relevant
option that is consulted when automatically setting the major mode.
Then auto-mode-alist (which matches the file name), then
magic-fallback-mode-alist (which matches the file contents, like
magic-mode-alist, but which is not nil by default).

That is why I suggested you actually read the "Choosing Modes" section of the
Emacs manual.

Any part of that algorithm might have changed between your unnamed previous
version and the current Emacs version, probably in response to specific bug
reports and after review by the maintainers.

The more comprehensive
fix, then, would be to set magic-mode-alist to t, yes? If so, what elisp
statement(s) do you think would best accomplish that?

No, t is not a valid alist.

You could remove the ".gif" entry from auto-mode-alist, and add an entry to
magic-fallback-mode-alist.  According to my /usr/share/file/magic, the regexp
should be "\\`GIF8".

Here is my guess at the lisp:

(setq auto-mode-alist
      (remove '("\\.gif\\'" . image-mode) auto-mode-alist))

(setq magic-fallback-mode-alist
      (cons '("\\`GIF8" . image-mode) magic-fallback-mode-alist))

2. Because the default value of auto-mode-alist matches the ".gif"
extension.

The documentation suggests that magic-mode-alist, if turned on, will override
auto-mode-alist.

More precisely: If there is an entry in magic-mode-alist that matches the filecontents, it has precedence over auto-mode-alist.

3. Because it is not obvious what the signature is for a text file --
perhaps
something like "\\`[[:print:]\t\f\r\n]", which is so general that it
would
prevent most of the existing automatic method from working.

Yes, the damned humans with their writing so random and the different languages
characters and syntaxes and punctuation etc. make such evaluation nigh
impossible. Probably for this reason, magic mode adopts a different strategy.
The linux "file" utility, referred to earlier in this thread, probably does this
also, as it makes fairly reliable evaluations of files' contents.

Yes: Instead of trying to detect text files by their content, detect all the
other kinds of files by their content or name (and then default to Fundamental
mode).

--
Kevin Rodgers
Denver, Colorado, USA




reply via email to

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