0
|
1 ;;; make-mode.el --- makefile editing commands for Emacs
|
|
2
|
|
3 ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Thomas Neumann <tom@smart.bo.open.de>
|
|
6 ;; Eric S. Raymond <esr@snark.thyrsus.com>
|
|
7 ;; Adapted-By: ESR
|
|
8 ;; Keywords: unix, tools
|
|
9
|
|
10 ;; RMS:
|
|
11 ;; This needs work.
|
|
12 ;; Also, the doc strings need fixing: the first line doesn't stand alone,
|
|
13 ;; and other usage is not high quality. Symbol names don't have `...'.
|
|
14
|
|
15 ;; This file is part of XEmacs.
|
|
16
|
|
17 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
18 ;; under the terms of the GNU General Public License as published by
|
|
19 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
20 ;; any later version.
|
|
21
|
|
22 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
23 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
25 ;; General Public License for more details.
|
|
26
|
|
27 ;; You should have received a copy of the GNU General Public License
|
|
28 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
2
|
29 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
30 ;; 02111-1307, USA.
|
0
|
31
|
2
|
32 ;;; Synched up with: FSF 19.34.
|
0
|
33
|
|
34 ;;; Commentary:
|
|
35
|
|
36 ;; A major mode for editing makefiles. The mode knows about Makefile
|
|
37 ;; syntax and defines M-n and M-p to move to next and previous productions.
|
|
38 ;;
|
|
39 ;; The keys $, =, : and . are electric; they try to help you fill in a
|
|
40 ;; macro reference, macro definition, ordinary target name, or special
|
|
41 ;; target name, respectively. Such names are completed using a list of
|
|
42 ;; targets and macro names parsed out of the makefile. This list is
|
|
43 ;; automatically updated, if necessary, whenever you invoke one of
|
|
44 ;; these commands. You can force it to be updated with C-c C-p.
|
|
45 ;;
|
|
46 ;; The command C-c C-f adds certain filenames in the current directory
|
|
47 ;; as targets. You can filter out filenames by setting the variable
|
|
48 ;; makefile-ignored-files-in-pickup-regex.
|
|
49 ;;
|
|
50 ;; The command C-c C-u grinds for a bit, then pops up a report buffer
|
|
51 ;; showing which target names are up-to-date with respect to their
|
|
52 ;; prerequisites, which targets are out-of-date, and which have no
|
|
53 ;; prerequisites.
|
|
54 ;;
|
|
55 ;; The command C-c C-b pops up a browser window listing all target and
|
|
56 ;; macro names. You can mark or unmark items wit C-c SPC, and insert
|
|
57 ;; all marked items back in the Makefile with C-c TAB.
|
|
58 ;;
|
|
59 ;; The command C-c TAB in the makefile buffer inserts a GNU make builtin.
|
|
60 ;; You will be prompted for the builtin's args.
|
|
61 ;;
|
|
62 ;; There are numerous other customization variables.
|
|
63
|
|
64 ;;
|
|
65 ;; To Do:
|
|
66 ;;
|
|
67 ;; * makefile-backslash-region should be given better behavior.
|
|
68 ;; * Consider binding C-c C-c to comment-region (like cc-mode).
|
|
69 ;; * Eliminate electric stuff entirely.
|
|
70 ;; * It might be nice to highlight targets differently depending on
|
|
71 ;; whether they are up-to-date or not. Not sure how this would
|
|
72 ;; interact with font-lock.
|
|
73 ;; * Would be nice to edit the commands in ksh-mode and have
|
|
74 ;; indentation and slashification done automatically. Hard.
|
|
75 ;; * Consider removing browser mode. It seems useless.
|
|
76 ;; * ":" should notice when a new target is made and add it to the
|
|
77 ;; list (or at least set makefile-need-target-pickup).
|
|
78 ;; * Make browser into a major mode.
|
|
79 ;; * Clean up macro insertion stuff. It is a mess.
|
|
80 ;; * Browser entry and exit is weird. Normalize.
|
|
81 ;; * Browser needs to be rewritten. Right now it is kind of a crock.
|
|
82 ;; Should at least:
|
|
83 ;; * Act more like dired/buffer menu/whatever.
|
|
84 ;; * Highlight as mouse traverses.
|
|
85 ;; * B2 inserts.
|
|
86 ;; * Update documentation above.
|
|
87 ;; * Update texinfo manual.
|
|
88 ;; * Update files.el.
|
|
89
|
|
90
|
|
91
|
|
92 ;;; Code:
|
|
93
|
|
94 (provide 'makefile)
|
|
95
|
|
96 ;; Sadly we need this for a macro.
|
2
|
97 (eval-when-compile
|
|
98 (require 'imenu))
|
0
|
99
|
|
100 ;;; ------------------------------------------------------------
|
|
101 ;;; Configurable stuff
|
|
102 ;;; ------------------------------------------------------------
|
|
103
|
|
104 (defvar makefile-browser-buffer-name "*Macros and Targets*"
|
|
105 "Name of the macro- and target browser buffer.")
|
|
106
|
|
107 (defvar makefile-target-colon ":"
|
|
108 "String to append to all target names inserted by `makefile-insert-target'.
|
|
109 \":\" or \"::\" are common values.")
|
|
110
|
|
111 (defvar makefile-macro-assign " = "
|
|
112 "String to append to all macro names inserted by `makefile-insert-macro'.
|
|
113 The normal value should be \" = \", since this is what
|
|
114 standard make expects. However, newer makes such as dmake
|
|
115 allow a larger variety of different macro assignments, so you
|
|
116 might prefer to use \" += \" or \" := \" .")
|
|
117
|
|
118 (defvar makefile-electric-keys nil
|
|
119 "If non-nil, install electric keybindings.
|
|
120 Default is nil.")
|
|
121
|
|
122 (defvar makefile-use-curly-braces-for-macros-p nil
|
|
123 "Controls the style of generated macro references.
|
|
124 t (actually non-nil) means macro references should use curly braces,
|
|
125 like `${this}'.
|
|
126 nil means use parentheses, like `$(this)'.")
|
|
127
|
|
128 (defvar makefile-tab-after-target-colon t
|
|
129 "If non-nil, insert a TAB after a target colon.
|
|
130 Otherwise, a space is inserted.
|
|
131 The default is t.")
|
|
132
|
|
133 (defvar makefile-browser-leftmost-column 10
|
|
134 "Number of blanks to the left of the browser selection mark.")
|
|
135
|
|
136 (defvar makefile-browser-cursor-column 10
|
|
137 "Column in which the cursor is positioned when it moves
|
|
138 up or down in the browser.")
|
|
139
|
|
140 (defvar makefile-backslash-column 48
|
|
141 "*Column in which `makefile-backslash-region' inserts backslashes.")
|
|
142
|
|
143 (defvar makefile-browser-selected-mark "+ "
|
|
144 "String used to mark selected entries in the browser.")
|
|
145
|
|
146 (defvar makefile-browser-unselected-mark " "
|
|
147 "String used to mark unselected entries in the browser.")
|
|
148
|
|
149 (defvar makefile-browser-auto-advance-after-selection-p t
|
|
150 "If non-nil, cursor will move after item is selected in browser.")
|
|
151
|
|
152 (defvar makefile-pickup-everything-picks-up-filenames-p nil
|
|
153 "If non-nil, `makefile-pickup-everything' picks up filenames as targets.
|
|
154 \(i.e. it calls `makefile-find-filenames-as-targets').
|
|
155 Otherwise filenames are omitted.")
|
|
156
|
|
157 (defvar makefile-cleanup-continuations-p t
|
|
158 "If non-nil, automatically clean up continuation lines when saving.
|
|
159 A line is cleaned up by removing all whitespace following a trailing
|
|
160 backslash. This is done silently.
|
|
161 IMPORTANT: Please note that enabling this option causes makefile-mode
|
|
162 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \'it seems necessary\'.")
|
|
163
|
|
164 (defvar makefile-browser-hook '())
|
|
165
|
|
166 ;;
|
|
167 ;; Special targets for DMake, Sun's make ...
|
|
168 ;;
|
|
169 (defvar makefile-special-targets-list
|
|
170 '(("DEFAULT") ("DONE") ("ERROR") ("EXPORT")
|
|
171 ("FAILED") ("GROUPEPILOG") ("GROUPPROLOG") ("IGNORE")
|
|
172 ("IMPORT") ("INCLUDE") ("INCLUDEDIRS") ("INIT")
|
|
173 ("KEEP_STATE") ("MAKEFILES") ("MAKE_VERSION") ("NO_PARALLEL")
|
|
174 ("PARALLEL") ("PHONY") ("PRECIOUS") ("REMOVE")
|
|
175 ("SCCS_GET") ("SILENT") ("SOURCE") ("SUFFIXES")
|
|
176 ("WAIT") ("c.o") ("C.o") ("m.o")
|
|
177 ("el.elc") ("y.c") ("s.o"))
|
|
178 "List of special targets.
|
|
179 You will be offered to complete on one of those in the minibuffer whenever
|
|
180 you enter a \".\" at the beginning of a line in makefile-mode.")
|
|
181
|
|
182 (defvar makefile-runtime-macros-list
|
2
|
183 '(("@") ("&") (">") ("<") ("*") ("^") ("+") ("?") ("%") ("$"))
|
0
|
184 "List of macros that are resolved by make at runtime.
|
|
185 If you insert a macro reference using makefile-insert-macro-ref, the name
|
|
186 of the macro is checked against this list. If it can be found its name will
|
|
187 not be enclosed in { } or ( ).")
|
|
188
|
|
189 ;; Note that the first big subexpression is used by font lock. Note
|
|
190 ;; that if you change this regexp you must fix the imenu index
|
|
191 ;; function defined at the end of the file.
|
|
192 (defconst makefile-dependency-regex
|
|
193 "^\\([^ \n\t#:]+\\([ \t]+[^ \t\n#:]+\\)*\\)[ \t]*:\\([ \t]*$\\|\\([^=\n].*$\\)\\)"
|
|
194 "Regex used to find dependency lines in a makefile.")
|
|
195
|
|
196 ;; Note that the first subexpression is used by font lock. Note that
|
|
197 ;; if you change this regexp you must fix the imenu index function
|
|
198 ;; defined at the end of the file.
|
|
199 (defconst makefile-macroassign-regex
|
|
200 "^\\([^ \n\t][^:#= \t\n]*\\)[ \t]*[*:+]?:?="
|
|
201 "Regex used to find macro assignment lines in a makefile.")
|
|
202
|
|
203 (defconst makefile-ignored-files-in-pickup-regex
|
|
204 "\\(^\\..*\\)\\|\\(.*~$\\)\\|\\(.*,v$\\)\\|\\(\\.[chy]\\)"
|
|
205 "Regex for filenames that will NOT be included in the target list.")
|
|
206
|
|
207 ;####
|
|
208 ;(add-to-list 'facemenu-unlisted-faces 'makefile-space-face)
|
|
209 ; Bogus FSFmacs crap.
|
2
|
210 (defvar makefile-space-face 'makefile-space-face
|
|
211 "Face to use for highlighting leading spaces in Font-Lock mode.")
|
0
|
212
|
|
213 ;Older version of same.
|
|
214 ;(defconst makefile-font-lock-keywords (purecopy
|
|
215 ; (list
|
|
216 ; '("^#.*$" . font-lock-comment-face)
|
|
217 ; '("[^$]#.*$" . font-lock-comment-face)
|
|
218 ; ;; rules
|
|
219 ; '("^\\([^ \t\n]*%?[^ \t\n]*[ \t]*::?\\)[ \t]" 1 font-lock-type-face t)
|
|
220 ; '("^\\(\\.[A-Za-z][A-Za-z]?\\..[ \t]*::?\\)" 1 font-lock-type-face t)
|
|
221 ; '("^[^ \t\n]+[ \t]*:;?\\(.*\\)$" 1 font-lock-doc-string-face t)
|
|
222 ; ;; variable definition
|
|
223 ; '("^[_A-Za-z0-9]+[ \t]*\+?=" . font-lock-function-name-face)
|
|
224 ; '("\\( \\|:=\\)[_A-Za-z0-9]+[ \t]*\\+=" . font-lock-function-name-face)
|
|
225 ; ;; variable references
|
|
226 ; '("\\(\\$\\$?\\([^ \t\n{(]\\|[{(][^ \t\n)}]+[)}]\\)\\)"
|
|
227 ; 1 font-lock-keyword-face t)
|
|
228 ; '("^include " . font-lock-string-face)
|
|
229 ; ))
|
|
230
|
|
231 (defconst makefile-font-lock-keywords (purecopy
|
|
232 (list
|
|
233 ;; Do macro assignments. These get the "variable-name" face rather
|
|
234 ;; arbitrarily.
|
|
235 (list makefile-macroassign-regex 1 'font-lock-variable-name-face)
|
|
236 ;;
|
|
237 ;; Variable references even in targets/strings/comments:
|
2
|
238 '("\\$[({]\\([a-zA-Z0-9_]+\\)[})]" 1 font-lock-reference-face prepend)
|
0
|
239 ;;
|
|
240 ;; Do dependencies. These get the function name face.
|
2
|
241 (list makefile-dependency-regex 1 'font-lock-function-name-face 'prepend)
|
0
|
242
|
|
243 ;; Highlight lines that contain just whitespace.
|
|
244 ;; They can cause trouble, especially if they start with a tab.
|
|
245 '("^[ \t]+$" . makefile-space-face)
|
|
246
|
|
247 ;; Highlight shell comments that Make treats as commands,
|
|
248 ;; since these can fool people.
|
2
|
249 '("^\t+#" 0 makefile-space-face t)
|
0
|
250
|
|
251 ;; Highlight spaces that precede tabs.
|
|
252 ;; They can make a tab fail to be effective.
|
|
253 '("^\\( +\\)\t" 1 makefile-space-face)))
|
|
254 "Additional expressions to highlight in makefiles")
|
|
255
|
|
256 (put 'makefile-mode 'font-lock-defaults '(makefile-font-lock-keywords))
|
|
257
|
|
258 ;;; ------------------------------------------------------------
|
|
259 ;;; The following configurable variables are used in the
|
|
260 ;;; up-to-date overview .
|
|
261 ;;; The standard configuration assumes that your `make' program
|
|
262 ;;; can be run in question/query mode using the `-q' option, this
|
|
263 ;;; means that the command
|
|
264 ;;;
|
|
265 ;;; make -q foo
|
|
266 ;;;
|
|
267 ;;; should return an exit status of zero if the target `foo' is
|
|
268 ;;; up to date and a nonzero exit status otherwise.
|
|
269 ;;; Many makes can do this although the docs/manpages do not mention
|
|
270 ;;; it. Try it with your favourite one. GNU make, System V make, and
|
|
271 ;;; Dennis Vadura's DMake have no problems.
|
|
272 ;;; Set the variable `makefile-brave-make' to the name of the
|
|
273 ;;; make utility that does this on your system.
|
|
274 ;;; To understand what this is all about see the function definition
|
|
275 ;;; of `makefile-query-by-make-minus-q' .
|
|
276 ;;; ------------------------------------------------------------
|
|
277
|
|
278 (defvar makefile-brave-make "make"
|
|
279 "A make that can handle the `-q' option.")
|
|
280
|
|
281 (defvar makefile-query-one-target-method 'makefile-query-by-make-minus-q
|
|
282 "Function to call to determine whether a make target is up to date.
|
|
283 The function must satisfy this calling convention:
|
|
284
|
|
285 * As its first argument, it must accept the name of the target to
|
|
286 be checked, as a string.
|
|
287
|
|
288 * As its second argument, it may accept the name of a makefile
|
|
289 as a string. Depending on what you're going to do you may
|
|
290 not need this.
|
|
291
|
|
292 * It must return the integer value 0 (zero) if the given target
|
|
293 should be considered up-to-date in the context of the given
|
|
294 makefile, any nonzero integer value otherwise.")
|
|
295
|
|
296 (defvar makefile-up-to-date-buffer-name "*Makefile Up-to-date overview*"
|
|
297 "Name of the Up-to-date overview buffer.")
|
|
298
|
|
299 ;;; --- end of up-to-date-overview configuration ------------------
|
|
300
|
|
301 (defvar makefile-mode-map nil
|
|
302 "The keymap that is used in Makefile mode.")
|
|
303
|
|
304 (if makefile-mode-map
|
|
305 ()
|
|
306 (setq makefile-mode-map (make-sparse-keymap 'makefile-mode-map))
|
|
307 ;; set up the keymap
|
|
308 (define-key makefile-mode-map "\C-c:" 'makefile-insert-target-ref)
|
|
309 (if makefile-electric-keys
|
|
310 (progn
|
|
311 (define-key makefile-mode-map "$" 'makefile-insert-macro-ref)
|
|
312 (define-key makefile-mode-map ":" 'makefile-electric-colon)
|
|
313 (define-key makefile-mode-map "=" 'makefile-electric-equal)
|
|
314 (define-key makefile-mode-map "." 'makefile-electric-dot)))
|
|
315 (define-key makefile-mode-map "\C-c\C-f" 'makefile-pickup-filenames-as-targets)
|
|
316 (define-key makefile-mode-map "\C-c\C-b" 'makefile-switch-to-browser)
|
|
317 (define-key makefile-mode-map "\C-c\C-p" 'makefile-pickup-everything)
|
|
318 (define-key makefile-mode-map "\C-c\C-u" 'makefile-create-up-to-date-overview)
|
|
319 (define-key makefile-mode-map "\C-c\C-i" 'makefile-insert-gmake-function)
|
|
320 (define-key makefile-mode-map "\C-c\C-\\" 'makefile-backslash-region)
|
|
321 (define-key makefile-mode-map "\M-p" 'makefile-previous-dependency)
|
|
322 (define-key makefile-mode-map "\M-n" 'makefile-next-dependency)
|
|
323 (define-key makefile-mode-map "\e\t" 'makefile-complete))
|
|
324
|
2
|
325 ;; XEmacs change
|
0
|
326 (defconst makefile-menubar-menu
|
|
327 (purecopy
|
|
328 '("Makefile"
|
|
329 ["Move to Next Dependency" makefile-next-dependency t]
|
|
330 ["Move to Previous Dependency" makefile-previous-dependency t]
|
|
331 "---"
|
|
332 ["Find Targets and Macros" makefile-pickup-everything t]
|
|
333 ["Complete Target or Macro" makefile-complete t]
|
|
334 ["Pop up Makefile Browser" makefile-switch-to-browser t])))
|
|
335
|
2
|
336 ;; XEmacs change
|
0
|
337 (defconst makefile-popup-menu
|
|
338 (purecopy
|
|
339 (cons "Makefile Mode Commands"
|
|
340 (cdr makefile-menubar-menu))))
|
|
341
|
|
342 (defvar makefile-browser-map nil
|
|
343 "The keymap that is used in the macro- and target browser.")
|
|
344 (if makefile-browser-map
|
|
345 ()
|
|
346 (setq makefile-browser-map (make-sparse-keymap))
|
|
347 (define-key makefile-browser-map "n" 'makefile-browser-next-line)
|
|
348 (define-key makefile-browser-map "\C-n" 'makefile-browser-next-line)
|
|
349 (define-key makefile-browser-map "p" 'makefile-browser-previous-line)
|
|
350 (define-key makefile-browser-map "\C-p" 'makefile-browser-previous-line)
|
|
351 (define-key makefile-browser-map " " 'makefile-browser-toggle)
|
|
352 (define-key makefile-browser-map "i" 'makefile-browser-insert-selection)
|
|
353 (define-key makefile-browser-map "I" 'makefile-browser-insert-selection-and-quit)
|
|
354 (define-key makefile-browser-map "\C-c\C-m" 'makefile-browser-insert-continuation)
|
|
355 (define-key makefile-browser-map "q" 'makefile-browser-quit)
|
|
356 ;; disable horizontal movement
|
|
357 (define-key makefile-browser-map "\C-b" 'undefined)
|
|
358 (define-key makefile-browser-map "\C-f" 'undefined))
|
|
359
|
|
360
|
|
361 (defvar makefile-mode-syntax-table nil)
|
|
362 (if makefile-mode-syntax-table
|
|
363 ()
|
|
364 (setq makefile-mode-syntax-table (make-syntax-table))
|
|
365 (modify-syntax-entry ?\( "() " makefile-mode-syntax-table)
|
|
366 (modify-syntax-entry ?\) ")( " makefile-mode-syntax-table)
|
|
367 (modify-syntax-entry ?\[ "(] " makefile-mode-syntax-table)
|
|
368 (modify-syntax-entry ?\] ")[ " makefile-mode-syntax-table)
|
|
369 (modify-syntax-entry ?\{ "(} " makefile-mode-syntax-table)
|
|
370 (modify-syntax-entry ?\} "){ " makefile-mode-syntax-table)
|
|
371 (modify-syntax-entry ?\' "\" " makefile-mode-syntax-table)
|
|
372 (modify-syntax-entry ?\` "\" " makefile-mode-syntax-table)
|
|
373 (modify-syntax-entry ?# "< " makefile-mode-syntax-table)
|
|
374 (modify-syntax-entry ?\n "> " makefile-mode-syntax-table))
|
|
375
|
|
376
|
|
377 ;;; ------------------------------------------------------------
|
|
378 ;;; Internal variables.
|
|
379 ;;; You don't need to configure below this line.
|
|
380 ;;; ------------------------------------------------------------
|
|
381
|
|
382 (defvar makefile-target-table nil
|
|
383 "Table of all target names known for this buffer.")
|
|
384
|
|
385 (defvar makefile-macro-table nil
|
|
386 "Table of all macro names known for this buffer.")
|
|
387
|
|
388 (defvar makefile-browser-client
|
|
389 "A buffer in Makefile mode that is currently using the browser.")
|
|
390
|
|
391 (defvar makefile-browser-selection-vector nil)
|
|
392 (defvar makefile-has-prereqs nil)
|
|
393 (defvar makefile-need-target-pickup t)
|
|
394 (defvar makefile-need-macro-pickup t)
|
|
395
|
|
396 (defvar makefile-mode-hook '())
|
|
397
|
|
398 ;; Each element looks like '("GNU MAKE FUNCTION" "ARG" "ARG" ... )
|
|
399 ;; Each "ARG" is used as a prompt for a required argument.
|
|
400 (defconst makefile-gnumake-functions-alist
|
|
401 '(
|
|
402 ;; Text functions
|
|
403 ("subst" "From" "To" "In")
|
|
404 ("patsubst" "Pattern" "Replacement" "In")
|
|
405 ("strip" "Text")
|
|
406 ("findstring" "Find what" "In")
|
|
407 ("filter" "Pattern" "Text")
|
|
408 ("filter-out" "Pattern" "Text")
|
|
409 ("sort" "List")
|
|
410 ;; Filename functions
|
|
411 ("dir" "Names")
|
|
412 ("notdir" "Names")
|
|
413 ("suffix" "Names")
|
|
414 ("basename" "Names")
|
2
|
415 ("addprefix" "Prefix" "Names")
|
0
|
416 ("addsuffix" "Suffix" "Names")
|
|
417 ("join" "List 1" "List 2")
|
|
418 ("word" "Index" "Text")
|
|
419 ("words" "Text")
|
|
420 ("firstword" "Text")
|
|
421 ("wildcard" "Pattern")
|
|
422 ;; Misc functions
|
|
423 ("foreach" "Variable" "List" "Text")
|
|
424 ("origin" "Variable")
|
|
425 ("shell" "Command")))
|
|
426
|
|
427
|
|
428 ;;; ------------------------------------------------------------
|
|
429 ;;; The mode function itself.
|
|
430 ;;; ------------------------------------------------------------
|
|
431
|
|
432 ;;;###autoload
|
|
433 (defun makefile-mode ()
|
|
434 "Major mode for editing Makefiles.
|
|
435 This function ends by invoking the function(s) `makefile-mode-hook'.
|
|
436
|
|
437 \\{makefile-mode-map}
|
|
438
|
|
439 In the browser, use the following keys:
|
|
440
|
|
441 \\{makefile-browser-map}
|
|
442
|
|
443 Makefile mode can be configured by modifying the following variables:
|
|
444
|
|
445 makefile-browser-buffer-name:
|
|
446 Name of the macro- and target browser buffer.
|
|
447
|
|
448 makefile-target-colon:
|
|
449 The string that gets appended to all target names
|
|
450 inserted by `makefile-insert-target'.
|
|
451 \":\" or \"::\" are quite common values.
|
|
452
|
|
453 makefile-macro-assign:
|
|
454 The string that gets appended to all macro names
|
|
455 inserted by `makefile-insert-macro'.
|
|
456 The normal value should be \" = \", since this is what
|
|
457 standard make expects. However, newer makes such as dmake
|
|
458 allow a larger variety of different macro assignments, so you
|
|
459 might prefer to use \" += \" or \" := \" .
|
|
460
|
|
461 makefile-tab-after-target-colon:
|
|
462 If you want a TAB (instead of a space) to be appended after the
|
|
463 target colon, then set this to a non-nil value.
|
|
464
|
|
465 makefile-browser-leftmost-column:
|
|
466 Number of blanks to the left of the browser selection mark.
|
|
467
|
|
468 makefile-browser-cursor-column:
|
|
469 Column in which the cursor is positioned when it moves
|
|
470 up or down in the browser.
|
|
471
|
|
472 makefile-browser-selected-mark:
|
|
473 String used to mark selected entries in the browser.
|
|
474
|
|
475 makefile-browser-unselected-mark:
|
|
476 String used to mark unselected entries in the browser.
|
|
477
|
|
478 makefile-browser-auto-advance-after-selection-p:
|
|
479 If this variable is set to a non-nil value the cursor
|
|
480 will automagically advance to the next line after an item
|
|
481 has been selected in the browser.
|
|
482
|
|
483 makefile-pickup-everything-picks-up-filenames-p:
|
|
484 If this variable is set to a non-nil value then
|
|
485 `makefile-pickup-everything' also picks up filenames as targets
|
|
486 (i.e. it calls `makefile-find-filenames-as-targets'), otherwise
|
|
487 filenames are omitted.
|
|
488
|
|
489 makefile-cleanup-continuations-p:
|
|
490 If this variable is set to a non-nil value then makefile-mode
|
|
491 will assure that no line in the file ends with a backslash
|
|
492 (the continuation character) followed by any whitespace.
|
|
493 This is done by silently removing the trailing whitespace, leaving
|
|
494 the backslash itself intact.
|
|
495 IMPORTANT: Please note that enabling this option causes makefile-mode
|
|
496 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \"it seems necessary\".
|
|
497
|
|
498 makefile-browser-hook:
|
|
499 A function or list of functions to be called just before the
|
|
500 browser is entered. This is executed in the makefile buffer.
|
|
501
|
|
502 makefile-special-targets-list:
|
|
503 List of special targets. You will be offered to complete
|
|
504 on one of those in the minibuffer whenever you enter a `.'.
|
|
505 at the beginning of a line in Makefile mode."
|
|
506
|
|
507 (interactive)
|
|
508 (kill-all-local-variables)
|
|
509 (make-local-variable 'local-write-file-hooks)
|
|
510 (setq local-write-file-hooks
|
|
511 '(makefile-cleanup-continuations makefile-warn-suspicious-lines))
|
|
512 (make-local-variable 'makefile-target-table)
|
|
513 (make-local-variable 'makefile-macro-table)
|
|
514 (make-local-variable 'makefile-has-prereqs)
|
|
515 (make-local-variable 'makefile-need-target-pickup)
|
|
516 (make-local-variable 'makefile-need-macro-pickup)
|
|
517
|
|
518 ;; Font lock.
|
2
|
519 (if (fboundp 'make-face)
|
0
|
520 (makefile-define-space-face))
|
2
|
521 (make-local-variable 'font-lock-defaults)
|
|
522 (setq font-lock-defaults '(makefile-font-lock-keywords))
|
0
|
523
|
|
524 ;; Add-log.
|
|
525 (make-local-variable 'add-log-current-defun-function)
|
|
526 (setq add-log-current-defun-function 'makefile-add-log-defun)
|
|
527
|
2
|
528 ;; Imenu.
|
|
529 (make-local-variable 'imenu-create-index-function)
|
|
530 (setq imenu-create-index-function 'makefile-menu-index-function)
|
0
|
531
|
|
532 ;; Dabbrev.
|
|
533 (make-local-variable 'dabbrev-abbrev-skip-leading-regexp)
|
|
534 (setq dabbrev-abbrev-skip-leading-regexp "\\$")
|
|
535
|
|
536 ;; Comment stuff.
|
|
537 (make-local-variable 'comment-start)
|
|
538 (setq comment-start "#")
|
|
539 (make-local-variable 'comment-end)
|
|
540 (setq comment-end "")
|
|
541 (make-local-variable 'comment-start-skip)
|
|
542 (setq comment-start-skip "#+[ \t]*")
|
|
543
|
|
544 ;; become the current major mode
|
|
545 (setq major-mode 'makefile-mode)
|
|
546 (setq mode-name "Makefile")
|
|
547
|
|
548 ;; Activate keymap and syntax table.
|
|
549 (use-local-map makefile-mode-map)
|
|
550 (set-syntax-table makefile-mode-syntax-table)
|
|
551
|
|
552 ;; Set menu
|
2
|
553 ;; XEmacs addition
|
0
|
554 (setq mode-popup-menu makefile-popup-menu)
|
|
555 (if (featurep 'menubar)
|
|
556 (progn
|
|
557 ;; make a local copy of the menubar, so our modes don't
|
|
558 ;; change the global menubar
|
|
559 (set-buffer-menubar current-menubar)
|
|
560 (add-submenu nil makefile-menubar-menu)))
|
|
561
|
|
562 ;; Real TABs are important in makefiles
|
|
563 (setq indent-tabs-mode t)
|
|
564 (run-hooks 'makefile-mode-hook))
|
|
565
|
|
566
|
|
567
|
|
568 ;;; Motion code.
|
|
569
|
|
570 (defun makefile-next-dependency ()
|
|
571 "Move point to the beginning of the next dependency line."
|
|
572 (interactive)
|
|
573 (let ((here (point)))
|
|
574 (end-of-line)
|
|
575 (if (re-search-forward makefile-dependency-regex (point-max) t)
|
|
576 (progn (beginning-of-line) t) ; indicate success
|
|
577 (goto-char here) nil)))
|
|
578
|
|
579 (defun makefile-previous-dependency ()
|
|
580 "Move point to the beginning of the previous dependency line."
|
|
581 (interactive)
|
|
582 (let ((here (point)))
|
|
583 (beginning-of-line)
|
|
584 (if (re-search-backward makefile-dependency-regex (point-min) t)
|
|
585 (progn (beginning-of-line) t) ; indicate success
|
|
586 (goto-char here) nil)))
|
|
587
|
|
588
|
|
589
|
|
590 ;;; Electric keys. Blech.
|
|
591
|
|
592 (defun makefile-electric-dot (arg)
|
|
593 "Prompt for the name of a special target to insert.
|
|
594 Only does electric insertion at beginning of line.
|
|
595 Anywhere else just self-inserts."
|
|
596 (interactive "p")
|
|
597 (if (bolp)
|
|
598 (makefile-insert-special-target)
|
|
599 (self-insert-command arg)))
|
|
600
|
|
601 (defun makefile-insert-special-target ()
|
|
602 "Propmt for and insert a special target name.
|
|
603 Uses `makefile-special-targets' list."
|
|
604 (interactive)
|
|
605 (makefile-pickup-targets)
|
|
606 (let ((special-target
|
|
607 (completing-read "Special target: "
|
|
608 makefile-special-targets-list nil nil nil)))
|
|
609 (if (zerop (length special-target))
|
|
610 ()
|
|
611 (insert "." special-target ":")
|
|
612 (makefile-forward-after-target-colon))))
|
|
613
|
|
614 (defun makefile-electric-equal (arg)
|
|
615 "Prompt for name of a macro to insert.
|
|
616 Only does prompting if point is at beginning of line.
|
|
617 Anywhere else just self-inserts."
|
|
618 (interactive "p")
|
|
619 (makefile-pickup-macros)
|
|
620 (if (bolp)
|
|
621 (call-interactively 'makefile-insert-macro)
|
|
622 (self-insert-command arg)))
|
|
623
|
|
624 (defun makefile-insert-macro (macro-name)
|
|
625 "Prepare definition of a new macro."
|
|
626 (interactive "sMacro Name: ")
|
|
627 (makefile-pickup-macros)
|
|
628 (if (not (zerop (length macro-name)))
|
|
629 (progn
|
|
630 (beginning-of-line)
|
|
631 (insert macro-name makefile-macro-assign)
|
|
632 (setq makefile-need-macro-pickup t)
|
|
633 (makefile-remember-macro macro-name))))
|
|
634
|
|
635 (defun makefile-insert-macro-ref (macro-name)
|
|
636 "Complete on a list of known macros, then insert complete ref at point."
|
|
637 (interactive
|
|
638 (list
|
|
639 (progn
|
|
640 (makefile-pickup-macros)
|
|
641 (completing-read "Refer to macro: " makefile-macro-table nil nil nil))))
|
|
642 (makefile-do-macro-insertion macro-name))
|
|
643
|
|
644 (defun makefile-insert-target (target-name)
|
|
645 "Prepare definition of a new target (dependency line)."
|
|
646 (interactive "sTarget: ")
|
|
647 (if (not (zerop (length target-name)))
|
|
648 (progn
|
|
649 (beginning-of-line)
|
|
650 (insert target-name makefile-target-colon)
|
|
651 (makefile-forward-after-target-colon)
|
|
652 (end-of-line)
|
|
653 (setq makefile-need-target-pickup t)
|
|
654 (makefile-remember-target target-name))))
|
|
655
|
|
656 (defun makefile-insert-target-ref (target-name)
|
|
657 "Complete on a list of known targets, then insert target-ref at point."
|
|
658 (interactive
|
|
659 (list
|
|
660 (progn
|
|
661 (makefile-pickup-targets)
|
|
662 (completing-read "Refer to target: " makefile-target-table nil nil nil))))
|
|
663 (if (not (zerop (length target-name)))
|
|
664 (insert target-name " ")))
|
|
665
|
|
666 (defun makefile-electric-colon (arg)
|
|
667 "Prompt for name of new target.
|
|
668 Prompting only happens at beginning of line.
|
|
669 Anywhere else just self-inserts."
|
|
670 (interactive "p")
|
|
671 (if (bolp)
|
|
672 (call-interactively 'makefile-insert-target)
|
|
673 (self-insert-command arg)))
|
|
674
|
|
675
|
|
676
|
|
677 ;;; ------------------------------------------------------------
|
|
678 ;;; Extracting targets and macros from an existing makefile
|
|
679 ;;; ------------------------------------------------------------
|
|
680
|
|
681 (defun makefile-pickup-targets ()
|
|
682 "Notice names of all target definitions in Makefile."
|
|
683 (interactive)
|
|
684 (if (not makefile-need-target-pickup)
|
|
685 nil
|
|
686 (setq makefile-need-target-pickup nil)
|
|
687 (setq makefile-target-table nil)
|
|
688 (setq makefile-has-prereqs nil)
|
|
689 (save-excursion
|
|
690 (goto-char (point-min))
|
|
691 (while (re-search-forward makefile-dependency-regex (point-max) t)
|
|
692 (makefile-add-this-line-targets)))
|
|
693 (message "Read targets OK.")))
|
|
694
|
|
695 (defun makefile-add-this-line-targets ()
|
|
696 (save-excursion
|
|
697 (beginning-of-line)
|
|
698 (let ((done-with-line nil)
|
|
699 (line-number (1+ (count-lines (point-min) (point)))))
|
|
700 (while (not done-with-line)
|
|
701 (skip-chars-forward " \t")
|
|
702 (if (not (setq done-with-line (or (eolp)
|
|
703 (char-equal (char-after (point)) ?:))))
|
|
704 (progn
|
|
705 (let* ((start-of-target-name (point))
|
|
706 (target-name
|
|
707 (progn
|
|
708 (skip-chars-forward "^ \t:#")
|
|
709 (buffer-substring start-of-target-name (point))))
|
|
710 (has-prereqs
|
|
711 (not (looking-at ":[ \t]*$"))))
|
|
712 (if (makefile-remember-target target-name has-prereqs)
|
|
713 (message "Picked up target \"%s\" from line %d"
|
|
714 target-name line-number)))))))))
|
|
715
|
|
716 (defun makefile-pickup-macros ()
|
|
717 "Notice names of all macro definitions in Makefile."
|
|
718 (interactive)
|
|
719 (if (not makefile-need-macro-pickup)
|
|
720 nil
|
|
721 (setq makefile-need-macro-pickup nil)
|
|
722 (setq makefile-macro-table nil)
|
|
723 (save-excursion
|
|
724 (goto-char (point-min))
|
|
725 (while (re-search-forward makefile-macroassign-regex (point-max) t)
|
|
726 (makefile-add-this-line-macro)
|
|
727 (forward-line 1)))
|
|
728 (message "Read macros OK.")))
|
|
729
|
|
730 (defun makefile-add-this-line-macro ()
|
|
731 (save-excursion
|
|
732 (beginning-of-line)
|
|
733 (skip-chars-forward " \t")
|
|
734 (if (not (eolp))
|
|
735 (let* ((start-of-macro-name (point))
|
|
736 (line-number (1+ (count-lines (point-min) (point))))
|
|
737 (macro-name (progn
|
|
738 (skip-chars-forward "^ \t:#=*")
|
|
739 (buffer-substring start-of-macro-name (point)))))
|
|
740 (if (makefile-remember-macro macro-name)
|
|
741 (message "Picked up macro \"%s\" from line %d"
|
|
742 macro-name line-number))))))
|
|
743
|
|
744 (defun makefile-pickup-everything (arg)
|
|
745 "Notice names of all macros and targets in Makefile.
|
|
746 Prefix arg means force pickups to be redone."
|
|
747 (interactive "P")
|
|
748 (if arg
|
|
749 (progn
|
|
750 (setq makefile-need-target-pickup t)
|
|
751 (setq makefile-need-macro-pickup t)))
|
|
752 (makefile-pickup-macros)
|
|
753 (makefile-pickup-targets)
|
|
754 (if makefile-pickup-everything-picks-up-filenames-p
|
|
755 (makefile-pickup-filenames-as-targets)))
|
|
756
|
|
757 (defun makefile-pickup-filenames-as-targets ()
|
|
758 "Scan the current directory for filenames to use as targets.
|
|
759 Checks each filename against `makefile-ignored-files-in-pickup-regex'
|
|
760 and adds all qualifying names to the list of known targets."
|
|
761 (interactive)
|
|
762 (let* ((dir (file-name-directory (buffer-file-name)))
|
|
763 (raw-filename-list (if dir
|
|
764 (file-name-all-completions "" dir)
|
|
765 (file-name-all-completions "" ""))))
|
|
766 (mapcar '(lambda (name)
|
|
767 (if (and (not (file-directory-p name))
|
|
768 (not (string-match makefile-ignored-files-in-pickup-regex
|
|
769 name)))
|
|
770 (if (makefile-remember-target name)
|
|
771 (message "Picked up file \"%s\" as target" name))))
|
|
772 raw-filename-list)))
|
|
773
|
|
774
|
|
775
|
|
776 ;;; Completion.
|
|
777
|
|
778 (defun makefile-complete ()
|
|
779 "Perform completion on Makefile construct preceding point.
|
|
780 Can complete variable and target names.
|
|
781 The context determines which are considered."
|
|
782 (interactive)
|
|
783 (let* ((beg (save-excursion
|
|
784 (skip-chars-backward "^$(){}:#= \t\n")
|
|
785 (point)))
|
|
786 (try (buffer-substring beg (point)))
|
|
787 (do-macros nil)
|
|
788 (paren nil))
|
|
789
|
|
790 (save-excursion
|
|
791 (goto-char beg)
|
|
792 (let ((pc (preceding-char)))
|
|
793 (cond
|
|
794 ;; Beginning of line means anything.
|
|
795 ((bolp)
|
|
796 ())
|
|
797
|
|
798 ;; Preceding "$" means macros only.
|
|
799 ((= pc ?$)
|
|
800 (setq do-macros t))
|
|
801
|
|
802 ;; Preceding "$(" or "${" means macros only.
|
|
803 ((and (or (= pc ?{)
|
|
804 (= pc ?\())
|
|
805 (progn
|
|
806 (setq paren pc)
|
|
807 (backward-char)
|
|
808 (and (not (bolp))
|
|
809 (= (preceding-char) ?$))))
|
|
810 (setq do-macros t)))))
|
|
811
|
|
812 ;; Try completion.
|
|
813 (let* ((table (append (if do-macros
|
|
814 '()
|
|
815 makefile-target-table)
|
|
816 makefile-macro-table))
|
|
817 (completion (try-completion try table)))
|
|
818 (cond
|
|
819 ;; Exact match, so insert closing paren or colon.
|
|
820 ((eq completion t)
|
|
821 (insert (if do-macros
|
|
822 (if (eq paren ?{)
|
|
823 ?}
|
|
824 ?\))
|
|
825 (if (save-excursion
|
|
826 (goto-char beg)
|
|
827 (bolp))
|
|
828 ":"
|
|
829 " "))))
|
|
830
|
|
831 ;; No match.
|
|
832 ((null completion)
|
|
833 (message "Can't find completion for \"%s\"" try)
|
|
834 (ding))
|
|
835
|
|
836 ;; Partial completion.
|
|
837 ((not (string= try completion))
|
|
838 ;; FIXME it would be nice to supply the closing paren if an
|
|
839 ;; exact, unambiguous match were found. That is not possible
|
|
840 ;; right now. Ditto closing ":" for targets.
|
|
841 (delete-region beg (point))
|
|
842
|
|
843 ;; DO-MACROS means doing macros only. If not that, then check
|
|
844 ;; to see if this completion is a macro. Special insertion
|
|
845 ;; must be done for macros.
|
|
846 (if (or do-macros
|
|
847 (assoc completion makefile-macro-table))
|
|
848 (let ((makefile-use-curly-braces-for-macros-p
|
|
849 (or (eq paren ?{)
|
|
850 makefile-use-curly-braces-for-macros-p)))
|
|
851 (delete-backward-char 2)
|
|
852 (makefile-do-macro-insertion completion)
|
|
853 (delete-backward-char 1))
|
|
854
|
|
855 ;; Just insert targets.
|
|
856 (insert completion)))
|
|
857
|
|
858 ;; Can't complete any more, so make completion list. FIXME
|
|
859 ;; this doesn't do the right thing when the completion is
|
|
860 ;; actually inserted. I don't think there is an easy way to do
|
|
861 ;; that.
|
|
862 (t
|
|
863 (message "Making completion list...")
|
|
864 (let ((list (all-completions try table)))
|
|
865 (with-output-to-temp-buffer "*Completions*"
|
|
866 (display-completion-list list)))
|
|
867 (message "Making completion list...done"))))))
|
|
868
|
|
869
|
|
870
|
|
871 ;; Backslashification. Stolen from cc-mode.el.
|
|
872
|
|
873 (defun makefile-backslashify-current-line (doit)
|
|
874 (end-of-line)
|
|
875 (if doit
|
|
876 (if (not (save-excursion
|
|
877 (forward-char -1)
|
|
878 (eq (char-after (point)) ?\\ )))
|
|
879 (progn
|
|
880 (if (>= (current-column) makefile-backslash-column)
|
|
881 (insert " \\")
|
|
882 (while (<= (current-column) makefile-backslash-column)
|
|
883 (insert "\t")
|
|
884 (end-of-line))
|
|
885 (delete-char -1)
|
|
886 (while (< (current-column) makefile-backslash-column)
|
|
887 (insert " ")
|
|
888 (end-of-line))
|
|
889 (insert "\\"))))
|
|
890 (if (not (bolp))
|
|
891 (progn
|
|
892 (forward-char -1)
|
|
893 (if (eq (char-after (point)) ?\\ )
|
|
894 (let ((saved (save-excursion
|
|
895 (end-of-line)
|
|
896 (point))))
|
|
897 (skip-chars-backward " \t")
|
|
898 (delete-region (point) saved)))))))
|
|
899
|
|
900 (defun makefile-backslash-region (beg end arg)
|
|
901 "Insert backslashes at end of every line in region.
|
|
902 Useful for defining multi-line rules.
|
2
|
903 If called with a prefix argument, trailing backslashes are removed."
|
0
|
904 (interactive "r\nP")
|
|
905 (save-excursion
|
|
906 (let ((do-lastline-p (progn (goto-char end) (not (bolp)))))
|
|
907 (save-restriction
|
|
908 (narrow-to-region beg end)
|
|
909 (goto-char (point-min))
|
|
910 (while (not (save-excursion
|
|
911 (forward-line 1)
|
|
912 (eobp)))
|
|
913 (makefile-backslashify-current-line (null arg))
|
|
914 (forward-line 1)))
|
|
915 (and do-lastline-p
|
|
916 (progn (goto-char end)
|
|
917 (makefile-backslashify-current-line (null arg)))))))
|
|
918
|
|
919
|
|
920
|
|
921 ;;; ------------------------------------------------------------
|
|
922 ;;; Browser mode.
|
|
923 ;;; ------------------------------------------------------------
|
|
924
|
|
925 (defun makefile-browser-format-target-line (target selected)
|
|
926 (format
|
|
927 (concat (make-string makefile-browser-leftmost-column ?\ )
|
|
928 (if selected
|
|
929 makefile-browser-selected-mark
|
|
930 makefile-browser-unselected-mark)
|
|
931 "%s%s")
|
|
932 target makefile-target-colon))
|
|
933
|
|
934 (defun makefile-browser-format-macro-line (macro selected)
|
|
935 (format
|
|
936 (concat (make-string makefile-browser-leftmost-column ?\ )
|
|
937 (if selected
|
|
938 makefile-browser-selected-mark
|
|
939 makefile-browser-unselected-mark)
|
|
940 (makefile-format-macro-ref macro))))
|
|
941
|
|
942 (defun makefile-browser-fill (targets macros)
|
|
943 (let ((inhibit-read-only t))
|
|
944 (goto-char (point-min))
|
|
945 (erase-buffer)
|
|
946 (mapconcat
|
|
947 (function
|
|
948 (lambda (item) (insert (makefile-browser-format-target-line (car item) nil) "\n")))
|
|
949 targets
|
|
950 "")
|
|
951 (mapconcat
|
|
952 (function
|
|
953 (lambda (item) (insert (makefile-browser-format-macro-line (car item) nil) "\n")))
|
|
954 macros
|
|
955 "")
|
|
956 (sort-lines nil (point-min) (point-max))
|
|
957 (goto-char (1- (point-max)))
|
|
958 (delete-char 1) ; remove unnecessary newline at eob
|
|
959 (goto-char (point-min))
|
|
960 (forward-char makefile-browser-cursor-column)))
|
|
961
|
|
962 ;;;
|
|
963 ;;; Moving up and down in the browser
|
|
964 ;;;
|
|
965
|
|
966 (defun makefile-browser-next-line ()
|
|
967 "Move the browser selection cursor to the next line."
|
|
968 (interactive)
|
|
969 (if (not (makefile-last-line-p))
|
|
970 (progn
|
|
971 (forward-line 1)
|
|
972 (forward-char makefile-browser-cursor-column))))
|
|
973
|
|
974 (defun makefile-browser-previous-line ()
|
|
975 "Move the browser selection cursor to the previous line."
|
|
976 (interactive)
|
|
977 (if (not (makefile-first-line-p))
|
|
978 (progn
|
|
979 (forward-line -1)
|
|
980 (forward-char makefile-browser-cursor-column))))
|
|
981
|
|
982 ;;;
|
|
983 ;;; Quitting the browser (returns to client buffer)
|
|
984 ;;;
|
|
985
|
|
986 (defun makefile-browser-quit ()
|
|
987 "Leave the browser and return to the makefile buffer."
|
|
988 (interactive)
|
|
989 (let ((my-client makefile-browser-client))
|
|
990 (setq makefile-browser-client nil) ; we quitted, so NO client!
|
|
991 (set-buffer-modified-p nil)
|
|
992 (kill-buffer (current-buffer))
|
|
993 (pop-to-buffer my-client)))
|
|
994
|
|
995 ;;;
|
|
996 ;;; Toggle state of a browser item
|
|
997 ;;;
|
|
998
|
|
999 (defun makefile-browser-toggle ()
|
|
1000 "Toggle the selection state of the browser item at the cursor position."
|
|
1001 (interactive)
|
|
1002 (let ((this-line (count-lines (point-min) (point))))
|
|
1003 (setq this-line (max 1 this-line))
|
|
1004 (makefile-browser-toggle-state-for-line this-line)
|
|
1005 (goto-line this-line)
|
|
1006 (let ((inhibit-read-only t))
|
|
1007 (beginning-of-line)
|
|
1008 (if (makefile-browser-on-macro-line-p)
|
|
1009 (let ((macro-name (makefile-browser-this-line-macro-name)))
|
2
|
1010 (delete-region (point) (progn (end-of-line) (point)))
|
0
|
1011 (insert
|
|
1012 (makefile-browser-format-macro-line
|
|
1013 macro-name
|
|
1014 (makefile-browser-get-state-for-line this-line))))
|
|
1015 (let ((target-name (makefile-browser-this-line-target-name)))
|
2
|
1016 (delete-region (point) (progn (end-of-line) (point)))
|
0
|
1017 (insert
|
|
1018 (makefile-browser-format-target-line
|
|
1019 target-name
|
|
1020 (makefile-browser-get-state-for-line this-line))))))
|
|
1021 (beginning-of-line)
|
|
1022 (forward-char makefile-browser-cursor-column)
|
|
1023 (if makefile-browser-auto-advance-after-selection-p
|
|
1024 (makefile-browser-next-line))))
|
|
1025
|
|
1026 ;;;
|
|
1027 ;;; Making insertions into the client buffer
|
|
1028 ;;;
|
|
1029
|
|
1030 (defun makefile-browser-insert-continuation ()
|
|
1031 "Insert a makefile continuation.
|
|
1032 In the makefile buffer, go to (end-of-line), insert a \'\\\'
|
|
1033 character, insert a new blank line, go to that line and indent by one TAB.
|
|
1034 This is most useful in the process of creating continued lines when copying
|
|
1035 large dependencies from the browser to the client buffer.
|
|
1036 \(point) advances accordingly in the client buffer."
|
|
1037 (interactive)
|
|
1038 (save-excursion
|
|
1039 (set-buffer makefile-browser-client)
|
|
1040 (end-of-line)
|
|
1041 (insert "\\\n\t")))
|
|
1042
|
|
1043 (defun makefile-browser-insert-selection ()
|
|
1044 "Insert all selected targets and/or macros in the makefile buffer.
|
|
1045 Insertion takes place at point."
|
|
1046 (interactive)
|
|
1047 (save-excursion
|
|
1048 (goto-line 1)
|
|
1049 (let ((current-line 1))
|
|
1050 (while (not (eobp))
|
|
1051 (if (makefile-browser-get-state-for-line current-line)
|
|
1052 (makefile-browser-send-this-line-item))
|
|
1053 (forward-line 1)
|
|
1054 (setq current-line (1+ current-line))))))
|
|
1055
|
|
1056 (defun makefile-browser-insert-selection-and-quit ()
|
|
1057 (interactive)
|
|
1058 (makefile-browser-insert-selection)
|
|
1059 (makefile-browser-quit))
|
|
1060
|
|
1061 (defun makefile-browser-send-this-line-item ()
|
|
1062 (if (makefile-browser-on-macro-line-p)
|
|
1063 (save-excursion
|
|
1064 (let ((macro-name (makefile-browser-this-line-macro-name)))
|
|
1065 (set-buffer makefile-browser-client)
|
|
1066 (insert (makefile-format-macro-ref macro-name) " ")))
|
|
1067 (save-excursion
|
|
1068 (let ((target-name (makefile-browser-this-line-target-name)))
|
|
1069 (set-buffer makefile-browser-client)
|
|
1070 (insert target-name " ")))))
|
|
1071
|
|
1072 (defun makefile-browser-start-interaction ()
|
|
1073 (use-local-map makefile-browser-map)
|
|
1074 (setq buffer-read-only t))
|
|
1075
|
|
1076 (defun makefile-browse (targets macros)
|
|
1077 (interactive)
|
|
1078 (if (zerop (+ (length targets) (length macros)))
|
|
1079 (progn
|
|
1080 (beep)
|
|
1081 (message "No macros or targets to browse! Consider running 'makefile-pickup-everything\'"))
|
|
1082 (let ((browser-buffer (get-buffer-create makefile-browser-buffer-name)))
|
|
1083 (pop-to-buffer browser-buffer)
|
|
1084 (make-variable-buffer-local 'makefile-browser-selection-vector)
|
|
1085 (makefile-browser-fill targets macros)
|
|
1086 (shrink-window-if-larger-than-buffer)
|
|
1087 (setq makefile-browser-selection-vector
|
|
1088 (make-vector (+ (length targets) (length macros)) nil))
|
|
1089 (makefile-browser-start-interaction))))
|
|
1090
|
|
1091 (defun makefile-switch-to-browser ()
|
|
1092 (interactive)
|
|
1093 (run-hooks 'makefile-browser-hook)
|
|
1094 (setq makefile-browser-client (current-buffer))
|
|
1095 (makefile-pickup-targets)
|
|
1096 (makefile-pickup-macros)
|
|
1097 (makefile-browse makefile-target-table makefile-macro-table))
|
|
1098
|
|
1099
|
|
1100
|
|
1101 ;;; ------------------------------------------------------------
|
|
1102 ;;; Up-to-date overview buffer
|
|
1103 ;;; ------------------------------------------------------------
|
|
1104
|
|
1105 (defun makefile-create-up-to-date-overview ()
|
|
1106 "Create a buffer containing an overview of the state of all known targets.
|
|
1107 Known targets are targets that are explicitly defined in that makefile;
|
|
1108 in other words, all targets that appear on the left hand side of a
|
|
1109 dependency in the makefile."
|
|
1110 (interactive)
|
|
1111 (if (y-or-n-p "Are you sure that the makefile being edited is consistent? ")
|
|
1112 ;;
|
|
1113 ;; The rest of this function operates on a temporary makefile, created by
|
|
1114 ;; writing the current contents of the makefile buffer.
|
|
1115 ;;
|
|
1116 (let ((saved-target-table makefile-target-table)
|
|
1117 (this-buffer (current-buffer))
|
|
1118 (makefile-up-to-date-buffer
|
|
1119 (get-buffer-create makefile-up-to-date-buffer-name))
|
|
1120 (filename (makefile-save-temporary))
|
|
1121 ;;
|
|
1122 ;; Forget the target table because it may contain picked-up filenames
|
|
1123 ;; that are not really targets in the current makefile.
|
|
1124 ;; We don't want to query these, so get a new target-table with just the
|
|
1125 ;; targets that can be found in the makefile buffer.
|
|
1126 ;; The 'old' target table will be restored later.
|
|
1127 ;;
|
|
1128 (real-targets (progn
|
|
1129 (makefile-pickup-targets)
|
|
1130 makefile-target-table))
|
|
1131 (prereqs makefile-has-prereqs)
|
|
1132 )
|
|
1133
|
|
1134 (set-buffer makefile-up-to-date-buffer)
|
|
1135 (setq buffer-read-only nil)
|
|
1136 (erase-buffer)
|
|
1137 (makefile-query-targets filename real-targets prereqs)
|
|
1138 (if (zerop (buffer-size)) ; if it did not get us anything
|
|
1139 (progn
|
|
1140 (kill-buffer (current-buffer))
|
|
1141 (message "No overview created!")))
|
|
1142 (set-buffer this-buffer)
|
|
1143 (setq makefile-target-table saved-target-table)
|
|
1144 (if (get-buffer makefile-up-to-date-buffer-name)
|
|
1145 (progn
|
|
1146 (pop-to-buffer (get-buffer makefile-up-to-date-buffer-name))
|
|
1147 (shrink-window-if-larger-than-buffer)
|
|
1148 (sort-lines nil (point-min) (point-max))
|
|
1149 (setq buffer-read-only t))))))
|
|
1150
|
|
1151 (defun makefile-save-temporary ()
|
|
1152 "Create a temporary file from the current makefile buffer."
|
|
1153 (let ((filename (makefile-generate-temporary-filename)))
|
|
1154 (write-region (point-min) (point-max) filename nil 0)
|
|
1155 filename)) ; return the filename
|
|
1156
|
|
1157 (defun makefile-generate-temporary-filename ()
|
|
1158 "Create a filename suitable for use in `makefile-save-temporary'.
|
|
1159 Be careful to allow brain-dead file systems (DOS, SYSV ...) to cope
|
|
1160 with the generated name!"
|
|
1161 (let ((my-name (user-login-name))
|
|
1162 (my-uid (int-to-string (user-uid))))
|
|
1163 (concat "mktmp"
|
|
1164 (if (> (length my-name) 3)
|
|
1165 (substring my-name 0 3)
|
|
1166 my-name)
|
|
1167 "."
|
|
1168 (if (> (length my-uid) 3)
|
|
1169 (substring my-uid 0 3)
|
|
1170 my-uid))))
|
|
1171
|
|
1172 (defun makefile-query-targets (filename target-table prereq-list)
|
|
1173 "Fill the up-to-date overview buffer.
|
|
1174 Checks each target in TARGET-TABLE using `makefile-query-one-target-method'
|
|
1175 and generates the overview, one line per target name."
|
|
1176 (insert
|
|
1177 (mapconcat
|
|
1178 (function (lambda (item)
|
|
1179 (let* ((target-name (car item))
|
|
1180 (no-prereqs (not (member target-name prereq-list)))
|
|
1181 (needs-rebuild (or no-prereqs
|
|
1182 (funcall
|
|
1183 makefile-query-one-target-method
|
|
1184 target-name
|
|
1185 filename))))
|
|
1186 (format "\t%s%s"
|
|
1187 target-name
|
|
1188 (cond (no-prereqs " .. has no prerequisites")
|
|
1189 (needs-rebuild " .. NEEDS REBUILD")
|
|
1190 (t " .. is up to date"))))
|
|
1191 ))
|
|
1192 target-table "\n"))
|
|
1193 (goto-char (point-min))
|
|
1194 (delete-file filename)) ; remove the tmpfile
|
|
1195
|
|
1196 (defun makefile-query-by-make-minus-q (target &optional filename)
|
|
1197 (not (zerop
|
|
1198 (call-process makefile-brave-make nil nil nil
|
|
1199 "-f" filename "-q" target))))
|
|
1200
|
|
1201
|
|
1202
|
|
1203 ;;; ------------------------------------------------------------
|
|
1204 ;;; Continuation cleanup
|
|
1205 ;;; ------------------------------------------------------------
|
|
1206
|
|
1207 (defun makefile-cleanup-continuations ()
|
|
1208 (if (eq major-mode 'makefile-mode)
|
|
1209 (if (and makefile-cleanup-continuations-p
|
|
1210 (not buffer-read-only))
|
|
1211 (save-excursion
|
|
1212 (goto-char (point-min))
|
|
1213 (while (re-search-forward "\\\\[ \t]+$" (point-max) t)
|
|
1214 (replace-match "\\" t t))))))
|
|
1215
|
|
1216
|
|
1217 ;;; ------------------------------------------------------------
|
|
1218 ;;; Warn of suspicious lines
|
|
1219 ;;; ------------------------------------------------------------
|
|
1220
|
|
1221 (defun makefile-warn-suspicious-lines ()
|
|
1222 (let ((dont-save nil))
|
|
1223 (if (eq major-mode 'makefile-mode)
|
|
1224 (let ((suspicious
|
|
1225 (save-excursion
|
|
1226 (goto-char (point-min))
|
|
1227 (re-search-forward
|
|
1228 "\\(^[\t]+$\\)\\|\\(^[ ]+[\t]\\)" (point-max) t))))
|
|
1229 (if suspicious
|
|
1230 (let ((line-nr (count-lines (point-min) suspicious)))
|
|
1231 (setq dont-save
|
|
1232 (not (y-or-n-p
|
|
1233 (format "Suspicious line %d. Save anyway "
|
|
1234 line-nr))))))))
|
|
1235 dont-save))
|
|
1236
|
|
1237
|
|
1238
|
|
1239 ;;; ------------------------------------------------------------
|
|
1240 ;;; GNU make function support
|
|
1241 ;;; ------------------------------------------------------------
|
|
1242
|
|
1243 (defun makefile-insert-gmake-function ()
|
|
1244 "Insert a GNU make function call.
|
|
1245 Asks for the name of the function to use (with completion).
|
|
1246 Then prompts for all required parameters."
|
|
1247 (interactive)
|
|
1248 (let* ((gm-function-name (completing-read
|
|
1249 "Function: "
|
|
1250 makefile-gnumake-functions-alist
|
|
1251 nil t nil))
|
|
1252 (gm-function-prompts
|
|
1253 (cdr (assoc gm-function-name makefile-gnumake-functions-alist))))
|
|
1254 (if (not (zerop (length gm-function-name)))
|
|
1255 (insert (makefile-format-macro-ref
|
|
1256 (concat gm-function-name " "
|
|
1257 (makefile-prompt-for-gmake-funargs
|
|
1258 gm-function-name gm-function-prompts)))
|
|
1259 " "))))
|
|
1260
|
|
1261 (defun makefile-prompt-for-gmake-funargs (function-name prompt-list)
|
|
1262 (mapconcat
|
|
1263 (function (lambda (one-prompt)
|
|
1264 (read-string (format "[%s] %s: " function-name one-prompt)
|
|
1265 nil)))
|
|
1266 prompt-list
|
|
1267 ","))
|
|
1268
|
|
1269
|
|
1270
|
|
1271 ;;; ------------------------------------------------------------
|
|
1272 ;;; Utility functions
|
|
1273 ;;; ------------------------------------------------------------
|
|
1274
|
|
1275 (defun makefile-do-macro-insertion (macro-name)
|
|
1276 "Insert a macro reference."
|
|
1277 (if (not (zerop (length macro-name)))
|
|
1278 (if (assoc macro-name makefile-runtime-macros-list)
|
|
1279 (insert "$" macro-name)
|
|
1280 (insert (makefile-format-macro-ref macro-name)))))
|
|
1281
|
|
1282 (defun makefile-remember-target (target-name &optional has-prereqs)
|
|
1283 "Remember a given target if it is not already remembered for this buffer."
|
|
1284 (if (not (zerop (length target-name)))
|
|
1285 (progn
|
|
1286 (if (not (assoc target-name makefile-target-table))
|
|
1287 (setq makefile-target-table
|
|
1288 (cons (list target-name) makefile-target-table)))
|
|
1289 (if has-prereqs
|
|
1290 (setq makefile-has-prereqs
|
|
1291 (cons target-name makefile-has-prereqs))))))
|
|
1292
|
|
1293 (defun makefile-remember-macro (macro-name)
|
|
1294 "Remember a given macro if it is not already remembered for this buffer."
|
|
1295 (if (not (zerop (length macro-name)))
|
|
1296 (if (not (assoc macro-name makefile-macro-table))
|
|
1297 (setq makefile-macro-table
|
|
1298 (cons (list macro-name) makefile-macro-table)))))
|
|
1299
|
|
1300 (defun makefile-forward-after-target-colon ()
|
|
1301 "Move point forward after inserting the terminating colon of a target.
|
|
1302 This acts according to the value of `makefile-tab-after-target-colon'."
|
|
1303 (if makefile-tab-after-target-colon
|
|
1304 (insert "\t")
|
|
1305 (insert " ")))
|
|
1306
|
|
1307 (defun makefile-browser-on-macro-line-p ()
|
|
1308 "Determine if point is on a macro line in the browser."
|
|
1309 (save-excursion
|
|
1310 (beginning-of-line)
|
|
1311 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t)))
|
|
1312
|
|
1313 (defun makefile-browser-this-line-target-name ()
|
|
1314 "Extract the target name from a line in the browser."
|
|
1315 (save-excursion
|
|
1316 (end-of-line)
|
|
1317 (skip-chars-backward "^ \t")
|
|
1318 (buffer-substring (point) (1- (makefile-end-of-line-point)))))
|
|
1319
|
|
1320 (defun makefile-browser-this-line-macro-name ()
|
|
1321 "Extract the macro name from a line in the browser."
|
|
1322 (save-excursion
|
|
1323 (beginning-of-line)
|
|
1324 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t)
|
|
1325 (let ((macro-start (point)))
|
|
1326 (skip-chars-forward "^})")
|
|
1327 (buffer-substring macro-start (point)))))
|
|
1328
|
|
1329 (defun makefile-format-macro-ref (macro-name)
|
|
1330 "Format a macro reference.
|
|
1331 Uses `makefile-use-curly-braces-for-macros-p'."
|
|
1332 (if (or (char-equal ?\( (string-to-char macro-name))
|
|
1333 (char-equal ?\{ (string-to-char macro-name)))
|
|
1334 (format "$%s" macro-name)
|
|
1335 (if makefile-use-curly-braces-for-macros-p
|
|
1336 (format "${%s}" macro-name)
|
|
1337 (format "$(%s)" macro-name))))
|
|
1338
|
|
1339 (defun makefile-browser-get-state-for-line (n)
|
|
1340 (aref makefile-browser-selection-vector (1- n)))
|
|
1341
|
|
1342 (defun makefile-browser-set-state-for-line (n to-state)
|
|
1343 (aset makefile-browser-selection-vector (1- n) to-state))
|
|
1344
|
|
1345 (defun makefile-browser-toggle-state-for-line (n)
|
|
1346 (makefile-browser-set-state-for-line n (not (makefile-browser-get-state-for-line n))))
|
|
1347
|
|
1348 (defun makefile-beginning-of-line-point ()
|
|
1349 (save-excursion
|
|
1350 (beginning-of-line)
|
|
1351 (point)))
|
|
1352
|
|
1353 (defun makefile-end-of-line-point ()
|
|
1354 (save-excursion
|
|
1355 (end-of-line)
|
|
1356 (point)))
|
|
1357
|
|
1358 (defun makefile-last-line-p ()
|
|
1359 (= (makefile-end-of-line-point) (point-max)))
|
|
1360
|
|
1361 (defun makefile-first-line-p ()
|
|
1362 (= (makefile-beginning-of-line-point) (point-min)))
|
|
1363
|
|
1364
|
|
1365
|
|
1366 ;;; Support for other packages, like add-log and imenu.
|
|
1367
|
|
1368 (defun makefile-add-log-defun ()
|
2
|
1369 "Return name of target or variable assignment that point is in.
|
|
1370 If it isn't in one, return nil."
|
0
|
1371 (save-excursion
|
2
|
1372 (let (found)
|
|
1373 (beginning-of-line)
|
|
1374 ;; Scan back line by line, noticing when we come to a
|
|
1375 ;; variable or rule definition, and giving up when we see
|
|
1376 ;; a line that is not part of either of those.
|
|
1377 (while (not found)
|
|
1378 (cond
|
|
1379 ((looking-at makefile-macroassign-regex)
|
|
1380 (setq found (buffer-substring-no-properties (match-beginning 1)
|
|
1381 (match-end 1))))
|
|
1382 ((looking-at makefile-dependency-regex)
|
|
1383 (setq found (buffer-substring-no-properties (match-beginning 1)
|
|
1384 (match-end 1))))
|
|
1385 ;; Don't keep looking across a blank line or comment. Give up.
|
|
1386 ((looking-at "$\\|#")
|
|
1387 (setq found 'bobp))
|
|
1388 ((bobp)
|
|
1389 (setq found 'bobp)))
|
|
1390 (or found
|
|
1391 (forward-line -1)))
|
|
1392 (if (stringp found) found))))
|
0
|
1393
|
2
|
1394 ;; FIXME it might be nice to have them separated by macro vs target.
|
|
1395 (defun makefile-menu-index-function ()
|
|
1396 ;; "Generate alist of indices for imenu."
|
|
1397 (let (alist
|
|
1398 stupid
|
|
1399 (re (concat makefile-dependency-regex
|
|
1400 "\\|"
|
|
1401 makefile-macroassign-regex)))
|
|
1402 (imenu-progress-message stupid 0)
|
|
1403 (goto-char (point-min))
|
|
1404 (while (re-search-forward re nil t)
|
|
1405 (imenu-progress-message stupid)
|
|
1406 (let ((n (if (match-beginning 1) 1 5)))
|
|
1407 (setq alist (cons
|
|
1408 (cons (buffer-substring (match-beginning n)
|
|
1409 (match-end n))
|
|
1410 (match-beginning n))
|
|
1411 alist))))
|
|
1412 (imenu-progress-message stupid 100)
|
|
1413 (nreverse alist)))
|
0
|
1414
|
|
1415 (defun makefile-define-space-face ()
|
|
1416 (make-face 'makefile-space-face)
|
2
|
1417 ;; XEmacs change
|
0
|
1418 (let* ((light-bg t)) ; ####
|
|
1419 (set-face-background 'makefile-space-face
|
|
1420 (if light-bg "black" "white")
|
|
1421 nil
|
|
1422 '(mono x)
|
|
1423 'append)
|
|
1424 (set-face-background 'makefile-space-face
|
|
1425 (if light-bg "black" "white")
|
|
1426 nil
|
|
1427 '(grayscale x)
|
|
1428 'append)
|
|
1429 (set-face-background 'makefile-space-face
|
|
1430 "hotpink"
|
|
1431 nil
|
|
1432 '(color x)
|
|
1433 'append)))
|
|
1434
|
|
1435 ;;; make-mode.el ends here
|