Joost has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I'm currently using xemacs with CPerl mode and it's working great except that I can't seem to find a mode / config setting to use for XS code.

My google/super searches haven't turned up any useful information. So, my question to whoever is using (x)emacs for XS code is: what's the "best" setting / mode to use for that?

Cheers,
Joost.

Replies are listed 'Best First'.
Re: XS mode for (x)emacs?
by Anonymous Monk on Aug 22, 2006 at 13:31 UTC
    perl/xs cperl

    http://rzlab.ucr.edu/debian/public_emacs

    ... set-key "\C-xp" 'gnuserv-edit) ;; Use c-mode for perl .xs files (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode)) (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-m +ode)) (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode)) (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode)) (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode)) (setq cperl-hairy t cperl-indent-level 4 ;; cperl-auto-newline t ;; cperl-auto-newline-after-colon t cperl-continued-statement-offset 4 cperl-brace-offset -4 cperl-label-offset -4 cperl-highlight-variables-indiscriminately t cperl-electric-lbrace-space nil ) (add-hook 'cperl-mode-hook (lambda () (cperl-set-style "K&R"))) (setq c-indent-level 8) (setq c-brace-imaginary-offset 0) (setq c-brace-offset -8) (setq c-argdecl-indent 8) (setq c-label-offset -8) ...

      As far as I can tell, the only thing relevant to XS there is

      (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))

      which is to say they set files ending in ".xs" to C mode. But XS files aren't C code. A snippet for example:

      # ----------------------------------------- MODULE = Mozilla::DOM PACKAGE = Mozilla::DOM::NSEvent PREFIX = m +oz_dom_ PRBool moz_dom_DispatchEvent (target, event) nsIDOMEventTarget *target; nsIDOMEvent *event; PREINIT: PRBool rv; CODE: target->DispatchEvent(event, &rv); RETVAL = rv; OUTPUT: RETVAL

      Though at a glance it looks like the syntax highlighting is okay in C mode. It would be neat if there was an XS mode, similar to mmm-mode in that it could use different modes in different regions of the page (e.g. in mmm-mode, the HTML is done differently than the %perl sections; the XS mode could distinguish the C code at the top from the XS code at the bottom).