all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Alan Mackenzie <acm@muc.de>
Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org
Subject: Re: Subversion of user chosen major mode by Emacs. [Was: My usage of imenu is broken.]
Date: Wed, 29 May 2024 22:17:48 +0300	[thread overview]
Message-ID: <86h6egsa03.fsf@gnu.org> (raw)
In-Reply-To: <ZlcOnAs_E2qn5NDi@ACM> (message from Alan Mackenzie on Wed, 29 May 2024 11:16:44 +0000)

> Date: Wed, 29 May 2024 11:16:44 +0000
> Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
> From: Alan Mackenzie <acm@muc.de>
> 
> > In the past, `auto-mode-alist` way used for that, but that did not
> > account for cases where the major mode is not specified via the file
> > name, but instead via `-*- mode -*-`, or via `interpreter-mode-alist`,
> > or via ...
> 
> That's a case of going for 100% perfection at the expense of the normal
> case.  People don't put -*- c-mode -*- into files.  Not as a general
> rule.
> 
> c-mode and c++-mode are registered trade marks of CC Mode, much as Emacs
> means GNU Emacs, not any other editor with similar functionality.  If
> somebody has specified -*- c-mode -*-, then they mean CC Mode.

Actually, this may or may not be true.  There are cases where people
put "-*- c++ -*-" etc. in files, but any mode supporting C++ will do.
As one example, consider the libstdc++ headers such as 'algorithm' and
others that have no file-name extension: it is clear that the mode
cookie there does not necessarily mean these files should only be
edited with c++-mode.  As another example, consider the *.h files that
are part of GDB sources: not every header file there will be
identified by Emacs as C++ just by looking at the contents, so the GDB
developers want to make sure Emacs turns on some C++ supporting mode
when editing these files.

As yet another example, consider our .dir-locals.el files: the
mode-specific settings there don't care whether the user uses c-mode
or c-ts-mode to edit our C sources.

And there can be other examples.  So sometimes the major mode symbol
does in fact stand for the type of content and not for the specific
mode it names.  And Emacs should support these use cases, because
users are rightfully annoyed when they need to duplicate the same
boring settings.

> or Emacs should provide something like -*- c-generic-mode -*-.

That'd be swell, and we do provide these in some cases.  But doing so
is only possible if the maintainers of the related modes agree to
cooperate to bring their modes closer.  And you at the time were not
very enthusiastic, to say the least, about any such involvement.  So
here we are.

> > Also it encouraged `c-ts-mode.el` (and friends) duplicating
> > the regexps used to specify "this is probably a C file", often doing it
> > slightly differently from the other major mode.
> 
> Surely a trivial problem, if a problem at all.

Actually, our experience since introduction of the *-ts-modes
indicates it is not a trivial problem at all.  To wit: we don't yet
have a good solution for it, and several naïve attempts proved to
cause problems we needed to fix.  It is surprising how a typical
mode's simplest definitions are tightly coupled with the
implementation of the basic features we need for major modes:
font-lock, indentation, syntax analysis, etc.  It turns out our
abstractions in that department leak like hell.

> > Instead, conceptually `auto-mode-alist` should now be used to specify
> > the type of content (tho represented not as something like a MIME type
> > but as a symbol that (usually) denotes a major mode), and then
> > `major-mode-remap` is used to decide which major mode to use for that
> > file type.
> 
> Oh deity, no!  auto-mode-alist specifies the MODE, not some abstract
> "content type".

See above: not necessarily true, at least not in all cases.

And note that mode symbols are used not only in auto-mode-alist.  A
very frequent use is as an argument to the likes of derived-mode-p.



  parent reply	other threads:[~2024-05-29 19:17 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-28 10:53 My usage of imenu is broken Alan Mackenzie
2024-05-28 11:34 ` Eli Zaretskii
2024-05-28 13:57   ` Alan Mackenzie
2024-05-28 18:29     ` Eli Zaretskii
2024-05-28 20:46       ` Alan Mackenzie
2024-05-28 21:28         ` Stefan Monnier
2024-05-29  6:04           ` Juri Linkov
2024-05-29 11:31         ` Eli Zaretskii
2024-05-29  5:38       ` Yuan Fu
2024-05-28 21:55     ` Stefan Monnier
2024-05-29 11:16       ` Subversion of user chosen major mode by Emacs. [Was: My usage of imenu is broken.] Alan Mackenzie
2024-05-29 11:43         ` Dmitry Gutov
2024-05-29 12:51           ` Subversion of user chosen major mode by Emacs Alan Mackenzie
2024-05-29 16:08             ` Dmitry Gutov
2024-05-29 16:38               ` Eli Zaretskii
2024-05-29 17:56                 ` Dmitry Gutov
2024-05-29 19:22               ` Alan Mackenzie
2024-05-29 19:45                 ` Andrea Corallo
2024-05-29 19:59                   ` Alan Mackenzie
2024-05-30  5:01                     ` Eli Zaretskii
2024-05-30 11:02                       ` Alan Mackenzie
2024-05-29 22:10                 ` Dmitry Gutov
2024-05-30  5:51                   ` Eli Zaretskii
2024-05-30  5:44                 ` Eli Zaretskii
2024-05-29 12:41         ` Subversion of user chosen major mode by Emacs. [Was: My usage of imenu is broken.] Eli Zaretskii
2024-05-29 13:29           ` Subversion of user chosen major mode by Emacs Alan Mackenzie
2024-05-29 14:20             ` Eli Zaretskii
2024-05-29 15:04               ` Stefan Monnier
2024-05-29 19:17         ` Eli Zaretskii [this message]
2024-05-30  1:32         ` Subversion of user chosen major mode by Emacs. [Was: My usage of imenu is broken.] Stefan Monnier
2024-05-30  5:25           ` Eli Zaretskii
2024-05-30  7:39             ` Po Lu
2024-05-30  7:53               ` Eli Zaretskii
2024-05-30 14:18             ` Stefan Monnier
2024-05-30 14:33               ` Po Lu
2024-05-30 15:08                 ` Stefan Monnier
2024-05-30 14:56               ` Eli Zaretskii
2024-05-30 15:12                 ` Stefan Monnier
2024-05-30 15:29                   ` Alan Mackenzie
2024-05-30 18:30                     ` Stefan Monnier
2024-05-30 16:06                   ` 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

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

  git send-email \
    --in-reply-to=86h6egsa03.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.