[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 3c16fa1 055/399: counsel.el (counsel-compile): Clean up
From: |
Oleh Krehel |
Subject: |
[elpa] master 3c16fa1 055/399: counsel.el (counsel-compile): Clean up |
Date: |
Sat, 20 Jul 2019 14:56:48 -0400 (EDT) |
branch: master
commit 3c16fa1dea4fd9e1071166800076efbb0a5d494f
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
counsel.el (counsel-compile): Clean up
Re #1941
---
counsel.el | 77 ++++++++++++++++++++++++++------------------------------------
1 file changed, 32 insertions(+), 45 deletions(-)
diff --git a/counsel.el b/counsel.el
index fa6961a..66bff80 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1174,12 +1174,13 @@ selected face."
("x" counsel-find-file-extern "open externally")))
;; Common helper for counsel
-(defun counsel--find-project-root (&optional domfile startdir)
+(defun counsel--find-project-root (domfile &optional startdir)
"Traverse up from `default-directory' or STARTDIR until we find DOMFILE.
-Returns a fully expanded path."
- (expand-file-name (locate-dominating-file
- (or startdir default-directory)
- (or domfile ".git"))))
+Return a fully expanded path."
+ (expand-file-name
+ (locate-dominating-file
+ (or startdir default-directory)
+ domfile)))
(defun counsel-locate-git-root ()
"Locate the root of the git repository containing the current buffer."
@@ -5101,7 +5102,6 @@ in the current window."
:unwind #'counsel--switch-buffer-unwind
:update-fn 'counsel--switch-buffer-update-fn))
-
;;** `counsel-compile'
(defvar counsel-compile-history nil
"History for `counsel-compile'.
@@ -5122,21 +5122,15 @@ properties include:
If you want to persist history between Emacs sessions you can as this
to variable to `savehist-additional-variables'.")
-(defvar counsel-compile-root-function 'counsel-locate-project-dwim
+(defvar counsel-compile-root-function 'counsel-project-current
"Function to find the project root for compile commands.")
-;; alternative project root finder for counsel-compile-root-function
-(defun counsel-locate-dir-locals ()
- "Locate the root of the project by looking for .dir-locals."
- (or (counsel--find-project-root ".dir-locals.el")
- (error "Couldn't find .dir-locals")))
-
-(defun counsel-locate-project-dwim ()
+(defun counsel-project-current ()
"Locate the root of the project by trying a series of things."
(or (when (fboundp 'project-current)
- (project-current))
- (counsel-locate-dir-locals)
- (counsel-locate-git-root)
+ (cdr (project-current)))
+ (counsel--find-project-root ".dir-locals.el")
+ (counsel--find-project-root ".git")
(error "Couldn't find project root")))
(defvar counsel-compile-local-builds
@@ -5153,13 +5147,12 @@ build environments.")
(defcustom counsel-compile-make-args "-k"
"Additional arguments for make.
-You may for example want to add -jN for the number of cores your
- have"
+You may for example want to add -jN for the number of cores you have."
:type 'string)
-(defcustom counsel-compile-make-pattern
- (rx (or "m" "M" "GNUM") "akefile")
- "Pattern for matching against makefiles.")
+(defcustom counsel-compile-make-pattern "\\(?:GNUM\\|[Mm]\\)akefile"
+ "Pattern for matching against makefiles."
+ :type 'regex)
(defcustom counsel-compile-build-directories
'("build" "builds" "bld" ".build")
@@ -5176,7 +5169,7 @@ are tagged with properties that `counsel-compile-history'
can use for
filtering results."
(let ((default-directory (or blddir srcdir)))
(mapcar
- (lambda(target)
+ (lambda (target)
(propertize
(concat
(propertize
@@ -5260,30 +5253,27 @@ The optional BLDDIR is useful for other helpers that
have found
(defun counsel--get-compile-candidates (&optional dir)
"Return the list of compile commands as directed by
`counsel-compile-local-builds'."
- (let ((cands))
+ (let (cands)
(if (stringp counsel-compile-local-builds)
(setq cands (list counsel-compile-local-builds))
- (mapc
- (lambda (c)
- (let ((more-cands
- (cond
- ((functionp c)
- (let ((fcands (funcall c dir)))
- (if (and fcands (nlistp fcands))
- (list fcands)
- fcands)))
- ((stringp c) (list c))
- ((listp c) c))))
- (when more-cands
- (setq cands (nconc cands more-cands)))))
- counsel-compile-local-builds)
+ (dolist (c counsel-compile-local-builds)
+ (let ((more-cands
+ (cond
+ ((functionp c)
+ (let ((fcands (funcall c dir)))
+ (if (and fcands (nlistp fcands))
+ (list fcands)
+ fcands)))
+ ((stringp c) (list c))
+ ((listp c) c))))
+ (when more-cands
+ (setq cands (nconc cands more-cands)))))
cands)))
;; This is a workaround to ensure we tag all the relevant meta-data in
;; our compile history. This also allows M-x compile to do fancy
;; things like infer default-directory from cd's in the string.
-
-(defun counsel-compile--update-history(proc)
+(defun counsel-compile--update-history (_proc)
"Update `counsel-compile-history' from the compilation state."
(let ((srcdir (funcall counsel-compile-root-function))
(blddir default-directory)
@@ -5315,17 +5305,14 @@ to further refine the compile options in the directory
specified by `blddir'."
cmd 0 (if cmdprop
(next-single-property-change 0 'cmd cmd))))))))
-;;;###auto load
+;;;###autoload
(defun counsel-compile (&optional dir)
"Call `compile' completing with smart suggestions, optionally for DIR."
(interactive)
(add-hook 'compilation-start-hook 'counsel-compile--update-history)
(ivy-read "Compile command: "
(counsel--get-compile-candidates dir)
- :require-match nil
- :sort nil
- :action (lambda (x) (counsel-compile--wrapper x))))
-
+ :action #'counsel-compile--wrapper))
;;* `counsel-mode'
(defvar counsel-mode-map
- [elpa] master 51c5874 042/399: counsel.el (counsel-find-file-map): Bind "`" to bookmarks, (continued)
- [elpa] master 51c5874 042/399: counsel.el (counsel-find-file-map): Bind "`" to bookmarks, Oleh Krehel, 2019/07/20
- [elpa] master 3de074a 049/399: counsel.el (counsel-find-file-copy): Add and bind., Oleh Krehel, 2019/07/20
- [elpa] master a538df1 053/399: ivy.el (ivy-make-magic-action): Point doc to the action function, Oleh Krehel, 2019/07/20
- [elpa] master 84b5ece 050/399: counsel.el (counsel-find-file-copy): Use ivy-inhibit-action, Oleh Krehel, 2019/07/20
- [elpa] master 9e3c855 052/399: ivy.el (ivy-make-magic-action): Fix bug, Oleh Krehel, 2019/07/20
- [elpa] master 9cf3f08 045/399: swiper.el (swiper-use-visual-line-p): New variable, Oleh Krehel, 2019/07/20
- [elpa] master 15e2c88 051/399: Restore buffer-list after counsel-switch-buffers, Oleh Krehel, 2019/07/20
- [elpa] master 80d40e4 046/399: Dynamically handle grep tool look-arounds, Oleh Krehel, 2019/07/20
- [elpa] master 0a4ad42 047/399: ivy-test.el (counsel--grep-regex): Add test for negative lookahead, Oleh Krehel, 2019/07/20
- [elpa] master 5f4e944 057/399: counsel.el: Fix finding dominating file, Oleh Krehel, 2019/07/20
- [elpa] master 3c16fa1 055/399: counsel.el (counsel-compile): Clean up,
Oleh Krehel <=
- [elpa] master 876b4ac 059/399: counsel.el (counsel-compile): Minor cleanup, Oleh Krehel, 2019/07/20
- [elpa] master 56201b1 056/399: counsel.el: Remove cl-extra, Oleh Krehel, 2019/07/20
- [elpa] master 859e3cb 061/399: counsel.el: Clean up compile history keeping, Oleh Krehel, 2019/07/20
- [elpa] master 072f238 058/399: counsel.el: Capitalize proper noun "Git", Oleh Krehel, 2019/07/20
- [elpa] master 5f5a263 054/399: counsel.el (counsel-compile): Add, Oleh Krehel, 2019/07/20
- [elpa] master adea72f 060/399: counsel.el: Simplify counsel-compile action, Oleh Krehel, 2019/07/20
- [elpa] master 50dc9e6 065/399: counsel.el (counsel--get-build-subdirs): Fix, Oleh Krehel, 2019/07/20
- [elpa] master 4e0d403 066/399: counsel.el (counsel--find-build-subdir): Simplify, Oleh Krehel, 2019/07/20
- [elpa] master 144e7d9 069/399: counsel.el: Clean up recent compile variables, Oleh Krehel, 2019/07/20
- [elpa] master 82e6c54 067/399: counsel.el: Clean up compile make invocation, Oleh Krehel, 2019/07/20