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: completing on makefile targets Date: Thu, 12 Sep 2019 11:24:42 -0700 Message-ID: <86r24l74ph.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="140711"; 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 Thu Sep 12 20:26:15 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 1i8TnK-000aTR-DG for ged-emacs-devel@m.gmane.org; Thu, 12 Sep 2019 20:26:14 +0200 Original-Received: from localhost ([::1]:37592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8TnJ-0007nL-0T for ged-emacs-devel@m.gmane.org; Thu, 12 Sep 2019 14:26:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55703) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i8TmO-0007hP-GH for emacs-devel@gnu.org; Thu, 12 Sep 2019 14:25:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i8TmM-0006Hv-5H for emacs-devel@gnu.org; Thu, 12 Sep 2019 14:25:15 -0400 Original-Received: from gateway34.websitewelcome.com ([192.185.148.119]:29233) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i8TmL-000640-SV for emacs-devel@gnu.org; Thu, 12 Sep 2019 14:25:14 -0400 Original-Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway34.websitewelcome.com (Postfix) with ESMTP id C80C037C369 for ; Thu, 12 Sep 2019 13:24:48 -0500 (CDT) Original-Received: from host2007.hostmonster.com ([67.20.76.71]) by cmsmtp with SMTP id 8TlviPzn990on8Tlwi90v6; Thu, 12 Sep 2019 13:24:48 -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=X0FU9by3IatuJT/QL9gIJ1u4hdeXm96neHq92yazwfA=; b=Lm391UlD6+dPTRwYaMAFC6JvRX PlHBLqzpHCt/HR+f0rWdmUpfaZh4OytCJqlPlcQdskAinKlA4ZZy7fZ9DcjPSiP/Ymgqeo8cu+RLo 6pBLhcXK88uRx92rNSYnP0AM0AGPplSXuXqtdVePj9wfiGt2sngvJFb3Po8BlD07hfVS/6156AvQO DIKz/GHfiKlWWT/TVr57/IHNLRI86Q7y7uc14Xid6NCtylZp0LUT6NQOLXkYViN9W/QydmcRCARu0 Dy/T7Iq2rkbCkTG0sUSR1Y/SLUTw/8Y9ycpDNorVh8cEke2+sqAlHkuL0XslhLQOT/xA+BSZdtkVV ePTbfcuA==; Original-Received: from [76.77.182.20] (port=53431 helo=Takver4) by host2007.hostmonster.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1i8Tlu-003BD7-SB for emacs-devel@gnu.org; Thu, 12 Sep 2019 12:24:46 -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: 1i8Tlu-003BD7-SB X-Source-Sender: (Takver4) [76.77.182.20]:53431 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.148.119 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:239999 Archived-At: When I start a compile from a Makefile, sometimes the completion recognizes the makefile targets, sometimes it doesn't. Some recent change to master made it stop working at all; it still sort of works in emacs 26. makefile-mode provides a function `makefile-completion-at-point', which could do the right thing, but it is not called by the default setup. Investigating, it seems the situation is quite complex. I'm not at all clear why it seemed to work. The completion is done by `completion-at-point', bound to TAB in the minibuffer. `completion-at-point' essentially runs the hook `completion-at-point-functions'. The completion is done in the minibuffer set up by `compilation-read-command', which calls `read-shell-command'. That calls `read-from-minibuffer' with a setup hook that includes `shell-completion-vars'. That sets many things, including `completion-at-point-functions', which is set to `comint-completion-at-point'. `comint-completion-at-point' just runs the hook `comint-dynamic-complete-functions'. `shell-completion-vars' also sets `comint-dynamic-complete-functions' to `shell-dynamic-complete-functions'. `shell-dynamic-complete-functions' does not include `makefile-completion-at-point' by default, so I added a let-binding of that in my custom function to start a compilation. Alternately, I could add the makefile completion function to the default value; this approach seems cleaner for debugging. That almost works; makefile-completion-at-point is called, but returns nil. That's because it uses the buffer-local variable `makefile-target-table' to store the targets for completion. The function `makefile-pickup-targets' fills that local variable. For some reason, let-binding `makefile-target-table' in my top level function does not work, so I now have this workaround: (defun sal-makefile-completions-at-point () (let ((makefile-target-table sal-makefile-target-table)) (makefile-completions-at-point))) (defun make-compile (command) (interactive (progn (makefile-pickup-targets) (list (let ((shell-dynamic-complete-functions (list #'sal-makefile-completions-at-point)) (sal-makefile-target-table (copy-sequence makefile-target-table))) (compilation-read-command compile-command))))) (compilation-start compile-command)) This works, but seems unnecessarily complicated (and mysterious). Why does let-binding `makefile-target-table' work in `sal-makefile-completions-at-point', but not in `make-compile'? One step to improving this to to provide a new function `makefile-targets' that always reads the Makefile and returns the target list, avoiding the local variable cache. There may be some very large makefile where this is too slow; the time is not noticeable in the Emacs master top level makefile (1190 lines). That requires knowing the "source" buffer while in the minibuffer; is there a standard way to get that? -- -- Stephe