[OS X Emacs] Answer to magic-mode-alist question - using to trigger obj-c mode

Kendall Gelner kendall.gelner at kigisoftware.com
Sat Aug 15 13:54:16 EDT 2009


I asked a question a few weeks ago on this list on how to fix a magic- 
mode-alist entry that was meant to properly recognize Objective-C files.

I didn't see an answer on the list, but I did get one from Stack  
Overflow:

http://stackoverflow.com/questions/1274986/how-to-get-emacs-magic-mode-alist-to-match-against-string-in-middle-of-file

To summarize, the final answer is:

(setq magic-mode-alist
       (append (list
	       '("\\(.\\|\n\\)*\n at implementation" . objc-mode)
	       '("\\(.\\|\n\\)*\n at interface" . objc-mode)
	       '("\\(.\\|\n\\)*\n at protocol" . objc-mode))
	      magic-mode-alist))

This solution has the happy side effect of .h files that are really  
C .h files still come up in the right mode (which is why you'd want  
magic-mode in the first place).

This I feel is a pretty robust fix - I included code in the regex to  
make sure each of those strings is at the beginning of a line, so  
random occurrences of "@implementation" or the other strings do not  
trigger the wrong mode.  Is there any direction as to how I can  
propose this get included in the official Aquamacs release?

If not, at least others on the list have the answer to a simple entry  
in .Emacs that will open Objective-C files in the right mode.

---> Kendall Gelner
        KiGi Software




More information about the MacOSX-Emacs mailing list