May 2004 Archives
May 28, 2004

More on XEmacs for MacOS X

Apple | Emacs

Hooray! I managed to get XEmacs' internal buffer structure hooked up into Cocoa's text system!

The first step was to build a library from the XEmacs source code, which I could link against my Cocoa-based project. This was pretty straightforward, adding a couple of defines and ifdefs to remove the main function from the library. I also added some rules to the makefile to build the actual library.

Then I built a very simple editor application using Cocoa's default text classes. Once this worked, I replaced the default NSTextStorage class with my own subclass that uses XEmacs' buffer internal structure to hold the characters. Since NSTextStorage's API makes use of NSString to get the string to be displayed, I also created a simple subclass of it, that accesses the characters directly from the buffer structure.

I can now edit my .bashrc file, insert, replace and delete characters in a window on screen, and have these operations reflect directly in the associated buffer structure.

One problem I need to solve is with Unicode characters. MacOS X APIs use unichar, a 16 bit short integer to represent Unicode characters, while XEmacs uses IChar, a 32 bit integer. I need to find a way to normalize XEmacs' multibyte characters to MacOS X's unicode characters. I haven't poked yet in the MacOS X's Foundation header files to see if there is anything that would do the job. If you know of something, please let me know.

The next step is to hook-up the XEmacs Lisp engine in the system. This is the first real challenge, since the important stuff in Emacs is done in Lisp.

Posted by ovidiu at 10:41 PM |
May 26, 2004

Mailing list for XEmacs on MacOS X


I've created a mailing list for discussing the port of XEmacs to MacOS X. The mailing list is hosted by the new Google Groups2. If you're interested, please visit and subscribe to the xemacs-macosx mailing list.

Posted by ovidiu at 08:29 PM |
May 23, 2004

NSTextStorage bug


This seems to be a well-known bug, but it took me three days of hunting to figure out what was going on :(

If you're trying to subclass the NSTextStorage class, you need to override one more method, in addition to the 4 methods described in Apple's documentation. The additional method is addAttribute:value:range::

- (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range;

Here is a simple NSTextStorage subclass that works in MacOS X 10.2, and hopefully in 10.3 as well:

@interface MyTextStorage : NSTextStorage {
  NSMutableAttributedString* string_;

@implementation MyTextStorage

- initWithAttributedString:(NSMutableAttributedString*)string
  [super init];
  string_ = [string retain];
  return self;

- (void)dealloc {
  [[NSNotificationCenter defaultCenter] removeObserver:self];
  [string_ release];
  [super dealloc];

- (NSString*)string
  return [string_ string];

- (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range
  [string_ addAttribute:name value:value range:range];

- (NSDictionary *)attributesAtIndex:(unsigned)index effectiveRange:(NSRangePointer)range
  return [string_ attributesAtIndex:index effectiveRange:range];

- (void)setAttributes:(NSDictionary *)attrs range:(NSRange)range {
  [string_ setAttributes:attrs range:range];

- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)string
  int origLen = [self length];
  [string_ replaceCharactersInRange:range withString:string];
  [self edited:NSTextStorageEditedCharacters range:range changeInLength:[self length] - origLen];


Update: This is strange. It looks like removing the call to [super init] in the -initWithAttributedString: method makes the system crash. The class works just fine with the super call, and the addAttribute:value:range: method definition removed. Really weird!

Posted by ovidiu at 07:08 PM |
May 20, 2004

gmail tips and tricks


If you're a gmail user, check out the gmail gems blog.

Especially useful are the search operators and the keyboard bindings.

Posted by ovidiu at 10:19 AM |
May 18, 2004

XEmacs on MacOS X

Apple | Emacs

For the past week I've been investigating porting XEmacs over MacOS X using the Cocoa, using the not-so-new text system, which is incredibly powerful.

All the previous attempts to port GNU Emacs or XEmacs to MacOS X have used the Carbon API, a lower level API used for compatibility with the older MacOS operating systems. The approach I have in mind plans to use the powerful display framework available in Cocoa.

So far I've investigated the internal organization of XEmacs and reviewed the major data structures. I don't have a rigorous plan yet, at this point I'm experimenting with different options available.

The best options so far seem to be the following:

  • provide an Objective-C wrapper on top of XEmacs' buffer structures, that make these appear as an NSTextStorage subclass.
  • for the display part, the NSTextView class provides most of the methods needed to implement the right display functionality. A proper Objective-C subclass would be able to intercept the mouse and keyboard events and update XEmacs' buffer structure with point information and new content.

Cocoa's display technology makes the display code in XEmacs redundant. One thing I'm worried about is the charset management and how to deal with different (and I think incompatible) methods for entering characters in different languages.

Nice to have, but non goals for this project:

  • Expose XEmacs' internals to languages other than Emacs Lisp: Python, Ruby etc. would be really nice. This way even more people would be exposed to this great editor.
  • port to GNUstep. Many years ago I contributed major components to this project. I don't know what is the status of the text system port in GNUstep.
Posted by ovidiu at 01:20 AM |
May 11, 2004

Google's official blog


Long overdue, Google finally has an official blog. This will hopefully help dissipate some of the misconceptions surrounding Google.

Posted by ovidiu at 09:13 AM |
Cool stuff
  Arduino TinyWebServer: part 3 and part 2
More from me
Picture gallery
Copyright © 2002-2016 Ovidiu Predescu.