[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
change pcomplete/make to include targets in included files
From: |
Stephen Leake |
Subject: |
change pcomplete/make to include targets in included files |
Date: |
Sat, 14 Sep 2019 02:46:16 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.2 (windows-nt) |
The patch below changes pcomplete/make to include targets in included
files. The new user option pcmpl-gnu-makefile-includes allows disabling
this.
Ok to commit?
To make this actually work in the prompt for 'compile', I had to modify
`shell-dynamic-complete-functions' to contain just
`pcomplete-completions-at-point'; I have not figured out why yet.
--
-- Stephe
diff --git a/etc/NEWS b/etc/NEWS
index 87666740df..244cda8b2b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1456,6 +1456,10 @@ available for output of asynchronous shell commands.
*** The function 'pcomplete-uniquify-list' has been renamed from
'pcomplete-uniqify-list'.
+*** By default, `pcomplete/make' now includes targets in included
+files, recursively. To recover the previous behavior, set new user
+option `pcmpl-gnu-makefile-includes' to nil.
+
** Auth-source
---
diff --git a/lisp/pcmpl-gnu.el b/lisp/pcmpl-gnu.el
index 391441bd79..2286bf4928 100644
--- a/lisp/pcmpl-gnu.el
+++ b/lisp/pcmpl-gnu.el
@@ -40,6 +40,11 @@ pcmpl-gnu-makefile-regexps
:type '(repeat regexp)
:group 'pcmpl-gnu)
+(defcustom pcmpl-gnu-makefile-includes t
+ "If non-nil, `pcomplete/make' includes targets in included files."
+ :type 'boolean
+ :group 'pcmpl-gnu)
+
;; Functions:
;;;###autoload
@@ -108,8 +113,45 @@ pcmpl-gnu-makefile-names
"Return a list of possible makefile names."
(pcomplete-entries (mapconcat 'identity pcmpl-gnu-makefile-regexps "\\|")))
+(defun pcmpl-gnu-make-targets ()
+ "Return a list of make targets in the current buffer."
+ (let (targets)
+ (goto-char (point-min))
+ (while (re-search-forward
+ "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]" nil t)
+ (setq
+ targets
+ (append (split-string
+ (buffer-substring-no-properties
+ (match-beginning 1) (match-end 1)))
+ targets)))
+ targets))
+
+(defun pcmpl-gnu-make-includes ()
+ "Return a list of all 'include' file names in the current buffer."
+ (let (filenames)
+ (goto-char (point-min))
+ (while (search-forward-regexp "^include +\\(.*\\)$" nil t)
+ (push (buffer-substring-no-properties
+ (match-beginning 1) (match-end 1))
+ filenames)
+ (forward-line 1))
+ filenames))
+
+(defun pcmpl-gnu-make-all-targets (makefile)
+ "Return a list of target names in MAKEFILE and all included files."
+ (with-temp-buffer
+ (ignore-errors ;Could be a directory or something.
+ (insert-file-contents makefile))
+ (let ((filenames (when pcmpl-gnu-makefile-includes
(pcmpl-gnu-make-includes)))
+ (targets (pcmpl-gnu-make-targets)))
+ (dolist (file filenames)
+ (when (file-readable-p file)
+ (setq targets (append (pcmpl-gnu-make-all-targets file) targets))))
+ targets)))
+
(defun pcmpl-gnu-make-rule-names ()
- "Return a list of possible make rule names in MAKEFILE."
+ "Return a list of possible make targets in a makefile in the current
directory."
(let* ((minus-f (member "-f" pcomplete-args))
(makefile (or (cadr minus-f)
(cond
@@ -119,12 +161,7 @@ pcmpl-gnu-make-rule-names
rules)
(if (not (file-readable-p makefile))
(unless minus-f (list "-f"))
- (with-temp-buffer
- (ignore-errors ;Could be a directory or something.
- (insert-file-contents makefile))
- (while (re-search-forward
- (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t)
- (setq rules (append (split-string (match-string 1)) rules))))
+ (setq rules (pcmpl-gnu-make-all-targets makefile))
(pcomplete-uniquify-list rules))))
(defcustom pcmpl-gnu-tarfile-regexp
- change pcomplete/make to include targets in included files,
Stephen Leake <=