unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* file mode synonymous with major mode
@ 2024-03-28  9:56 Heime
  2024-03-28 10:08 ` Joost Kremers
  0 siblings, 1 reply; 4+ messages in thread
From: Heime @ 2024-03-28  9:56 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: file mode synonymous with major mode
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Joost Kremers @ 2024-03-28 10:08 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

On Thu, Mar 28 2024, Heime 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").)

-- 
Joost Kremers
Life has its moments



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: file mode synonymous with major mode
  2024-03-28 10:08 ` Joost Kremers
@ 2024-03-28 19:22   ` tpeplt
  2024-03-29  1:14     ` Emanuel Berg
  0 siblings, 1 reply; 4+ messages in thread
From: tpeplt @ 2024-03-28 19:22 UTC (permalink / raw)
  To: Joost Kremers; +Cc: Heime, Heime via Users list for the GNU Emacs text editor

Joost Kremers <joostkremers@fastmail.fm> writes:

> On Thu, Mar 28 2024, Heime 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.

You can create a new buffer simply by switching to it with C-x b (bound
to ‘switch-to-buffer’):

C-x b a-new-buffer

That buffer will have your default major mode, which is usually
Fundamental mode.  You can then change that mode to, for example,
emacs-lisp-mode, by entering the command ‘emacs-lisp-mode’:

M-x emacs-lisp-mode

Your new buffer will now have its major mode changed to one that is
normally associated with Emacs Lisp files and yet still have no
association with any file.

Likewise, you could have a file of Emacs Lisp code associated with a
buffer in emacs-lisp-mode and could change its major mode to, for
example, text mode:

M-x text-mode

In that case, even though your file has Emacs Lisp code, the buffer
associated with it could be operated on as though it was plain text.

(Besides looking at the first field of the Emacs mode line near the
bottom of the screen, it is also possible to determine which major mode
is in effect by evaluating the variable ‘major-mode’, either in a Lisp
expression or by typing C-h v major-mode RET.)

--



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: file mode synonymous with major mode
  2024-03-28 19:22   ` tpeplt
@ 2024-03-29  1:14     ` Emanuel Berg
  0 siblings, 0 replies; 4+ messages in thread
From: Emanuel Berg @ 2024-03-29  1:14 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-29  1:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).