I thought this would be simple when I tried to do it, however I'm stuck.
When I add octave-mode to my ~/.emacs thus:
(add-to-list 'auto-mode-alist ("\\.m$" . octave-mode))
Opening an Octave file, .m, I instead end up in the OBJC major mode ... this is because auto-mode-alist contains:
(\.m\' . objc-mode)
which comes first in the A-list.
I've tried:
(setq auto-mode-alist (delete '( \.m\' . objc-mode) auto-mode-alist))
and I've even tried:
(setq ama '())
(setq objc '(\.m\' . objc-mode))
(dolist (item auto-mode-alist)
(if (not (eq (cdr (last objc)) (cdr (last item))))
(setq ama (list ama item))))
(setq auto-mode-alist ama)
Any suggestions on either removing the objc-mode from the alist or ensuring that octave-mode supercedes it would be great.
There are essentially two questions here. One is how to remove the element from the list. The other is how to automatically open *.m
files in octave-mode. You shouldn't need to remove the element to override it. The provided form
(add-to-list 'auto-mode-alist ("\\.m$" . octave-mode))
causes an error. Instead you should use
(add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))
or better yet:
(add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))
These two forms will add the element to the beginning of the association list, meaning filenames will be checked against it first, never making it to the objc-mode element lower down the list.
If you really want to remove the element from the list, here are a couple of ways.
One way that only deletes the exact cons cell '("\\.m\\'" . objc-mode)
:
(setq auto-mode-alist (delete '("\\.m\\'" . objc-mode) auto-mode-alist))
Another way that will delete anything in the association list associated with "\\.m\\'"
:
(require 'cl-lib)
(cl-remove "\\.m\\'" auto-mode-alist :test 'equal :key 'car)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With