From 9a707ae30d6a0d8e9acccef69641499e5805b2c7 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 20 Jul 2017 11:18:28 +0100 Subject: [PATCH] dot/emacs, el/dot-emacs.el: Improve compilation machinery. Allow setting of a compilation directory, by making the prefix-argument machinery much more complicated. --- dot/emacs | 2 +- el/dot-emacs.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/dot/emacs b/dot/emacs index bc89bfd..49dbe70 100644 --- a/dot/emacs +++ b/dot/emacs @@ -620,7 +620,7 @@ (global-set-key [?\C-c ?p ?<] 'mdw-mpc-prev) (global-set-key [?\C-c ?p ?>] 'mdw-mpc-next) (global-set-key [?\C-c ?p ??] 'mdw-mpc-now-playing) - (global-set-key [?\C-c ?k] 'compile) + (global-set-key [?\C-c ?k] 'mdw-compile) (global-set-key [?\C-x ?3] 'mdw-split-window-horizontally) (global-set-key [?\M-#] 'calc-dispatch) (global-set-key [?\C-x ?/] 'auto-fill-mode) diff --git a/el/dot-emacs.el b/el/dot-emacs.el index 6b19dab..93cec99 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -293,6 +293,56 @@ it's currently off." (or transient-mark-mode (setq transient-mark-mode 'only)) (set-mark (mark t))))) +;; Improved compilation machinery. + +(setq compile-command + (let ((ncpu (with-temp-buffer + (insert-file-contents "/proc/cpuinfo") + (buffer-string) + (count-matches "^processor\\s-*:")))) + (format "make -j%d -k" (* 2 ncpu)))) + +(defun mdw-compilation-buffer-name (mode) + (concat "*" (downcase mode) ": " + (abbreviate-file-name default-directory) "*")) +(setq compilation-buffer-name-function 'mdw-compilation-buffer-name) + +(eval-after-load "compile" + '(progn + (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile))) + +(defun mdw-compile (command &optional directory comint) + "Initiate a compilation COMMAND, maybe in a different DIRECTORY. +The DIRECTORY may be nil to not change. If COMINT is t, then +start an interactive compilation. + +Interactively, prompt for the command if the variable +`compilation-read-command' is non-nil, or if requested through +the prefix argument. Prompt for the directory, and run +interactively, if requested through the prefix. + +Use a prefix of 4, 5, 6, or 7, or type C-u between one and three times, to +force prompting for a directory. + +Use a prefix of 2, 3, 6, or 7, or type C-u three times, to force +prompting for the command. + +Use a prefix of 1, 3, 5, or 7, or type C-u twoce or three times, +to force interactive compilation." + (interactive + (let* ((prefix (prefix-numeric-value current-prefix-arg)) + (command (eval compile-command)) + (dir (and (plusp (logand prefix #x54)) + (read-directory-name "Compile in directory: ")))) + (list (if (or compilation-read-command + (plusp (logand prefix #x42))) + (compilation-read-command command) + command) + dir + (plusp (logand prefix #x51))))) + (let ((default-directory (or directory default-directory))) + (compile command comint))) + ;; Functions for sexp diary entries. (defun mdw-not-org-mode (form) -- 2.11.0