From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: change pcomplete/make to include targets in included files Date: Sat, 14 Sep 2019 21:43:41 -0400 Message-ID: References: <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="49077"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: emacs-devel To: Stephen Leake Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Sep 15 03:43:57 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 1i9Ja0-000Cfz-I4 for ged-emacs-devel@m.gmane.org; Sun, 15 Sep 2019 03:43:57 +0200 Original-Received: from localhost ([::1]:52898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9JZz-0001Pj-FT for ged-emacs-devel@m.gmane.org; Sat, 14 Sep 2019 21:43:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45082) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9JZu-0001Pa-Av for emacs-devel@gnu.org; Sat, 14 Sep 2019 21:43:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9JZs-0007JQ-Tg for emacs-devel@gnu.org; Sat, 14 Sep 2019 21:43:49 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:51377) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i9JZs-0007It-LQ for emacs-devel@gnu.org; Sat, 14 Sep 2019 21:43:48 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id D63AB447C32; Sat, 14 Sep 2019 21:43:46 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 6525E447C2E; Sat, 14 Sep 2019 21:43:45 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1568511825; bh=lSRjHpAqxmNfxuLYfurWXDsYRuWsZJx9oQijEmksxvo=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=GIGPQv8RRRhIf8N1Zq4k4xQmiNGEbZrYK0no9jh+ZOqhysw5lzTxFIy1DA5RtMcJk Ft3iY5TaAVDAENd+Qc7wDXQDyeFO0mlpUQMGHl5f7iN5GH+iPNkx/sJ7vq91WkOrNz jngJ7QP6T2BlxaYaTZsN2BK+4BF19Vq6j/v0I1fpIM/RE1olpKM1+UOb1OYKYM8/VJ W4UKS5b+pHF7SAFXw69YIZSOhcckYt5FAK/uuNlENmhG7G2xoGAQpwPKtwTw5MO52q kuVN3J86qSkKvy1PM7ZFPdrc4jSD1qYDElXu9bQ6Y4k6JV5Us+PgLdErjSiS1ngere 1LPT7hdmQu++g== Original-Received: from alfajor (104-222-123-223.cpe.teksavvy.com [104.222.123.223]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id BF13D120642; Sat, 14 Sep 2019 21:43:44 -0400 (EDT) In-Reply-To: <86muf7p5w7.fsf@stephe-leake.org> (Stephen Leake's message of "Sat, 14 Sep 2019 02:46:16 -0700") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 132.204.25.50 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:240038 Archived-At: Stephen Leake [2019-09-14 02:46:16] wrote: > 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? Sounds good to me, but see comments below. > 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. I don't see this change in the patch (which I think is good), so I assume you're waiting to figure it out before acting on it, right? > +(defcustom pcmpl-gnu-makefile-includes t > + "If non-nil, `pcomplete/make' includes targets in included files." > + :type 'boolean > + :group 'pcmpl-gnu) AFAICT the ":group 'pcmpl-gnu" is redundant here (as it is on the other defcustoms in this file). > + (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))) I see you replaced (match-string 1) with (buffer-substring-no-properties (match-beginning 1) (match-end 1)). I think dropping text-properties is OK, but you can do it with (match-string-no-properties 1). Other than dropping properties, you can also optimize the code using `nconc` instead of `append`. > + (while (search-forward-regexp "^include +\\(.*\\)$" nil t) > + (push (buffer-substring-no-properties > + (match-beginning 1) (match-end 1)) > + filenames) > + (forward-line 1)) Same here, and I think the forward-line is not needed. > +(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)) I think we could use `with-demoted-errors` here, since the error case should only occur in cases where there's really something odd which the user may want to be know about. > + (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))) You can completely eliminate this `append` by passing the `targets` argument as an additional arg to pcmpl-gnu-make-all-targets (itself passed to pcmpl-gnu-make-targets). Stefan