From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Leake Newsgroups: gmane.emacs.devel Subject: change pcomplete/make to include targets in included files Date: Sat, 14 Sep 2019 02:46:16 -0700 Message-ID: <86muf7p5w7.fsf@stephe-leake.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="34561"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (windows-nt) To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Sep 14 11:46:55 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1i94dq-0008te-NA for ged-emacs-devel@m.gmane.org; Sat, 14 Sep 2019 11:46:55 +0200 Original-Received: from localhost ([::1]:49130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i94do-000764-WB for ged-emacs-devel@m.gmane.org; Sat, 14 Sep 2019 05:46:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43039) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i94dJ-00075v-R3 for emacs-devel@gnu.org; Sat, 14 Sep 2019 05:46:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i94dH-0004VX-Se for emacs-devel@gnu.org; Sat, 14 Sep 2019 05:46:20 -0400 Original-Received: from gateway31.websitewelcome.com ([192.185.143.39]:37747) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i94dH-0004V0-Je for emacs-devel@gnu.org; Sat, 14 Sep 2019 05:46:19 -0400 Original-Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 9238152827 for ; Sat, 14 Sep 2019 04:46:17 -0500 (CDT) Original-Received: from host2007.hostmonster.com ([67.20.76.71]) by cmsmtp with SMTP id 94dFitMlB2qH794dFimsA7; Sat, 14 Sep 2019 04:46:17 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=stephe-leake.org; s=default; h=Content-Type:MIME-Version:Message-ID:Date: Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=5+5HS0PgCat7ppv+Id2ozkMt2KeKc0q+0rk0HJ/yd1g=; b=fZR9POsLI3ZGxN62FxvrkVYwDr sBmtd72EaW+N0r3oh+p5kgwkFSVq1cnZdCM/NcPlEMb0zvsRymCijqZsroyIHx6na+vqwbmDQJ0bK iPveC1go7snocyaaVsbf98GAKfKDq9H/UnmZJzUB75HUqD2t1QjwtNU/ZOrg7ofpe1qmdaCgrAcWU gUHp26KLnkATImTEGxYPChTDELZ4s/GkoT0q7crcN2xg08vQ39X7oHA7uGPT/dfpPi2gWoVrMxXqu 8xMFLq4a3Fwq5x2588P/MYHZek1fUS5F84XAAvSt6sycr92CjnXDHSP9FTCMQi2AU4fG4Sso3laJ9 2Azuwiow==; Original-Received: from [76.77.182.20] (port=49811 helo=Takver4) by host2007.hostmonster.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1i94dE-0005ap-VR for emacs-devel@gnu.org; Sat, 14 Sep 2019 03:46:17 -0600 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - host2007.hostmonster.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stephe-leake.org X-BWhitelist: no X-Source-IP: 76.77.182.20 X-Source-L: No X-Exim-ID: 1i94dE-0005ap-VR X-Source-Sender: (Takver4) [76.77.182.20]:49811 X-Source-Auth: stephen_leake@stephe-leake.org X-Email-Count: 1 X-Source-Cap: c3RlcGhlbGU7c3RlcGhlbGU7aG9zdDIwMDcuaG9zdG1vbnN0ZXIuY29t X-Local-Domain: yes X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 192.185.143.39 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:240027 Archived-At: 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