www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Compile And Run in emacs

reply "Aytug" <aytuggurbuz gmail.com> writes:
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?
Nov 30 2012
next sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 11/30/2012 03:13 PM, 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.
I have the following in my Makefile: deneme: ${ALL_FILES} ${DMD} ${SOURCES} ${LIBRARIES} -of$ ${OPTIONS} ./$ The last line there executes the program that has just been built. As an aside, if you do C-u,M-x,compile then you can interact with the program's standard input as well.
 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?
You can set any key binding that you like in Emacs. I've never bothered to change it though: A quick M-x,M-p brings up the last compile command and I just hit Enter. (M-p is a key binding of mine that works better with the Dvorak keyboard, which means "up".) Ali -- D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html
Nov 30 2012
prev sibling next sibling parent reply "Dan" <dbdavidson yahoo.com> writes:
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 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) -------------------------------------------------------------------
Nov 30 2012
parent reply "Dan" <dbdavidson yahoo.com> writes:
The lisp code: http://pastebin.com/myAABm5G
Nov 30 2012
parent "Aytug" <aytuggurbuz gmail.com> writes:
On Friday, 30 November 2012 at 23:40:42 UTC, Dan wrote:
 The lisp code: http://pastebin.com/myAABm5G
Thanks Dan, that was really helpful :)
Nov 30 2012
prev sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 12/01/2012 12:13 AM, 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?
It is emacs. Every key binding is a possible alternative. I use (global-set-key (kbd "\C-c c") 'compile) (global-set-key (kbd "\C-c n") 'next-error) Usually I just run non-interactive programs from within compile, M-x compile dmd -run program args <<< "program input" or M-x compile make && ./program args <<< "program input" or just M-x compile ./program args <<< "program input" or even M-x gdb r <<< "program input" otherwise I have a separate console (are you using a sane window manager?) or use M-x ansi-term.
Nov 30 2012