Last update August 18, 2012

Editor Support /
Emacs Editor

d-mode for Emacs

The currently maintained version of the d-mode, compatible with Emacs 23 and Emacs 24, can be found at its development page at Github.

This is the d-mode written from scratch by Bill Baxter and currently maintained by a small team of contributors.

Support for older Emacsen

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

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.

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.

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)
 '("^\\([^ \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: August 18, 2012 18:39 (diff))