help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keybinding that loops through Major Modes


From: Emanuel Berg
Subject: Re: Keybinding that loops through Major Modes
Date: Mon, 02 Nov 2020 21:59:23 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Christopher Dimech wrote:

> Is it difficult to make an keybinding that if I continue to press
> it, it will loop through a list of major modes in a predefined
> order (e.g. text-mode, org-mode, normal-mode, text-mode, ...)

Not difficult but perhaps not a good idea since it is probably better
to let Emacs set the major mode automatically.

If it doesn't do it to your liking there are many ways to set it up,
depending on the situation.

Based on file extension:

(let ((modes (list
     '("\\.bal\\'" . balance-mode)
     '("\\.lu\\'"  . lua-mode)
     '("\\.nqp\\'" . perl-mode)
     '("\\.php\\'" . html-mode)
     '("\\.pic\\'" . nroff-mode)
     '("\\.pl\\'"  . prolog-mode)
     '("\\.tex\\'" . latex-mode)
     '("\\.xr\\'"  . conf-xdefaults-mode)
     '("*"         . text-mode) )))
  (setf auto-mode-alist (nconc modes auto-mode-alist)) )

For scripts, use the hash-bang line, topmost. You probably want it
anyway. For example, for zsh:

#! /bin/zsh

You can also force a mode like this, also topmost:

;;; -*- emacs-lisp -*-

For the rare cases none of these methods will do, I think M-x
perl-mode RET will do...

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]