unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: help-gnu-emacs@gnu.org
Subject: Re: file mode synonymous with major mode
Date: Fri, 29 Mar 2024 02:14:53 +0100	[thread overview]
Message-ID: <87le61x2ia.fsf@dataswamp.org> (raw)
In-Reply-To: 87h6gqf9g9.fsf@gmail.com

tpeplt wrote:

>>> Reading the emacs manual '24.3 Choosing File Modes'. Is it
>>> correct to assert that the file mode is synonymous with
>>> the major mode ?
>>>
>>> https://www.gnu.org/software/emacs/manual/html_node/emacs/Choosing-Modes.html
>>
>> Given that that page talks about both major and minor
>> modes, I'd say no. It rather refers to any modes activated
>> for a specific file.
>>
>> Note that it's hardly an issue. "File mode" does not have
>> any specific meaning in Emacs (unlike major and minor
>> mode), so I wouldn't worry about it too much. (In fact,
>> going through the manual, there appears to be another use
>> of the term "file mode", referring to what is more commonly
>> called "file permissions": see (info "(emacs) Misc File
>> Ops").)
>
> Also, the major mode that is in effect for a given buffer
> may have nothing to do with ANY file. For example, the
> *scratch* buffer and Help buffers have no file associated
> with them, but both have a major mode. [...]

I think you are over-theorizing around a supposed concept that
actually isn't really there or, if it is, is much better
tackled from a/the practical angle.

Buffer have modes and filenames are the best ways to set them.

If it doesn't happen automatically, use Elisp as below to set
it based on the file extension (filename suffix).

If that cannot happen the file name can be used in full, there
is an example of that below.

If everything fails or cannot be done (why?), use file local
variable as described here as the last way:

  (info "(emacs) Specifying File Variables")

[Note:
  As good as using the filename are using unique elements in
  the file that appear naturally, e.g. the hashbang initial
  line of shell scripts - for example "#! /bin/zsh" for zsh -
  as you want that anyway, it is even better that Emacs can
  just use it to set the buffer to the correct mode when you
  find the file.]

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/mode-by-filename.el

(setq auto-mode-alist `(
    ("\\.bal\\'"     . balance-mode)
    ("\\.cl\\'"      . common-lisp-mode)
    ("\\.dat\\'"     . gnuplot-mode)
    ("\\.gpi\\'"     . gnuplot-mode)
    ("\\.grm\\'"     . sml-mode)
    ("\\.lu\\'"      . lua-mode)
    ("\\.nqp\\'"     . perl-mode)
    ("\\.php\\'"     . html-mode)
    ("\\.pic\\'"     . nroff-mode)
    ("\\.pl\\'"      . prolog-mode)
    ("\\.sed\\'"     . conf-mode)
    ("\\.service\\'" . conf-mode)
    ("\\.tap\\'"     . gcode-mode)
    ("\\.tex\\'"     . latex-mode)
    ("\\.xr\\'"      . conf-xdefaults-mode)
    ("torrc\\'"      . conf-mode)
    ("keys\\'"       . conf-mode)
    ("DOS\\'"        . text-mode)
  ,@auto-mode-alist) )

(provide 'mode-by-filename)

-- 
underground experts united
https://dataswamp.org/~incal




      reply	other threads:[~2024-03-29  1:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28  9:56 file mode synonymous with major mode Heime
2024-03-28 10:08 ` Joost Kremers
2024-03-28 19:22   ` tpeplt
2024-03-29  1:14     ` Emanuel Berg [this message]

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=87le61x2ia.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --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).