Created
December 24, 2016 10:15
-
-
Save Swoorup/16414600b5da17c555606976526a22b1 to your computer and use it in GitHub Desktop.
d-lang helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; This file was obtained from | |
;; http://forum.dlang.org/post/wcqxlaceqljsdsultiie@forum.dlang.org | |
(defun run-current-project-args (args) | |
(setq cmdStr (concat "time dub " 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) | |
(projectile-with-default-dir (projectile-project-root) | |
(compile cmdStr) | |
;; (async-shell-command cmdStr) | |
) | |
(set-buffer "*running dub*") | |
(rename-buffer buffname t) | |
)) | |
(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)) | |
(defun run-current-project () | |
(interactive) | |
(run-current-project-args "")) | |
(provide 'd-lang) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment