summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranck Cuny <franckcuny@gmail.com>2016-02-22 13:55:10 -0800
committerFranck Cuny <franckcuny@gmail.com>2016-02-22 13:55:10 -0800
commitc0111fe313edf4b8bc13cd0f3702853f5b61b766 (patch)
tree74e86ca5226361bf5b74d145514b8bebb27e33cf
parent[emacs] start to rewrite the code to manage the UI (diff)
downloademacs.d-c0111fe313edf4b8bc13cd0f3702853f5b61b766.tar.gz
[emacs] move functions for pants to it's own file
-rw-r--r--emacs.d/core/core-defun.el63
-rw-r--r--emacs.d/core/core-load-paths.el1
-rw-r--r--emacs.d/core/core-pants.el65
3 files changed, 66 insertions, 63 deletions
diff --git a/emacs.d/core/core-defun.el b/emacs.d/core/core-defun.el
index 855d17f..5180e68 100644
--- a/emacs.d/core/core-defun.el
+++ b/emacs.d/core/core-defun.el
@@ -39,67 +39,4 @@
(ansi-term (getenv "SHELL")))
(switch-to-buffer-other-window "*ansi-term*")))
-;; this functions are to make it easy to work with `pants'
-(defvar fcuny/build-command "cd ~/src/source && ./pants --no-colors"
- "Command to use to execute the target")
-
-(defvar fcuny/build-file "BUILD"
- "Name of the file containing our build targets")
-
-(defun fcuny/--find-directory-containing-build-file (file)
- "Find the directory containing the build file."
- (let ((root nil)
- try)
- (while (not (or root
- (null file)
- (string-match locate-dominating-stop-dir-regexp file)))
- (setq try (if (stringp fcuny/build-file)
- (file-exists-p (expand-file-name fcuny/build-file file))))
- (cond (try (setq root file))
- ((equal file (setq file (file-name-directory
- (directory-file-name file))))
- (setq file nil))))
- (and root (expand-file-name (file-name-as-directory root)))))
-
-(defun fcuny/--build-action (target)
- (compile (format "%s binary %s" fcuny/build-command target)))
-
-(defun fcuny/--build-target-list (file)
- "Generate a list of existing targets"
- (let ((build-command (format "%s list %s:" fcuny/build-command file))
- targets target)
- (with-temp-buffer
- (insert
- (shell-command-to-string build-command))
- (goto-char (point-min))
- (while (re-search-forward "^\\(.+\\)$" nil t)
- (setq target (match-string 1))
- (unless (or (save-excursion
- (goto-char (match-beginning 0))
- (forward-line -1)
- (looking-at "^# Not a target:"))
- (string-match "^\\." target))
- (push target targets))))
- (helm
- (helm :sources
- `((name . "Targets")
- (candidates . ,targets)
- (action . fcuny/build-action))))))
-
-(defun fcuny/find-build-file ()
- "Find the build file and if it exists, open it."
- (interactive)
- (let ((build-file (fcuny/--find-directory-containing-build-file (file-name-directory (buffer-file-name)))))
- (if build-file
- (find-file (concat build-file fcuny/build-file))
- (error "Could not find %s" fcuny/build-file))))
-
-(defun fcuny/build-run-target ()
- "List the targets for a BUILD file."
- (interactive)
- (let ((build-file (fcuny/--find-directory-containing-build-file (file-name-directory (buffer-file-name)))))
- (if build-file
- (fcuny/--build-target-list build-file)
- (error "Could not find %s" fcuny/build-file))))
-
(provide 'core-defun)
diff --git a/emacs.d/core/core-load-paths.el b/emacs.d/core/core-load-paths.el
index e7258cd..e3ae7ec 100644
--- a/emacs.d/core/core-load-paths.el
+++ b/emacs.d/core/core-load-paths.el
@@ -10,4 +10,5 @@
(require 'core-org)
(require 'core-autocompletion)
(require 'core-bindings)
+(require 'core-pants)
(require 'core-modes)
diff --git a/emacs.d/core/core-pants.el b/emacs.d/core/core-pants.el
new file mode 100644
index 0000000..af3b35d
--- /dev/null
+++ b/emacs.d/core/core-pants.el
@@ -0,0 +1,65 @@
+;; this functions are to make it easy to work with `pants'
+
+(defvar fcuny/build-command "cd ~/src/source && ./pants --no-colors"
+ "Command to use to execute the target")
+
+(defvar fcuny/build-file "BUILD"
+ "Name of the file containing our build targets")
+
+(defun fcuny/--find-directory-containing-build-file (file)
+ "Find the directory containing the build file."
+ (let ((root nil)
+ try)
+ (while (not (or root
+ (null file)
+ (string-match locate-dominating-stop-dir-regexp file)))
+ (setq try (if (stringp fcuny/build-file)
+ (file-exists-p (expand-file-name fcuny/build-file file))))
+ (cond (try (setq root file))
+ ((equal file (setq file (file-name-directory
+ (directory-file-name file))))
+ (setq file nil))))
+ (and root (expand-file-name (file-name-as-directory root)))))
+
+(defun fcuny/--build-action (target)
+ (compile (format "%s binary %s" fcuny/build-command target)))
+
+(defun fcuny/--build-target-list (file)
+ "Generate a list of existing targets"
+ (let ((build-command (format "%s list %s:" fcuny/build-command file))
+ targets target)
+ (with-temp-buffer
+ (insert
+ (shell-command-to-string build-command))
+ (goto-char (point-min))
+ (while (re-search-forward "^\\(.+\\)$" nil t)
+ (setq target (match-string 1))
+ (unless (or (save-excursion
+ (goto-char (match-beginning 0))
+ (forward-line -1)
+ (looking-at "^# Not a target:"))
+ (string-match "^\\." target))
+ (push target targets))))
+ (helm
+ (helm :sources
+ `((name . "Targets")
+ (candidates . ,targets)
+ (action . fcuny/--build-action))))))
+
+(defun fcuny/find-build-file ()
+ "Find the build file and if it exists, open it."
+ (interactive)
+ (let ((build-file (fcuny/--find-directory-containing-build-file (file-name-directory (buffer-file-name)))))
+ (if build-file
+ (find-file (concat build-file fcuny/build-file))
+ (error "Could not find %s" fcuny/build-file))))
+
+(defun fcuny/build-run-target ()
+ "List the targets for a BUILD file."
+ (interactive)
+ (let ((build-file (fcuny/--find-directory-containing-build-file (file-name-directory (buffer-file-name)))))
+ (if build-file
+ (fcuny/--build-target-list build-file)
+ (error "Could not find %s" fcuny/build-file))))
+
+(provide 'core-pants)