frede@hpwale.HP.COM (Fred Ehrhardt) (02/08/88)
Can anyone answer a question about modifying Gnuemacs' auto-mode-alist? I'd like files with a .c suffix to cause c++-mode to be loaded and run, and files with a .doc suffix to invoke nroff-mode. The Gnu manual suggests that this can be done using E-lisp. If I have to modify auto-mode-alist, how do I do this, either for me alone, or for all users on my system (default.el??) ? Thanks for the help, Fred Ehrhardt Hewlett-Packard Waltham Division
rsnyder@hpesoc1.HP.COM (Rob Snyder) (02/10/88)
Try putting this in you .el file: (setq auto-mode-alist (cons '("\\.c" . c++-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.doc" . nroff-mode) auto-mode-alist)) Rob Snyder Hewlett-Packard Entry Systems Operation Cupertino, CA Disclaimer: blah blah, blah, yakety, yak, yak, and so on and so forth
wolfgang@mgm.mit.edu (Wolfgang Rupprecht) (02/10/88)
You can add new modes by adding this to your .emacs file: (setq auto-mode-alist (cons '("\\.foo$" . foo-mode) auto-mode-alist)) This will put all files ending in the '.foo' extension into foo-mode. Alternately, you may put the above line into the file ~emacs/lisp/site-load.el (and re-make emacs) if you want to make it a system-wide default. -wolfgang --- Wolfgang Rupprecht ARPA: wolfgang@mgm.mit.edu (IP 18.82.0.114) 326 Commonwealth Ave. UUCP: mit-eddie!mgm.mit.edu!wolfgang Boston, Ma. 02115 TEL: (617) 267-4365
ras@blade.UUCP (R.A. Schnitzler) (02/13/88)
Posting-Front-End: GNU Emacs 18.41.4 of Fri May 22 1987 on blade (berkeley-unix) Rob Snyder (and other people) have suggested solutions such as: > (setq auto-mode-alist > (cons '("\\.c" . c++-mode) auto-mode-alist)) > (setq auto-mode-alist > (cons '("\\.doc" . nroff-mode) auto-mode-alist)) This certainly is fine, but I find it a bit cumbersome. Since no one else has mentioned this, here is my simple way of doing this: (defun auto-mode (pattern function) (setq auto-mode-alist (cons (cons pattern function) auto-mode-alist))) (auto-mode "\\.doc" 'nroff-mode) (auto-mode "\\.c" 'c++-mode) etc. By introducing the function, I make the declaration of modes more readable, and it is conceptually easier for me to add/delete/change/review them. "It's worse than that, Ray Schnitzler it's physics, Jim" Bell Communication Research arpa: schnitz!bellcore.com uucp: ...!bellcore!schnitz -- "It's worse than that, Ray Schnitzler it's physics, Jim" Bell Communication Research arpa: schnitz!bellcore.com uucp: ...!bellcore!schnitz
warsaw@cme-durer.ARPA (Barry A. Warsaw) (02/13/88)
In article <3990004@hpesoc1.HP.COM>, rsnyder@hpesoc1.HP.COM (Rob Snyder) writes: > Try putting this in you .el file: > (setq auto-mode-alist > (cons '("\\.c" . c++-mode) auto-mode-alist)) > (setq auto-mode-alist > (cons '("\\.doc" . nroff-mode) auto-mode-alist)) > > Rob Snyder > Hewlett-Packard Entry Systems Operation > Cupertino, CA > > Disclaimer: blah blah, blah, yakety, yak, yak, and so on and so forth I use the following line to set text-mode on the files that vnews uses to reply and followup to articles: (setq auto-mode-alist (append '(("^/tmp/\\(post\\|fol\\)a[0-9]*" . text-mode) auto-mode-alist))) My question is: what's the difference between using append and cons? Is there a difference? I think I used a template I saw in one of gnu's .el files
arc1@eagle.ukc.ac.uk (A.R.Curtis) (02/14/88)
In article <760003@hpwale.HP.COM> frede@hpwale.HP.COM (Fred Ehrhardt) writes: >Can anyone answer a question about modifying Gnuemacs' auto-mode-alist? >I'd like files with a .c suffix to cause c++-mode to be loaded and run, >and files with a .doc suffix to invoke nroff-mode. The Gnu manual >suggests that this can be done using E-lisp. Ok, suppose we do it just for yourself. I've never installed emacs (what a shame) and so I can't really help you there (though intuition tells me that defaults.el might be right). The auto-mode-alist consists of a list of pairs associating file name patterns with modes (..... ("\\.c$" . c++-mode) ("\\.doc$" . nroff-mode) .....) would be what you want. I have things like this in my .emacs, e.g. ;;; all files ending ".n(roff)", ".doc(ument)" are assumed to be for nroff. (if (assoc "\\.n$" auto-mode-alist) nil (nconc auto-mode-alist '(("\\.n$" . nroff-mode)))) (if (assoc "\\.doc$" auto-mode-alist) nil (nconc auto-mode-alist '(("\\.doc$" . nroff-mode)))) (plus some others....) Hope this is of some help Tony .-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-. | Tony Curtis |Computing Lab., Univ. Kent At Canterbury | | ..!mcvax!ukc!arc1 arc1@uk.ac.ukc |Canterbury, Kent CT2 7NZ | `-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-'
markl@PTT.LCS.MIT.EDU (02/16/88)
From: warsaw@cme-durer.ARPA (Barry A. Warsaw) Date: 12 Feb 88 21:37:43 GMT Organization: National Bureau of Standards (setq auto-mode-alist (append '(("^/tmp/\\(post\\|fol\\)a[0-9]*" . text-mode) auto-mode-alist))) My question is: what's the difference between using append and cons? Is there a difference? I think I used a template I saw in one of gnu's .el files From the documentation: ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- append: Concatenate arguments and make the result a list. The result is a list whose elements are the elements of all the arguments. Each argument may be a list, vector or string. cons: Create a new cons, give it CAR and CDR as components, and return it. ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- One immediately obvious difference is therefore that (append nil '(a)) gives '(a) whereas (cons nil '(a)) gives '(nil a). markl Internet: markl@ptt.lcs.mit.edu Mark L. Lambert MIT Laboratory for Computer Science Distributed Systems Group ----------
frede@hpwale.HP.COM (Fred Ehrhardt) (02/17/88)
Thanks to the suggestions from several Net-ters, I've wound up with this Elisp code in my .emacs. This lets c++-mode override the c-mode in the original auto-mode-alist. (setq auto-mode-alist (append '(("\\.c$" . c++-mode) ("\\.doc$" . nroff-mode)) auto-mode-alist))