rusty@sdcarl.UUCP (rusty c. wright) (06/29/85)
I decided that since i don't like the *scratch* buffer being put in lisp mode that i should be able to fix my .emacs file to put it in fundamental mode. That i was able to do. Then i decided that i should be able to disable the automatic setting of c mode in a similar fashion. The following is what i came up with, but it doesn't work (for c mode; it works fine for the *scratch* buffer). If i type in the if statement manually (using esc esc [eval-expression]) it works, but it won't work when it is used thusly in my .emacs file. What's wrong? (setq find-file-hook (progn (if (string-equal (eval mode-name) "C") (fundamental-mode)) (if (string-equal (buffer-name) "*scratch*") (fundamental-mode)) ) ) As far as i'm concerned, c mode is much too "clever" for my tastes. It has way too many stylistic decisions built into it to be generally useful (and besides, the style used is especially hideous). -- rusty c. wright {ucbvax,ihnp4,akgua,hplabs,sdcsvax}!sdcarl!rusty
buehring@waltz (07/05/85)
[No, no, you don't understand how radio works...] To make *scratch* start out in a certain mode, just put the commands to do it at the end of your .emacs file -- I do this... ;;; initial mode for *scratch* (text-mode) (auto-fill-mode 1) A word about "hooks" -- a hook holds the SYMBOL for a function to be called at a later time (see FUNCALL). For instance. (setq find-file-hook 'fundamental-mode) or you can use lambda to contruct a short function for the hook... (setq text-mode-hook '(lambda () (auto-fill-mode 1) (setq fill-column 78))) But doing this... (setq find-file-hook (progn (if (string-equal (eval mode-name) "C") (fundamental-mode)) (if (string-equal (buffer-name) "*scratch*") (fundamental-mode)) ) ) causes the mode to be set NOW and mearly assigns the hook the value of the result (probably nil). If you want to override C mode on files that end in ".c", the right place to do it is the auto mode list. You could snarf the following from "loaddefs.el" and modify it for your .emacs file (change "defvar" to "setq" and delete the doc string). (defvar auto-mode-alist '(("\\.text$" . text-mode) ("\\.text~$" . text-mode) ("\\.texinfo$" . texinfo-mode) ("\\.texinfo~$" . texinfo-mode) ;; Mailer puts message to be edited in /tmp/Re.... or Message ("^/tmp/Re" . text-mode) ("/Message[0-9]*$" . text-mode) ("\\.c$" . c-mode) ("\\.c~$" . c-mode) ("\\.h$" . c-mode) ("\\.h~$" . c-mode) ("\\.y$" . c-mode) ("\\.y~$" . c-mode) ("\\.scm$" . lisp-mode) ("\\.scm~$" . lisp-mode) ("\\..*emacs" . lisp-mode) ("\\.el$" . lisp-mode) ("\\.el~$" . lisp-mode) ("\\.ml$" . lisp-mode) ("\\.ml~$" . lisp-mode) ("\\.l$" . lisp-mode) ("\\.l~$" . lisp-mode)) "Alist of filename patterns vs corresponding major mode functions. Each element looks like (REGEXP . FUNCTION). Visiting a file whose name matches REGEXP causes FUNCTION to be called.") Ain't Lisp Grand? /Walt/ ARPA: Buehring%Waltz%TI-CSL@CSNet-Relay UUCP: {convex!smu, texsun, ut-sally, rice} ! waltz ! buehring
vijay@topaz.ARPA (P. Vijay) (07/08/85)
In article <34300005@waltz>, buehring@waltz writes: > > If you want to override C mode on files that end in ".c", the right > place to do it is the auto mode list. You could snarf the following > from "loaddefs.el" and modify it for your .emacs file (change > "defvar" to "setq" and delete the doc string). > > [Lists the auto-mode-list definition] > It is better to write a function that zaps your pattern/mode combination in place, in the variable. This way, if the emacs maintainer on site decides to change the mode settings for various patterns, you don't have to update your .emacs. I use the following function to do my customization. ;;; Set up my own auto-mode assoc. list..... ;;; Major differences from the system defaults are for Mailer generated ;;; file names like /tmp/Re..., etc. Instead of text-mode, I want ;;; Mail-mode ;;; (defun Fix-Auto-Mode-Alist (File-Name-Pattern Major-Mode-Function) "Searches auto-mode-alist for a cons pair with FILE-NAME-PATTERN as its car. If found, MAJOR-MODE-FUNCTION is rplacd in place. If not found, (FILE-NAME-PATTERN . MAJOR-MODE-FUNCTION) is added to auto-mode-alist." (interactive "sFile name pattern (regexp): \nSMajor mode function: \n") (let ((temp (assoc File-Name-Pattern auto-mode-alist))) (if temp (rplacd temp Major-Mode-Function) (setq auto-mode-alist (nconc auto-mode-alist (list (cons File-Name-Pattern Major-Mode-Function)) ))))) ;; Vnews/PostNews stuff (Fix-Auto-Mode-Alist "^/tmp/rep[0-9]+$" 'mail-mode) (Fix-Auto-Mode-Alist "^/tmp/post[0-9]+$" 'text-mode) As I noted above, I don't have to worry about anyone changing the default auto-mode-alist, by adding more patterns, etc... --Vijay--