[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 114ae96 070/399: counsel.el: Find project root more flexib
From: |
Oleh Krehel |
Subject: |
[elpa] master 114ae96 070/399: counsel.el: Find project root more flexibly |
Date: |
Sat, 20 Jul 2019 14:56:51 -0400 (EDT) |
branch: master
commit 114ae9635fe59bff127042d59f35017f10161566
Author: Basil L. Contovounesios <address@hidden>
Commit: Oleh Krehel <address@hidden>
counsel.el: Find project root more flexibly
(counsel-compile-root-function): Remove, replacing with...
(counsel-compile-root-functions): ...this new variable.
(counsel-project-current): Remove, replacing with...
(counsel--compile-root): ...this new function.
(counsel--root-project, counsel--root-dir-locals)
(counsel--root-git): New functions.
(counsel-locate-git-root): Use counsel--root-git.
(counsel-compile-get-make-invocation)
(counsel-compile-get-build-directories)
(counsel-compile-get-filtered-history)
(counsel-compile--update-history): Use counsel--compile-root.
Fixes #1963
---
counsel.el | 48 ++++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 14 deletions(-)
diff --git a/counsel.el b/counsel.el
index c92925b..f8e6e8a 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1181,7 +1181,7 @@ Like `locate-dominating-file', but DIR defaults to
(defun counsel-locate-git-root ()
"Return the root of the Git repository containing the current buffer."
- (or (counsel--dominating-file ".git")
+ (or (counsel--root-git)
(error "Not in a Git repository")))
;;;###autoload
@@ -5119,17 +5119,37 @@ The properties include:
This variable is suitable for addition to
`savehist-additional-variables'.")
-(defvar counsel-compile-root-function #'counsel-project-current
- "Function to find the project root for compile commands.")
-
-(defun counsel-project-current ()
- "Locate the root of the project by trying a series of things."
- (or (and (fboundp 'project-current)
- (cdr (project-current)))
- (counsel--dominating-file ".dir-locals.el")
- (counsel--dominating-file ".git")
+(defvar counsel-compile-root-functions
+ '(counsel--root-project
+ counsel--root-dir-locals
+ counsel--root-git)
+ "Special hook to find the project root for compile commands.
+Each function on this hook is called in turn with no arguments
+and should return either a directory, or nil if no root was
+found.")
+
+(defun counsel--compile-root ()
+ "Return root of current project or signal an error on failure.
+The root is determined by `counsel-compile-root-functions'."
+ (or (run-hook-with-args-until-success 'counsel-compile-root-functions)
(error "Couldn't find project root")))
+(defun counsel--root-project ()
+ "Return root of current project or nil on failure.
+Use `project-current' to determine the root."
+ (and (fboundp 'project-current)
+ (cdr (project-current))))
+
+(defun counsel--root-dir-locals ()
+ "Return root of current project or nil on failure.
+Use the presence of a `dir-locals-file' to determine the root."
+ (counsel--dominating-file dir-locals-file))
+
+(defun counsel--root-git ()
+ "Return root of current project or nil on failure.
+Use the presence of a \".git\" file to determine the root."
+ (counsel--dominating-file ".git"))
+
(defvar counsel-compile-local-builds
'(counsel-compile-get-filtered-history
counsel-compile-get-build-directories
@@ -5189,7 +5209,7 @@ make -nqp |\
The optional BLDDIR is useful for other helpers that have found
subdirectories that builds may be invoked in."
- (let ((srcdir (funcall counsel-compile-root-function)))
+ (let ((srcdir (counsel--compile-root)))
(when (directory-files (or blddir srcdir) nil
counsel-compile-make-pattern t)
(counsel--get-make-targets srcdir blddir))))
@@ -5211,7 +5231,7 @@ subdirectories that builds may be invoked in."
(defun counsel-compile-get-build-directories (&optional dir)
"Return a list of potential build directories."
- (let* ((srcdir (or dir (funcall counsel-compile-root-function)))
+ (let* ((srcdir (or dir (counsel--compile-root)))
(blddir (counsel--find-build-subdir srcdir))
(props `(srcdir ,srcdir blddir ,blddir recursive t)))
(mapcar (lambda (s)
@@ -5225,7 +5245,7 @@ subdirectories that builds may be invoked in."
;; No easy way to make directory local, would buffer local make more sense?
(defun counsel-compile-get-filtered-history (&optional dir)
"Return a compile history relevant to current project."
- (let ((root (or dir (funcall counsel-compile-root-function)))
+ (let ((root (or dir (counsel--compile-root)))
history)
(dolist (item counsel-compile-history)
(let ((srcdir (get-text-property 0 'srcdir item))
@@ -5255,7 +5275,7 @@ This is determined by `counsel-compile-local-builds',
which see."
;; things like infer `default-directory' from 'cd's in the string.
(defun counsel-compile--update-history (_proc)
"Update `counsel-compile-history' from the compilation state."
- (let* ((srcdir (funcall counsel-compile-root-function))
+ (let* ((srcdir (counsel--compile-root))
(blddir default-directory)
(cmd (concat
(propertize (car compilation-arguments) 'cmd t)
- [elpa] master c2788de 082/399: counsel.el (counsel--switch-buffer-update-fn): if to cond, (continued)
- [elpa] master c2788de 082/399: counsel.el (counsel--switch-buffer-update-fn): if to cond, Oleh Krehel, 2019/07/20
- [elpa] master 1439e8d 064/399: counsel.el: Simplify compile build dir collection, Oleh Krehel, 2019/07/20
- [elpa] master 7e8a362 068/399: counsel.el (counsel--get-make-targets): Clean up, Oleh Krehel, 2019/07/20
- [elpa] master d64b268 074/399: counsel.el (counsel-compile): counsel--get-build-subdirs, Oleh Krehel, 2019/07/20
- [elpa] master 6f0f32f 084/399: counsel.el (counsel-git-grep-count-function): Promote to defcustom, Oleh Krehel, 2019/07/20
- [elpa] master 25336fd 075/399: counsel.el (counsel-compile): counsel-compile-local-builds, Oleh Krehel, 2019/07/20
- [elpa] master db905cc 088/399: counsel.el (counsel-compile-phony-pattern): Use plain regex, Oleh Krehel, 2019/07/20
- [elpa] master 4e07e6f 048/399: ivy.el (ivy-make-magic-action): Add docstring to the generated lambda, Oleh Krehel, 2019/07/20
- [elpa] master 8a40934 062/399: counsel.el: Clean up compile candidates list, Oleh Krehel, 2019/07/20
- [elpa] master 0c30e3f 063/399: counsel.el: Minor compile history cleanup, Oleh Krehel, 2019/07/20
- [elpa] master 114ae96 070/399: counsel.el: Find project root more flexibly,
Oleh Krehel <=
- [elpa] master 5aa263c 079/399: counsel.el (counsel-compile-make-pattern): Fix regex, Oleh Krehel, 2019/07/20
- [elpa] master cc50da2 080/399: counsel.el (counsel-dired-jump-args): Fix -type d, Oleh Krehel, 2019/07/20
- [elpa] master a473519 086/399: Fix error in ivy-make-magic-action, Oleh Krehel, 2019/07/20
- [elpa] master 9ce9e4e 090/399: counsel.el (counsel-compile-phony-pattern): Fixup, Oleh Krehel, 2019/07/20
- [elpa] master 1046fc7 095/399: ivy.el (ivy-avy): Use non-obsolete avy-process, Oleh Krehel, 2019/07/20
- [elpa] master 27add46 092/399: Anchor pcre lookaround patterns to bol, Oleh Krehel, 2019/07/20
- [elpa] master 3e1e905 083/399: Fix virtual buffers in counsel-switch-buffer, Oleh Krehel, 2019/07/20
- [elpa] master cbdc9c9 078/399: counsel.el (counsel--compile-get-make-targets): Rename, Oleh Krehel, 2019/07/20
- [elpa] master e7146e5 089/399: counsel.el (counsel-git-grep-count-function): Fix, Oleh Krehel, 2019/07/20
- [elpa] master b180abf 087/399: counsel.el (counsel-compile): clean-up get-make-targets, Oleh Krehel, 2019/07/20