Questions tagged [major-mode]

The mode that determines the editing behavior of Emacs while that buffer is current. The mode line normally shows the name of the current major mode, in parentheses.

Filter by
Sorted by
Tagged with
36
votes
4answers
8k views

How to override major mode bindings

Sometimes my global keybindings are overridden by a major mode. An easy example is the following setting in my init file (global-set-key (kbd "C-j") 'newline-and-indent) But annoyingly this ...
14
votes
1answer
1k views

How do I automatically load a mode for a specific set of file extensions?

I'd like to load the yaml-mode for any files named *.yml or *.yaml.
13
votes
4answers
412 views

Differences between setting major mode keys with a hook versus adding them to the mode map

Assume that I have downloaded a major mode called magical-mode, and it has its own magical keymap called magical-mode-map. This mode also provides a hook magical-mode-hook which is run each time ...
7
votes
2answers
879 views

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

I would like to set the major mode for a file as you would using file-local variables Local Variables: mode: text End: but in .dir-locals.el in order not to “pollute” the file in question. Is this ...
30
votes
6answers
12k views

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

I am trying out a new major mode, how can I take advantage of Emacs' documentation system to get a listing of key bindings available in that specific buffer?
24
votes
1answer
763 views

How can I quickly toggle between a file and a *scratch* buffer having the same major mode?

At times while working on a code, it's useful to quickly open a *scratch* buffer to paste a snippet from that code file. If I am working on a Perl script, I would like to quickly open a *scratch* ...
13
votes
6answers
759 views

how to get buffers (not just files) to honor auto-mode-alist?

Q: how can I get new buffers to honor the mapping in auto-mode-alist? When finding a file, Emacs compares the file extension to the auto-mode-alist to determine which major mode to use for the file's ...
15
votes
4answers
4k views

Automatically formatting SQL code

There are some general well-known coding standards and styles for SQL (e.g. capitalizing reserved words, placing main keywords in different lines, etc.). Does Emacs come with any modes for this, or ...
14
votes
2answers
6k views

Run command when opening a file of a specific filetype

I'm trying to get a lisp script to run some commands for me when I open a file of a specific filetype. I know that I'm working in the correct init file because if I remove the theme from it, emacs has ...
8
votes
1answer
582 views

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

I don't like the way electric indent mode works in latex-mode. Everywhere else (at least everywhere I use), it's great. How can I permanently disable electric indent mode for latex mode only, but ...
9
votes
1answer
2k views

Why does *compilation* buffer show control characters?

I'm using the *compilation* buffer to build a C++ application on Centos 5 and Centos 6. The buffer shows the build and includes references to files that are part of the build. However, I'm getting ...
8
votes
2answers
562 views

Make buffer read-only on a per-file basis

I know I can set something like -*- mode: read-only-mode -*- inside a commentary and Emacs will open the corresponding file as read-only. My problem is that I still want to read files that include ...
7
votes
3answers
2k views

Auto enable minor modes in fundamental-mode

By design, the fundamental-mode is bare bones as other major modes are supposed to derive from this one. From the info page (elisp) Major Modes, we have: This is the major mode command for ...
6
votes
1answer
532 views

Specify major-mode for files with multiple extensions

In my .emacs file, I have: (setq-default major-mode (lambda () (let ((buffer-file-name (replace-regexp-in-string "\\.tmp$" "" ...
5
votes
1answer
1k views

Writing a Major Mode

What are some resources for learning to write a major mode for a programming language such as Haskell? I know such things exist but I would like to learn how to do it, it seems like a fun and ...
5
votes
1answer
1k views

How can I change which shell script mode I'm in?

Occasionally, emacs opens a file in shell-script[fish] when I want it to open in shell-script[bash]. How can I manually change the subtype of shell-script mode that I'm in?
4
votes
1answer
946 views

Change the default mode used when opening a new buffer

For example, we can open a new buffer with C-x b <new-buffer-name>, and by default, this new buffer opens in fundamental-mode, which is not very useful to me. I would like to change this to open ...
2
votes
2answers
272 views

Create new major mode from cc-mode that allows comments with two dashes

It is possible and relatively easy to create a new major mode, deriving from c-mode, and just add two dashes '--' to work as comments too? I have checked many resources, but couldn't find anything ...
2
votes
1answer
732 views

Scratch always starts in fundamental mode

I don't know what change in my configuration caused this, but scratch buffer always starts in fundamental-mode. I would like to have emacs-lisp-mode in the scratch buffer. I tried to do (setq initial-...
2
votes
1answer
57 views

Modify mode's font-locking without changing source code

Suppose I want to make additions to a major mode's syntax highlighting, how would I do this without modifying the major mode's source code? Some ideas: Redefine variable in .emacs Define a minor ...
1
vote
1answer
69 views

Cperl-mode syntax highlighting breaks when inserting a newline into a here doc

in cperl-mode, here docs are colored with a font-lock-string-face. However if you used any function that inserts a newline on a blank line (e.g. M-: (insert "\n")) it will cause all code after the ...
1
vote
2answers
191 views

How to detect mode, then execute?

I'm currently using autoheader. I have this configuration, which causes the <?php tag to be inserted in other modes: (defsubst my/header-title () "Insert buffer's first row." (insert "<?...
1
vote
1answer
622 views

Highlighting YAML comments correctly

See https://lists.gnu.org/archive/html/emacs-devel/2015-12/msg01046.html for more background. YAML defines a comment as a # either preceded by the beginning of the line or whitespace (more ...
1
vote
1answer
71 views

Complex comment-start (and end) sequence

As far as I understand there is syntax flags only for comment delimiters made up of two characters but if I have comment delimiters of length greater than two characters is it possible to change ...
0
votes
1answer
186 views

How do I enable a mode, when another mode runs?

All I want to do is enable tern-mode, when I enter js-mode. I know that a hook called js-mode is run when I open a javascript file but for some reason tern-mode is not enabled. In my init.el file I ...