unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* change pcomplete/make to include targets in included files
@ 2019-09-14  9:46 Stephen Leake
  2019-09-14 10:08 ` Eli Zaretskii
  2019-09-15  1:43 ` Stefan Monnier
  0 siblings, 2 replies; 9+ messages in thread
From: Stephen Leake @ 2019-09-14  9:46 UTC (permalink / raw)
  To: emacs-devel

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



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-09-16 23:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-14  9:46 change pcomplete/make to include targets in included files Stephen Leake
2019-09-14 10:08 ` Eli Zaretskii
2019-09-14 10:57   ` Eli Zaretskii
2019-09-14 22:04     ` Stephen Leake
2019-09-14 22:03   ` Stephen Leake
2019-09-15  1:43 ` Stefan Monnier
2019-09-15 19:50   ` Stephen Leake
2019-09-15 20:56     ` Stefan Monnier
2019-09-16 23:33       ` Stephen Leake

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).