[Arcana] Fwd: emacs mode question

Roland McGrath roland at frob.com
Thu Jun 18 16:50:03 CDT 2009

I switched to the Emacs weenie list.

I was going to mention the hack below that I've used for ages.
It popped to mind if you want to punt on real magic magic and just
tailor for some trivial heuristics that work well enough in your own life.
(I have another one for add-log-mailing-address-by-file-name-alist.)

But you don't need any new hooks for this approach, actually.
Just add '("blah-project/.*\.h$" . objc-mode) elts to auto-mode-alist.

 (defconst c-set-style-by-file-name-alist
   '(("/linux/" . "linux")
     ("elfutils" . "gnu")
     ("/redhat/" . "gnu")
     ("/gnu/" . "gnu")
   "Alist (REGEXP . STRING) of regexps to match buffer-file-name.
The STRING of the earliest matching elt is a style for `c-set-style'
A REGEXP that is not a string always matches, so use t for a default elt.")
 (defun c-set-style-by-file-name ()
   "Call c-set-style with arg from c-set-style-by-file-name-alist elt
matching buffer-file-name, if any match."
   (if buffer-file-name
	 (let ((aname (abbreviate-file-name buffer-file-name))
	       (tail c-set-style-by-file-name-alist))
	   (while (and tail
		       (stringp (car (car tail)))
		       (not (string-match (car (car tail)) buffer-file-name))
		       (not (string-match (car (car tail)) aname))
	     (setq tail (cdr tail)))
	   (if tail
	       (c-set-style (cdr (car tail))))))))
 (add-hook 'c-mode-common-hook 'c-set-style-by-file-name)


More information about the Arcana mailing list