Last update June 3, 2010

Editor Support /
Emacs Editor



Option 1: EmacsDMode is the latest D-mode for Emacs. It is a rewrite of D-mode from scratch. Put it into your emacs site-lisp directory and follow the instructions in the d-mode.el file to compile the file and add the proper auto-load setup to your .emacs file. This version requires a recent cc-mode (>5.30), so if you're using an earlier version of cc-mode, it's time to upgrade. The new cc-mode is all around much better. See also DProgrammingLanguage page at EmacsWiki.

Option 2: For D support on Emacs 21.x only is Ben Hinkle's mode. The zip file d-mode.zip contains both d-mode and a few other tools that may or may not work on newer versions of emacs.

Note: Ben's version above does not work on versions of Emacs greater than 21.x. I've tried on 22.0.something and on a cvs checkout (23.0.0, emacs-unicode-2 branch), and the d-mode command caused the same errors on both. It seems like there might be some sort of api mismatch or something, but that's just a guess. -- MichaelA September 20, 2006

Option 3: If that doesn't work for you then you can try java-mode. That seems to do a pretty decent job on D code. It's better than c++-mode, at least. Newer versions of emacs may have a csharp-mode too.

Sort of an Option 3, but not really: For emacs 22.x, if you Google you may find another d-mode.el by Sam Steingold. This is not a d-mode for the D Programming Langauge, but a d-mode for some sort of C-like extension language for CLISP: CLISP's d-mode (Here's an example of that other D code if you're curious). The funny thing is that this actually does a reasonable job formatting and highlighting DigitalMars D code. I was using it happily for weeks before I realized it was a mode for the wrong D.

History

  • Updated Dec 7, 2003 by Ben Hinkle ( NG:D/19993).
  • Updated Feb 24, 2007 by Bill Baxter
  • Updated Mar 2, 2007 by Bill Baxter

Emacs 22 for Win32

A note for windows Emacs users -- you can get a more recent version of emacs for Windows than the FSF's 21.x from the EmacsW32 project. But word I hear is that Emacs 22 will be release "Officially" before too long, then you'll be able to find it for Windows from the FSF emacs site. Apparently it's not too difficult to build from sources either.

Support for Compilation (M-x compile)

Many of DMD's compilation error messages lack a category prefix (like "Error" or "Warning"). Without the category, the messages don't match Emacs' built-in error matching regexps used for M-x next-error after a M-x compile. That makes M-x compile unable to take you to the the file and line where the error is.

Add this to your .emacs and it should fix it.

(require 'compile)
(add-to-list
 'compilation-error-regexp-alist
 '("^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|.\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
   1 2 nil (3 . 4)))

Also (this is Windows-specific) but if you don't have your DMD stuff always added to your path by default, you can add it in your .emacs. I always have an environment variable set called "DMDDIR" that points to where DMD is installed. Then I add this to my .emacs (uncomment the INCLUDE part if you have some default includes you want to add):

; modify executable path to include DMD stuff
(setq exec-path (cons "C:/dmd/bin" exec-path))
; Or this more tricky version that uses a DMDDIR environment variable
;(setq exec-path (cons 
;		 (concat (replace-regexp-in-string "\\\\" "/" (getenv "DMDDIR")) "/dmd/bin")
;		 exec-path))
(let ((DMDDIR (getenv "DMDDIR")))
  (setenv "PATH" 
	  (concat DMDDIR "\\dmd\\bin;" 
		  DMDDIR "\\dm\\bin;" 
		  DMDDIR "\\dsss\\bin;"
		  (getenv "PATH") ))
  (setenv "LIB" 
	  (concat DMDDIR "\\dmd\\lib;" 
		  DMDDIR "\\dm\\lib;" 
		  (getenv "LIB") ))
;  (setenv "INCLUDE" 
;	  (concat DMDDIR "\\dmd\\lib;" 
;		  DMDDIR "\\dm\\lib;" 
;		  (getenv "INCLUDE") ))
  )

Support for flymake

Flymake-mode is a mode for emacs which compiles edited files in the background and highlights possible errors. Here is a version modified to support dsss building.

(Note: the link above is currently broken. I've added a Flymake configuration example to the EmacsWiki?. -- GrahamFawcett?)

If you want to automatically enable flymake when editing .d files just add following somewhere where emacs can find it (.emacs):

(add-hook 'd-mode-hook 'flymake-mode)

Change the d-mode-hook to something else if you're not in d-mode while editing .d -files.

FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: June 3, 2010 21:06 (diff))