summaryrefslogtreecommitdiff
path: root/lisp/km-compile.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2016-01-10 23:43:14 -0500
committerKyle Meyer <kyle@kyleam.com>2016-01-12 22:15:25 -0500
commit8d97d1f2063f19c0c679e54fc082691a495c9303 (patch)
tree77cc0ce12ecceb5739b5d0e35a5bc2eab09a9adc /lisp/km-compile.el
parent2d395ef1ccedd51e3c11b1eb8ff552f03bae4797 (diff)
downloademacs.d-8d97d1f2063f19c0c679e54fc082691a495c9303.tar.gz
Rewrite configuration with use-package
Diffstat (limited to 'lisp/km-compile.el')
-rw-r--r--lisp/km-compile.el94
1 files changed, 94 insertions, 0 deletions
diff --git a/lisp/km-compile.el b/lisp/km-compile.el
new file mode 100644
index 0000000..4812afd
--- /dev/null
+++ b/lisp/km-compile.el
@@ -0,0 +1,94 @@
+;;; km-compile.el --- Compilation extensions
+
+;; Copyright (C) 2012-2016 Kyle Meyer <kyle@kyleam.com>
+
+;; Author: Kyle Meyer <kyle@kyleam.com>
+;; URL: https://github.com/kyleam/emacs.d
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+
+(require 'compile)
+(require 'dash)
+
+(defvar km/compilation-buffer-name-prefix "compilation: ")
+
+(defun km/compilation-name-by-directory (&optional mode)
+ (let ((name (if (and mode (not (equal mode "compilation")))
+ (downcase mode)
+ (concat km/compilation-buffer-name-prefix
+ (abbreviate-file-name default-directory)))))
+ (concat "*" name "*")))
+
+(defun km/compilation-buffer-p (buffer)
+ (with-current-buffer buffer
+ (and (derived-mode-p 'compilation-mode)
+ (string-prefix-p (concat "*" km/compilation-buffer-name-prefix)
+ (buffer-name)))))
+
+;;;###autoload
+(defun km/compile-in-home-dir ()
+ (interactive)
+ (let ((default-directory "~/"))
+ (call-interactively #'compile)))
+
+;;;###autoload
+(defun km/compilation-recompile (&optional arg)
+ "Recompile buffer.
+By default, use `compilation-last-buffer'. If ARG is 0, get
+buffer with name given by `km/compilation-name-by-directory'.
+Otherwise, if ARG is non-nil, prompt with buffers from
+`km/compilation-buffer-list'."
+ (interactive (list (and current-prefix-arg
+ (prefix-numeric-value current-prefix-arg))))
+ (with-current-buffer (km/compilation--get-buffer arg)
+ (if (derived-mode-p 'occur-mode)
+ (revert-buffer)
+ (recompile))))
+
+(defun km/compilation-display-buffer (&optional arg)
+ "Display compilation buffer.
+By default, use `compilation-last-buffer'. If ARG is 0, get
+buffer with name given by `km/compilation-name-by-directory'.
+Otherwise, if ARG is non-nil, prompt with buffers from
+`km/compilation-buffer-list'."
+ (interactive (list (and current-prefix-arg
+ (prefix-numeric-value current-prefix-arg))))
+ (display-buffer (km/compilation--get-buffer arg)))
+
+(defun km/compilation--get-buffer (&optional arg)
+ (cond
+ ((and (not arg)
+ (buffer-live-p compilation-last-buffer)
+ compilation-last-buffer))
+ ((and (numberp arg)
+ (= arg 0))
+ (get-buffer (km/compilation-name-by-directory)))
+ (t
+ (let ((cbufs (-map #'buffer-name (km/compilation-buffer-list)))
+ buf)
+ (cl-case (length cbufs)
+ (0 (user-error "No compilation buffers found"))
+ (1 (setq buf (car cbufs)))
+ (t (setq buf (completing-read "Compilation buffer: " cbufs
+ nil nil nil nil (car cbufs)))))
+ buf))))
+
+(defun km/compilation-buffer-list ()
+ (-filter #'km/compilation-buffer-p (buffer-list)))
+
+(provide 'km-compile)
+;;; km-compile.el ends here