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.

rlandster
  • 213
  • 3
  • 8
  • "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 '19 at 23:53
  • 1
    It sounds like your real question is asked and answered here: https://emacs.stackexchange.com/questions/28008/how-do-i-paste-code-without-auto-indentation – npostavs Mar 31 '19 at 02:57

3 Answers3

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")'
Drew
  • 75,699
  • 9
  • 109
  • 225
clemera
  • 3,401
  • 13
  • 40
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

Tyler
  • 21,719
  • 1
  • 52
  • 92
  • 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 '21 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 '21 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.

AAAfarmclub
  • 159
  • 3
  • 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 03 '22 at 03:29