🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.help
Article #189842

Re: c++-mode.el

#189842
From: Josh Mittleman
Date: Tue, 06 Nov 1990 16:19
49 lines
2554 bytes
The automatic invocation of a mode based on the filename extension is
controlled by the variable auto-mode-alist, which contains association
pairs of the form ("\\.c$" . c-mode).  To have c++-mode automatically
invoked for files with a ".cc" extension, for example, you need to add
a new cons onto this list:

(setq auto-mode-alist (cons '("\\.cc$" . c++-mode)))

We now run into a couple problems.  The first is that c++-mode is not
defined by default (at least not in my emacs).  I added the following
code to my .emacs file to load it when needed:

(defun c++-mode ()
  "Load and start up c++-mode"
  (interactive)
  (autoload 'c++-mode "c++-mode")
  (c++-mode))

The second problem is that you may want to have c++-mode invoked for
*.h files.  auto-mode-alist already has a cons for that, which loads
c-mode.  There may be an easier solution to this problem, but I solved
it by adding this to my .emacs file, too.  It arranges that c++-mode
will be invoked for all *.C and *.h, and removes the duplicate entry
from auto-mode-alist.  It isn't elegant, but it works.

(defun strip-h (alist)
  (let ((first (car alist)))
    (cond
     ((not first)
      nil)
     ((string= (car first) "\\.h$")
      (cdr alist))
     (t
      (cons (car alist) (strip-h (cdr alist)))))))


(if (not (assoc "\\.C$" auto-mode-alist))
    (setq auto-mode-alist (cons '("\\.C$" . c++-mode) auto-mode-alist)))
(let ((h-file-mode (assoc "\\.h$" auto-mode-alist)))
  (cond ((not h-file-mode)
  (setq auto-mode-alist (cons '("\\.h$" . c++-mode) auto-mode-alist)))
 ((not (eq (cdr h-file-mode) 'c++-mode))
  (setq auto-mode-alist (cons '("\\.h$" . c++-mode) 
         (strip-h auto-mode-alist))))))
-- 

------------------------------------------------------------------------------
Joshua Mittleman (mittle@ibm.com or joshua@paul.rutgers.edu)
J2-C28 T.J. Watson Research Institute, PO Box 704, Yorktown Heights, NY  10598
Technical Details
Message-ID: <Nov.6.11.19.27.1990.4109@yoko.rutgers.edu>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!bu.edu!shelby!rutgers!aramis.rutgers.edu!paul.rutgers.edu!yoko.rutgers.edu!joshua
References: <125503@linus.mitre.org>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 103b8b,10c7f806c9b1fa88
X-Google-Attributes: gid103b8b,public
X-Google-ArrivalTime: 1990-11-06 08:19:31 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!bu.edu!shelby!rutgers!aramis.rutgers.edu!paul.rutgers.edu!yoko.rutgers.edu!joshua
From: joshua@yoko.rutgers.edu (Josh Mittleman)
Newsgroups: gnu.emacs.help
Subject: Re: c++-mode.el
Message-ID: <Nov.6.11.19.27.1990.4109@yoko.rutgers.edu>
Date: 6 Nov 90 16:19:31 GMT
References: <125503@linus.mitre.org>
Organization: Rutgers Univ., New Brunswick, N.J.
Lines: 49
Posted: Tue Nov  6 17:19:31 1990