9

If I type emacs test.sh Emacs insists on putting me in Shell-script mode. Another time I want to edit the file help.txt and then Emacs puts me in Text mode. But sometimes I don't want any of this, especially when I am doing a large paste into Emacs from some other source.

How do I start Emacs in "nothing" mode? No special indenting, spacing, etc., and Emacs simply takes the characters in as they are entered.

UPDATE: Here is an example. Copy the following text to your clipboard, open emacs (even in fundamental mode) and paste.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<EntityDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:shibmd="urn:mace:shibboleth:metadata:1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 ID="FARM20190311T2248"
 Name="https://www.example.com/"
 entityID="https://www.example.com/" validUntil="2020-03-11T22:48:12Z"><ds:Signature>
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>

Emacs insists on changing the spacing (even in fundamental mode and using -q) to this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<EntityDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:shibmd="urn:mace:shibboleth:metadata:1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 ID="FARM20190311T2248"
  Name="https://www.example.com/"
   entityID="https://www.example.com/" validUntil="2020-03-11T22:48:12Z"><ds:Signature>
   <ds:SignedInfo>
   <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>

Try the same experiment with vi or nano. Those programs (at least on my computer) do not change the spacing.

I am using GNU Emacs 24.5.1 on Debian stretch.

2
  • "Emacs [24.5.1] insists on changing the spacing (even in fundamental mode and using -q)" -- I cannot reproduce that in Emacs 25.3 or 26.1. Test again with emacs -Q to ensure Debian hasn't installed some site-lisp which is causing this? If that doesn't change things, try a newer version of Emacs?
    – phils
    Mar 30, 2019 at 23:53
  • 1
    It sounds like your real question is asked and answered here: emacs.stackexchange.com/questions/28008/…
    – npostavs
    Mar 31, 2019 at 2:57

3 Answers 3

16

When you use M-x find-file-literally Emacs will not invoke a mode that is based on the file name. Instead, it uses fundamental-mode as the major mode.

From the command line you can use something like this:

emacs --eval '(find-file-literally "yourfile.ext")'
3
  • This does not solve my problem. I have clarified the issue with an example.
    – rlandster
    Mar 30, 2019 at 21:37
  • can I use it also for emacsclient ?
    – alper
    Jul 1, 2020 at 18:49
  • 1
    Yes @alper: emacsclient -e (find-file-literally "path/file.ext")
    – ocodo
    Jul 3, 2022 at 3:26
11

Emacs modes are established for each file you open, so opening Emacs in "nothing mode" doesn't necessarily accomplish what you're after. Each file you open after starting Emacs will get its own mode applied.

You can use the command @clemera provides to open a file in fundamental mode from the command line. You can do the same from an already-running Emacs via M-x find-file-literally. You can "turn-off" the major mode for a file you've already opened by selecting fundamental mode (which is basically "nothing mode"): M-x fundamental-mode

2
  • A valid use case for no modes, or fundamental mode, is for opening large text files that I don't want slowed down with mode processing.
    – Kent Bull
    Sep 13, 2021 at 21:55
  • @KentBull I don't dispute fundamental mode has a valid use case. My point is that 'opening Emacs in fundamental mode' doesn't make sense, because the modes are applied to the files as you open them, not to Emacs in general. That is, you need to open a file in fundamental mode, not emacs.
    – Tyler
    Sep 27, 2021 at 14:55
5

I'm running:
GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2018-08-26, modified by Debian

$ emacs yourfile.txt --eval '(fundamental-mode)'

You have to put the --eval after the file name or it appears to set the mode based on the file name.

1
  • To ensure there is no pollution from the original mode (e.g. debugging a mode) --eval (find-file-literally "yourfile.txt") is going to be better.
    – ocodo
    Jul 3, 2022 at 3:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.