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
56
votes
7answers
2k views

How can I use Emacs to edit questions, answers, and comments here?

Emacs as a StackExchange client? How can I use Emacs to edit questions, answers, and comments here on the Emacs Stack Exchange site? Broadly, what possible methods exist? Kill and yank This works, ...
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 ...
31
votes
3answers
11k views

How do I get the current major mode?

If I am editing a .tex file in emacs, by default (for me) the bottom right corner of the frame will say "LaTeX/P". However, I won't get to that mode by typing "M-x LaTeX/P-mode"; I can only get to it ...
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
765 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* ...
18
votes
4answers
5k views

How to edit jsx (react) files in emacs?

I've use js2-mode but it don't indent html in javascript properly. I've found this repo https://github.com/jsx/jsx-mode.el but it's not for react, it's for some other jsx. What do you use for editing ...
17
votes
2answers
3k views

Using a different font for each major mode

Is it possible to set different fonts following the major mode? Say Inconsolata-12 in org-mode buffers and Symbola-12 in all remaining modes. Or at least, is it possible to do a (set-frame-font "...
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 ...
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
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 ...
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 ...
11
votes
2answers
256 views

Use two major-mode-maps in the same buffer

I've run into a few situations where it would be highly convenient to have to have the keymap of one major-mode act as a fallback keymap for another major-mode. For instance: I write a lot of LaTeX ...
11
votes
1answer
5k views

Javascript mode compatible with es6

Does anyone know of a javascript editing mode that supports the es6 syntax additions (arrow functions, extends, imports, generators, etc.)? I've done some quick searching but it looks like so far ...
10
votes
2answers
624 views

Remember modes for files without extensions

I've started editing a lot of files that have no extensions, but are still in a major mode format. I'm the only Emacs user on the team, and I don't want to make it a painfully obvious that my editor ...
10
votes
2answers
354 views

Why don't major modes just inspect the faces?

When writing a major mode, it's often useful to know 'is point in a string?' 'is point in a comment?'. Most major modes seem to attempt to parse the programming language. For example: python-syntax-...
10
votes
4answers
338 views

How do I inherit from prog-mode, whilst still supporting older emacsen?

I'm writing a major mode for a programming language, but I want to support older Emacs versions. prog-mode is relatively new. I want to inherit from prog-mode if it's defined, but still do something ...
9
votes
3answers
1k views

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

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, ...
9
votes
2answers
2k views

How do I write a simple `completion-at-point-functions` function?

I'm considering writing a major mode for editing Magic: the Gathering decks. Most of it seems pretty straightforward but I have one question. There are about 15 000 unique Magic cards available (...
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 ...
9
votes
1answer
5k views

How do I associate a file extension with a specific mode? [duplicate]

I would like emacs to switch to gnuplot-mode when I open a file ending in .g or .gnuplot. I tried ;; gnuplot mode-name (add-to-list 'gnuplot-mode '("\\.g\\'" . gnuplot-mode)) or ;; gnuplot mode-...
9
votes
1answer
587 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
2answers
156 views

How to write a major mode that does not open the file but provides a view on it

I would like to write a major mode for inspecting netCDF files. These are binary files which can be multiple GB in size. So I don't want to open them in emacs. The interaction that I have in mind is ...
8
votes
2answers
563 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 ...
8
votes
1answer
2k views

How to disable the org-mode in a buffer

For a test purpose, I enabled the org-mode by M-x org-mode in a buffer (e.g., in scratch buffer). How to disable it? Doing again an M-x org-mode does not turn it off.
8
votes
1answer
1k views

Which mode to use for ECMAScript 6?

Is there a mode out there that has syntax higlighting (and possibly more, but this is the least I want) for a more recent ecmascript? I'm especially interested in one that has support for template ...
8
votes
1answer
250 views

How do I create a simple syntax table for a major mode?

I'm trying to understand how syntax tables work, but my minimal major mode doesn't highlight anything. I've written the following elisp, which is just supposed to highlight comments: (defconst my-...
8
votes
2answers
793 views

How to activate semantic-mode for specific major modes only?

I've seen this question a lot. But none of the replies fixed my issue: the minor mode stays on in others modes. So far, I have tried: (use-package stickyfunc-enhance :config ;; (add-to-list '...
7
votes
3answers
385 views

permanently change buffer mode of a file?

Beginner question: In OSX 10.6.8, Aquamacs has many buffer modes. My .tex files open in TeX mode, but I would like to open them in LaTeX mode. I can change the Mode with "Change Buffer Mode", but ...
7
votes
3answers
561 views

What's the difference between words and symbols?

When defining a syntax table for a major mode, I can define both word constituents and symbol constituents. When should I use each? For example, given a programming language that writes variables in ...
7
votes
1answer
143 views

How do I find the code for the current major mode?

How do I find the elisp code for the major mode in use in the current buffer?
7
votes
4answers
840 views

How to obtain a list of all functions exclusively provided by a certain major mode

This question in inspired by https://stackoverflow.com/q/605785/. By M-x describe-function <TAB> I can get a list of all interactive or nonintractive functions available in the current state of ...
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 ...
7
votes
2answers
886 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 ...
6
votes
2answers
382 views

How to associate more than one file extension with a given mode in `use-package`

When using use-package, is there a way to associate more than one file extension with a particular mode in one place instead of multiple locations? Case in point is that I would like to associate ...
6
votes
2answers
2k views

How to change comment character from # (hash) to % (percent sign) for Octave major mode

By default, comment-region inserts # for comments in Octave major mode: # foo I want to modify the behavior so that it inserts the percent sign % foo I used the following (setq octave-mode-hook ...
6
votes
1answer
264 views

# -*- mode: … -*- string fallback

So I know that I can put at the first or second line of a file a line such as: # -*- mode: conf -*- to tell Emacs what major mode I want the file to be opened with. But if that mode isn't installed ...
6
votes
1answer
533 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$" "" ...
6
votes
1answer
294 views

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

Upon reading (emacs) Program Modes: Entering a programming language mode runs the custom Lisp functions specified in the hook variable prog-mode-hook, followed by those specified in the mode's ...
6
votes
1answer
553 views

Is possible to execute a key binding in a function?

Say, the C-M-j is bound to c-indent-new-comment-line for c-mode (and c++-mode) and indent-new-comment-line for other modes, but I want to define a function that will execute C-M-j to c-indent-new-...
6
votes
2answers
132 views

what are the options to write a language grammar for a new major mode?

I am writing a major mode for a programming language that has a well-defined grammar: it has a BNF, formalised in some happy files. I don't particularly want to re-implement the BNF as a series of ...
5
votes
3answers
266 views

How to never have a major mode enabled automatically

looks like Emacs tries to be smart, switching to an annoying change-log-mode often when i am editing a changelog file. I would like to disable it, but i just find info about how to interactively ...
5
votes
2answers
780 views

CSS code completion as in Firebug

One of the convenient features of in-browser inspectors like Firebug is that it is so easy to tweak CSS stylesheets. As you type in the attribute position, all possible attributes are shown in a ...
5
votes
3answers
942 views

Make names of major modes shorter in the mode-line

I want to make names of major modes shorter. No longer than three characters. Is there any packages that do something like that? It's better to shorten mode names in automatic fashion, so one doesn't ...
5
votes
1answer
769 views

Inferior Lisp Mode vs Superior Lisp Mode

Can someone explain all the differences in the various lisp modes (inferior, superior, slime, cider)? Which came first? Which are extra packages? What should one use?
5
votes
3answers
122 views

elisp: retaining data structure after inserting string representation to buffer?

I'm currently writing a major mode (for interacting with a remote Grid Engine) which involves fetching data, parsing it into an alist, formating the alist into a string and then inserting the ...
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
213 views

How can I make emacs ignore part of the file name when deciding major mode?

If you have a GPG-encrypted file, say notes.org.gpg, emacs figures out that the major mode has to be set to org-mode. This applies in general to any major mode out there; you do not need to modify the ...
5
votes
2answers
161 views

How do I handle multiple string delimeters in a major mode?

I'm trying to write a major mode for a language that supports normal strings and triple-quoted strings ("foo" and """foo"""). (defconst my-string-mode-syntax-table (let ((table (make-syntax-table)))...
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?