[comp.emacs] Mode toggle

norm@athena.mit.edu (Wayne M Miller) (03/23/91)

A few days ago I posted a request for help concerning a function
to toggle between three separate modes.  What follows is the
improved version of the function.

;; Easy switch-mode (C-c C-t)
(setq my-mode-queue
      (list 'latex-mode 'c-mode 'fundamental-mode))

(defun my-toggle-mode ()
  "Toggle major modes quickly."
  (interactive)
  (funcall (car my-mode-queue))
  (setq my-mode-queue
	(append (cdr my-mode-queue) (list (car my-mode-queue))))
  (refresh-mode-line))

(defun refresh-mode-line ()
  (save-excursion (set-buffer (other-buffer)))
  (set-buffer-modified-p (buffer-modified-p))
  (sit-for 0))

(global-set-key "\C-c\C-t" 'my-toggle-mode)

This version has the advantage of storing the modes in a variable,
rather than creating a separate function for each mode, changing the
binding of the key after each call.

I would like to eventually convert this function to a more generic
toggle function that takes as an argument a list of commands to
cycle through.  However, I am new to elisp, so I am having trouble
doing this.  If anyone has any suggestions, please contact me.

--
==============================================================================
    Wayne M Miller	   |     "What can you say about a society that
    norm@athena.mit.edu	   |      says God is dead and Elvis is alive?"
==============================================================================