diff options
| author | Stephen Leake | 2019-09-18 17:42:30 -0700 |
|---|---|---|
| committer | Stephen Leake | 2019-09-18 17:42:30 -0700 |
| commit | b478444099655f36f7b243e21e8f98051299ca8f (patch) | |
| tree | 0ae6a93784efbb8618aceaa9f670198e52f96537 | |
| parent | 3d442312889ef2d14c07282d0aff6199d00cc165 (diff) | |
| download | emacs-b478444099655f36f7b243e21e8f98051299ca8f.tar.gz emacs-b478444099655f36f7b243e21e8f98051299ca8f.zip | |
Enhance 'pcomplete/make' to complete on targets in included makefiles
* lisp/pcmpl-gnu.el (pcmpl-gnu-makefile-includes): New.
(pcmpl-gnu-make-targets): New, factored out of pcmpl-gnu-make-all-targets.
(pcmpl-gnu-make-includes): New.
(pcmpl-gnu-make-all-targets): Use new functions.
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/pcmpl-gnu.el | 49 |
2 files changed, 47 insertions, 7 deletions
| @@ -1456,6 +1456,11 @@ available for output of asynchronous shell commands. | |||
| 1456 | *** The function 'pcomplete-uniquify-list' has been renamed from | 1456 | *** The function 'pcomplete-uniquify-list' has been renamed from |
| 1457 | 'pcomplete-uniqify-list'. | 1457 | 'pcomplete-uniqify-list'. |
| 1458 | 1458 | ||
| 1459 | --- | ||
| 1460 | *** 'pcomplete/make' now completes on targets in included files, recursively. | ||
| 1461 | To recover the previous behavior, set new user option | ||
| 1462 | `pcmpl-gnu-makefile-includes' to nil. | ||
| 1463 | |||
| 1459 | ** Auth-source | 1464 | ** Auth-source |
| 1460 | 1465 | ||
| 1461 | --- | 1466 | --- |
diff --git a/lisp/pcmpl-gnu.el b/lisp/pcmpl-gnu.el index 391441bd79c..8ec5d93a68a 100644 --- a/lisp/pcmpl-gnu.el +++ b/lisp/pcmpl-gnu.el | |||
| @@ -40,6 +40,13 @@ | |||
| 40 | :type '(repeat regexp) | 40 | :type '(repeat regexp) |
| 41 | :group 'pcmpl-gnu) | 41 | :group 'pcmpl-gnu) |
| 42 | 42 | ||
| 43 | (defcustom pcmpl-gnu-makefile-includes t | ||
| 44 | "If non-nil, `pcomplete/make' completes on targets in included files." | ||
| 45 | :type 'boolean | ||
| 46 | :group 'pcmpl-gnu | ||
| 47 | :version 27.1 | ||
| 48 | :safe 'booleanp) | ||
| 49 | |||
| 43 | ;; Functions: | 50 | ;; Functions: |
| 44 | 51 | ||
| 45 | ;;;###autoload | 52 | ;;;###autoload |
| @@ -108,8 +115,41 @@ | |||
| 108 | "Return a list of possible makefile names." | 115 | "Return a list of possible makefile names." |
| 109 | (pcomplete-entries (mapconcat 'identity pcmpl-gnu-makefile-regexps "\\|"))) | 116 | (pcomplete-entries (mapconcat 'identity pcmpl-gnu-makefile-regexps "\\|"))) |
| 110 | 117 | ||
| 118 | (defun pcmpl-gnu-make-targets (targets) | ||
| 119 | "Add to TARGETS the list of makefile targets in the current buffer. | ||
| 120 | Return the new list." | ||
| 121 | (goto-char (point-min)) | ||
| 122 | (while (re-search-forward | ||
| 123 | "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]" nil t) | ||
| 124 | (setq targets (nconc (split-string (match-string-no-properties 1)) | ||
| 125 | targets))) | ||
| 126 | targets) | ||
| 127 | |||
| 128 | (defun pcmpl-gnu-make-includes () | ||
| 129 | "Return a list of all included file names in the current buffer." | ||
| 130 | (let (filenames) | ||
| 131 | (goto-char (point-min)) | ||
| 132 | (while (search-forward-regexp "^include +\\(.*\\)$" nil t) | ||
| 133 | (push (match-string-no-properties 1) filenames)) | ||
| 134 | filenames)) | ||
| 135 | |||
| 136 | (defun pcmpl-gnu-make-all-targets (makefile targets) | ||
| 137 | "Add to TARGETS the list of target names in MAKEFILE and files it includes. | ||
| 138 | Return the new list." | ||
| 139 | (with-temp-buffer | ||
| 140 | (with-demoted-errors ;Could be a directory or something. | ||
| 141 | (insert-file-contents makefile)) | ||
| 142 | |||
| 143 | (let ((filenames (when pcmpl-gnu-makefile-includes (pcmpl-gnu-make-includes)))) | ||
| 144 | (setq targets (pcmpl-gnu-make-targets targets)) | ||
| 145 | (dolist (file filenames) | ||
| 146 | (when (file-readable-p file) | ||
| 147 | (setq targets (pcmpl-gnu-make-all-targets file targets)))) | ||
| 148 | )) | ||
| 149 | targets) | ||
| 150 | |||
| 111 | (defun pcmpl-gnu-make-rule-names () | 151 | (defun pcmpl-gnu-make-rule-names () |
| 112 | "Return a list of possible make rule names in MAKEFILE." | 152 | "Return a list of possible make targets in a makefile in the current directory." |
| 113 | (let* ((minus-f (member "-f" pcomplete-args)) | 153 | (let* ((minus-f (member "-f" pcomplete-args)) |
| 114 | (makefile (or (cadr minus-f) | 154 | (makefile (or (cadr minus-f) |
| 115 | (cond | 155 | (cond |
| @@ -119,12 +159,7 @@ | |||
| 119 | rules) | 159 | rules) |
| 120 | (if (not (file-readable-p makefile)) | 160 | (if (not (file-readable-p makefile)) |
| 121 | (unless minus-f (list "-f")) | 161 | (unless minus-f (list "-f")) |
| 122 | (with-temp-buffer | 162 | (setq rules (pcmpl-gnu-make-all-targets makefile rules)) |
| 123 | (ignore-errors ;Could be a directory or something. | ||
| 124 | (insert-file-contents makefile)) | ||
| 125 | (while (re-search-forward | ||
| 126 | (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t) | ||
| 127 | (setq rules (append (split-string (match-string 1)) rules)))) | ||
| 128 | (pcomplete-uniquify-list rules)))) | 163 | (pcomplete-uniquify-list rules)))) |
| 129 | 164 | ||
| 130 | (defcustom pcmpl-gnu-tarfile-regexp | 165 | (defcustom pcmpl-gnu-tarfile-regexp |