Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 313895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:09:01+00:00 2026-05-12T08:09:01+00:00

I’m a user of Aquamacs under OS X, which by default does not recognize

  • 0

I’m a user of Aquamacs under OS X, which by default does not recognize .m files as Objective-C but instead treats them as matlab files – from the mailing list, the reason for this is that it was felt by the maintainer that he wanted a clean way to distinguish Obj-C files from others before he added a solution into the distribution.

Thus, I was trying to come up with a proper magic-mode-alist that would help to properly identify Objective-C files and switch to the right mode – after some thought, it seemed like all I would nee to check for are the presence of one of three keywords:

@implementation
@interface
@protocol

Any Objectve-C file should have one of those strings in it, and they also would very likely not not be in a Matlab file.

I then tried coming up with a magic-mode-alist variant to recognize @implementation, my first try was:

(add-to-list
 'magic-mode-alist
 '(".*^\@implementation.*" . objc-mode))

Basically – check for @implementation anywhere in the file at the start of a line.

After putting this into my .emacs file though, it seemed to have no effect – opening a .m file with @implementation in it, did not switch to Obj-C mode.

Does anyone know what the issue might be with my magic-mode-alist entry? The only examples I could find just matched text at the very beginning of a file (for nxml-mode), and not for strings in the middle of a file. It seems like something must be wrong with my regex, but as noted a few variants of the same theme seemed to have no effect.

I have working entries in my .emacs file for auto-mode-alist to pull up the right mode today so I don’t need any advice on how to do that, I’d like to solve this the “right” way.

EDIT:

Thanks to the accepted response below, here is the final code I have in my .Emacs file:

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

Note that I use “\n” as a replacement for “^” (beginning of line) in the regex, as it’s important to accurately determine the type – otherwise the .emacs file itself would come up in obj-c mode just because @implementation was in there.

Something else to be aware of I came across researching this is that magic-mode-alist is only given a certain number of characters at the beginning of a file to work with (defined by magic-mode-regexp-match-limit, with default of 4000 characters), presumably for performance reasons. Normally that’s more than enough to find the start of @implementation or @interface blocks, but if you insert revision comments in the headers of files as some people do, you may need to increase this substantially. Just as a backup, I plan to also include the code that makes .m files always open in obj-mode using auto-mode-alist, since my Matlab days are far behind me – but hopefully this magic-mode change can go into the official distribution of Aquamacs at least, if not Emacs 23 itself (the regexs probably should be beefed up a little more for that to happen).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:09:01+00:00Added an answer on May 12, 2026 at 8:09 am

    In emacs regular expressions, . does not match newlines. Also, the ^ character is not special (matching beginning of line) unless it’s the first character in the regexp (for historical reasons, according to the manual).

    So you need something like:

    (add-to-list
     'magic-mode-alist
     '("\\(.\\|\n\\)*@implementation" . objc-mode))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
In order to apply a triggered animation to all ToolTip s in my app,
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.