Skip to main content
23 votes
Accepted

How to disable the org-mode in a buffer

Doing again an M-x org-mode does not turn it off. This convention is for minor-modes - Doing a M-x "minor-mode-name" again disables that minor mode. org-mode is a major mode. When you do this, emacs ...
Jeeves's user avatar
  • 619
19 votes
Accepted

How to edit jsx (react) files in emacs?

Solution 1: Step 1, Use https://github.com/felipeochoa/rjsx-mode Step 2, Install Emacs 25+, see https://github.com/mooz/js2-mode/issues/291 Step 3, Patch rjsx-mode with below code (defadvice js-...
chen bin's user avatar
  • 4,877
18 votes

How to edit jsx (react) files in emacs?

In Emacs release 27 and later, JSX support is built into the default JavaScript mode for Emacs, js-mode. If the use of JSX is anticipated, then JSX support will be automatically enabled in JavaScript ...
Jackson Ray Hamilton's user avatar
16 votes
Accepted

Disabling electric-indent-mode for one mode (latex mode) only

The command you need is electric-indent-local-mode. You can use this to turn off electric-indent-mode in any buffer by calling it manually: M-x electric-indent-local-mode. This is a toggle, so calling ...
Tyler's user avatar
  • 22.4k
16 votes
Accepted

How to start emacs in "nothing" mode (`fundamental-mode`)

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 ...
clemera's user avatar
  • 3,486
15 votes
Accepted

How do I force a mode on a specific file through special comments

You can use a file-local variable to specify the mode. You can either put them at the top of the file, like so: # -*- mode: sh -*- or at the bottom of the file, like so: # Local Variables: # mode: ...
Dan's user avatar
  • 33.1k
11 votes

How to start emacs in "nothing" mode (`fundamental-mode`)

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 ...
Tyler's user avatar
  • 22.4k
10 votes
Accepted

How to never have a major mode enabled automatically

Emacs keeps a list of regexp-mode pairs in an alist called auto-mode-alist. Any file you open has it's name matched against the nodes in the alist; every match activates a mode. So, what you want to ...
Gastove's user avatar
  • 1,551
10 votes
Accepted

How to compile and run a C++ file?

That's a lot of questions, but I will try to answer them in such a way that you can look up all the answers in detail. Emacs is primarily a text editor; you will use it to edit your C++ files. ...
db48x's user avatar
  • 18.4k
10 votes

# -*- mode: ... -*- string fallback

Found it: # -*- mode: conf; mode: apache -*- It seems that the last valid mode wins, so I need to put the my wanted mode last, and the fallback mode(s) before it.
Chen Levy's user avatar
  • 385
10 votes
Accepted

How to check if a major mode derives from another?

Function derived-mode-p does that. So in your case: (derived-mode-p '(c-mode c++-mode glsl-mode)). C-h f tells you: derived-mode-p is a compiled Lisp function in subr.el. (derived-mode-p &rest ...
Drew's user avatar
  • 78k
10 votes
Accepted

Is a Lisp program in both prog-mode and lisp-mode?

Does it mean that C programming is running under prog-mode and c-mode? No, because, as you later quote: Major modes are mutually exclusive; each buffer has one and only one major mode at any time. ...
Basil's user avatar
  • 12.5k
10 votes

Is there a standard mode for .ini files?

conf-mode.el says: This mode is designed to edit many similar varieties of Conf/Ini files and Java properties. It started out from Aurélien Tisné's ini-mode. conf-space-keywords were inspired ...
Stefan's user avatar
  • 26.5k
9 votes

Writing a Major Mode

There is a section of the Elisp manual specifically about this. I'd recommend that you start by reading that. After that, I'd recommend that you look at the code for some simple major modes that ...
Drew's user avatar
  • 78k
9 votes
Accepted

Find out, which mode is in use

See major-mode variable to find out major mode: Symbol for current buffer’s major mode. See cond function to do something depending on mode: Try each clause until one succeeds. Each clause ...
muffinmad's user avatar
  • 2,320
8 votes
Accepted

Enable mode if file content contains a matching string

I would like to enable [some mode] whenever a file I open contains a specific string, or a regex This is exactly what magic-mode-alist is for (there is also magic-fallback-mode-alist if you want the ...
npostavs's user avatar
  • 9,213
7 votes
Accepted

Retrieve all the major modes equipped with emacs

To list major modes defined with define-derived-mode macro you can grep el files in emacs-source/lisp folder like grep -A 1 '(define-derived-mode' **/*.el But maybe browsing built-in packages would ...
muffinmad's user avatar
  • 2,320
6 votes
Accepted

How to prevent line wrapping in code, but allow it in help/info buffers?

(defun my-truncate-lines-disable () "Disable line truncation, even in split windows." (let ((inhibit-message t) ; No messages in the echo area - needs emacs 25+ message-log-max ; No ...
Kaushal Modi's user avatar
  • 25.7k
6 votes

How do I list all key-bindings available in a given buffer?

Currently, probably the best way to discover keybindings is by using the which-key package. This package is central in distributions like Spacemacs and Doom emacs. It provides various commands for ...
dalanicolai's user avatar
  • 7,865
6 votes

Automatically formatting SQL code

If you don't mind calling out to a python process, then this works (pip install sqlparse): (defun sqlparse-region (beg end) (interactive "r") (shell-command-on-region beg end "python -c '...
5fec's user avatar
  • 196
6 votes
Accepted

File mode name with -mode suffix or not?

Don't name your file x-mode.el if it does not actually provide a mode of some sort: that seems confusing. If you are providing library x, just call the file x.el. From what I've seen, most modes (...
glucas's user avatar
  • 20.6k
6 votes
Accepted

File-local variable to force specific shell for shell-script major mode

C-hf sh-mode says: This mode adapts to the variations between shells (see sh-set-shell) by means of an inheritance based feature lookup (see sh-feature). This mechanism applies to all ...
phils's user avatar
  • 51.7k
6 votes

How to start emacs in "nothing" mode (`fundamental-mode`)

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 ...
AAAfarmclub's user avatar
6 votes
Accepted

Why won't `emacs -nw -f org-mode foo` open `foo` in `org-mode`?

I was able to do it by switching the order around emacs -nw foo -f org-mode After reading the help, if the function is a command, it is just like pressing a key command to do it. There's also the --...
shoshin's user avatar
  • 914
6 votes

How are major modes and local keymaps associated?

You do have to be a bit careful with the terminology. Each buffer has a single "local keymap", and therefore it's sensible to avoid using that terminology to refer to other keymaps. current-local-...
phils's user avatar
  • 51.7k
5 votes

How to set major mode for a file in .dir-locals.el?

The following .dir-locals.el works just fine for me to set the major mode of all files in a directory to shell-script-mode: ((nil . ((mode . shell-script)))) The obvious downside is that you can't ...
Resigned June 2023's user avatar
5 votes

How does one change a .el file to lisp-interaction mode?

Interactively: M-x lisp-interaction-mode RET For a single file, make the first line of that file: ;; -*- mode: lisp-interaction; -*- For all files, add to your init file: (add-to-list 'auto-mode-...
phils's user avatar
  • 51.7k
5 votes
Accepted

When writing a new major mode, should it add itself to auto-mode-alist?

Note that if your library is intended to be installed via package.el (or similar) and you have included an autoload cookie for foo-mode, and you choose to implement the auto-mode-alist manipulation, ...
phils's user avatar
  • 51.7k
5 votes

How to make all variables and functions of a mode visible without activating the mode

@phils gave you what is almost always the correct answer, that is, it is the right answer for most major and minor modes; but in the case of eshell you need to do something else: (add-hook 'eshell-...
Omar's user avatar
  • 4,842
5 votes
Accepted

does one has to explicity enable python-mode etc. to work with python files?

python-mode.el (from https://gitlab.com/python-mode-devs/python-mode) has more "bells-and-whistles" than python.el (included with Emacs). Things like better integration with IPython and auto-...
nega's user avatar
  • 3,276

Only top scored, non community-wiki answers of a minimum length are eligible