Use setf
setf
to change the value in place:
(setf (cdr (rassoc 'javascript-mode auto-mode-alist)) 'js2-mode)
If you want to replace a value in the list, then setf
is the generalized machinery you need to do so. For the more idiomatic way to deal with the auto-mode-alist
, see @Drew's answer (and his explanation of shadowing).