emacs-devel
[Top][All Lists]
Advanced

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

Re: change pcomplete/make to include targets in included files


From: Stefan Monnier
Subject: Re: change pcomplete/make to include targets in included files
Date: Sat, 14 Sep 2019 21:43:41 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

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




reply via email to

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