unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: "Text is read-only"... except it isn't... or shouldn't be
Date: Thu, 16 May 2013 00:27:16 -0600	[thread overview]
Message-ID: <kn1u6r$2qc$1@ger.gmane.org> (raw)
In-Reply-To: <51937603.1050304@mousecar.com>

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	other threads:[~2013-05-16  6:27 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-13  9:47 "Text is read-only"... except it isn't... or shouldn't be ken
2013-05-13 16:13 ` Eli Zaretskii
2013-05-13 16:51   ` ken
2013-05-13 17:08     ` Eli Zaretskii
2013-05-14  2:34       ` ken
2013-05-14  6:46         ` Eli Zaretskii
2013-05-14  8:59           ` Peter Dyballa
2013-05-14 12:22             ` ken
2013-05-14 13:39               ` Eli Zaretskii
2013-05-14 20:39                 ` ken
2013-05-14 20:42                   ` Eli Zaretskii
2013-05-14 20:45                     ` Jai Dayal
2013-05-14 21:39                       ` Óscar Fuentes
2013-05-14 23:23                       ` How to unsubscribe (was: "Text is read-only"... except it isn't... or shouldn't be) Bob Proulx
2013-05-15  2:16                         ` Jai Dayal
2013-05-15  7:23                           ` Eli Zaretskii
2013-05-16 12:50                           ` Suvayu Ali
2013-05-14 21:36                     ` "Text is read-only"... except it isn't... or shouldn't be ken
2013-05-15  5:17                   ` Kevin Rodgers
2013-05-15  7:28                     ` Eli Zaretskii
2013-05-15 11:56                       ` ken
2013-05-15 12:30                         ` Eli Zaretskii
     [not found]                       ` <mailman.25840.1368618972.855.help-gnu-emacs@gnu.org>
2013-05-16  3:49                         ` Jason Rumney
2013-05-15 11:48                     ` ken
2013-05-16  6:27                       ` Kevin Rodgers [this message]
2013-05-16 11:08                         ` Essential question [re: Re: "Text is read-only"... except it isn't... or shouldn't be] ken
2013-05-16 13:30                           ` Kevin Rodgers
2013-05-16 14:26                             ` ken
2013-05-16 14:39                               ` Peter Dyballa
2013-05-18 13:59                               ` Kevin Rodgers
2013-05-19 12:10                                 ` ken
2013-05-16 14:23                           ` ken
2013-05-16 14:41                             ` Peter Dyballa
2013-05-16 14:48                             ` Dmitry Gutov
2013-05-16 22:00                               ` Xue Fuqiao
2013-05-14 11:58           ` "Text is read-only"... except it isn't... or shouldn't be ken
2013-05-13 17:59     ` ken
2013-05-13 18:10       ` Eli Zaretskii
2013-05-13 18:15       ` Bob Proulx
2013-05-14  2:26         ` ken
     [not found]         ` <mailman.25692.1368498372.855.help-gnu-emacs@gnu.org>
2013-05-14  2:38           ` Barry Margolin

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='kn1u6r$2qc$1@ger.gmane.org' \
    --to=kevin.d.rodgers@gmail.com \
    --cc=help-gnu-emacs@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.
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).