summaryrefslogtreecommitdiff
path: root/lisp/pcmpl-gnu.el
diff options
context:
space:
mode:
authorStephen Leake <stephen_leake@stephe-leake.org>2019-09-18 17:42:30 -0700
committerStephen Leake <stephen_leake@stephe-leake.org>2019-09-18 17:42:30 -0700
commitb478444099655f36f7b243e21e8f98051299ca8f (patch)
tree0ae6a93784efbb8618aceaa9f670198e52f96537 /lisp/pcmpl-gnu.el
parent3d442312889ef2d14c07282d0aff6199d00cc165 (diff)
downloademacs-b478444099655f36f7b243e21e8f98051299ca8f.tar.gz
Enhance 'pcomplete/make' to complete on targets in included makefiles
* lisp/pcmpl-gnu.el (pcmpl-gnu-makefile-includes): New. (pcmpl-gnu-make-targets): New, factored out of pcmpl-gnu-make-all-targets. (pcmpl-gnu-make-includes): New. (pcmpl-gnu-make-all-targets): Use new functions.
Diffstat (limited to 'lisp/pcmpl-gnu.el')
-rw-r--r--lisp/pcmpl-gnu.el49
1 files changed, 42 insertions, 7 deletions
diff --git a/lisp/pcmpl-gnu.el b/lisp/pcmpl-gnu.el
index 391441bd79c..8ec5d93a68a 100644
--- a/lisp/pcmpl-gnu.el
+++ b/lisp/pcmpl-gnu.el
@@ -40,6 +40,13 @@
:type '(repeat regexp)
:group 'pcmpl-gnu)
+(defcustom pcmpl-gnu-makefile-includes t
+ "If non-nil, `pcomplete/make' completes on targets in included files."
+ :type 'boolean
+ :group 'pcmpl-gnu
+ :version 27.1
+ :safe 'booleanp)
+
;; Functions:
;;;###autoload
@@ -108,8 +115,41 @@
"Return a list of possible makefile names."
(pcomplete-entries (mapconcat 'identity pcmpl-gnu-makefile-regexps "\\|")))
+(defun pcmpl-gnu-make-targets (targets)
+ "Add to TARGETS the list of makefile targets in the current buffer.
+Return the new list."
+ (goto-char (point-min))
+ (while (re-search-forward
+ "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]" nil t)
+ (setq targets (nconc (split-string (match-string-no-properties 1))
+ targets)))
+ targets)
+
+(defun pcmpl-gnu-make-includes ()
+ "Return a list of all included file names in the current buffer."
+ (let (filenames)
+ (goto-char (point-min))
+ (while (search-forward-regexp "^include +\\(.*\\)$" nil t)
+ (push (match-string-no-properties 1) filenames))
+ filenames))
+
+(defun pcmpl-gnu-make-all-targets (makefile targets)
+ "Add to TARGETS the list of target names in MAKEFILE and files it includes.
+Return the new list."
+ (with-temp-buffer
+ (with-demoted-errors ;Could be a directory or something.
+ (insert-file-contents makefile))
+
+ (let ((filenames (when pcmpl-gnu-makefile-includes (pcmpl-gnu-make-includes))))
+ (setq targets (pcmpl-gnu-make-targets targets))
+ (dolist (file filenames)
+ (when (file-readable-p file)
+ (setq targets (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 +159,7 @@
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 rules))
(pcomplete-uniquify-list rules))))
(defcustom pcmpl-gnu-tarfile-regexp