From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Mapping file types to major modes Date: Fri, 23 Sep 2022 11:45:46 -0400 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6927"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 23 17:50:47 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1obkwx-0001dm-KZ for ged-emacs-devel@m.gmane-mx.org; Fri, 23 Sep 2022 17:50:47 +0200 Original-Received: from localhost ([::1]:49508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obkww-0004oP-5M for ged-emacs-devel@m.gmane-mx.org; Fri, 23 Sep 2022 11:50:46 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obksE-0000nL-4h for emacs-devel@gnu.org; Fri, 23 Sep 2022 11:45:54 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:12147) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obksB-0006m5-LG for emacs-devel@gnu.org; Fri, 23 Sep 2022 11:45:53 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id ED85D10013B; Fri, 23 Sep 2022 11:45:49 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id EF63F1000EF; Fri, 23 Sep 2022 11:45:47 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1663947947; bh=RTTJOApTcB3tR7csEggfllGDbeBR7KLhYxDz6V/SNVs=; h=From:To:Subject:Date:From; b=mCw7L6aD7mNmbUNfM13X29I/Ufe0wKmY3SGmesIJXnsiY2xhkgSXLWdZ9zWfa39Qe npXIaGyIE+JyUjKGX9+2NC1bCsDvPjTLs9rCo2+sSzcB/r/3m984mjYHSGAQajEIu4 NGVUbEGNLag42ccxYv+V+9PCuKQobKT+cqP9mATPST/D5Tedqiy8jtiVxzrYB17pak WRwvoodTxuVFu0sWBOJMu3ND7LXd6fJW3+flfnIbFhHpi1oTACYxjcklu+gHttfeQR +CCaSNtnD0SDdIc2blACIMZRrmjSVrCMxTR+PVwOg8Q23LkRuDp1NohbvbMoWM2flt 7LfTzkiMBEVsw== Original-Received: from alfajor (unknown [45.44.229.252]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id D6002120A92; Fri, 23 Sep 2022 11:45:47 -0400 (EDT) Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:296055 Archived-At: Hi, Emacs has various facilities to decide which major mode to use for which file based on its name and/or contents. All those facilities specify directly the mode to use. This is usually exactly what we want because there's only ever 1 major mode for that type. But for some file types this is inconvenient because there are various alternative major modes that can be used for that file type. I'm thinking of things like Perl files (`perl-mode` vs `cperl-mode`), LaTeX files (`latex-mode` vs AUCTeX's equivalent (whose name it not clear, sadly)), HTML files (lots of alternatives), but also XPM (`c-mode` or `image-mode`), Postscript (`ps-mode` vs `doc-view-mode`), and we could even include the qualitatively different cases of `.tex` files (`tex-mode` or `latex-mode`), or `.pl` files (`prolog-mode` vs `perl-mode`), ... We have various ways to deal with those different cases, which are variously convenient/successful, but for things like `cperl-mode` vs `perl-mode` or `latex-mode` vs AUCTeX the usual solution is not satisfactory since it looks like: (defalias 'perl-mode #'cperl-mode) or equivalent, which means that the "other" mode becomes unavailable (AUCTeX now does it via advising which at least makes it reversible, but it's still not very satisfactory). The way I tend to think of it is that we'd like to divide the mode choice into two steps: A) recognize the file type. B) choose the mode to use for that type. But that's not what we have and retro-fitting that might make the common case (where there's only 1 mode) more painful. IOW it would take work and lead to a worse result in the most common case, which doesn't sound very enticing. So instead I suggest we *treat* the current mode entries in `auto-mode-alist` (and `mode:` cookies, `magic-mode-alist`, ...) as types rather than as mode names. So all it takes is to add some "mode remapping" layer to decide which major mode to actually use when the "type/mode". So instead of (defalias 'perl-mode #'cperl-mode) We could have (add-to-list 'major-mode-alist '(perl-mode . cperl-mode)) I'm thinking of using an implementation with: (cl-defgeneric major-mode-remap (mode) "Choose which mode to use for MODE." (or (alist-get mode major-mode-alist) mode)) Such that we can also use dynamic remapping (via `cl-defmethod`) e.g for `.tex` files. Stefan