Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

running D from emacs

By: a guest on Nov 30th, 2012  |  syntax: Lisp  |  size: 2.42 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (defun unittest-d-file (args)
  2.   (interactive "sEnter args:")
  3.   (setq fname (buffer-file-name))
  4.   (setq cmdStr (concat "time rdmd -unittest --main \""   fname "\" " args))
  5.   (setq buffname (format "*%s*" cmdStr))
  6.   (save-excursion
  7.     (message (concat "Running:" cmdStr))
  8.     (if (not (eq nil (get-buffer buffname))) (kill-buffer buffname))
  9.     (setq compilation-scroll-output t)
  10.     (compile cmdStr)
  11.     (set-buffer "*compilation*")
  12.     (rename-buffer buffname t)
  13.     ))
  14.  
  15. (defun run-current-file-args (args)
  16.   (let (extention-alist fname suffix progName cmdStr)
  17.     (setq extention-alist ; a keyed list of file suffix to comand-line program to run
  18.           '(
  19.             ("php" . "php")
  20.             ("pl" . "perl")
  21.             ("py" . "python")
  22.             ("rb" . "ruby")
  23.             ("rspec" . "rspec")
  24.             ("js" . "js")
  25.             ("sh" . "bash")
  26.             ("bash" . "bash")
  27.             ("ml" . "ocaml")
  28.             ("vbs" . "cscript")
  29.             ("java" . "javac")
  30.             ("go" . "rungo.sh")
  31.             ("d" . "rdmd")
  32.             ("html" . "firefox")
  33.             )
  34.           )
  35.     (setq fname (buffer-file-name))
  36.     (setq suffix (file-name-extension fname))
  37.     (setq progName (cdr (assoc suffix extention-alist)))
  38.     (setq cmdStr (concat "time " progName " \""   fname "\" " args))
  39.     (setq buffname (format "*%s*" cmdStr))
  40.  
  41.     (if (string-equal suffix "el")
  42.         (load-file fname)
  43.       (if progName                    ; is not nil
  44.           (save-excursion
  45.             (message (concat "Running:" cmdStr))
  46.             (if (not (eq nil (get-buffer buffname))) (kill-buffer buffname))
  47.             (setq compilation-scroll-output t)
  48.             (compile cmdStr)
  49.             (set-buffer "*compilation*")
  50.             (rename-buffer buffname t)
  51.         (message "No recognized program file suffix for this file.")
  52.         )))))
  53.  
  54. (defun run-current-file ()
  55.   "Execute or compile the current file.
  56. For example, if the current buffer is the file x.pl,
  57. then it'll call “perl x.pl” in a shell.
  58. The file can be php, perl, python, ruby, javascript, bash, ocaml, java.
  59. File suffix is used to determine what program to run."
  60.   (interactive)
  61.   (run-current-file-args ""))
  62.  
  63. (defun run-current-file-prompt (args)
  64.   (interactive "sEnter args:")
  65.   (run-current-file-args args))
  66.  
  67. (global-set-key "\C-c@"         'run-current-file-prompt)
  68. (global-set-key "\C-c#"         'unittest-d-file)