I'm not sure whether the use of apply
is recommended here. Is there a better/standard solution for setting the major mode dynamically? I cou开发者_如何学Cldn't find any other.
Background:
Whenever I get the
X has auto save data; consider M-x recover-this-file
message in Emacs, I wonder what the difference between the current file and the auto-save version is. Since most of the time I can't be bothered to look it up, I tried to automate the task:
(defun ediff-auto-save ()
"Ediff current file and its auto-save pendant."
(interactive)
(let ((auto-file-name (make-auto-save-file-name))
(file-major-mode major-mode))
(ediff-files buffer-file-name auto-file-name)
(switch-to-buffer-other-window (file-name-nondirectory auto-file-name))
(apply file-major-mode '())
(other-window 1))) ;; back to ediff panel
The code does what I want, it opens the auto-save file and starts ediff. I also set the auto-save file's major mode to the major mode of the original file for consistent font lock.
While apply can certainly be used for this, funcall might be better suited
(funcall file-major-mode)
it differs from apply in that it doesn't take a list of arguments, just the arguments. Both of the following are equivalent:
(funcall '+ 1 2)
(apply '+ '(1 2))
It looks fine to me - that's what apply is for.
Besides, you said it yourself: the code does what you want! :-)
精彩评论