[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master b180abf 087/399: counsel.el (counsel-compile): clean-up ge
From: |
Oleh Krehel |
Subject: |
[elpa] master b180abf 087/399: counsel.el (counsel-compile): clean-up get-make-targets |
Date: |
Sat, 20 Jul 2019 14:56:54 -0400 (EDT) |
branch: master
commit b180abf2cb8149047245df8b35ac8ae2f9c5b9f0
Author: Alex Bennée <address@hidden>
Commit: Oleh Krehel <address@hidden>
counsel.el (counsel-compile): clean-up get-make-targets
The original code called a pipeline of shell functions to get the list
of PHONY targets. One of the consequence of this is we picked up a
bunch of noise if the make crapped out with an error. To avoid this we
bring all the text extraction into emacs with a temp buffer and only
process it if make is happy.
This is also a first step towards what we would need if we wanted to
use counsel--async-command to gather stuff and update the targets
dynamically.
---
v2
- use bare form of (rx) for phony macro
- tweak wording in comments
- push/nconc/sort the results
- revert de-hyphenating
- let*->let
Fixes #1972
---
counsel.el | 46 +++++++++++++++++++++++++++++++---------------
1 file changed, 31 insertions(+), 15 deletions(-)
diff --git a/counsel.el b/counsel.el
index 27eeb1e..bbe6884 100644
--- a/counsel.el
+++ b/counsel.el
@@ -5196,32 +5196,48 @@ N in your system."
"List of potential build subdirectory names to check for."
:type '(repeat directory))
+(defvar counsel-compile-phony-pattern
+ (rx bol ".PHONY:" space (group (+ print)) eol)
+ "Regexp for extracting phony targets from Makefiles.")
+
;; This is loosely based on the Bash Make completion code
+(defun counsel-compile--probe-make-targets (dir)
+ "Return a list of Make targets for DIR.
+
+Return an empty list is Make exits with an error. This might
+happen because some sort of configuration needs to be done first
+or the source tree is pristine and being used for multiple build
+trees."
+ (let ((default-directory dir)
+ (targets))
+ (with-temp-buffer
+ ;; 0 = no-rebuild, -q & 1 needs rebuild, 2 error (for GNUMake at
+ ;; least)
+ (when (> 2 (call-process "make" nil t nil "-nqp"))
+ (goto-char (point-min))
+ (while (re-search-forward counsel-compile-phony-pattern nil t)
+ (push (split-string (match-string-no-properties 1))
+ targets))))
+ (sort (apply #'nconc targets) 'string-lessp)))
+
(defun counsel--compile-get-make-targets (srcdir &optional blddir)
"Return a list of Make targets for a given SRCDIR/BLDDIR combination.
We search the Makefile for a list of phony targets which are
-generally the top-level targets a Make system provides.
+generally the top level targets a Make system provides.
The resulting strings are tagged with properties that
`counsel-compile-history' can use for filtering results."
- (let* ((default-directory (or blddir srcdir))
- (fmt (format (propertize "make %s %%s" 'cmd t)
- counsel-compile-make-args))
- (suffix (and blddir
- (concat (propertize " in " 'face 'font-lock-warning-face)
- (propertize blddir 'face 'dired-directory))))
- (props `(srcdir ,srcdir blddir ,default-directory)))
+ (let ((fmt (format (propertize "make %s %%s" 'cmd t)
+ counsel-compile-make-args))
+ (suffix (and blddir
+ (concat (propertize " in " 'face 'font-lock-warning-face)
+ (propertize blddir 'face 'dired-directory))))
+ (props `(srcdir ,srcdir blddir ,default-directory)))
(mapcar (lambda (target)
(setq target (concat (format fmt target) suffix))
(add-text-properties 0 (length target) props target)
target)
- (split-string (shell-command-to-string "\
-make -nqp |\
- grep -B 1 PHONY |\
- grep ':' |\
- cut -d ':' -f 1 |\
- sort")
- "\n"))))
+ (counsel-compile--probe-make-targets (or blddir srcdir)))))
(defun counsel-compile-get-make-invocation (&optional blddir)
"Have a look in the root directory for any build control files.
- [elpa] master 114ae96 070/399: counsel.el: Find project root more flexibly, (continued)
- [elpa] master 114ae96 070/399: counsel.el: Find project root more flexibly, Oleh Krehel, 2019/07/20
- [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 <=
- [elpa] master 456e575 093/399: Don't bury killed buffers after counsel-switch-buffer, Oleh Krehel, 2019/07/20
- [elpa] master 1c84179 098/399: counsel.el (counsel-rg): Add an example to the doc, Oleh Krehel, 2019/07/20
- [elpa] master b154260 097/399: counsel.el (counsel-grep): Fix TRAMP problems, Oleh Krehel, 2019/07/20
- [elpa] master adab07d 101/399: counsel.el: Simplify counsel-git-grep, Oleh Krehel, 2019/07/20
- [elpa] master 5b4dbbc 096/399: ivy.el: Silence byte-compiler, Oleh Krehel, 2019/07/20
- [elpa] master 3954bfe 081/399: counsel.el (counsel-compile): Don't modify compilation-start-hook permanently, Oleh Krehel, 2019/07/20
- [elpa] master d92d43a 085/399: counsel.el (counsel-compile-root-functions): Tidy, Oleh Krehel, 2019/07/20
- [elpa] master 2356a1d 091/399: ivy-test.el (counsel--grep-regex): Extend test, Oleh Krehel, 2019/07/20
- [elpa] master cdd7ada 094/399: counsel.el (counsel-url-expand): Avoid null error, Oleh Krehel, 2019/07/20
- [elpa] master 089107a 099/399: counsel.el (counsel-ag): Add a keyword argument caller, Oleh Krehel, 2019/07/20