1 ;;; make-mode.el --- makefile editing commands for Emacs
3 ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
5 ;; Author: Thomas Neumann <tom@smart.bo.open.de>
6 ;; Eric S. Raymond <esr@snark.thyrsus.com>
9 ;; Keywords: unix, tools
13 ;; Also, the doc strings need fixing: the first line doesn't stand alone,
14 ;; and other usage is not high quality. Symbol names don't have `...'.
16 ;; This file is part of GNU Emacs.
18 ;; GNU Emacs is free software; you can redistribute it and/or modify
19 ;; it under the terms of the GNU General Public License as published by
20 ;; the Free Software Foundation; either version 2, or (at your option)
23 ;; GNU Emacs is distributed in the hope that it will be useful,
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 ;; GNU General Public License for more details.
28 ;; You should have received a copy of the GNU General Public License
29 ;; along with GNU Emacs; see the file COPYING. If not, write to the
30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
31 ;; Boston, MA 02111-1307, USA.
35 ;; A major mode for editing makefiles. The mode knows about Makefile
36 ;; syntax and defines M-n and M-p to move to next and previous productions.
38 ;; The keys $, =, : and . are electric; they try to help you fill in a
39 ;; macro reference, macro definition, ordinary target name, or special
40 ;; target name, respectively. Such names are completed using a list of
41 ;; targets and macro names parsed out of the makefile. This list is
42 ;; automatically updated, if necessary, whenever you invoke one of
43 ;; these commands. You can force it to be updated with C-c C-p.
45 ;; The command C-c C-f adds certain filenames in the current directory
46 ;; as targets. You can filter out filenames by setting the variable
47 ;; makefile-ignored-files-in-pickup-regex.
49 ;; The command C-c C-u grinds for a bit, then pops up a report buffer
50 ;; showing which target names are up-to-date with respect to their
51 ;; prerequisites, which targets are out-of-date, and which have no
54 ;; The command C-c C-b pops up a browser window listing all target and
55 ;; macro names. You can mark or unmark items wit C-c SPC, and insert
56 ;; all marked items back in the Makefile with C-c TAB.
58 ;; The command C-c TAB in the makefile buffer inserts a GNU make builtin.
59 ;; You will be prompted for the builtin's args.
61 ;; There are numerous other customization variables.
66 ;; * Eliminate electric stuff entirely.
67 ;; * It might be nice to highlight targets differently depending on
68 ;; whether they are up-to-date or not. Not sure how this would
69 ;; interact with font-lock.
70 ;; * Would be nice to edit the commands in ksh-mode and have
71 ;; indentation and slashification done automatically. Hard.
72 ;; * Consider removing browser mode. It seems useless.
73 ;; * ":" should notice when a new target is made and add it to the
74 ;; list (or at least set makefile-need-target-pickup).
75 ;; * Make browser into a major mode.
76 ;; * Clean up macro insertion stuff. It is a mess.
77 ;; * Browser entry and exit is weird. Normalize.
78 ;; * Browser needs to be rewritten. Right now it is kind of a crock.
80 ;; * Act more like dired/buffer menu/whatever.
81 ;; * Highlight as mouse traverses.
83 ;; * Update documentation above.
84 ;; * Update texinfo manual.
93 ;; Sadly we need this for a macro.
97 ;;; ------------------------------------------------------------
98 ;;; Configurable stuff
99 ;;; ------------------------------------------------------------
101 (defvar makefile-browser-buffer-name "*Macros and Targets*"
102 "Name of the macro- and target browser buffer.")
104 (defvar makefile-target-colon ":"
105 "String to append to all target names inserted by `makefile-insert-target'.
106 \":\" or \"::\" are common values.")
108 (defvar makefile-macro-assign " = "
109 "String to append to all macro names inserted by `makefile-insert-macro'.
110 The normal value should be \" = \", since this is what
111 standard make expects. However, newer makes such as dmake
112 allow a larger variety of different macro assignments, so you
113 might prefer to use \" += \" or \" := \" .")
115 (defvar makefile-electric-keys nil
116 "If non-nil, install electric keybindings.
119 (defvar makefile-use-curly-braces-for-macros-p nil
120 "Controls the style of generated macro references.
121 t (actually non-nil) means macro references should use curly braces,
123 nil means use parentheses, like `$(this)'.")
125 (defvar makefile-tab-after-target-colon t
126 "If non-nil, insert a TAB after a target colon.
127 Otherwise, a space is inserted.
130 (defvar makefile-browser-leftmost-column 10
131 "Number of blanks to the left of the browser selection mark.")
133 (defvar makefile-browser-cursor-column 10
134 "Column in which the cursor is positioned when it moves
135 up or down in the browser.")
137 (defvar makefile-backslash-column 48
138 "*Column in which `makefile-backslash-region' inserts backslashes.")
140 (defvar makefile-backslash-align t
141 "If non-nil, `makefile-backslash-region' will align backslashes.")
143 (defvar makefile-browser-selected-mark "+ "
144 "String used to mark selected entries in the browser.")
146 (defvar makefile-browser-unselected-mark " "
147 "String used to mark unselected entries in the browser.")
149 (defvar makefile-browser-auto-advance-after-selection-p t
150 "If non-nil, cursor will move after item is selected in browser.")
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.")
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\'.")
164 (defvar makefile-browser-hook '())
167 ;; Special targets for DMake, Sun's make ...
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.")
182 (defvar makefile-runtime-macros-list
183 '(("@") ("&") (">") ("<") ("*") ("^") ("+") ("?") ("%") ("$"))
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 ( ).")
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.")
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.")
203 (defconst makefile-ignored-files-in-pickup-regex
204 "\\(^\\..*\\)\\|\\(.*~$\\)\\|\\(.*,v$\\)\\|\\(\\.[chy]\\)"
205 "Regex for filenames that will NOT be included in the target list.")
207 (if (fboundp 'facemenu-unlisted-faces)
208 (add-to-list 'facemenu-unlisted-faces 'makefile-space-face))
209 (defvar makefile-space-face 'makefile-space-face
210 "Face to use for highlighting leading spaces in Font-Lock mode.")
212 (defconst makefile-font-lock-keywords
214 ;; Do macro assignments. These get the "variable-name" face rather
216 (list makefile-macroassign-regex 1 'font-lock-variable-name-face)
218 ;; Do dependencies. These get the function name face.
219 (list makefile-dependency-regex 1 'font-lock-function-name-face)
221 ;; Variable references even in targets/strings/comments:
222 '("\\$[({]\\([-a-zA-Z0-9_.]+\\)[}):]" 1 font-lock-reference-face prepend)
224 ;; Highlight lines that contain just whitespace.
225 ;; They can cause trouble, especially if they start with a tab.
226 '("^[ \t]+$" . makefile-space-face)
228 ;; Highlight shell comments that Make treats as commands,
229 ;; since these can fool people.
230 '("^\t+#" 0 makefile-space-face t)
232 ;; Highlight spaces that precede tabs.
233 ;; They can make a tab fail to be effective.
234 '("^\\( +\\)\t" 1 makefile-space-face)))
236 ;;; ------------------------------------------------------------
237 ;;; The following configurable variables are used in the
238 ;;; up-to-date overview .
239 ;;; The standard configuration assumes that your `make' program
240 ;;; can be run in question/query mode using the `-q' option, this
241 ;;; means that the command
245 ;;; should return an exit status of zero if the target `foo' is
246 ;;; up to date and a nonzero exit status otherwise.
247 ;;; Many makes can do this although the docs/manpages do not mention
248 ;;; it. Try it with your favourite one. GNU make, System V make, and
249 ;;; Dennis Vadura's DMake have no problems.
250 ;;; Set the variable `makefile-brave-make' to the name of the
251 ;;; make utility that does this on your system.
252 ;;; To understand what this is all about see the function definition
253 ;;; of `makefile-query-by-make-minus-q' .
254 ;;; ------------------------------------------------------------
256 (defvar makefile-brave-make "make"
257 "A make that can handle the `-q' option.")
259 (defvar makefile-query-one-target-method 'makefile-query-by-make-minus-q
260 "Function to call to determine whether a make target is up to date.
261 The function must satisfy this calling convention:
263 * As its first argument, it must accept the name of the target to
264 be checked, as a string.
266 * As its second argument, it may accept the name of a makefile
267 as a string. Depending on what you're going to do you may
270 * It must return the integer value 0 (zero) if the given target
271 should be considered up-to-date in the context of the given
272 makefile, any nonzero integer value otherwise.")
274 (defvar makefile-up-to-date-buffer-name "*Makefile Up-to-date overview*"
275 "Name of the Up-to-date overview buffer.")
277 ;;; --- end of up-to-date-overview configuration ------------------
279 (defvar makefile-mode-map nil
280 "The keymap that is used in Makefile mode.")
282 (if makefile-mode-map
284 (setq makefile-mode-map (make-sparse-keymap))
286 (define-key makefile-mode-map "\C-c:" 'makefile-insert-target-ref)
287 (if makefile-electric-keys
289 (define-key makefile-mode-map "$" 'makefile-insert-macro-ref)
290 (define-key makefile-mode-map ":" 'makefile-electric-colon)
291 (define-key makefile-mode-map "=" 'makefile-electric-equal)
292 (define-key makefile-mode-map "." 'makefile-electric-dot)))
293 (define-key makefile-mode-map "\C-c\C-f" 'makefile-pickup-filenames-as-targets)
294 (define-key makefile-mode-map "\C-c\C-b" 'makefile-switch-to-browser)
295 (define-key makefile-mode-map "\C-c\C-c" 'comment-region)
296 (define-key makefile-mode-map "\C-c\C-p" 'makefile-pickup-everything)
297 (define-key makefile-mode-map "\C-c\C-u" 'makefile-create-up-to-date-overview)
298 (define-key makefile-mode-map "\C-c\C-i" 'makefile-insert-gmake-function)
299 (define-key makefile-mode-map "\C-c\C-\\" 'makefile-backslash-region)
300 (define-key makefile-mode-map "\M-p" 'makefile-previous-dependency)
301 (define-key makefile-mode-map "\M-n" 'makefile-next-dependency)
302 (define-key makefile-mode-map "\e\t" 'makefile-complete)
305 (define-key makefile-mode-map [menu-bar makefile-mode]
306 (cons "Makefile" (make-sparse-keymap "Makefile")))
308 (define-key makefile-mode-map [menu-bar makefile-mode browse]
309 '("Pop up Makefile Browser" . makefile-switch-to-browser))
310 (define-key makefile-mode-map [menu-bar makefile-mode complete]
311 '("Complete Target or Macro" . makefile-complete))
312 (define-key makefile-mode-map [menu-bar makefile-mode pickup]
313 '("Find Targets and Macros" . makefile-pickup-everything))
315 (define-key makefile-mode-map [menu-bar makefile-mode prev]
316 '("Move to Previous Dependency" . makefile-previous-dependency))
317 (define-key makefile-mode-map [menu-bar makefile-mode next]
318 '("Move to Next Dependency" . makefile-next-dependency)))
320 (defvar makefile-browser-map nil
321 "The keymap that is used in the macro- and target browser.")
322 (if makefile-browser-map
324 (setq makefile-browser-map (make-sparse-keymap))
325 (define-key makefile-browser-map "n" 'makefile-browser-next-line)
326 (define-key makefile-browser-map "\C-n" 'makefile-browser-next-line)
327 (define-key makefile-browser-map "p" 'makefile-browser-previous-line)
328 (define-key makefile-browser-map "\C-p" 'makefile-browser-previous-line)
329 (define-key makefile-browser-map " " 'makefile-browser-toggle)
330 (define-key makefile-browser-map "i" 'makefile-browser-insert-selection)
331 (define-key makefile-browser-map "I" 'makefile-browser-insert-selection-and-quit)
332 (define-key makefile-browser-map "\C-c\C-m" 'makefile-browser-insert-continuation)
333 (define-key makefile-browser-map "q" 'makefile-browser-quit)
334 ;; disable horizontal movement
335 (define-key makefile-browser-map "\C-b" 'undefined)
336 (define-key makefile-browser-map "\C-f" 'undefined))
339 (defvar makefile-mode-syntax-table nil)
340 (if makefile-mode-syntax-table
342 (setq makefile-mode-syntax-table (make-syntax-table))
343 (modify-syntax-entry ?\( "() " makefile-mode-syntax-table)
344 (modify-syntax-entry ?\) ")( " makefile-mode-syntax-table)
345 (modify-syntax-entry ?\[ "(] " makefile-mode-syntax-table)
346 (modify-syntax-entry ?\] ")[ " makefile-mode-syntax-table)
347 (modify-syntax-entry ?\{ "(} " makefile-mode-syntax-table)
348 (modify-syntax-entry ?\} "){ " makefile-mode-syntax-table)
349 (modify-syntax-entry ?\' "\" " makefile-mode-syntax-table)
350 (modify-syntax-entry ?\` "\" " makefile-mode-syntax-table)
351 (modify-syntax-entry ?# "< " makefile-mode-syntax-table)
352 (modify-syntax-entry ?\n "> " makefile-mode-syntax-table))
355 ;;; ------------------------------------------------------------
356 ;;; Internal variables.
357 ;;; You don't need to configure below this line.
358 ;;; ------------------------------------------------------------
360 (defvar makefile-target-table nil
361 "Table of all target names known for this buffer.")
363 (defvar makefile-macro-table nil
364 "Table of all macro names known for this buffer.")
366 (defvar makefile-browser-client
367 "A buffer in Makefile mode that is currently using the browser.")
369 (defvar makefile-browser-selection-vector nil)
370 (defvar makefile-has-prereqs nil)
371 (defvar makefile-need-target-pickup t)
372 (defvar makefile-need-macro-pickup t)
374 (defvar makefile-mode-hook '())
376 ;; Each element looks like '("GNU MAKE FUNCTION" "ARG" "ARG" ... )
377 ;; Each "ARG" is used as a prompt for a required argument.
378 (defconst makefile-gnumake-functions-alist
381 ("subst" "From" "To" "In")
382 ("patsubst" "Pattern" "Replacement" "In")
384 ("findstring" "Find what" "In")
385 ("filter" "Pattern" "Text")
386 ("filter-out" "Pattern" "Text")
388 ;; Filename functions
393 ("addprefix" "Prefix" "Names")
394 ("addsuffix" "Suffix" "Names")
395 ("join" "List 1" "List 2")
396 ("word" "Index" "Text")
399 ("wildcard" "Pattern")
401 ("foreach" "Variable" "List" "Text")
402 ("origin" "Variable")
403 ("shell" "Command")))
406 ;;; ------------------------------------------------------------
407 ;;; The mode function itself.
408 ;;; ------------------------------------------------------------
411 (defun makefile-mode ()
412 "Major mode for editing Makefiles.
413 This function ends by invoking the function(s) `makefile-mode-hook'.
415 \\{makefile-mode-map}
417 In the browser, use the following keys:
419 \\{makefile-browser-map}
421 Makefile mode can be configured by modifying the following variables:
423 makefile-browser-buffer-name:
424 Name of the macro- and target browser buffer.
426 makefile-target-colon:
427 The string that gets appended to all target names
428 inserted by `makefile-insert-target'.
429 \":\" or \"::\" are quite common values.
431 makefile-macro-assign:
432 The string that gets appended to all macro names
433 inserted by `makefile-insert-macro'.
434 The normal value should be \" = \", since this is what
435 standard make expects. However, newer makes such as dmake
436 allow a larger variety of different macro assignments, so you
437 might prefer to use \" += \" or \" := \" .
439 makefile-tab-after-target-colon:
440 If you want a TAB (instead of a space) to be appended after the
441 target colon, then set this to a non-nil value.
443 makefile-browser-leftmost-column:
444 Number of blanks to the left of the browser selection mark.
446 makefile-browser-cursor-column:
447 Column in which the cursor is positioned when it moves
448 up or down in the browser.
450 makefile-browser-selected-mark:
451 String used to mark selected entries in the browser.
453 makefile-browser-unselected-mark:
454 String used to mark unselected entries in the browser.
456 makefile-browser-auto-advance-after-selection-p:
457 If this variable is set to a non-nil value the cursor
458 will automagically advance to the next line after an item
459 has been selected in the browser.
461 makefile-pickup-everything-picks-up-filenames-p:
462 If this variable is set to a non-nil value then
463 `makefile-pickup-everything' also picks up filenames as targets
464 (i.e. it calls `makefile-find-filenames-as-targets'), otherwise
465 filenames are omitted.
467 makefile-cleanup-continuations-p:
468 If this variable is set to a non-nil value then makefile-mode
469 will assure that no line in the file ends with a backslash
470 (the continuation character) followed by any whitespace.
471 This is done by silently removing the trailing whitespace, leaving
472 the backslash itself intact.
473 IMPORTANT: Please note that enabling this option causes makefile-mode
474 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \"it seems necessary\".
476 makefile-browser-hook:
477 A function or list of functions to be called just before the
478 browser is entered. This is executed in the makefile buffer.
480 makefile-special-targets-list:
481 List of special targets. You will be offered to complete
482 on one of those in the minibuffer whenever you enter a `.'.
483 at the beginning of a line in Makefile mode."
486 (kill-all-local-variables)
487 (make-local-variable 'local-write-file-hooks)
488 (setq local-write-file-hooks
489 '(makefile-cleanup-continuations makefile-warn-suspicious-lines))
490 (make-local-variable 'makefile-target-table)
491 (make-local-variable 'makefile-macro-table)
492 (make-local-variable 'makefile-has-prereqs)
493 (make-local-variable 'makefile-need-target-pickup)
494 (make-local-variable 'makefile-need-macro-pickup)
497 (if (fboundp 'make-face)
498 (makefile-define-space-face))
499 (make-local-variable 'font-lock-defaults)
500 (setq font-lock-defaults '(makefile-font-lock-keywords))
503 (make-local-variable 'add-log-current-defun-function)
504 (setq add-log-current-defun-function 'makefile-add-log-defun)
507 (make-local-variable 'imenu-create-index-function)
508 (setq imenu-create-index-function 'makefile-menu-index-function)
511 (make-local-variable 'dabbrev-abbrev-skip-leading-regexp)
512 (setq dabbrev-abbrev-skip-leading-regexp "\\$")
515 (make-local-variable 'fill-paragraph-function)
516 (setq fill-paragraph-function 'makefile-fill-paragraph)
519 (make-local-variable 'comment-start)
520 (setq comment-start "#")
521 (make-local-variable 'comment-end)
522 (setq comment-end "")
523 (make-local-variable 'comment-start-skip)
524 (setq comment-start-skip "#+[ \t]*")
526 ;; become the current major mode
527 (setq major-mode 'makefile-mode)
528 (setq mode-name "Makefile")
530 ;; Activate keymap and syntax table.
531 (use-local-map makefile-mode-map)
532 (set-syntax-table makefile-mode-syntax-table)
534 ;; Real TABs are important in makefiles
535 (setq indent-tabs-mode t)
536 (run-hooks 'makefile-mode-hook))
542 (defun makefile-next-dependency ()
543 "Move point to the beginning of the next dependency line."
545 (let ((here (point)))
547 (if (re-search-forward makefile-dependency-regex (point-max) t)
548 (progn (beginning-of-line) t) ; indicate success
549 (goto-char here) nil)))
551 (defun makefile-previous-dependency ()
552 "Move point to the beginning of the previous dependency line."
554 (let ((here (point)))
556 (if (re-search-backward makefile-dependency-regex (point-min) t)
557 (progn (beginning-of-line) t) ; indicate success
558 (goto-char here) nil)))
562 ;;; Electric keys. Blech.
564 (defun makefile-electric-dot (arg)
565 "Prompt for the name of a special target to insert.
566 Only does electric insertion at beginning of line.
567 Anywhere else just self-inserts."
570 (makefile-insert-special-target)
571 (self-insert-command arg)))
573 (defun makefile-insert-special-target ()
574 "Prompt for and insert a special target name.
575 Uses `makefile-special-targets' list."
577 (makefile-pickup-targets)
578 (let ((special-target
579 (completing-read "Special target: "
580 makefile-special-targets-list nil nil nil)))
581 (if (zerop (length special-target))
583 (insert "." special-target ":")
584 (makefile-forward-after-target-colon))))
586 (defun makefile-electric-equal (arg)
587 "Prompt for name of a macro to insert.
588 Only does prompting if point is at beginning of line.
589 Anywhere else just self-inserts."
591 (makefile-pickup-macros)
593 (call-interactively 'makefile-insert-macro)
594 (self-insert-command arg)))
596 (defun makefile-insert-macro (macro-name)
597 "Prepare definition of a new macro."
598 (interactive "sMacro Name: ")
599 (makefile-pickup-macros)
600 (if (not (zerop (length macro-name)))
603 (insert macro-name makefile-macro-assign)
604 (setq makefile-need-macro-pickup t)
605 (makefile-remember-macro macro-name))))
607 (defun makefile-insert-macro-ref (macro-name)
608 "Complete on a list of known macros, then insert complete ref at point."
612 (makefile-pickup-macros)
613 (completing-read "Refer to macro: " makefile-macro-table nil nil nil))))
614 (makefile-do-macro-insertion macro-name))
616 (defun makefile-insert-target (target-name)
617 "Prepare definition of a new target (dependency line)."
618 (interactive "sTarget: ")
619 (if (not (zerop (length target-name)))
622 (insert target-name makefile-target-colon)
623 (makefile-forward-after-target-colon)
625 (setq makefile-need-target-pickup t)
626 (makefile-remember-target target-name))))
628 (defun makefile-insert-target-ref (target-name)
629 "Complete on a list of known targets, then insert target-ref at point."
633 (makefile-pickup-targets)
634 (completing-read "Refer to target: " makefile-target-table nil nil nil))))
635 (if (not (zerop (length target-name)))
636 (insert target-name " ")))
638 (defun makefile-electric-colon (arg)
639 "Prompt for name of new target.
640 Prompting only happens at beginning of line.
641 Anywhere else just self-inserts."
644 (call-interactively 'makefile-insert-target)
645 (self-insert-command arg)))
649 ;;; ------------------------------------------------------------
650 ;;; Extracting targets and macros from an existing makefile
651 ;;; ------------------------------------------------------------
653 (defun makefile-pickup-targets ()
654 "Notice names of all target definitions in Makefile."
656 (if (not makefile-need-target-pickup)
658 (setq makefile-need-target-pickup nil)
659 (setq makefile-target-table nil)
660 (setq makefile-has-prereqs nil)
662 (goto-char (point-min))
663 (while (re-search-forward makefile-dependency-regex (point-max) t)
664 (makefile-add-this-line-targets)))
665 (message "Read targets OK.")))
667 (defun makefile-add-this-line-targets ()
670 (let ((done-with-line nil)
671 (line-number (1+ (count-lines (point-min) (point)))))
672 (while (not done-with-line)
673 (skip-chars-forward " \t")
674 (if (not (setq done-with-line (or (eolp)
675 (char-equal (char-after (point)) ?:))))
677 (let* ((start-of-target-name (point))
680 (skip-chars-forward "^ \t:#")
681 (buffer-substring start-of-target-name (point))))
683 (not (looking-at ":[ \t]*$"))))
684 (if (makefile-remember-target target-name has-prereqs)
685 (message "Picked up target \"%s\" from line %d"
686 target-name line-number)))))))))
688 (defun makefile-pickup-macros ()
689 "Notice names of all macro definitions in Makefile."
691 (if (not makefile-need-macro-pickup)
693 (setq makefile-need-macro-pickup nil)
694 (setq makefile-macro-table nil)
696 (goto-char (point-min))
697 (while (re-search-forward makefile-macroassign-regex (point-max) t)
698 (makefile-add-this-line-macro)
700 (message "Read macros OK.")))
702 (defun makefile-add-this-line-macro ()
705 (skip-chars-forward " \t")
707 (let* ((start-of-macro-name (point))
708 (line-number (1+ (count-lines (point-min) (point))))
710 (skip-chars-forward "^ \t:#=*")
711 (buffer-substring start-of-macro-name (point)))))
712 (if (makefile-remember-macro macro-name)
713 (message "Picked up macro \"%s\" from line %d"
714 macro-name line-number))))))
716 (defun makefile-pickup-everything (arg)
717 "Notice names of all macros and targets in Makefile.
718 Prefix arg means force pickups to be redone."
722 (setq makefile-need-target-pickup t)
723 (setq makefile-need-macro-pickup t)))
724 (makefile-pickup-macros)
725 (makefile-pickup-targets)
726 (if makefile-pickup-everything-picks-up-filenames-p
727 (makefile-pickup-filenames-as-targets)))
729 (defun makefile-pickup-filenames-as-targets ()
730 "Scan the current directory for filenames to use as targets.
731 Checks each filename against `makefile-ignored-files-in-pickup-regex'
732 and adds all qualifying names to the list of known targets."
734 (let* ((dir (file-name-directory (buffer-file-name)))
735 (raw-filename-list (if dir
736 (file-name-all-completions "" dir)
737 (file-name-all-completions "" ""))))
738 (mapcar '(lambda (name)
739 (if (and (not (file-directory-p name))
740 (not (string-match makefile-ignored-files-in-pickup-regex
742 (if (makefile-remember-target name)
743 (message "Picked up file \"%s\" as target" name))))
750 (defun makefile-complete ()
751 "Perform completion on Makefile construct preceding point.
752 Can complete variable and target names.
753 The context determines which are considered."
755 (let* ((beg (save-excursion
756 (skip-chars-backward "^$(){}:#= \t\n")
758 (try (buffer-substring beg (point)))
764 (let ((pc (preceding-char)))
766 ;; Beginning of line means anything.
770 ;; Preceding "$" means macros only.
774 ;; Preceding "$(" or "${" means macros only.
781 (= (preceding-char) ?$))))
782 (setq do-macros t)))))
785 (let* ((table (append (if do-macros
787 makefile-target-table)
788 makefile-macro-table))
789 (completion (try-completion try table)))
791 ;; Exact match, so insert closing paren or colon.
793 (insert (if do-macros
805 (message "Can't find completion for \"%s\"" try)
808 ;; Partial completion.
809 ((not (string= try completion))
810 ;; FIXME it would be nice to supply the closing paren if an
811 ;; exact, unambiguous match were found. That is not possible
812 ;; right now. Ditto closing ":" for targets.
813 (delete-region beg (point))
815 ;; DO-MACROS means doing macros only. If not that, then check
816 ;; to see if this completion is a macro. Special insertion
817 ;; must be done for macros.
819 (assoc completion makefile-macro-table))
820 (let ((makefile-use-curly-braces-for-macros-p
822 makefile-use-curly-braces-for-macros-p)))
823 (delete-backward-char 2)
824 (makefile-do-macro-insertion completion)
825 (delete-backward-char 1))
827 ;; Just insert targets.
828 (insert completion)))
830 ;; Can't complete any more, so make completion list. FIXME
831 ;; this doesn't do the right thing when the completion is
832 ;; actually inserted. I don't think there is an easy way to do
835 (message "Making completion list...")
836 (let ((list (all-completions try table)))
837 (with-output-to-temp-buffer "*Completions*"
838 (display-completion-list list)))
839 (message "Making completion list...done"))))))
843 ;; Backslashification. Stolen from cc-mode.el.
845 (defun makefile-backslash-region (from to delete-flag)
846 "Insert, align, or delete end-of-line backslashes on the lines in the region.
847 With no argument, inserts backslashes and aligns existing backslashes.
848 With an argument, deletes the backslashes.
850 This function does not modify the last line of the region if the region ends
851 right at the start of the following line; it does not modify blank lines
852 at the start of the region. So you can put the region around an entire macro
853 definition and conveniently use this command."
857 (let ((column makefile-backslash-column)
858 (endmark (make-marker)))
859 (move-marker endmark to)
860 ;; Compute the smallest column number past the ends of all the lines.
861 (if makefile-backslash-align
863 (if (not delete-flag)
864 (while (< (point) to)
866 (if (= (preceding-char) ?\\)
867 (progn (forward-char -1)
868 (skip-chars-backward " \t")))
869 (setq column (max column (1+ (current-column))))
871 ;; Adjust upward to a tab column, if that doesn't push
873 (if (> (% column tab-width) 0)
874 (let ((adjusted (* (/ (+ column tab-width -1) tab-width)
876 (if (< adjusted (window-width))
877 (setq column adjusted))))))
878 ;; Don't modify blank lines at start of region.
880 (while (and (< (point) endmark) (eolp))
882 ;; Add or remove backslashes on all the lines.
883 (while (and (< (point) endmark)
884 ;; Don't backslashify the last line
885 ;; if the region ends right at the start of the next line.
888 (< (point) endmark)))
889 (if (not delete-flag)
890 (makefile-append-backslash column)
891 (makefile-delete-backslash))
893 (move-marker endmark nil))))
895 (defun makefile-append-backslash (column)
897 ;; Note that "\\\\" is needed to get one backslash.
898 (if (= (preceding-char) ?\\)
899 (progn (forward-char -1)
900 (delete-horizontal-space)
901 (indent-to column (if makefile-backslash-align nil 1)))
902 (indent-to column (if makefile-backslash-align nil 1))
905 (defun makefile-delete-backslash ()
910 (if (looking-at "\\\\")
911 (delete-region (1+ (point))
912 (progn (skip-chars-backward " \t") (point)))))))
918 (defun makefile-fill-paragraph (arg)
919 ;; Fill comments, backslashed lines, and variable definitions
925 ;; Found a comment. Set the fill prefix and then fill.
926 (let ((fill-prefix (buffer-substring-no-properties (match-beginning 0)
928 (fill-paragraph-function nil))
932 ;; Must look for backslashed-region before looking for variable
937 (= (preceding-char) ?\\)
940 (= (preceding-char) ?\\))))
941 ;; A backslash region. Find beginning and end, remove
942 ;; backslashes, fill, and then reapply backslahes.
947 (while (= (preceding-char) ?\\)
953 (while (= (preceding-char) ?\\)
957 (narrow-to-region beginning end)
958 (makefile-backslash-region (point-min) (point-max) t)
959 (let ((fill-paragraph-function nil))
960 (fill-paragraph nil))
961 (makefile-backslash-region (point-min) (point-max) nil)
962 (goto-char (point-max))
963 (if (< (skip-chars-backward "\n") 0)
964 (delete-region (point) (point-max))))))
966 ((looking-at makefile-macroassign-regex)
967 ;; Have a macro assign. Fill just this line, and then backslash
970 (narrow-to-region (point) (save-excursion
974 (let ((fill-paragraph-function nil))
975 (fill-paragraph nil))
976 (makefile-backslash-region (point-min) (point-max) nil)))))
978 ;; Always return non-nil so we don't fill anything else.
983 ;;; ------------------------------------------------------------
985 ;;; ------------------------------------------------------------
987 (defun makefile-browser-format-target-line (target selected)
989 (concat (make-string makefile-browser-leftmost-column ?\ )
991 makefile-browser-selected-mark
992 makefile-browser-unselected-mark)
994 target makefile-target-colon))
996 (defun makefile-browser-format-macro-line (macro selected)
998 (concat (make-string makefile-browser-leftmost-column ?\ )
1000 makefile-browser-selected-mark
1001 makefile-browser-unselected-mark)
1002 (makefile-format-macro-ref macro))))
1004 (defun makefile-browser-fill (targets macros)
1005 (let ((inhibit-read-only t))
1006 (goto-char (point-min))
1010 (lambda (item) (insert (makefile-browser-format-target-line (car item) nil) "\n")))
1015 (lambda (item) (insert (makefile-browser-format-macro-line (car item) nil) "\n")))
1018 (sort-lines nil (point-min) (point-max))
1019 (goto-char (1- (point-max)))
1020 (delete-char 1) ; remove unnecessary newline at eob
1021 (goto-char (point-min))
1022 (forward-char makefile-browser-cursor-column)))
1025 ;;; Moving up and down in the browser
1028 (defun makefile-browser-next-line ()
1029 "Move the browser selection cursor to the next line."
1031 (if (not (makefile-last-line-p))
1034 (forward-char makefile-browser-cursor-column))))
1036 (defun makefile-browser-previous-line ()
1037 "Move the browser selection cursor to the previous line."
1039 (if (not (makefile-first-line-p))
1042 (forward-char makefile-browser-cursor-column))))
1045 ;;; Quitting the browser (returns to client buffer)
1048 (defun makefile-browser-quit ()
1049 "Leave the browser and return to the makefile buffer."
1051 (let ((my-client makefile-browser-client))
1052 (setq makefile-browser-client nil) ; we quitted, so NO client!
1053 (set-buffer-modified-p nil)
1054 (kill-buffer (current-buffer))
1055 (pop-to-buffer my-client)))
1058 ;;; Toggle state of a browser item
1061 (defun makefile-browser-toggle ()
1062 "Toggle the selection state of the browser item at the cursor position."
1064 (let ((this-line (count-lines (point-min) (point))))
1065 (setq this-line (max 1 this-line))
1066 (makefile-browser-toggle-state-for-line this-line)
1067 (goto-line this-line)
1068 (let ((inhibit-read-only t))
1070 (if (makefile-browser-on-macro-line-p)
1071 (let ((macro-name (makefile-browser-this-line-macro-name)))
1072 (delete-region (point) (progn (end-of-line) (point)))
1074 (makefile-browser-format-macro-line
1076 (makefile-browser-get-state-for-line this-line))))
1077 (let ((target-name (makefile-browser-this-line-target-name)))
1078 (delete-region (point) (progn (end-of-line) (point)))
1080 (makefile-browser-format-target-line
1082 (makefile-browser-get-state-for-line this-line))))))
1084 (forward-char makefile-browser-cursor-column)
1085 (if makefile-browser-auto-advance-after-selection-p
1086 (makefile-browser-next-line))))
1089 ;;; Making insertions into the client buffer
1092 (defun makefile-browser-insert-continuation ()
1093 "Insert a makefile continuation.
1094 In the makefile buffer, go to (end-of-line), insert a \'\\\'
1095 character, insert a new blank line, go to that line and indent by one TAB.
1096 This is most useful in the process of creating continued lines when copying
1097 large dependencies from the browser to the client buffer.
1098 \(point) advances accordingly in the client buffer."
1101 (set-buffer makefile-browser-client)
1105 (defun makefile-browser-insert-selection ()
1106 "Insert all selected targets and/or macros in the makefile buffer.
1107 Insertion takes place at point."
1111 (let ((current-line 1))
1113 (if (makefile-browser-get-state-for-line current-line)
1114 (makefile-browser-send-this-line-item))
1116 (setq current-line (1+ current-line))))))
1118 (defun makefile-browser-insert-selection-and-quit ()
1120 (makefile-browser-insert-selection)
1121 (makefile-browser-quit))
1123 (defun makefile-browser-send-this-line-item ()
1124 (if (makefile-browser-on-macro-line-p)
1126 (let ((macro-name (makefile-browser-this-line-macro-name)))
1127 (set-buffer makefile-browser-client)
1128 (insert (makefile-format-macro-ref macro-name) " ")))
1130 (let ((target-name (makefile-browser-this-line-target-name)))
1131 (set-buffer makefile-browser-client)
1132 (insert target-name " ")))))
1134 (defun makefile-browser-start-interaction ()
1135 (use-local-map makefile-browser-map)
1136 (setq buffer-read-only t))
1138 (defun makefile-browse (targets macros)
1140 (if (zerop (+ (length targets) (length macros)))
1143 (message "No macros or targets to browse! Consider running 'makefile-pickup-everything\'"))
1144 (let ((browser-buffer (get-buffer-create makefile-browser-buffer-name)))
1145 (pop-to-buffer browser-buffer)
1146 (make-variable-buffer-local 'makefile-browser-selection-vector)
1147 (makefile-browser-fill targets macros)
1148 (shrink-window-if-larger-than-buffer)
1149 (setq makefile-browser-selection-vector
1150 (make-vector (+ (length targets) (length macros)) nil))
1151 (makefile-browser-start-interaction))))
1153 (defun makefile-switch-to-browser ()
1155 (run-hooks 'makefile-browser-hook)
1156 (setq makefile-browser-client (current-buffer))
1157 (makefile-pickup-targets)
1158 (makefile-pickup-macros)
1159 (makefile-browse makefile-target-table makefile-macro-table))
1163 ;;; ------------------------------------------------------------
1164 ;;; Up-to-date overview buffer
1165 ;;; ------------------------------------------------------------
1167 (defun makefile-create-up-to-date-overview ()
1168 "Create a buffer containing an overview of the state of all known targets.
1169 Known targets are targets that are explicitly defined in that makefile;
1170 in other words, all targets that appear on the left hand side of a
1171 dependency in the makefile."
1173 (if (y-or-n-p "Are you sure that the makefile being edited is consistent? ")
1175 ;; The rest of this function operates on a temporary makefile, created by
1176 ;; writing the current contents of the makefile buffer.
1178 (let ((saved-target-table makefile-target-table)
1179 (this-buffer (current-buffer))
1180 (makefile-up-to-date-buffer
1181 (get-buffer-create makefile-up-to-date-buffer-name))
1182 (filename (makefile-save-temporary))
1184 ;; Forget the target table because it may contain picked-up filenames
1185 ;; that are not really targets in the current makefile.
1186 ;; We don't want to query these, so get a new target-table with just the
1187 ;; targets that can be found in the makefile buffer.
1188 ;; The 'old' target table will be restored later.
1190 (real-targets (progn
1191 (makefile-pickup-targets)
1192 makefile-target-table))
1193 (prereqs makefile-has-prereqs)
1196 (set-buffer makefile-up-to-date-buffer)
1197 (setq buffer-read-only nil)
1199 (makefile-query-targets filename real-targets prereqs)
1200 (if (zerop (buffer-size)) ; if it did not get us anything
1202 (kill-buffer (current-buffer))
1203 (message "No overview created!")))
1204 (set-buffer this-buffer)
1205 (setq makefile-target-table saved-target-table)
1206 (if (get-buffer makefile-up-to-date-buffer-name)
1208 (pop-to-buffer (get-buffer makefile-up-to-date-buffer-name))
1209 (shrink-window-if-larger-than-buffer)
1210 (sort-lines nil (point-min) (point-max))
1211 (setq buffer-read-only t))))))
1213 (defun makefile-save-temporary ()
1214 "Create a temporary file from the current makefile buffer."
1215 (let ((filename (makefile-generate-temporary-filename)))
1216 (write-region (point-min) (point-max) filename nil 0)
1217 filename)) ; return the filename
1219 (defun makefile-generate-temporary-filename ()
1220 "Create a filename suitable for use in `makefile-save-temporary'.
1221 Be careful to allow brain-dead file systems (DOS, SYSV ...) to cope
1222 with the generated name!"
1223 (let ((my-name (user-login-name))
1224 (my-uid (int-to-string (user-uid))))
1226 (if (> (length my-name) 3)
1227 (substring my-name 0 3)
1230 (if (> (length my-uid) 3)
1231 (substring my-uid 0 3)
1234 (defun makefile-query-targets (filename target-table prereq-list)
1235 "Fill the up-to-date overview buffer.
1236 Checks each target in TARGET-TABLE using `makefile-query-one-target-method'
1237 and generates the overview, one line per target name."
1240 (function (lambda (item)
1241 (let* ((target-name (car item))
1242 (no-prereqs (not (member target-name prereq-list)))
1243 (needs-rebuild (or no-prereqs
1245 makefile-query-one-target-method
1250 (cond (no-prereqs " .. has no prerequisites")
1251 (needs-rebuild " .. NEEDS REBUILD")
1252 (t " .. is up to date"))))
1255 (goto-char (point-min))
1256 (delete-file filename)) ; remove the tmpfile
1258 (defun makefile-query-by-make-minus-q (target &optional filename)
1260 (call-process makefile-brave-make nil nil nil
1261 "-f" filename "-q" target))))
1265 ;;; ------------------------------------------------------------
1266 ;;; Continuation cleanup
1267 ;;; ------------------------------------------------------------
1269 (defun makefile-cleanup-continuations ()
1270 (if (eq major-mode 'makefile-mode)
1271 (if (and makefile-cleanup-continuations-p
1272 (not buffer-read-only))
1274 (goto-char (point-min))
1275 (while (re-search-forward "\\\\[ \t]+$" (point-max) t)
1276 (replace-match "\\" t t))))))
1279 ;;; ------------------------------------------------------------
1280 ;;; Warn of suspicious lines
1281 ;;; ------------------------------------------------------------
1283 (defun makefile-warn-suspicious-lines ()
1284 (let ((dont-save nil))
1285 (if (eq major-mode 'makefile-mode)
1288 (goto-char (point-min))
1290 "\\(^[\t]+$\\)\\|\\(^[ ]+[\t]\\)" (point-max) t))))
1292 (let ((line-nr (count-lines (point-min) suspicious)))
1295 (format "Suspicious line %d. Save anyway "
1301 ;;; ------------------------------------------------------------
1302 ;;; GNU make function support
1303 ;;; ------------------------------------------------------------
1305 (defun makefile-insert-gmake-function ()
1306 "Insert a GNU make function call.
1307 Asks for the name of the function to use (with completion).
1308 Then prompts for all required parameters."
1310 (let* ((gm-function-name (completing-read
1312 makefile-gnumake-functions-alist
1314 (gm-function-prompts
1315 (cdr (assoc gm-function-name makefile-gnumake-functions-alist))))
1316 (if (not (zerop (length gm-function-name)))
1317 (insert (makefile-format-macro-ref
1318 (concat gm-function-name " "
1319 (makefile-prompt-for-gmake-funargs
1320 gm-function-name gm-function-prompts)))
1323 (defun makefile-prompt-for-gmake-funargs (function-name prompt-list)
1325 (function (lambda (one-prompt)
1326 (read-string (format "[%s] %s: " function-name one-prompt)
1333 ;;; ------------------------------------------------------------
1334 ;;; Utility functions
1335 ;;; ------------------------------------------------------------
1337 (defun makefile-do-macro-insertion (macro-name)
1338 "Insert a macro reference."
1339 (if (not (zerop (length macro-name)))
1340 (if (assoc macro-name makefile-runtime-macros-list)
1341 (insert "$" macro-name)
1342 (insert (makefile-format-macro-ref macro-name)))))
1344 (defun makefile-remember-target (target-name &optional has-prereqs)
1345 "Remember a given target if it is not already remembered for this buffer."
1346 (if (not (zerop (length target-name)))
1348 (if (not (assoc target-name makefile-target-table))
1349 (setq makefile-target-table
1350 (cons (list target-name) makefile-target-table)))
1352 (setq makefile-has-prereqs
1353 (cons target-name makefile-has-prereqs))))))
1355 (defun makefile-remember-macro (macro-name)
1356 "Remember a given macro if it is not already remembered for this buffer."
1357 (if (not (zerop (length macro-name)))
1358 (if (not (assoc macro-name makefile-macro-table))
1359 (setq makefile-macro-table
1360 (cons (list macro-name) makefile-macro-table)))))
1362 (defun makefile-forward-after-target-colon ()
1363 "Move point forward after inserting the terminating colon of a target.
1364 This acts according to the value of `makefile-tab-after-target-colon'."
1365 (if makefile-tab-after-target-colon
1369 (defun makefile-browser-on-macro-line-p ()
1370 "Determine if point is on a macro line in the browser."
1373 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t)))
1375 (defun makefile-browser-this-line-target-name ()
1376 "Extract the target name from a line in the browser."
1379 (skip-chars-backward "^ \t")
1380 (buffer-substring (point) (1- (makefile-end-of-line-point)))))
1382 (defun makefile-browser-this-line-macro-name ()
1383 "Extract the macro name from a line in the browser."
1386 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t)
1387 (let ((macro-start (point)))
1388 (skip-chars-forward "^})")
1389 (buffer-substring macro-start (point)))))
1391 (defun makefile-format-macro-ref (macro-name)
1392 "Format a macro reference.
1393 Uses `makefile-use-curly-braces-for-macros-p'."
1394 (if (or (char-equal ?\( (string-to-char macro-name))
1395 (char-equal ?\{ (string-to-char macro-name)))
1396 (format "$%s" macro-name)
1397 (if makefile-use-curly-braces-for-macros-p
1398 (format "${%s}" macro-name)
1399 (format "$(%s)" macro-name))))
1401 (defun makefile-browser-get-state-for-line (n)
1402 (aref makefile-browser-selection-vector (1- n)))
1404 (defun makefile-browser-set-state-for-line (n to-state)
1405 (aset makefile-browser-selection-vector (1- n) to-state))
1407 (defun makefile-browser-toggle-state-for-line (n)
1408 (makefile-browser-set-state-for-line n (not (makefile-browser-get-state-for-line n))))
1410 (defun makefile-beginning-of-line-point ()
1415 (defun makefile-end-of-line-point ()
1420 (defun makefile-last-line-p ()
1421 (= (makefile-end-of-line-point) (point-max)))
1423 (defun makefile-first-line-p ()
1424 (= (makefile-beginning-of-line-point) (point-min)))
1428 ;;; Support for other packages, like add-log and imenu.
1430 (defun makefile-add-log-defun ()
1431 "Return name of target or variable assignment that point is in.
1432 If it isn't in one, return nil."
1436 ;; Scan back line by line, noticing when we come to a
1437 ;; variable or rule definition, and giving up when we see
1438 ;; a line that is not part of either of those.
1441 ((looking-at makefile-macroassign-regex)
1442 (setq found (buffer-substring-no-properties (match-beginning 1)
1444 ((looking-at makefile-dependency-regex)
1445 (setq found (buffer-substring-no-properties (match-beginning 1)
1447 ;; Don't keep looking across a blank line or comment. Give up.
1448 ((looking-at "$\\|#")
1451 (setq found 'bobp)))
1454 (if (stringp found) found))))
1456 ;; FIXME it might be nice to have them separated by macro vs target.
1457 (defun makefile-menu-index-function ()
1458 ;; "Generate alist of indices for imenu."
1461 (re (concat makefile-dependency-regex
1463 makefile-macroassign-regex)))
1464 (imenu-progress-message stupid 0)
1465 (goto-char (point-min))
1466 (while (re-search-forward re nil t)
1467 (imenu-progress-message stupid)
1468 (let ((n (if (match-beginning 1) 1 5)))
1470 (cons (buffer-substring (match-beginning n)
1472 (match-beginning n))
1474 (imenu-progress-message stupid 100)
1477 (defun makefile-define-space-face ()
1478 (make-face 'makefile-space-face)
1479 (or (not (eq window-system 'x))
1480 (face-differs-from-default-p 'makefile-space-face)
1481 (let* ((params (frame-parameters))
1482 (light-bg (cdr (assq 'background-mode params)))
1483 (bg-color (cond ((eq (cdr (assq 'display-type params)) 'mono)
1484 (if light-bg "black" "white"))
1485 ((eq (cdr (assq 'display-type params)) 'grayscale)
1486 (if light-bg "black" "white"))
1487 (light-bg ; Light color background.
1489 (t ; Dark color background.
1491 (set-face-background 'makefile-space-face bg-color))))
1493 ;;; make-mode.el ends here