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

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

Re: file mode synonymous with major mode


From: Emanuel Berg
Subject: Re: file mode synonymous with major mode
Date: Fri, 29 Mar 2024 02:14:53 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

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 via email to

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