简体   繁体   中英

Overwriting auto load for a major mode

I want to set auto mode for files that have a particular name like this:

(add-to-list 'auto-mode-alist '("\\particular-file-name\\'" . some-major-mode))

This seems to work, but when there is another auto mode preset for the same file name, then the preset one seems to have priority, and my setting is ignored. How can I override that or disable the preset? Particularly, I want to have all files named config to have a certain major mode, but Conf[Unix] mode seems to have priority over my setting.

It probably happens due to

;;;###autoload
(add-to-list 'auto-mode-alist '(...))

in the major-mode el file. The autoload instructions are evaluated after ~/.emacs .

You can try to load your setup in the after-init-hook

(add-hook 'after-init-hook
      (function (lambda()
          (add-to-list 'auto-mode-alist '(...)))))

It might be better when ;;;###autoload users would append their entries to auto-mode-list (setting the APPEND option of add-to-list ). But this seems to be uncommon.

There is an error in your regexp, it would not match the filename ("config") the correct regexp is

1) If you want to match a file named 'config'

"config\\'"

2) If you want to match files with extension '.config'

"\\.config\\'"

In case you are wondering \\' matches end of the string. In your regexp the string \\\\ translates to a \\ in regexp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM