comparison lisp/files.el @ 76258:ec75921d5b7b

(set-auto-mode-0): Use `indirect-function'. (hack-one-local-variable): Don't reapply current major mode.
author Chong Yidong <cyd@stupidchicken.com>
date Thu, 01 Mar 2007 17:06:40 +0000
parents bebed32eb12f
children 2a5ebeee48fc edf631bdbb7a ec58e5c426ef
comparison
equal deleted inserted replaced
76257:50979609adb0 76258:ec75921d5b7b
2283 (defun set-auto-mode-0 (mode &optional keep-mode-if-same) 2283 (defun set-auto-mode-0 (mode &optional keep-mode-if-same)
2284 "Apply MODE and return it. 2284 "Apply MODE and return it.
2285 If optional arg KEEP-MODE-IF-SAME is non-nil, MODE is chased of 2285 If optional arg KEEP-MODE-IF-SAME is non-nil, MODE is chased of
2286 any aliases and compared to current major mode. If they are the 2286 any aliases and compared to current major mode. If they are the
2287 same, do nothing and return nil." 2287 same, do nothing and return nil."
2288 (when keep-mode-if-same 2288 (unless (and keep-mode-if-same
2289 (while (symbolp (symbol-function mode)) 2289 (eq (indirect-function mode)
2290 (setq mode (symbol-function mode))) 2290 (indirect-function major-mode)))
2291 (if (eq mode major-mode) 2291 (when mode
2292 (setq mode nil))) 2292 (funcall mode)
2293 (when mode 2293 mode)))
2294 (funcall mode)
2295 mode))
2296 2294
2297 (defun set-auto-mode-1 () 2295 (defun set-auto-mode-1 ()
2298 "Find the -*- spec in the buffer. 2296 "Find the -*- spec in the buffer.
2299 Call with point at the place to start searching from. 2297 Call with point at the place to start searching from.
2300 If one is found, set point to the beginning 2298 If one is found, set point to the beginning
2809 (if (funcall function exp) 2807 (if (funcall function exp)
2810 (setq ok t))) 2808 (setq ok t)))
2811 ok))))))) 2809 ok)))))))
2812 2810
2813 (defun hack-one-local-variable (var val) 2811 (defun hack-one-local-variable (var val)
2814 "Set local variable VAR with value VAL." 2812 "Set local variable VAR with value VAL.
2813 If VAR is `mode', call `VAL-mode' as a function unless it's
2814 already the major mode."
2815 (cond ((eq var 'mode) 2815 (cond ((eq var 'mode)
2816 (funcall (intern (concat (downcase (symbol-name val)) "-mode")))) 2816 (let ((mode (intern (concat (downcase (symbol-name val))
2817 "-mode"))))
2818 (unless (eq (indirect-function mode)
2819 (indirect-function major-mode))
2820 (funcall mode))))
2817 ((eq var 'eval) 2821 ((eq var 'eval)
2818 (save-excursion (eval val))) 2822 (save-excursion (eval val)))
2819 (t 2823 (t
2820 ;; Make sure the string has no text properties. 2824 ;; Make sure the string has no text properties.
2821 ;; Some text properties can get evaluated in various ways, 2825 ;; Some text properties can get evaluated in various ways,