2

When creating a new buffer via:

  1. C-x b
  2. NonExistentBufferName RET RET

I would like Emacs to ask me what major mode this buffer is going to use upon opening. Moreover, I want Emacs to infer the major mode in some cases based on the buffer's name:

  1. C-x b
  2. test.org(no such buffer so far) RET RET => org-mode is used without asking me anything.

Could anybody advice if I can use any package for this? Or is it achievable at all via pure elisp?

P.S. I'm using ido if it matters.

  • I've migrated this over to emacs.SE. Flag for merger with your other question. Please don't cross post the next time. – Bhargav Rao May 11 at 22:56
2

Add entries in the magic-mode-alist/auto-mode-alist (in your init file most likely) if you want emacs to automatically determine major mode from buffer/file names (C-h v auto-mode-alist for info).

To interactively set the major mode just use M-x <mode-name, eg. c-mode>.

If you actually want emacs to interactively prompt you for a major mode every time you open a buffer, that could be achieved via a small advice to function you use to visit files (the ido functions in your case).

  • auto-mode-alist seems to be working only with file buffers. Yeah, I'm looking for a way to have Emacs prompt me for a major mode. I tried to find the right function to hook it up – Dmitry Senin May 11 at 19:48
  • @DmitrySenin yea that is for file buffers, perhaps magic-mode-alist would meet your needs. Otherwise, you could write a small function for completing read of available modes and advise the finding function – pickle rick May 11 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.