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