I added the following line to my init file to replace ruby-mode with enh-ruby-mode:
(setq auto-mode-alist (mapcar (lambda (x) (if (eq (cdr x) 'ruby-mode) (cons (car x) 'enh-ruby-mode) x)) auto-mode-alist)) But it works only for the first file. The first ruby file I open is in enh-ruby-mode. But in the process the following command is executed:
/usr/share/emacs/26.3/lisp/progmodes/ruby-mode.el.gz:
;;;###autoload (add-to-list 'auto-mode-alist (cons (purecopy (concat "\\(?:\\.\\(?:" "rbw?\\|ru\\|rake\\|thor" "\\|jbuilder\\|rabl\\|gemspec\\|podspec" "\\)" "\\|/" "\\(?:Gem\\|Rake\\|Cap\\|Thor" "\\|Puppet\\|Berks" "\\|Vagrant\\|Guard\\|Pod\\)file" "\\)\\'")) 'ruby-mode)) (The same line is in /usr/share/emacs/26.3/lisp/loaddefs.el.) Which means the second and the following files are opened in ruby-mode.
I guess to remedy this I've got to not change the line in auto-mode-alist, but add one. Anyways, how does this autoload thing work? When does loaddefs.el get executed? Is there a way to keep the line out of the file?
auto-mode-alistas they see fit. I would open a bug report. In the meantime, you can force the autoload with(require 'ruby-mode)in your init file and then hackauto-mode-alistto your heart's content.ruby-mode, how doesemacsknow that it has to updateauto-mode-alist? Okay, probably fromloaddefs.el. But is it a generated file? When does the generation happen? When isloaddefsexecuted? And why does requiringruby-modesolve it?emacsis built,ruby-mode'sadd-to-listcall is copied toloaddefs.el. As such whenemacsstartsruby-modeis set up to be used for ruby files. But it also provides forruby-modefunction to be autoloaded. Then when I changeauto-mode-alist, something triggers the function,rube-mode.elgets loaded, and the line is back inauto-mode-alist.