On Friday, 30 November 2012 at 23:13:10 UTC, Aytug wrote:
So I have installed dmd, gdc, emacs and d-mode.el on my Debian
machine.
I can compile the program fine with M-compile. The problem
starts
after that.
I cannot run the output file properly from within emacs. Either
there is a way and I cannot find it, or there really is no way.
What I try instead:
1. Write the sourcecode.
2. M-compile.
3. Launch a separate terminal, and run the executable from
there.
Or,
3. Launch a shell in emacs, and use that. Which sucks.
What am I doing wrong? Isn't there a "compile&run" option? And
one more thing, is there maybe a C-* alternative to M-compile
since it takes time to type that everytime?
I use the lisp code below. Then from the source with main I do:
C-c @ To run the main in the current buffer
C-c # To run the unit test in the current buffer
Thanks
Dan
---------------------- lisp code
(defun unittest-d-file (args)
(interactive "sEnter args:")
(setq fname (buffer-file-name))
(setq cmdStr (concat "time rdmd -unittest --main \"" fname
"\" " args))
(setq buffname (format "*%s*" cmdStr))
(save-excursion
(message (concat "Running:" cmdStr))
(if (not (eq nil (get-buffer buffname))) (kill-buffer
buffname))
(setq compilation-scroll-output t)
(compile cmdStr)
(set-buffer "*compilation*")
(rename-buffer buffname t)
))
(defun run-current-file-args (args)
(let (extention-alist fname suffix progName cmdStr)
(setq extention-alist ; a keyed list of file suffix to
comand-line program to run
'(
("php" . "php")
("pl" . "perl")
("py" . "python")
("rb" . "ruby")
("rspec" . "rspec")
("js" . "js")
("sh" . "bash")
("bash" . "bash")
("ml" . "ocaml")
("vbs" . "cscript")
("java" . "javac")
("go" . "rungo.sh")
("d" . "rdmd")
("html" . "firefox")
)
)
(setq fname (buffer-file-name))
(setq suffix (file-name-extension fname))
(setq progName (cdr (assoc suffix extention-alist)))
(setq cmdStr (concat "time " progName " \"" fname "\" "
args))
(setq buffname (format "*%s*" cmdStr))
(if (string-equal suffix "el")
(load-file fname)
(if progName ; is not nil
(save-excursion
(message (concat "Running:" cmdStr))
(if (not (eq nil (get-buffer buffname))) (kill-buffer
buffname))
(setq compilation-scroll-output t)
(compile cmdStr)
(set-buffer "*compilation*")
(rename-buffer buffname t)
(message "No recognized program file suffix for this
file.")
)))))
(defun run-current-file ()
"Execute or compile the current file.
For example, if the current buffer is the file x.pl,
then it'll call “perl x.pl” in a shell.
The file can be php, perl, python, ruby, javascript, bash, ocaml,
java.
File suffix is used to determine what program to run."
(interactive)
(run-current-file-args ""))
(defun run-current-file-prompt (args)
(interactive "sEnter args:")
(run-current-file-args args))
(global-set-key "\C-c@" 'run-current-file-prompt)
(global-set-key "\C-c#" 'unittest-d-file)
-------------------------------------------------------------------