;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/set-mode.el (defun get-hooks (&optional mode) (unless mode (setq mode major-mode) ) (let ((hooks)) (obarray-map (lambda (e) (when (and (boundp e) (string-match (format "^%s.+hook$" mode) (symbol-name e)) ) (push e hooks) )) obarray) hooks) ) ;; (get-hooks) ;; (get-hooks "gnus") ;; (get-hooks "text") ;; (get-hooks 'emacs-lisp) (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)