;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/set-mode.el (defun mode-p (fun) (let*((sfx "-mode") (len (length sfx)) ) (and (functionp fun) (string= sfx (substring (symbol-name fun) (- len))) ))) (defun set-mode (&optional fun) (interactive (list (completing-read "mode: " obarray (lambda (e) (mode-p e)) t ; require-match nil nil (symbol-name #'normal-mode) ))) (if fun (let ((f (if (stringp fun) (intern fun) fun) )) (when (mode-p f) (apply (list f)) )) (normal-mode) )) ;; (set-mode #'kill-emacs) ; safe as not a mode ;; (set-mode #'fundamental-mode) ; mode function ;; (set-mode "emacs-lisp-mode") ; mode function name ;; (set-mode) ; derive mode from extention/hashbang ;; M-x set-mode RET conf-mode RET ; interactive explicit ;; M-x set-mode RET RET ; ditto derive (provide 'set-mode)