emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

completing on makefile targets


From: Stephen Leake
Subject: completing on makefile targets
Date: Thu, 12 Sep 2019 11:24:42 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (windows-nt)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]