unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
To: emacs-devel <emacs-devel@gnu.org>
Subject: completing on makefile targets
Date: Thu, 12 Sep 2019 11:24:42 -0700	[thread overview]
Message-ID: <86r24l74ph.fsf@stephe-leake.org> (raw)

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



             reply	other threads:[~2019-09-12 18:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-12 18:24 Stephen Leake [this message]
2019-09-12 19:41 ` completing on makefile targets Stefan Monnier
2019-09-12 21:38   ` Stephen Leake
2019-09-12 22:26     ` Stefan Monnier
2019-09-14  0:55       ` 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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=86r24l74ph.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 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).