chiark / gitweb /
dot/emacs, el/dot-emacs.el: Improve compilation machinery.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 20 Jul 2017 10:18:28 +0000 (11:18 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 20 Jul 2017 10:22:56 +0000 (11:22 +0100)
Allow setting of a compilation directory, by making the prefix-argument
machinery much more complicated.

dot/emacs
el/dot-emacs.el

index bc89bfd869a26ae3ef6c67ed03bff713a737ce46..49dbe7079afe6ff89ad3922b5d8ed74a09c5552c 100644 (file)
--- a/dot/emacs
+++ b/dot/emacs
   (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)
index 6b19dab1164ac08a93e1bd25f0143d6dac3dd5d7..93cec991399651715731a525c4931c8372d43bde 100644 (file)
@@ -293,6 +293,56 @@ (defadvice exchange-point-and-mark
         (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)