Wednesday, May 20, 2009

nXhtml and Doxymacs

Update 2009-05-29: a simple fix makes doxymacs work with nXhtml and mumamo, courtesy of Lennart Borgman. This is required up to at least version 1.8.0 of doxymacs. Edit doxymacs.el or just redefine the function in your .emacs:

(defun doxymacs-font-lock ()                                                                   
  "Turn on font-lock for Doxygen keywords."                                                                                           
  ;; FIXME How do I turn *off* font-lock for Doxygen keywords?                                    
  (interactive)                                                                                                                                         
  (if (functionp 'font-lock-add-keywords)                                                                                         
      ;; Use new (proper?) font-lock-add-keywords function                                        
      ;;(font-lock-add-keywords nil doxymacs-doxygen-keywords)                             
      (font-lock-add-keywords major-mode doxymacs-doxygen-keywords)                                                                                     
    ;; Use old-school way                                                                         
    (let ((old (if (eq (car-safe font-lock-keywords) t)                                       
                 (cdr font-lock-keywords)                                                                                                                      
               font-lock-keywords)))                                                                                                                           
      (setq font-lock-keywords (append old doxymacs-doxygen-keywords)))))

nXhtml is very cool for writing code in HTML/PHP/JS/CSS/XSLT/... And you want to comment your code. Lately, that's been mostly PHP for me. The best Emacs-based solution seems to be Doxymacs. However, the two don't mix. nXhtml's mumamo-mode kills Doxymacs on major mode switches. Here's a quick solution:

(defun ensure-doxymacs-mode ()
    (doxymacs-mode 1)
  )
(add-hook 'php-mode-hook 'ensure-doxymacs-mode)

I also tried to get Doxymacs font-locking to work with some similar tricks, but that seems to require quite a lot more work. It just isn't seem to be worth it.

No comments:

Post a Comment