66
votes
How do I list all key-bindings available in a given buffer?
C-h b will list all the bindings available in a buffer. This is a mnemonic for help (C-h) bindings (b).
You can also get a list of keybindings via C-h m, which is help for the major and minor modes ...
63
votes
Accepted
How do I get the current major mode?
I think the simplest way is to check the value of the buffer-local major-mode variable, with either of:
C-hv major-mode RET
M-: major-mode RET
49
votes
Accepted
How to override major mode bindings
There is a "shortcut" approach too for the same solution if you don't want to define your own minor mode (that I talk about in my first answer).
You can install the use-package package available from ...
36
votes
How to override major mode bindings
You can define your own minor mode and its key map and have that override all other modes (minor + major). That's exactly why I chose to write my own minor mode.
Steps to have your key bindings ...
35
votes
Accepted
How can I use Emacs to edit questions, answers, and comments here?
See the Stack Exchange for Emacs project. From their page:
SX will be a full featured Stack Exchange mode for GNU Emacs 24+.
Using the official API, we aim to create a more versatile experience
...
28
votes
How do I list all key-bindings available in a given buffer?
I use the command helm-descbinds, which is available via melpa. I mapped it to C-h b because it is basically a drop-in replacement for describe-bindings. The benefit is that it is easier to navigate ...
28
votes
How do I associate a file extension with a specific mode?
The full syntax for specifying file extensions for gnuplot-mode is:
(add-to-list 'auto-mode-alist '("\\.g\\'" . gnuplot-mode))
The other point to verify is that you are using Bruce Ravel's recent (...
25
votes
Accepted
How do I automatically load a mode for a specific set of file extensions?
Add these lines to your .emacs file:
(require 'yaml-mode)
(add-to-list 'auto-mode-alist '("\\.ya?ml\\'" . yaml-mode))
The auto-mode-alist is a variable which emacs consults whenever a new file is ...
25
votes
Accepted
How can I quickly toggle between a file and a *scratch* buffer having the same major mode?
It will be convenient to bind the below function to a key binding of your choice.
If you are currently working on a FILE buffer, calling the below function will toggle between FILE's major-mode ...
22
votes
Accepted
Using a different font for each major mode
buffer-face-set and buffer-face-mode in Emacs 23 or later is designed for exactly this. From the Emacs wiki:
;; Use variable width font faces in current buffer
(defun my-buffer-face-mode-variable ()...
21
votes
Accepted
Run command when opening a file of a specific filetype
In Emacs terminology, these are two different steps:
Associate files with the .ts extension with the major mode typescript-mode.
Run the function tss-setup-current-buffer when Typescript mode starts.
...
21
votes
Accepted
How do I write a simple `completion-at-point-functions` function?
Documentation
The API completion at point function can be found in the documentation of completion-at-point-functions
Each function on this hook is called in turns without any argument and
...
20
votes
Why does *compilation* buffer show control characters?
These are indeed escape sequences which the terminal should interpret as orders to change the text color. Normally they shouldn't be used when the compiler is invoked from Emacs (the terminal type ...
20
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 ...
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-...
16
votes
Accepted
Differences between setting major mode keys with a hook versus adding them to the mode map
The second approach is preferable as it modifies the mode's keymap just once.
If you do it using the mode's hook then that will be called every time that mode is enabled in some buffer. Doing so ...
16
votes
How to edit jsx (react) files in emacs?
In the upcoming release of Emacs 27, JSX support is now built into the default JavaScript mode for Emacs, js-mode. (Try it out! You can build from
source using the Emacs 27 release candidate, or e.g....
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 ...
14
votes
How do I get the current major mode?
C-h m gives you help on the current mode, and it typically tells you the name of the command that turns the mode on.
For example, in Emacs-Lisp mode C-h m tells you that you are in Emacs-Lisp mode. ...
14
votes
How to associate more than one file extension with a given mode in `use-package`
The following should work:
(use-package js2-mode
:mode (("\\.js\\'" . js2-mode)
("\\.jsx\\'" . js2-mode))
...
:ensure t)
13
votes
Remember modes for files without extensions
There are a number of ways to identify the major mode for a file that don't rely on an extension, see Choosing File Modes in the manual.
Depending on the kinds of files you are dealing with, perhaps ...
13
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 ...
12
votes
Specify major-mode for files with multiple extensions
The auto-mode-alist variable does what you need. Never bind anything to the major-mode variable.
The documentation explains how you can set major-modes per file extension and, most importantly, it ...
12
votes
Accepted
Why don't major modes just inspect the faces?
The problem is that it is not more robust.
Firstly, the major modes are precisely the ones responsible for deciding what's a comment or a string. If they were able to successfully define them for the ...
12
votes
Accepted
Use two major-mode-maps in the same buffer
This turned out to be simpler then expected. As suggested in the comments here and on the question:
(with-eval-after-load 'erc
(require 'markdown-mode)
(require 'cl-lib)
(setq erc-mode-map
...
12
votes
Accepted
Inferior Lisp Mode vs Superior Lisp Mode
When you run a process inside Emacs, that process is "inferior" (i.e. a subprocess).
IELM M-x ielm is the builtin Inferior Emacs Lisp Mode. It's relatively featureless, but can definitely come in ...
11
votes
Accepted
How do I inherit from prog-mode, whilst still supporting older emacsen?
At the cost of an extra top-level symbol binding, there's a very neat solution which avoids repeating the define-derived-mode form:
(defalias 'my-fancy-parent-mode
(if (fboundp 'prog-mode) 'prog-...
11
votes
How can I use Emacs to edit questions, answers, and comments here?
edit-server might be of some help. It lets you edit any text field inside Chrome with Emacs and then send the text back to the browser with minimum effort. Not exactly what you wanted, but its an ...
11
votes
Accepted
How to change comment character from # (hash) to % (percent sign) for Octave major mode
Inside your hook put this: (setq comment-start "% "). Also, this will explain why:
comment-region is an interactive compiled Lisp function.
(comment-region BEG END &optional ARG)
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
major-mode × 253key-bindings × 20
minor-mode × 20
indentation × 13
syntax-highlighting × 13
buffers × 12
font-lock × 11
init-file × 10
keymap × 10
org-mode × 9
hooks × 9
comment × 8
elisp × 6
regular-expressions × 6
syntax × 5
spacemacs × 4
files × 4
use-package × 4
help × 4
formatting × 4
javascript × 4
smie × 4
derived-mode × 4
magit × 3
python × 3