0

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?

  • This looks like a land grab to me: it should be up to the users to set auto-mode-alist as 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 hack auto-mode-alist to your heart's content. – NickD Jul 23 at 2:38
  • @NickD Can you possibly explain how it works? Without requiring ruby-mode, how does emacs know that it has to update auto-mode-alist? Okay, probably from loaddefs.el. But is it a generated file? When does the generation happen? When is loaddefs executed? And why does requiring ruby-mode solve it? – x-yuri Jul 23 at 9:55
  • My guess is that when emacs is built, ruby-mode's add-to-list call is copied to loaddefs.el. As such when emacs starts ruby-mode is set up to be used for ruby files. But it also provides for ruby-mode function to be autoloaded. Then when I change auto-mode-alist, something triggers the function, rube-mode.el gets loaded, and the line is back in auto-mode-alist. – x-yuri Jul 24 at 8:05
  • @NickD You might want to check out my answer. Also, if you're going to file a bug report, please add a link here afterwards. – x-yuri Jul 24 at 9:06
  • I don't use ruby or ruby-mode or enh-ruby-mode, so I'm not going to file a bug report. – NickD Jul 24 at 16:49
0

The thing can be reproduced with expand-region package installed.

From what I can see, when enh-ruby-mode gets activated, expand-region loads enh-ruby-mode-expansions.el. But that in its turn loads ruby-mode-expansions.el, which requires ruby-mode.el.

As a result, when you open a ruby file, enh-ruby-mode gets activated, but still ruby-mode.el is also loaded.

So, if I change auto-mode-alist in my init file, then when I open a ruby file, ruby-mode.el gets executed, and adds the association with ruby-mode back.

To avoid that one has to require ruby-mode.el in advance (before opening ruby files).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.