all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
To: emacs-devel <emacs-devel@gnu.org>
Subject: change pcomplete/make to include targets in included files
Date: Sat, 14 Sep 2019 02:46:16 -0700	[thread overview]
Message-ID: <86muf7p5w7.fsf@stephe-leake.org> (raw)

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



             reply	other threads:[~2019-09-14  9:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-14  9:46 Stephen Leake [this message]
2019-09-14 10:08 ` change pcomplete/make to include targets in included files 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86muf7p5w7.fsf@stephe-leake.org \
    --to=stephen_leake@stephe-leake.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.