Mercurial > emacs
annotate lisp/progmodes/make-mode.el @ 2590:9dace03bd76c
(find-tag-interactive): New function to read args for find-tag et al.
(find-tag-noselect, find-tag, find-tag-other-window, find-tag-other-frame,
find-tag-regexp): Use it.
(find-tag, find-tag-other-window): Take new arg REGEXP-P, pass to
find-tag-noselect.
(find-tag-regexp): Call either find-tag-other-window or find-tag, rather
than find-tag-noselect and switch-to-buffer[-other-window].
(tags-location-stack): New defvar.
(find-tag-noselect): If NEXT-P is '-, pop location off tags-location-stack.
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Mon, 26 Apr 1993 19:21:01 +0000 |
parents | 5f2c2994cbca |
children | 09647458cad9 |
rev | line source |
---|---|
809 | 1 ;;; makefile.el --- makefile editing commands for Emacs |
2 | |
841 | 3 ;; Copyright (C) 1992 Free Software Foundation, Inc. |
4 | |
809 | 5 ;; Author: Thomas Neumann <tom@smart.bo.open.de> |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
6 ;; Eric S. Raymond <esr@snark.thyrsus.com> |
809 | 7 ;; Adapted-By: ESR |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
809
diff
changeset
|
8 ;; Keywords: unix, tools |
809 | 9 |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
10 ;; $Id: makefile.el,v 1.3 1993/04/20 20:01:16 esr Exp $ |
809 | 11 |
12 ;; This file is part of GNU Emacs. | |
13 | |
14 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
15 ;; it under the terms of the GNU General Public License as published by | |
16 ;; the Free Software Foundation; either version 1, or (at your option) | |
17 ;; any later version. | |
18 | |
19 ;; GNU Emacs is distributed in the hope that it will be useful, | |
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ;; GNU General Public License for more details. | |
23 | |
24 ;; You should have received a copy of the GNU General Public License | |
25 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
26 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
27 | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
28 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
29 |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
30 ;; A major mode for editing makefiles. The mode knows about Makefile |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
31 ;; syntax and defines M-n and M-p to move to next and previous productions. |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
32 ;; |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
33 ;; The keys $, =, : and . are electric; they try to help you fill in a |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
34 ;; macro reference, macro definition, ordinary target name, or special |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
35 ;; target name, respectively. Such names are completed using a list of |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
36 ;; targets and macro names parsed out of the makefile. This list is |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
37 ;; automatically updated, if necessary, whenever you invoke one of |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
38 ;; these commands. You can force it to be updated with C-c C-p. |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
39 ;; |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
40 ;; The command C-c f adds certain filenames in the current directory |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
41 ;; as targets. You can filter out filenames by setting the variable |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
42 ;; makefile-ignored-files-in-pickup-regex. |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
43 ;; |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
44 ;; The command C-c C-u grinds for a bit, then pops up a report buffer |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
45 ;; showing which target names are up-to-date with respect to their |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
46 ;; prerequisites, which targets are out-of-date, and which have no |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
47 ;; prerequisites. |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
48 ;; |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
49 ;; The command C-c b pops up a browser window listing all target and |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
50 ;; macro names. You can mark or unmark items wit C-c SPC, and insert |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
51 ;; all marked items back in the Makefile with C-c TAB. |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
52 ;; |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
53 ;; The command C-c TAB in the makefile buffer inserts a GNU make builtin. |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
54 ;; You will be prompted for the builtin's args. |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
55 ;; |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
56 ;; There are numerous other customization variables. |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
57 |
809 | 58 ;;; Code: |
59 | |
60 (provide 'makefile) | |
61 | |
62 ;;; ------------------------------------------------------------ | |
63 ;;; Configureable stuff | |
64 ;;; ------------------------------------------------------------ | |
65 | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
66 (defconst makefile-mode-name "makefile" |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
67 "The \"pretty name\" of makefile-mode, as it appears in the modeline.") |
809 | 68 |
69 (defvar makefile-browser-buffer-name "*Macros and Targets*" | |
70 "Name of the macro- and target browser buffer.") | |
71 | |
72 (defvar makefile-target-colon ":" | |
73 "The string that gets appended to all target names | |
74 inserted by makefile-insert-target. | |
75 \":\" or \"::\" are quite common values.") | |
76 | |
77 (defvar makefile-macro-assign " = " | |
78 "The string that gets appended to all macro names | |
79 inserted by makefile-insert-macro. | |
80 The normal value should be \" = \", since this is what | |
81 standard make expects. However, newer makes such as dmake | |
82 allow a larger variety of different macro assignments, so you | |
83 might prefer to use \" += \" or \" := \" .") | |
84 | |
85 (defvar makefile-use-curly-braces-for-macros-p nil | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
86 "Controls the style of generated macro references. |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
87 Set this variable to a non-nil value if you prefer curly braces |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
88 in macro-references, so it looks like ${this}. A value of nil |
809 | 89 will cause makefile-mode to use parantheses, making macro references |
90 look like $(this) .") | |
91 | |
92 (defvar makefile-tab-after-target-colon t | |
93 "If you want a TAB (instead of a space) to be appended after the | |
94 target colon, then set this to a non-nil value.") | |
95 | |
96 (defvar makefile-browser-leftmost-column 10 | |
97 "Number of blanks to the left of the browser selection mark.") | |
98 | |
99 (defvar makefile-browser-cursor-column 10 | |
100 "Column in which the cursor is positioned when it moves | |
101 up or down in the browser.") | |
102 | |
103 (defvar makefile-browser-selected-mark "+ " | |
104 "String used to mark selected entries in the browser.") | |
105 | |
106 (defvar makefile-browser-unselected-mark " " | |
107 "String used to mark unselected entries in the browser.") | |
108 | |
109 (defvar makefile-browser-auto-advance-after-selection-p t | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
110 "If non-nil, the cursor will automagically advance to the next line after |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
111 an item has been selected in the browser.") |
809 | 112 |
113 (defvar makefile-pickup-everything-picks-up-filenames-p nil | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
114 "If non-nil, makefile-pickup-everything also picks up filenames as targets |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
115 (i.e. it calls makefile-find-filenames-as-targets), otherwise filenames are |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
116 omitted.") |
809 | 117 |
118 (defvar makefile-cleanup-continuations-p t | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
119 "If non-nil, makefile-mode will assure that no line in the file ends with a |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
120 backslash (the continuation character) followed by any whitespace. This is |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
121 done by silently removing the trailing whitespace, leaving the backslash itself |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
122 intact. IMPORTANT: Please note that enabling this option causes makefile-mode |
809 | 123 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \'it seems necessary\'.") |
124 | |
125 (defvar makefile-browser-hook '() | |
126 "A function or list of functions to be called just before the | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
127 browser is entered. This is executed in the makefile buffer.") |
809 | 128 |
129 ;; | |
130 ;; Special targets for DMake, Sun's make ... | |
131 ;; | |
132 (defvar makefile-special-targets-list | |
133 '(("DEFAULT") ("DONE") ("ERROR") ("EXPORT") | |
134 ("FAILED") ("GROUPEPILOG") ("GROUPPROLOG") ("IGNORE") | |
135 ("IMPORT") ("INCLUDE") ("INCLUDEDIRS") ("INIT") | |
136 ("KEEP_STATE") ("MAKEFILES") ("MAKE_VERSION") ("NO_PARALLEL") | |
137 ("PARALLEL") ("PHONY") ("PRECIOUS") ("REMOVE") | |
138 ("SCCS_GET") ("SILENT") ("SOURCE") ("SUFFIXES") | |
139 ("WAIT") ("c.o") ("C.o") ("m.o") | |
140 ("el.elc") ("y.c") ("s.o")) | |
141 "List of special targets. You will be offered to complete | |
142 on one of those in the minibuffer whenever you enter a \".\" | |
143 at the beginning of a line in makefile-mode.") | |
144 | |
145 (defvar makefile-runtime-macros-list | |
146 '(("@") ("&") (">") ("<") ("*") ("^") ("?") ("%")) | |
147 "List of macros that are resolved by make at runtime. | |
148 If you insert a macro reference using makefile-insert-macro-ref, the name | |
149 of the macro is checked against this list. If it can be found its name will | |
150 not be enclosed in { } or ( ).") | |
151 | |
152 (defconst makefile-dependency-regex | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
153 "^[^ \t#:]+\\([ \t]+[^ \t#:]+\\)*[ \t]*:\\([ \t]*$\\|\\([^=\n].*$\\)\\)" |
809 | 154 "Regex used to find dependency lines in a makefile.") |
155 | |
156 (defconst makefile-macroassign-regex | |
157 "^[^ \t][^:#=]*[\\*:\\+]?:?=.*$" | |
158 "Regex used to find macro assignment lines in a makefile.") | |
159 | |
160 (defconst makefile-ignored-files-in-pickup-regex | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
161 "\\(^\\..*\\)\\|\\(.*~$\\)\\|\\(.*,v$\\)\\|(\\.[chy]\\)" |
809 | 162 "Regex for filenames that will NOT be included in the target list.") |
163 | |
164 ;;; ------------------------------------------------------------ | |
165 ;;; The following configurable variables are used in the | |
166 ;;; up-to-date overview . | |
167 ;;; The standard configuration assumes that your `make' programm | |
168 ;;; can be run in question/query mode using the `-q' option, this | |
169 ;;; means that the command | |
170 ;;; | |
171 ;;; make -q foo | |
172 ;;; | |
173 ;;; should return an exit status of zero if the target `foo' is | |
174 ;;; up to date and a nonzero exit status otherwise. | |
175 ;;; Many makes can do this although the docs/manpages do not mention | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
176 ;;; it. Try it with your favourite one. GNU make, System V make, and |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
177 ;;; Dennis Vadura's DMake have no problems. |
809 | 178 ;;; Set the variable `makefile-brave-make' to the name of the |
179 ;;; make utility that does this on your system. | |
180 ;;; To understand what this is all about see the function defintion | |
181 ;;; of `makefile-query-by-make-minus-q' . | |
182 ;;; ------------------------------------------------------------ | |
183 | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
184 (defvar makefile-brave-make "make" |
809 | 185 "A make that can handle the \'-q\' option.") |
186 | |
187 (defvar makefile-query-one-target-method 'makefile-query-by-make-minus-q | |
188 "A function symbol [one that can be used as the first argument to | |
189 funcall] that provides a function that must conform to the following | |
190 interface: | |
191 | |
192 * As its first argument, it must accept the name of the target to | |
193 be checked, as a string. | |
194 | |
195 * As its second argument, it may accept the name of a makefile | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
196 as a string. Depending on what you're going to do you may |
809 | 197 not need this. |
198 | |
199 * It must return the integer value 0 (zero) if the given target | |
200 should be considered up-to-date in the context of the given | |
201 makefile, any nonzero integer value otherwise.") | |
202 | |
203 (defvar makefile-up-to-date-buffer-name "*Makefile Up-to-date overview*" | |
204 "Name of the Up-to-date overview buffer.") | |
205 | |
206 ;;; --- end of up-to-date-overview configuration ------------------ | |
207 | |
208 (defvar makefile-mode-map nil | |
209 "The keymap that is used in makefile-mode.") | |
210 (if makefile-mode-map | |
211 () | |
212 (setq makefile-mode-map (make-sparse-keymap)) | |
213 ;; set up the keymap | |
214 (define-key makefile-mode-map "$" 'makefile-insert-macro-ref) | |
215 (define-key makefile-mode-map "\C-c:" 'makefile-insert-target-ref) | |
216 (define-key makefile-mode-map ":" 'makefile-electric-colon) | |
217 (define-key makefile-mode-map "=" 'makefile-electric-equal) | |
218 (define-key makefile-mode-map "." 'makefile-electric-dot) | |
219 (define-key makefile-mode-map "\C-c\C-f" 'makefile-pickup-filenames-as-targets) | |
220 (define-key makefile-mode-map "\C-c\C-b" 'makefile-switch-to-browser) | |
221 (define-key makefile-mode-map "\C-c\C-p" 'makefile-pickup-everything) | |
222 (define-key makefile-mode-map "\C-c\C-u" 'makefile-create-up-to-date-overview) | |
223 (define-key makefile-mode-map "\C-c\C-i" 'makefile-insert-gmake-function) | |
224 (define-key makefile-mode-map "\M-p" 'makefile-previous-dependency) | |
225 (define-key makefile-mode-map "\M-n" 'makefile-next-dependency)) | |
226 | |
227 (defvar makefile-browser-map nil | |
228 "The keymap that is used in the macro- and target browser.") | |
229 (if makefile-browser-map | |
230 () | |
231 (setq makefile-browser-map (make-sparse-keymap)) | |
232 (define-key makefile-browser-map "n" 'makefile-browser-next-line) | |
233 (define-key makefile-browser-map "\C-n" 'makefile-browser-next-line) | |
234 (define-key makefile-browser-map "p" 'makefile-browser-previous-line) | |
235 (define-key makefile-browser-map "\C-p" 'makefile-browser-previous-line) | |
236 (define-key makefile-browser-map " " 'makefile-browser-toggle) | |
237 (define-key makefile-browser-map "i" 'makefile-browser-insert-selection) | |
238 (define-key makefile-browser-map "I" 'makefile-browser-insert-selection-and-quit) | |
239 (define-key makefile-browser-map "\C-c\C-m" 'makefile-browser-insert-continuation) | |
240 (define-key makefile-browser-map "q" 'makefile-browser-quit) | |
241 ;; disable horizontal movement | |
242 (define-key makefile-browser-map "\C-b" 'undefined) | |
243 (define-key makefile-browser-map "\C-f" 'undefined)) | |
244 | |
245 | |
246 (defvar makefile-mode-syntax-table nil | |
247 "The syntax-table used in makefile mode.") | |
248 (if makefile-mode-syntax-table | |
249 () | |
250 (setq makefile-mode-syntax-table (make-syntax-table)) | |
251 (modify-syntax-entry ?\( "() " makefile-mode-syntax-table) | |
252 (modify-syntax-entry ?\) ")( " makefile-mode-syntax-table) | |
253 (modify-syntax-entry ?\[ "(] " makefile-mode-syntax-table) | |
254 (modify-syntax-entry ?\] "([ " makefile-mode-syntax-table) | |
255 (modify-syntax-entry ?\{ "(} " makefile-mode-syntax-table) | |
256 (modify-syntax-entry ?\} "){ " makefile-mode-syntax-table) | |
257 (modify-syntax-entry ?# "< " makefile-mode-syntax-table) | |
258 (modify-syntax-entry ?\n "> " makefile-mode-syntax-table)) | |
259 | |
260 | |
261 ;;; ------------------------------------------------------------ | |
262 ;;; Internal variables. | |
263 ;;; You don't need to configure below this line. | |
264 ;;; ------------------------------------------------------------ | |
265 | |
266 (defvar makefile-target-table nil | |
267 "Table of all targets that have been inserted in | |
268 this Makefile buffer using makefile-insert-target or picked up | |
269 using makefile-pickup-targets.") | |
270 | |
271 (defvar makefile-macro-table nil | |
272 "Table of all macros that have been iserted in | |
273 this Makefile buffer using makefile-insert-macro or picked up | |
274 using makefile-pickup-macros.") | |
275 | |
276 (defvar makefile-browser-client | |
277 "A buffer in makefile-mode that is currently using the browser.") | |
278 | |
279 (defvar makefile-browser-selection-vector nil) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
280 (defvar makefile-has-prereqs nil) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
281 (defvar makefile-need-target-pickup t) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
282 (defvar makefile-need-macro-pickup t) |
809 | 283 |
284 (defvar makefile-mode-hook '()) | |
285 | |
286 (defconst makefile-gnumake-functions-alist | |
287 '( | |
288 ;; Text functions | |
289 ("subst" "From" "To" "In") | |
290 ("patsubst" "Pattern" "Replacement" "In") | |
291 ("strip" "Text") | |
292 ("findstring" "Find what" "In") | |
293 ("filter" "Pattern" "Text") | |
294 ("filter-out" "Pattern" "Text") | |
295 ("sort" "List") | |
296 ;; Filename functions | |
297 ("dir" "Names") | |
298 ("notdir" "Names") | |
299 ("suffix" "Names") | |
300 ("basename" "Names") | |
301 ("addsuffix" "Suffix" "Names") | |
302 ("join" "List 1" "List 2") | |
303 ("word" "Index" "Text") | |
304 ("words" "Text") | |
305 ("firstword" "Text") | |
306 ("wildcard" "Pattern") | |
307 ;; Misc functions | |
308 ("foreach" "Variable" "List" "Text") | |
309 ("origin" "Variable") | |
310 ("shell" "Command")) | |
311 "A list of GNU make 3.62 function names associated with | |
312 the prompts for each function. | |
313 This is used in the function makefile-insert-gmake-function .") | |
314 | |
315 | |
316 ;;; ------------------------------------------------------------ | |
317 ;;; The mode function itself. | |
318 ;;; ------------------------------------------------------------ | |
319 | |
2534
0099d6be2b11
(makefile-mode): Fix typo in autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
2400
diff
changeset
|
320 ;;;###autoload |
809 | 321 (defun makefile-mode () |
322 "Major mode for editing Makefiles. | |
323 Calling this function invokes the function(s) \"makefile-mode-hook\" before | |
324 doing anything else. | |
325 | |
326 \\{makefile-mode-map} | |
327 | |
328 In the browser, use the following keys: | |
329 | |
330 \\{makefile-browser-map} | |
331 | |
332 makefile-mode can be configured by modifying the following | |
333 variables: | |
334 | |
335 makefile-mode-name: | |
336 The \"pretty name\" of makefile-mode, as it | |
337 appears in the modeline. | |
338 | |
339 makefile-browser-buffer-name: | |
340 Name of the macro- and target browser buffer. | |
341 | |
342 makefile-target-colon: | |
343 The string that gets appended to all target names | |
344 inserted by makefile-insert-target. | |
345 \":\" or \"::\" are quite common values. | |
346 | |
347 makefile-macro-assign: | |
348 The string that gets appended to all macro names | |
349 inserted by makefile-insert-macro. | |
350 The normal value should be \" = \", since this is what | |
351 standard make expects. However, newer makes such as dmake | |
352 allow a larger variety of different macro assignments, so you | |
353 might prefer to use \" += \" or \" := \" . | |
354 | |
355 makefile-tab-after-target-colon: | |
356 If you want a TAB (instead of a space) to be appended after the | |
357 target colon, then set this to a non-nil value. | |
358 | |
359 makefile-browser-leftmost-column: | |
360 Number of blanks to the left of the browser selection mark. | |
361 | |
362 makefile-browser-cursor-column: | |
363 Column in which the cursor is positioned when it moves | |
364 up or down in the browser. | |
365 | |
366 makefile-browser-selected-mark: | |
367 String used to mark selected entries in the browser. | |
368 | |
369 makefile-browser-unselected-mark: | |
370 String used to mark unselected entries in the browser. | |
371 | |
372 makefile-browser-auto-advance-after-selection-p: | |
373 If this variable is set to a non-nil value the cursor | |
374 will automagically advance to the next line after an item | |
375 has been selected in the browser. | |
376 | |
377 makefile-pickup-everything-picks-up-filenames-p: | |
378 If this variable is set to a non-nil value then | |
379 makefile-pickup-everything also picks up filenames as targets | |
380 (i.e. it calls makefile-find-filenames-as-targets), otherwise | |
381 filenames are omitted. | |
382 | |
383 makefile-cleanup-continuations-p: | |
384 If this variable is set to a non-nil value then makefile-mode | |
385 will assure that no line in the file ends with a backslash | |
386 (the continuation character) followed by any whitespace. | |
387 This is done by silently removing the trailing whitespace, leaving | |
388 the backslash itself intact. | |
389 IMPORTANT: Please note that enabling this option causes makefile-mode | |
390 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \'it seems necessary\'. | |
391 | |
392 makefile-browser-hook: | |
393 A function or list of functions to be called just before the | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
394 browser is entered. This is executed in the makefile buffer. |
809 | 395 |
396 makefile-special-targets-list: | |
397 List of special targets. You will be offered to complete | |
398 on one of those in the minibuffer whenever you enter a \".\" | |
399 at the beginning of a line in makefile-mode." | |
400 (interactive) | |
401 (kill-all-local-variables) | |
402 (if (not (memq 'makefile-cleanup-continuations write-file-hooks)) | |
403 (setq write-file-hooks | |
404 (append write-file-hooks (list 'makefile-cleanup-continuations)))) | |
405 (make-variable-buffer-local 'makefile-target-table) | |
406 (make-variable-buffer-local 'makefile-macro-table) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
407 (make-variable-buffer-local 'makefile-has-prereqs) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
408 (make-variable-buffer-local 'makefile-need-target-pickup) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
409 (make-variable-buffer-local 'makefile-need-macro-pickup) |
809 | 410 (setq comment-start "#") |
411 (setq comment-end "") | |
412 (setq comment-start-skip "#[ \t]*") | |
413 ;; become the current major mode | |
414 (setq major-mode 'makefile-mode) | |
415 (setq mode-name makefile-mode-name) | |
416 ;; activate keymap | |
417 (use-local-map makefile-mode-map) | |
418 (set-syntax-table makefile-mode-syntax-table) | |
419 (run-hooks 'makefile-mode-hook)) | |
420 | |
421 (defun makefile-next-dependency () | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
422 "Move (point) to the beginning of the next dependency line below (point)." |
809 | 423 (interactive) |
424 (let ((here (point))) | |
425 (end-of-line) | |
426 (if (re-search-forward makefile-dependency-regex (point-max) t) | |
427 (progn (beginning-of-line) t) ; indicate success | |
428 (goto-char here) nil))) | |
429 | |
430 (defun makefile-previous-dependency () | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
431 "Move (point) to the beginning of the next dependency line above (point)." |
809 | 432 (interactive) |
433 (let ((here (point))) | |
434 (beginning-of-line) | |
435 (if (re-search-backward makefile-dependency-regex (point-min) t) | |
436 (progn (beginning-of-line) t) ; indicate success | |
437 (goto-char here) nil))) | |
438 | |
439 | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
440 ;;; Stuff below here depends on the pickup state |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
441 |
809 | 442 (defun makefile-electric-dot () |
443 "At (bol), offer completion on makefile-special-targets-list. | |
444 Anywhere else just insert a dot." | |
445 (interactive) | |
446 (if (bolp) | |
447 (makefile-insert-special-target) | |
448 (insert "."))) | |
449 | |
450 (defun makefile-insert-special-target () | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
451 "Complete on makefile-special-targets-list, insert result at (point)." |
809 | 452 (interactive) |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
453 (makefile-pickup-targets) |
809 | 454 (let |
455 ((special-target | |
456 (completing-read "Special target: " | |
457 makefile-special-targets-list nil nil nil))) | |
458 (if (zerop (length special-target)) | |
459 () | |
460 (insert (format ".%s:" special-target)) | |
461 (makefile-forward-after-target-colon)))) | |
462 | |
463 (defun makefile-electric-equal () | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
464 "At (bol) do makefile-insert-macro. Anywhere else just self-insert." |
809 | 465 (interactive) |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
466 (makefile-pickup-macros) |
809 | 467 (if (bolp) |
468 (call-interactively 'makefile-insert-macro) | |
469 (insert "="))) | |
470 | |
471 (defun makefile-insert-macro (macro-name) | |
472 "Prepare definition of a new macro." | |
473 (interactive "sMacro Name: ") | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
474 (makefile-pickup-macros) |
809 | 475 (if (not (zerop (length macro-name))) |
476 (progn | |
477 (beginning-of-line) | |
478 (insert (format "%s%s" macro-name makefile-macro-assign)) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
479 (setq makefile-need-macro-pickup t) |
809 | 480 (makefile-remember-macro macro-name)))) |
481 | |
482 (defun makefile-insert-macro-ref (macro-name) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
483 "Complete on a list of known macros, then insert complete ref at (point)." |
809 | 484 (interactive |
485 (list | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
486 (progn |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
487 (makefile-pickup-macros) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
488 (completing-read "Refer to macro: " makefile-macro-table nil nil nil)))) |
809 | 489 (if (not (zerop (length macro-name))) |
490 (if (assoc macro-name makefile-runtime-macros-list) | |
491 (insert (format "$%s " macro-name)) | |
492 (insert (makefile-format-macro-ref macro-name) " ")))) | |
493 | |
494 (defun makefile-insert-target (target-name) | |
495 "Prepare definition of a new target (dependency line)." | |
496 (interactive "sTarget: ") | |
497 (if (not (zerop (length target-name))) | |
498 (progn | |
499 (beginning-of-line) | |
500 (insert (format "%s%s" target-name makefile-target-colon)) | |
501 (makefile-forward-after-target-colon) | |
502 (end-of-line) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
503 (setq makefile-need-target-pickup t) |
809 | 504 (makefile-remember-target target-name)))) |
505 | |
506 (defun makefile-insert-target-ref (target-name) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
507 "Complete on a list of known targets, then insert target-ref at (point) ." |
809 | 508 (interactive |
509 (list | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
510 (pogn |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
511 (makefile-pickup-targets) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
512 (completing-read "Refer to target: " makefile-target-table nil nil nil)))) |
809 | 513 (if (not (zerop (length target-name))) |
514 (progn | |
515 (insert (format "%s " target-name))))) | |
516 | |
517 (defun makefile-electric-colon () | |
518 "At (bol) defines a new target, anywhere else just self-insert ." | |
519 (interactive) | |
520 (if (bolp) | |
521 (call-interactively 'makefile-insert-target) | |
522 (insert ":"))) | |
523 | |
524 ;;; ------------------------------------------------------------ | |
525 ;;; Extracting targets and macros from an existing makefile | |
526 ;;; ------------------------------------------------------------ | |
527 | |
528 (defun makefile-pickup-targets () | |
529 "Scan a buffer that contains a makefile for target definitions (dependencies) | |
530 and add them to the list of known targets." | |
531 (interactive) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
532 (if (not makefile-need-target-pickup) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
533 nil |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
534 (setq makefile-need-target-pickup nil) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
535 (setq makefile-target-table nil) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
536 (setq makefile-has-prereqs nil) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
537 (save-excursion |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
538 (goto-char (point-min)) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
539 (while (re-search-forward makefile-dependency-regex (point-max) t) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
540 (makefile-add-this-line-targets))) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
541 (message "Read targets OK."))) |
809 | 542 |
543 (defun makefile-add-this-line-targets () | |
544 (save-excursion | |
545 (beginning-of-line) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
546 (let ((done-with-line nil) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
547 (line-number (1+ (count-lines (point-min) (point))))) |
809 | 548 (while (not done-with-line) |
549 (skip-chars-forward " \t") | |
550 (if (not (setq done-with-line (or (eolp) | |
551 (char-equal (char-after (point)) ?:)))) | |
552 (progn | |
553 (let* ((start-of-target-name (point)) | |
554 (target-name | |
555 (progn | |
556 (skip-chars-forward "^ \t:#") | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
557 (buffer-substring start-of-target-name (point)))) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
558 (has-prereqs |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
559 (not (looking-at ":[ \t]*$")))) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
560 (if (makefile-remember-target target-name has-prereqs) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
561 (message "Picked up target \"%s\" from line %d" |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
562 target-name line-number))))))))) |
809 | 563 |
564 | |
565 (defun makefile-pickup-macros () | |
566 "Scan a buffer that contains a makefile for macro definitions | |
567 and add them to the list of known macros." | |
568 (interactive) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
569 (if (not makefile-need-macro-pickup) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
570 nil |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
571 (setq makefile-need-macro-pickup nil) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
572 (setq makefile-macro-table nil) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
573 (save-excursion |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
574 (goto-char (point-min)) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
575 (while (re-search-forward makefile-macroassign-regex (point-max) t) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
576 (makefile-add-this-line-macro) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
577 (forward-line 1))) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
578 (message "Read macros OK."))) |
809 | 579 |
580 (defun makefile-add-this-line-macro () | |
581 (save-excursion | |
582 (beginning-of-line) | |
583 (skip-chars-forward " \t") | |
584 (if (not (eolp)) | |
585 (let* ((start-of-macro-name (point)) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
586 (line-number (1+ (count-lines (point-min) (point)))) |
809 | 587 (macro-name (progn |
588 (skip-chars-forward "^ \t:#=*") | |
589 (buffer-substring start-of-macro-name (point))))) | |
590 (if (makefile-remember-macro macro-name) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
591 (message "Picked up macro \"%s\" from line %d" |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
592 macro-name line-number)))))) |
809 | 593 |
594 (defun makefile-pickup-everything () | |
595 "Calls makefile-pickup-targets and makefile-pickup-macros. | |
596 See their documentation for what they do." | |
597 (interactive) | |
598 (makefile-pickup-macros) | |
599 (makefile-pickup-targets) | |
600 (if makefile-pickup-everything-picks-up-filenames-p | |
601 (makefile-pickup-filenames-as-targets))) | |
602 | |
603 | |
604 (defun makefile-pickup-filenames-as-targets () | |
605 "Scan the current directory for filenames, check each filename | |
606 against makefile-ignored-files-in-pickup-regex and add all qualifying | |
607 names to the list of known targets." | |
608 (interactive) | |
609 (let* ((dir (file-name-directory (buffer-file-name))) | |
610 (raw-filename-list (if dir | |
611 (file-name-all-completions "" dir) | |
612 (file-name-all-completions "" "")))) | |
613 (mapcar '(lambda (name) | |
614 (if (and (not (file-directory-p name)) | |
615 (not (string-match makefile-ignored-files-in-pickup-regex | |
616 name))) | |
617 (if (makefile-remember-target name) | |
618 (message "Picked up file \"%s\" as target" name)))) | |
619 raw-filename-list))) | |
620 | |
621 ;;; ------------------------------------------------------------ | |
622 ;;; The browser window | |
623 ;;; ------------------------------------------------------------ | |
624 | |
625 (defun makefile-browser-format-target-line (target selected) | |
626 (format | |
627 (concat (make-string makefile-browser-leftmost-column ?\ ) | |
628 (if selected | |
629 makefile-browser-selected-mark | |
630 makefile-browser-unselected-mark) | |
631 "%s%s") | |
632 target makefile-target-colon)) | |
633 | |
634 (defun makefile-browser-format-macro-line (macro selected) | |
635 (format | |
636 (concat (make-string makefile-browser-leftmost-column ?\ ) | |
637 (if selected | |
638 makefile-browser-selected-mark | |
639 makefile-browser-unselected-mark) | |
640 (makefile-format-macro-ref macro)))) | |
641 | |
642 (defun makefile-browser-fill (targets macros) | |
643 (setq buffer-read-only nil) | |
644 (goto-char (point-min)) | |
645 (erase-buffer) | |
646 (mapconcat | |
647 (function | |
648 (lambda (item) (insert (makefile-browser-format-target-line (car item) nil) "\n"))) | |
649 targets | |
650 "") | |
651 (mapconcat | |
652 (function | |
653 (lambda (item) (insert (makefile-browser-format-macro-line (car item) nil) "\n"))) | |
654 macros | |
655 "") | |
656 (sort-lines nil (point-min) (point-max)) | |
657 (goto-char (1- (point-max))) | |
658 (delete-char 1) ; remove unnecessary newline at eob | |
659 (goto-char (point-min)) | |
660 (forward-char makefile-browser-cursor-column) | |
661 (setq buffer-read-only t)) | |
662 | |
663 ;;; | |
664 ;;; Moving up and down in the browser | |
665 ;;; | |
666 | |
667 (defun makefile-browser-next-line () | |
668 "Move the browser selection cursor to the next line." | |
669 (interactive) | |
670 (if (not (makefile-last-line-p)) | |
671 (progn | |
672 (forward-line 1) | |
673 (forward-char makefile-browser-cursor-column)))) | |
674 | |
675 (defun makefile-browser-previous-line () | |
676 "Move the browser selection cursor to the previous line." | |
677 (interactive) | |
678 (if (not (makefile-first-line-p)) | |
679 (progn | |
680 (forward-line -1) | |
681 (forward-char makefile-browser-cursor-column)))) | |
682 | |
683 ;;; | |
684 ;;; Quitting the browser (returns to client buffer) | |
685 ;;; | |
686 | |
687 (defun makefile-browser-quit () | |
688 "Leave the makefile-browser-buffer and return to the buffer | |
689 from that it has been entered." | |
690 (interactive) | |
691 (let ((my-client makefile-browser-client)) | |
692 (setq makefile-browser-client nil) ; we quitted, so NO client! | |
693 (set-buffer-modified-p nil) | |
694 (kill-buffer (current-buffer)) | |
695 (pop-to-buffer my-client))) | |
696 | |
697 ;;; | |
698 ;;; Toggle state of a browser item | |
699 ;;; | |
700 | |
701 (defun makefile-browser-toggle () | |
702 "Toggle the selection state of the browser item at the cursor position." | |
703 (interactive) | |
704 (let ((this-line (count-lines (point-min) (point)))) | |
705 (setq this-line (max 1 this-line)) | |
706 (makefile-browser-toggle-state-for-line this-line) | |
707 (goto-line this-line) | |
708 (setq buffer-read-only nil) | |
709 (beginning-of-line) | |
710 (if (makefile-browser-on-macro-line-p) | |
711 (let ((macro-name (makefile-browser-this-line-macro-name))) | |
712 (kill-line) | |
713 (insert | |
714 (makefile-browser-format-macro-line | |
715 macro-name | |
716 (makefile-browser-get-state-for-line this-line)))) | |
717 (let ((target-name (makefile-browser-this-line-target-name))) | |
718 (kill-line) | |
719 (insert | |
720 (makefile-browser-format-target-line | |
721 target-name | |
722 (makefile-browser-get-state-for-line this-line))))) | |
723 (setq buffer-read-only t) | |
724 (beginning-of-line) | |
725 (forward-char makefile-browser-cursor-column) | |
726 (if makefile-browser-auto-advance-after-selection-p | |
727 (makefile-browser-next-line)))) | |
728 | |
729 ;;; | |
730 ;;; Making insertions into the client buffer | |
731 ;;; | |
732 | |
733 (defun makefile-browser-insert-continuation () | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
734 "Insert a makefile continuation. |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
735 In the browser\'s client buffer, go to (end-of-line), insert a \'\\\' |
809 | 736 character, insert a new blank line, go to that line and indent by one TAB. |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
737 This is most useful in the process of creating continued lines when copying |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
738 large dependencies from the browser to the client buffer. |
809 | 739 (point) advances accordingly in the client buffer." |
740 (interactive) | |
741 (save-excursion | |
742 (set-buffer makefile-browser-client) | |
743 (end-of-line) | |
744 (insert "\\\n\t"))) | |
745 | |
746 (defun makefile-browser-insert-selection () | |
747 "Insert all browser-selected targets and/or macros in the browser\'s | |
748 client buffer. | |
749 Insertion takes place at (point)." | |
750 (interactive) | |
751 (save-excursion | |
752 (goto-line 1) | |
753 (let ((current-line 1)) | |
754 (while (not (eobp)) | |
755 (if (makefile-browser-get-state-for-line current-line) | |
756 (makefile-browser-send-this-line-item)) | |
757 (forward-line 1) | |
758 (setq current-line (1+ current-line)))))) | |
759 | |
760 (defun makefile-browser-insert-selection-and-quit () | |
761 (interactive) | |
762 (makefile-browser-insert-selection) | |
763 (makefile-browser-quit)) | |
764 | |
765 (defun makefile-browser-send-this-line-item () | |
766 (if (makefile-browser-on-macro-line-p) | |
767 (save-excursion | |
768 (let ((macro-name (makefile-browser-this-line-macro-name))) | |
769 (set-buffer makefile-browser-client) | |
770 (insert (makefile-format-macro-ref macro-name) " "))) | |
771 (save-excursion | |
772 (let ((target-name (makefile-browser-this-line-target-name))) | |
773 (set-buffer makefile-browser-client) | |
774 (insert target-name " "))))) | |
775 | |
776 (defun makefile-browser-start-interaction () | |
777 (use-local-map makefile-browser-map) | |
778 (setq buffer-read-only t)) | |
779 | |
780 (defun makefile-browse (targets macros) | |
781 (interactive) | |
782 (if (zerop (+ (length targets) (length macros))) | |
783 (progn | |
784 (beep) | |
785 (message "No macros or targets to browse! Consider running 'makefile-pickup-everything\'")) | |
786 (let ((browser-buffer (get-buffer-create makefile-browser-buffer-name))) | |
787 (pop-to-buffer browser-buffer) | |
788 (make-variable-buffer-local 'makefile-browser-selection-vector) | |
789 (makefile-browser-fill targets macros) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
790 (shrink-window-if-larger-than-buffer) |
809 | 791 (setq makefile-browser-selection-vector |
792 (make-vector (+ (length targets) (length macros)) nil)) | |
793 (makefile-browser-start-interaction)))) | |
794 | |
795 (defun makefile-switch-to-browser () | |
796 (interactive) | |
797 (run-hooks 'makefile-browser-hook) | |
798 (setq makefile-browser-client (current-buffer)) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
799 (makefile-pickup-targets) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
800 (makefile-pickup-macros) |
809 | 801 (makefile-browse makefile-target-table makefile-macro-table)) |
802 | |
803 | |
804 ;;; ------------------------------------------------------------ | |
805 ;;; Up-to-date overview buffer | |
806 ;;; ------------------------------------------------------------ | |
807 | |
808 (defun makefile-create-up-to-date-overview () | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
809 "Create a buffer containing an overview of the state of all known targets. |
809 | 810 Known targets are targets that are explicitly defined in that makefile; |
811 in other words, all targets that appear on the left hand side of a | |
812 dependency in the makefile." | |
813 (interactive) | |
814 (if (y-or-n-p "Are you sure that the makefile being edited is consistent? ") | |
815 ;; | |
816 ;; The rest of this function operates on a temporary makefile, created by | |
817 ;; writing the current contents of the makefile buffer. | |
818 ;; | |
819 (let ((saved-target-table makefile-target-table) | |
820 (this-buffer (current-buffer)) | |
821 (makefile-up-to-date-buffer | |
822 (get-buffer-create makefile-up-to-date-buffer-name)) | |
823 (filename (makefile-save-temporary)) | |
824 ;; | |
825 ;; Forget the target table because it may contain picked-up filenames | |
826 ;; that are not really targets in the current makefile. | |
827 ;; We don't want to query these, so get a new target-table with just the | |
828 ;; targets that can be found in the makefile buffer. | |
829 ;; The 'old' target table will be restored later. | |
830 ;; | |
831 (real-targets (progn | |
832 (makefile-pickup-targets) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
833 makefile-target-table)) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
834 (prereqs makefile-has-prereqs) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
835 ) |
809 | 836 |
837 (set-buffer makefile-up-to-date-buffer) | |
838 (setq buffer-read-only nil) | |
839 (erase-buffer) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
840 (makefile-query-targets filename real-targets prereqs) |
809 | 841 (if (zerop (buffer-size)) ; if it did not get us anything |
842 (progn | |
843 (kill-buffer (current-buffer)) | |
844 (message "No overview created!"))) | |
845 (set-buffer this-buffer) | |
846 (setq makefile-target-table saved-target-table) | |
847 (if (get-buffer makefile-up-to-date-buffer-name) | |
848 (progn | |
849 (pop-to-buffer (get-buffer makefile-up-to-date-buffer-name)) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
850 (shrink-window-if-larger-than-buffer) |
809 | 851 (sort-lines nil (point-min) (point-max)) |
852 (setq buffer-read-only t)))))) | |
853 | |
854 (defun makefile-save-temporary () | |
855 "Create a temporary file from the current makefile buffer." | |
856 (let ((filename (makefile-generate-temporary-filename))) | |
857 (write-region (point-min) (point-max) filename nil 0) | |
858 filename)) ; return the filename | |
859 | |
860 (defun makefile-generate-temporary-filename () | |
861 "Create a filename suitable for use in makefile-save-temporary. | |
862 Be careful to allow brain-dead file systems (DOS, SYSV ...) to cope | |
863 with the generated name !" | |
864 (let ((my-name (user-login-name)) | |
865 (my-uid (int-to-string (user-uid)))) | |
866 (concat "mktmp" | |
867 (if (> (length my-name) 3) | |
868 (substring my-name 0 3) | |
869 my-name) | |
870 "." | |
871 (if (> (length my-uid) 3) | |
872 (substring my-uid 0 3) | |
873 my-uid)))) | |
874 | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
875 (defun makefile-query-targets (filename target-table prereq-list) |
809 | 876 "This function fills the up-to-date-overview-buffer. |
877 It checks each target in target-table using makefile-query-one-target-method | |
878 and generates the overview, one line per target name." | |
879 (insert | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
880 (mapconcat |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
881 (function (lambda (item) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
882 (let* ((target-name (car item)) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
883 (no-prereqs (not (member target-name prereq-list))) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
884 (needs-rebuild (or no-prereqs |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
885 (funcall |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
886 makefile-query-one-target-method |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
887 target-name |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
888 filename)))) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
889 (format "\t%s%s" |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
890 target-name |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
891 (cond (no-prereqs " .. has no prerequisites") |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
892 (needs-rebuild " .. NEEDS REBUILD") |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
893 (t " .. is up to date")))) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
894 )) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
895 target-table "\n")) |
809 | 896 (goto-char (point-min)) |
897 (delete-file filename)) ; remove the tmpfile | |
898 | |
899 (defun makefile-query-by-make-minus-q (target &optional filename) | |
900 (not (zerop (call-process makefile-brave-make nil nil nil "-f" filename "-q" target)))) | |
901 | |
902 ;;; ------------------------------------------------------------ | |
903 ;;; Continuation cleanup | |
904 ;;; ------------------------------------------------------------ | |
905 | |
906 (defun makefile-cleanup-continuations () | |
907 (if (eq major-mode 'makefile-mode) | |
908 (if (and makefile-cleanup-continuations-p | |
909 (not buffer-read-only)) | |
910 (save-excursion | |
911 (goto-char (point-min)) | |
912 (while (re-search-forward "\\\\[ \t]+$" (point-max) t) | |
913 (replace-match "\\" t t)))))) | |
914 | |
915 ;;; ------------------------------------------------------------ | |
916 ;;; GNU make function support | |
917 ;;; ------------------------------------------------------------ | |
918 | |
919 (defun makefile-insert-gmake-function () | |
920 "This function is intended to help you using the numerous | |
921 macro-like \'function calls\' of GNU make. | |
922 It will ask you for the name of the function you wish to | |
923 use (with completion), then, after you selected the function, | |
924 it will prompt you for all required parameters. | |
925 This function \'knows\' about the required parameters of every | |
926 GNU make function and will use meaningfull prompts for the | |
927 various args, making it much easier to take advantage of this | |
928 powerfull GNU make feature." | |
929 (interactive) | |
930 (let* ((gm-function-name (completing-read | |
931 "Function: " | |
932 makefile-gnumake-functions-alist | |
933 nil t nil)) | |
934 (gm-function-prompts | |
935 (cdr (assoc gm-function-name makefile-gnumake-functions-alist)))) | |
936 (if (not (zerop (length gm-function-name))) | |
937 (insert (makefile-format-macro-ref | |
938 (concat gm-function-name " " | |
939 (makefile-prompt-for-gmake-funargs | |
940 gm-function-name gm-function-prompts))) | |
941 " ")))) | |
942 | |
943 (defun makefile-prompt-for-gmake-funargs (function-name prompt-list) | |
944 (mapconcat | |
945 (function (lambda (one-prompt) | |
946 (read-string (format "[%s] %s: " function-name one-prompt) nil))) | |
947 prompt-list | |
948 ",")) | |
949 | |
950 | |
951 | |
952 ;;; ------------------------------------------------------------ | |
953 ;;; Utility functions | |
954 ;;; ------------------------------------------------------------ | |
955 | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
956 (defun makefile-remember-target (target-name &optional has-prereqs) |
809 | 957 "Remember a given target if it is not already remembered for this buffer." |
958 (if (not (zerop (length target-name))) | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
959 (progn |
809 | 960 (if (not (assoc target-name makefile-target-table)) |
961 (setq makefile-target-table | |
2559
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
962 (cons (list target-name) makefile-target-table))) |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
963 (if has-prereqs |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
964 (setq makefile-has-prereqs |
5f2c2994cbca
Rewritten and simplified, commentary added. It now will usually
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2534
diff
changeset
|
965 (cons target-name makefile-has-prereqs)))))) |
809 | 966 |
967 (defun makefile-remember-macro (macro-name) | |
968 "Remember a given macro if it is not already remembered for this buffer." | |
969 (if (not (zerop (length macro-name))) | |
970 (if (not (assoc macro-name makefile-macro-table)) | |
971 (setq makefile-macro-table | |
972 (cons (list macro-name) makefile-macro-table))))) | |
973 | |
974 (defun makefile-forward-after-target-colon () | |
975 "Move point forward after the terminating colon | |
976 of a target has been inserted. | |
977 This accts according to the value of makefile-tab-after-target-colon ." | |
978 (if makefile-tab-after-target-colon | |
979 (insert "\t") | |
980 (insert " "))) | |
981 | |
982 (defun makefile-browser-on-macro-line-p () | |
983 "Determine if point is on a macro line in the browser." | |
984 (save-excursion | |
985 (beginning-of-line) | |
986 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t))) | |
987 | |
988 (defun makefile-browser-this-line-target-name () | |
989 "Extract the target name from a line in the browser." | |
990 (save-excursion | |
991 (end-of-line) | |
992 (skip-chars-backward "^ \t") | |
993 (buffer-substring (point) (1- (makefile-end-of-line-point))))) | |
994 | |
995 (defun makefile-browser-this-line-macro-name () | |
996 "Extract the macro name from a line in the browser." | |
997 (save-excursion | |
998 (beginning-of-line) | |
999 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t) | |
1000 (let ((macro-start (point))) | |
1001 (skip-chars-forward "^})") | |
1002 (buffer-substring macro-start (point))))) | |
1003 | |
1004 (defun makefile-format-macro-ref (macro-name) | |
1005 "Format a macro reference according to the value of the | |
1006 configuration variable makefile-use-curly-braces-for-macros-p ." | |
1007 (if makefile-use-curly-braces-for-macros-p | |
1008 (format "${%s}" macro-name) | |
1009 (format "$(%s)" macro-name))) | |
1010 | |
1011 (defun makefile-browser-get-state-for-line (n) | |
1012 (aref makefile-browser-selection-vector (1- n))) | |
1013 | |
1014 (defun makefile-browser-set-state-for-line (n to-state) | |
1015 (aset makefile-browser-selection-vector (1- n) to-state)) | |
1016 | |
1017 (defun makefile-browser-toggle-state-for-line (n) | |
1018 (makefile-browser-set-state-for-line n (not (makefile-browser-get-state-for-line n)))) | |
1019 | |
1020 (defun makefile-beginning-of-line-point () | |
1021 (save-excursion | |
1022 (beginning-of-line) | |
1023 (point))) | |
1024 | |
1025 (defun makefile-end-of-line-point () | |
1026 (save-excursion | |
1027 (end-of-line) | |
1028 (point))) | |
1029 | |
1030 (defun makefile-last-line-p () | |
1031 (= (makefile-end-of-line-point) (point-max))) | |
1032 | |
1033 (defun makefile-first-line-p () | |
1034 (= (makefile-beginning-of-line-point) (point-min))) | |
1035 | |
1036 ;; makefile.el ends here |