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 (defgroup makefile nil
102 "Makefile editing commands for Emacs."
106 (defface makefile-space-face
107 '((((class color
)) (:background
"hotpink"))
108 (t (:reverse-video t
)))
109 "Face to use for highlighting leading spaces in Font-Lock mode."
113 (defcustom makefile-browser-buffer-name
"*Macros and Targets*"
114 "Name of the macro- and target browser buffer."
118 (defcustom makefile-target-colon
":"
119 "String to append to all target names inserted by `makefile-insert-target'.
120 \":\" or \"::\" are common values."
124 (defcustom makefile-macro-assign
" = "
125 "String to append to all macro names inserted by `makefile-insert-macro'.
126 The normal value should be \" = \", since this is what
127 standard make expects. However, newer makes such as dmake
128 allow a larger variety of different macro assignments, so you
129 might prefer to use \" += \" or \" := \" ."
133 (defcustom makefile-electric-keys nil
134 "If non-nil, Makefile mode should install electric keybindings.
139 (defcustom makefile-use-curly-braces-for-macros-p nil
140 "Controls the style of generated macro references.
141 Non-nil means macro references should use curly braces, like `${this}'.
142 nil means use parentheses, like `$(this)'."
146 (defcustom makefile-tab-after-target-colon t
147 "If non-nil, insert a TAB after a target colon.
148 Otherwise, a space is inserted.
153 (defcustom makefile-browser-leftmost-column
10
154 "Number of blanks to the left of the browser selection mark."
158 (defcustom makefile-browser-cursor-column
10
159 "Column the cursor goes to when it moves up or down in the Makefile browser."
163 (defcustom makefile-backslash-column
48
164 "*Column in which `makefile-backslash-region' inserts backslashes."
168 (defcustom makefile-backslash-align t
169 "If non-nil, `makefile-backslash-region' will align backslashes."
173 (defcustom makefile-browser-selected-mark
"+ "
174 "String used to mark selected entries in the Makefile browser."
178 (defcustom makefile-browser-unselected-mark
" "
179 "String used to mark unselected entries in the Makefile browser."
183 (defcustom makefile-browser-auto-advance-after-selection-p t
184 "If non-nil, cursor will move after item is selected in Makefile browser."
188 (defcustom makefile-pickup-everything-picks-up-filenames-p nil
189 "If non-nil, `makefile-pickup-everything' picks up filenames as targets.
190 This means it calls `makefile-pickup-filenames-as-targets'.
191 Otherwise filenames are omitted."
195 (defcustom makefile-cleanup-continuations-p t
196 "If non-nil, automatically clean up continuation lines when saving.
197 A line is cleaned up by removing all whitespace following a trailing
198 backslash. This is done silently.
199 IMPORTANT: Please note that enabling this option causes makefile-mode
200 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \"it seems necessary\"."
204 (defvar makefile-browser-hook
'())
207 ;; Special targets for DMake, Sun's make ...
209 (defcustom makefile-special-targets-list
210 '(("DEFAULT") ("DONE") ("ERROR") ("EXPORT")
211 ("FAILED") ("GROUPEPILOG") ("GROUPPROLOG") ("IGNORE")
212 ("IMPORT") ("INCLUDE") ("INCLUDEDIRS") ("INIT")
213 ("KEEP_STATE") ("MAKEFILES") ("MAKE_VERSION") ("NO_PARALLEL")
214 ("PARALLEL") ("PHONY") ("PRECIOUS") ("REMOVE")
215 ("SCCS_GET") ("SILENT") ("SOURCE") ("SUFFIXES")
216 ("WAIT") ("c.o") ("C.o") ("m.o")
217 ("el.elc") ("y.c") ("s.o"))
218 "List of special targets.
219 You will be offered to complete on one of those in the minibuffer whenever
220 you enter a \".\" at the beginning of a line in makefile-mode."
221 :type
'(repeat (list string
))
224 (defcustom makefile-runtime-macros-list
225 '(("@") ("&") (">") ("<") ("*") ("^") ("+") ("?") ("%") ("$"))
226 "List of macros that are resolved by make at runtime.
227 If you insert a macro reference using makefile-insert-macro-ref, the name
228 of the macro is checked against this list. If it can be found its name will
229 not be enclosed in { } or ( )."
230 :type
'(repeat (list string
))
233 ;; Note that the first big subexpression is used by font lock. Note
234 ;; that if you change this regexp you must fix the imenu index
235 ;; function defined at the end of the file.
236 (defconst makefile-dependency-regex
237 "^ *\\([^ \n\t#:=]+\\([ \t]+\\([^ \t\n#:=]+\\|\\$[({][^ \t\n#})]+[})]\\)\\)*\\)[ \t]*:\\([ \t]*$\\|\\([^=\n].*$\\)\\)"
238 "Regex used to find dependency lines in a makefile.")
240 ;; Note that the first subexpression is used by font lock. Note that
241 ;; if you change this regexp you must fix the imenu index function
242 ;; defined at the end of the file.
243 (defconst makefile-macroassign-regex
244 "^ *\\([^ \n\t][^:#= \t\n]*\\)[ \t]*[*:+]?:?="
245 "Regex used to find macro assignment lines in a makefile.")
247 (defconst makefile-ignored-files-in-pickup-regex
248 "\\(^\\..*\\)\\|\\(.*~$\\)\\|\\(.*,v$\\)\\|\\(\\.[chy]\\)"
249 "Regex for filenames that will NOT be included in the target list.")
251 (if (fboundp 'facemenu-unlisted-faces
)
252 (add-to-list 'facemenu-unlisted-faces
'makefile-space-face
))
253 (defvar makefile-space-face
'makefile-space-face
254 "Face to use for highlighting leading spaces in Font-Lock mode.")
256 (defconst makefile-font-lock-keywords
258 ;; Do macro assignments. These get the "variable-name" face rather
260 (list makefile-macroassign-regex
1 'font-lock-variable-name-face
)
262 ;; Do dependencies. These get the function name face.
263 (list makefile-dependency-regex
1 'font-lock-function-name-face
)
265 ;; Variable references even in targets/strings/comments:
266 '("\\$[({]\\([-a-zA-Z0-9_.]+\\)[}):]" 1 font-lock-constant-face prepend
)
268 ;; Automatic variable references.
269 '("\\$\\([@%<?^+*]\\)" 1 font-lock-reference-face prepend
)
271 ;; Highlight lines that contain just whitespace.
272 ;; They can cause trouble, especially if they start with a tab.
273 '("^[ \t]+$" . makefile-space-face
)
275 ;; Highlight shell comments that Make treats as commands,
276 ;; since these can fool people.
277 '("^\t+#" 0 makefile-space-face t
)
279 ;; Highlight spaces that precede tabs.
280 ;; They can make a tab fail to be effective.
281 '("^\\( +\\)\t" 1 makefile-space-face
)))
283 ;;; ------------------------------------------------------------
284 ;;; The following configurable variables are used in the
285 ;;; up-to-date overview .
286 ;;; The standard configuration assumes that your `make' program
287 ;;; can be run in question/query mode using the `-q' option, this
288 ;;; means that the command
292 ;;; should return an exit status of zero if the target `foo' is
293 ;;; up to date and a nonzero exit status otherwise.
294 ;;; Many makes can do this although the docs/manpages do not mention
295 ;;; it. Try it with your favourite one. GNU make, System V make, and
296 ;;; Dennis Vadura's DMake have no problems.
297 ;;; Set the variable `makefile-brave-make' to the name of the
298 ;;; make utility that does this on your system.
299 ;;; To understand what this is all about see the function definition
300 ;;; of `makefile-query-by-make-minus-q' .
301 ;;; ------------------------------------------------------------
303 (defcustom makefile-brave-make
"make"
304 "How to invoke make, for `makefile-query-targets'.
305 This should identify a `make' command that can handle the `-q' option."
309 (defcustom makefile-query-one-target-method
'makefile-query-by-make-minus-q
310 "Function to call to determine whether a make target is up to date.
311 The function must satisfy this calling convention:
313 * As its first argument, it must accept the name of the target to
314 be checked, as a string.
316 * As its second argument, it may accept the name of a makefile
317 as a string. Depending on what you're going to do you may
320 * It must return the integer value 0 (zero) if the given target
321 should be considered up-to-date in the context of the given
322 makefile, any nonzero integer value otherwise."
326 (defcustom makefile-up-to-date-buffer-name
"*Makefile Up-to-date overview*"
327 "Name of the Up-to-date overview buffer."
331 ;;; --- end of up-to-date-overview configuration ------------------
333 (defvar makefile-mode-map nil
334 "The keymap that is used in Makefile mode.")
336 (if makefile-mode-map
338 (setq makefile-mode-map
(make-sparse-keymap))
340 (define-key makefile-mode-map
"\C-c:" 'makefile-insert-target-ref
)
341 (if makefile-electric-keys
343 (define-key makefile-mode-map
"$" 'makefile-insert-macro-ref
)
344 (define-key makefile-mode-map
":" 'makefile-electric-colon
)
345 (define-key makefile-mode-map
"=" 'makefile-electric-equal
)
346 (define-key makefile-mode-map
"." 'makefile-electric-dot
)))
347 (define-key makefile-mode-map
"\C-c\C-f" 'makefile-pickup-filenames-as-targets
)
348 (define-key makefile-mode-map
"\C-c\C-b" 'makefile-switch-to-browser
)
349 (define-key makefile-mode-map
"\C-c\C-c" 'comment-region
)
350 (define-key makefile-mode-map
"\C-c\C-p" 'makefile-pickup-everything
)
351 (define-key makefile-mode-map
"\C-c\C-u" 'makefile-create-up-to-date-overview
)
352 (define-key makefile-mode-map
"\C-c\C-i" 'makefile-insert-gmake-function
)
353 (define-key makefile-mode-map
"\C-c\C-\\" 'makefile-backslash-region
)
354 (define-key makefile-mode-map
"\M-p" 'makefile-previous-dependency
)
355 (define-key makefile-mode-map
"\M-n" 'makefile-next-dependency
)
356 (define-key makefile-mode-map
"\e\t" 'makefile-complete
)
359 (define-key makefile-mode-map
[menu-bar makefile-mode
]
360 (cons "Makefile" (make-sparse-keymap "Makefile")))
362 (define-key makefile-mode-map
[menu-bar makefile-mode browse
]
363 '("Pop up Makefile Browser" . makefile-switch-to-browser
))
364 (define-key makefile-mode-map
[menu-bar makefile-mode complete
]
365 '("Complete Target or Macro" . makefile-complete
))
366 (define-key makefile-mode-map
[menu-bar makefile-mode pickup
]
367 '("Find Targets and Macros" . makefile-pickup-everything
))
369 (define-key makefile-mode-map
[menu-bar makefile-mode prev
]
370 '("Move to Previous Dependency" . makefile-previous-dependency
))
371 (define-key makefile-mode-map
[menu-bar makefile-mode next
]
372 '("Move to Next Dependency" . makefile-next-dependency
)))
374 (defvar makefile-browser-map nil
375 "The keymap that is used in the macro- and target browser.")
376 (if makefile-browser-map
378 (setq makefile-browser-map
(make-sparse-keymap))
379 (define-key makefile-browser-map
"n" 'makefile-browser-next-line
)
380 (define-key makefile-browser-map
"\C-n" 'makefile-browser-next-line
)
381 (define-key makefile-browser-map
"p" 'makefile-browser-previous-line
)
382 (define-key makefile-browser-map
"\C-p" 'makefile-browser-previous-line
)
383 (define-key makefile-browser-map
" " 'makefile-browser-toggle
)
384 (define-key makefile-browser-map
"i" 'makefile-browser-insert-selection
)
385 (define-key makefile-browser-map
"I" 'makefile-browser-insert-selection-and-quit
)
386 (define-key makefile-browser-map
"\C-c\C-m" 'makefile-browser-insert-continuation
)
387 (define-key makefile-browser-map
"q" 'makefile-browser-quit
)
388 ;; disable horizontal movement
389 (define-key makefile-browser-map
"\C-b" 'undefined
)
390 (define-key makefile-browser-map
"\C-f" 'undefined
))
393 (defvar makefile-mode-syntax-table nil
)
394 (if makefile-mode-syntax-table
396 (setq makefile-mode-syntax-table
(make-syntax-table))
397 (modify-syntax-entry ?\
( "() " makefile-mode-syntax-table
)
398 (modify-syntax-entry ?\
) ")( " makefile-mode-syntax-table
)
399 (modify-syntax-entry ?\
[ "(] " makefile-mode-syntax-table
)
400 (modify-syntax-entry ?\
] ")[ " makefile-mode-syntax-table
)
401 (modify-syntax-entry ?\
{ "(} " makefile-mode-syntax-table
)
402 (modify-syntax-entry ?\
} "){ " makefile-mode-syntax-table
)
403 (modify-syntax-entry ?
\' "\" " makefile-mode-syntax-table
)
404 (modify-syntax-entry ?\
` "\" " makefile-mode-syntax-table
)
405 (modify-syntax-entry ?
# "< " makefile-mode-syntax-table
)
406 (modify-syntax-entry ?
\n "> " makefile-mode-syntax-table
))
409 ;;; ------------------------------------------------------------
410 ;;; Internal variables.
411 ;;; You don't need to configure below this line.
412 ;;; ------------------------------------------------------------
414 (defvar makefile-target-table nil
415 "Table of all target names known for this buffer.")
417 (defvar makefile-macro-table nil
418 "Table of all macro names known for this buffer.")
420 (defvar makefile-browser-client
421 "A buffer in Makefile mode that is currently using the browser.")
423 (defvar makefile-browser-selection-vector nil
)
424 (defvar makefile-has-prereqs nil
)
425 (defvar makefile-need-target-pickup t
)
426 (defvar makefile-need-macro-pickup t
)
428 (defvar makefile-mode-hook
'())
430 ;; Each element looks like '("GNU MAKE FUNCTION" "ARG" "ARG" ... )
431 ;; Each "ARG" is used as a prompt for a required argument.
432 (defconst makefile-gnumake-functions-alist
435 ("subst" "From" "To" "In")
436 ("patsubst" "Pattern" "Replacement" "In")
438 ("findstring" "Find what" "In")
439 ("filter" "Pattern" "Text")
440 ("filter-out" "Pattern" "Text")
442 ;; Filename functions
447 ("addprefix" "Prefix" "Names")
448 ("addsuffix" "Suffix" "Names")
449 ("join" "List 1" "List 2")
450 ("word" "Index" "Text")
453 ("wildcard" "Pattern")
455 ("foreach" "Variable" "List" "Text")
456 ("origin" "Variable")
457 ("shell" "Command")))
460 ;;; ------------------------------------------------------------
461 ;;; The mode function itself.
462 ;;; ------------------------------------------------------------
465 (defun makefile-mode ()
466 "Major mode for editing Makefiles.
467 This function ends by invoking the function(s) `makefile-mode-hook'.
469 \\{makefile-mode-map}
471 In the browser, use the following keys:
473 \\{makefile-browser-map}
475 Makefile mode can be configured by modifying the following variables:
477 makefile-browser-buffer-name:
478 Name of the macro- and target browser buffer.
480 makefile-target-colon:
481 The string that gets appended to all target names
482 inserted by `makefile-insert-target'.
483 \":\" or \"::\" are quite common values.
485 makefile-macro-assign:
486 The string that gets appended to all macro names
487 inserted by `makefile-insert-macro'.
488 The normal value should be \" = \", since this is what
489 standard make expects. However, newer makes such as dmake
490 allow a larger variety of different macro assignments, so you
491 might prefer to use \" += \" or \" := \" .
493 makefile-tab-after-target-colon:
494 If you want a TAB (instead of a space) to be appended after the
495 target colon, then set this to a non-nil value.
497 makefile-browser-leftmost-column:
498 Number of blanks to the left of the browser selection mark.
500 makefile-browser-cursor-column:
501 Column in which the cursor is positioned when it moves
502 up or down in the browser.
504 makefile-browser-selected-mark:
505 String used to mark selected entries in the browser.
507 makefile-browser-unselected-mark:
508 String used to mark unselected entries in the browser.
510 makefile-browser-auto-advance-after-selection-p:
511 If this variable is set to a non-nil value the cursor
512 will automagically advance to the next line after an item
513 has been selected in the browser.
515 makefile-pickup-everything-picks-up-filenames-p:
516 If this variable is set to a non-nil value then
517 `makefile-pickup-everything' also picks up filenames as targets
518 (i.e. it calls `makefile-pickup-filenames-as-targets'), otherwise
519 filenames are omitted.
521 makefile-cleanup-continuations-p:
522 If this variable is set to a non-nil value then makefile-mode
523 will assure that no line in the file ends with a backslash
524 (the continuation character) followed by any whitespace.
525 This is done by silently removing the trailing whitespace, leaving
526 the backslash itself intact.
527 IMPORTANT: Please note that enabling this option causes makefile-mode
528 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \"it seems necessary\".
530 makefile-browser-hook:
531 A function or list of functions to be called just before the
532 browser is entered. This is executed in the makefile buffer.
534 makefile-special-targets-list:
535 List of special targets. You will be offered to complete
536 on one of those in the minibuffer whenever you enter a `.'.
537 at the beginning of a line in Makefile mode."
540 (kill-all-local-variables)
541 (make-local-variable 'local-write-file-hooks
)
542 (setq local-write-file-hooks
543 '(makefile-cleanup-continuations makefile-warn-suspicious-lines
))
544 (make-local-variable 'makefile-target-table
)
545 (make-local-variable 'makefile-macro-table
)
546 (make-local-variable 'makefile-has-prereqs
)
547 (make-local-variable 'makefile-need-target-pickup
)
548 (make-local-variable 'makefile-need-macro-pickup
)
551 (make-local-variable 'font-lock-defaults
)
552 (setq font-lock-defaults
'(makefile-font-lock-keywords))
555 (make-local-variable 'add-log-current-defun-function
)
556 (setq add-log-current-defun-function
'makefile-add-log-defun
)
559 (make-local-variable 'imenu-create-index-function
)
560 (setq imenu-create-index-function
'makefile-menu-index-function
)
563 (make-local-variable 'dabbrev-abbrev-skip-leading-regexp
)
564 (setq dabbrev-abbrev-skip-leading-regexp
"\\$")
567 (make-local-variable 'fill-paragraph-function
)
568 (setq fill-paragraph-function
'makefile-fill-paragraph
)
571 (make-local-variable 'comment-start
)
572 (setq comment-start
"#")
573 (make-local-variable 'comment-end
)
574 (setq comment-end
"")
575 (make-local-variable 'comment-start-skip
)
576 (setq comment-start-skip
"#+[ \t]*")
578 ;; become the current major mode
579 (setq major-mode
'makefile-mode
)
580 (setq mode-name
"Makefile")
582 ;; Activate keymap and syntax table.
583 (use-local-map makefile-mode-map
)
584 (set-syntax-table makefile-mode-syntax-table
)
586 ;; Real TABs are important in makefiles
587 (setq indent-tabs-mode t
)
588 (run-hooks 'makefile-mode-hook
))
594 (defun makefile-next-dependency ()
595 "Move point to the beginning of the next dependency line."
597 (let ((here (point)))
599 (if (re-search-forward makefile-dependency-regex
(point-max) t
)
600 (progn (beginning-of-line) t
) ; indicate success
601 (goto-char here
) nil
)))
603 (defun makefile-previous-dependency ()
604 "Move point to the beginning of the previous dependency line."
606 (let ((here (point)))
608 (if (re-search-backward makefile-dependency-regex
(point-min) t
)
609 (progn (beginning-of-line) t
) ; indicate success
610 (goto-char here
) nil
)))
614 ;;; Electric keys. Blech.
616 (defun makefile-electric-dot (arg)
617 "Prompt for the name of a special target to insert.
618 Only does electric insertion at beginning of line.
619 Anywhere else just self-inserts."
622 (makefile-insert-special-target)
623 (self-insert-command arg
)))
625 (defun makefile-insert-special-target ()
626 "Prompt for and insert a special target name.
627 Uses `makefile-special-targets' list."
629 (makefile-pickup-targets)
630 (let ((special-target
631 (completing-read "Special target: "
632 makefile-special-targets-list nil nil nil
)))
633 (if (zerop (length special-target
))
635 (insert "." special-target
":")
636 (makefile-forward-after-target-colon))))
638 (defun makefile-electric-equal (arg)
639 "Prompt for name of a macro to insert.
640 Only does prompting if point is at beginning of line.
641 Anywhere else just self-inserts."
643 (makefile-pickup-macros)
645 (call-interactively 'makefile-insert-macro
)
646 (self-insert-command arg
)))
648 (defun makefile-insert-macro (macro-name)
649 "Prepare definition of a new macro."
650 (interactive "sMacro Name: ")
651 (makefile-pickup-macros)
652 (if (not (zerop (length macro-name
)))
655 (insert macro-name makefile-macro-assign
)
656 (setq makefile-need-macro-pickup t
)
657 (makefile-remember-macro macro-name
))))
659 (defun makefile-insert-macro-ref (macro-name)
660 "Complete on a list of known macros, then insert complete ref at point."
664 (makefile-pickup-macros)
665 (completing-read "Refer to macro: " makefile-macro-table nil nil nil
))))
666 (makefile-do-macro-insertion macro-name
))
668 (defun makefile-insert-target (target-name)
669 "Prepare definition of a new target (dependency line)."
670 (interactive "sTarget: ")
671 (if (not (zerop (length target-name
)))
674 (insert target-name makefile-target-colon
)
675 (makefile-forward-after-target-colon)
677 (setq makefile-need-target-pickup t
)
678 (makefile-remember-target target-name
))))
680 (defun makefile-insert-target-ref (target-name)
681 "Complete on a list of known targets, then insert target-ref at point."
685 (makefile-pickup-targets)
686 (completing-read "Refer to target: " makefile-target-table nil nil nil
))))
687 (if (not (zerop (length target-name
)))
688 (insert target-name
" ")))
690 (defun makefile-electric-colon (arg)
691 "Prompt for name of new target.
692 Prompting only happens at beginning of line.
693 Anywhere else just self-inserts."
696 (call-interactively 'makefile-insert-target
)
697 (self-insert-command arg
)))
701 ;;; ------------------------------------------------------------
702 ;;; Extracting targets and macros from an existing makefile
703 ;;; ------------------------------------------------------------
705 (defun makefile-pickup-targets ()
706 "Notice names of all target definitions in Makefile."
708 (if (not makefile-need-target-pickup
)
710 (setq makefile-need-target-pickup nil
)
711 (setq makefile-target-table nil
)
712 (setq makefile-has-prereqs nil
)
714 (goto-char (point-min))
715 (while (re-search-forward makefile-dependency-regex
(point-max) t
)
716 (makefile-add-this-line-targets)))
717 (message "Read targets OK.")))
719 (defun makefile-add-this-line-targets ()
722 (let ((done-with-line nil
)
723 (line-number (1+ (count-lines (point-min) (point)))))
724 (while (not done-with-line
)
725 (skip-chars-forward " \t")
726 (if (not (setq done-with-line
(or (eolp)
727 (char-equal (char-after (point)) ?
:))))
729 (let* ((start-of-target-name (point))
732 (skip-chars-forward "^ \t:#")
733 (buffer-substring start-of-target-name
(point))))
735 (not (looking-at ":[ \t]*$"))))
736 (if (makefile-remember-target target-name has-prereqs
)
737 (message "Picked up target \"%s\" from line %d"
738 target-name line-number
)))))))))
740 (defun makefile-pickup-macros ()
741 "Notice names of all macro definitions in Makefile."
743 (if (not makefile-need-macro-pickup
)
745 (setq makefile-need-macro-pickup nil
)
746 (setq makefile-macro-table nil
)
748 (goto-char (point-min))
749 (while (re-search-forward makefile-macroassign-regex
(point-max) t
)
750 (makefile-add-this-line-macro)
752 (message "Read macros OK.")))
754 (defun makefile-add-this-line-macro ()
757 (skip-chars-forward " \t")
759 (let* ((start-of-macro-name (point))
760 (line-number (1+ (count-lines (point-min) (point))))
762 (skip-chars-forward "^ \t:#=*")
763 (buffer-substring start-of-macro-name
(point)))))
764 (if (makefile-remember-macro macro-name
)
765 (message "Picked up macro \"%s\" from line %d"
766 macro-name line-number
))))))
768 (defun makefile-pickup-everything (arg)
769 "Notice names of all macros and targets in Makefile.
770 Prefix arg means force pickups to be redone."
774 (setq makefile-need-target-pickup t
)
775 (setq makefile-need-macro-pickup t
)))
776 (makefile-pickup-macros)
777 (makefile-pickup-targets)
778 (if makefile-pickup-everything-picks-up-filenames-p
779 (makefile-pickup-filenames-as-targets)))
781 (defun makefile-pickup-filenames-as-targets ()
782 "Scan the current directory for filenames to use as targets.
783 Checks each filename against `makefile-ignored-files-in-pickup-regex'
784 and adds all qualifying names to the list of known targets."
786 (let* ((dir (file-name-directory (buffer-file-name)))
787 (raw-filename-list (if dir
788 (file-name-all-completions "" dir
)
789 (file-name-all-completions "" ""))))
790 (mapcar '(lambda (name)
791 (if (and (not (file-directory-p name
))
792 (not (string-match makefile-ignored-files-in-pickup-regex
794 (if (makefile-remember-target name
)
795 (message "Picked up file \"%s\" as target" name
))))
802 (defun makefile-complete ()
803 "Perform completion on Makefile construct preceding point.
804 Can complete variable and target names.
805 The context determines which are considered."
807 (let* ((beg (save-excursion
808 (skip-chars-backward "^$(){}:#= \t\n")
810 (try (buffer-substring beg
(point)))
816 (let ((pc (preceding-char)))
818 ;; Beginning of line means anything.
822 ;; Preceding "$" means macros only.
826 ;; Preceding "$(" or "${" means macros only.
833 (= (preceding-char) ?$
))))
834 (setq do-macros t
)))))
837 (let* ((table (append (if do-macros
839 makefile-target-table
)
840 makefile-macro-table
))
841 (completion (try-completion try table
)))
843 ;; Exact match, so insert closing paren or colon.
845 (insert (if do-macros
857 (message "Can't find completion for \"%s\"" try
)
860 ;; Partial completion.
861 ((not (string= try completion
))
862 ;; FIXME it would be nice to supply the closing paren if an
863 ;; exact, unambiguous match were found. That is not possible
864 ;; right now. Ditto closing ":" for targets.
865 (delete-region beg
(point))
867 ;; DO-MACROS means doing macros only. If not that, then check
868 ;; to see if this completion is a macro. Special insertion
869 ;; must be done for macros.
871 (assoc completion makefile-macro-table
))
872 (let ((makefile-use-curly-braces-for-macros-p
874 makefile-use-curly-braces-for-macros-p
)))
875 (delete-backward-char 2)
876 (makefile-do-macro-insertion completion
)
877 (delete-backward-char 1))
879 ;; Just insert targets.
880 (insert completion
)))
882 ;; Can't complete any more, so make completion list. FIXME
883 ;; this doesn't do the right thing when the completion is
884 ;; actually inserted. I don't think there is an easy way to do
887 (message "Making completion list...")
888 (let ((list (all-completions try table
)))
889 (with-output-to-temp-buffer "*Completions*"
890 (display-completion-list list
)))
891 (message "Making completion list...done"))))))
895 ;; Backslashification. Stolen from cc-mode.el.
897 (defun makefile-backslash-region (from to delete-flag
)
898 "Insert, align, or delete end-of-line backslashes on the lines in the region.
899 With no argument, inserts backslashes and aligns existing backslashes.
900 With an argument, deletes the backslashes.
902 This function does not modify the last line of the region if the region ends
903 right at the start of the following line; it does not modify blank lines
904 at the start of the region. So you can put the region around an entire macro
905 definition and conveniently use this command."
909 (let ((column makefile-backslash-column
)
910 (endmark (make-marker)))
911 (move-marker endmark to
)
912 ;; Compute the smallest column number past the ends of all the lines.
913 (if makefile-backslash-align
915 (if (not delete-flag
)
916 (while (< (point) to
)
918 (if (= (preceding-char) ?
\\)
919 (progn (forward-char -
1)
920 (skip-chars-backward " \t")))
921 (setq column
(max column
(1+ (current-column))))
923 ;; Adjust upward to a tab column, if that doesn't push
925 (if (> (% column tab-width
) 0)
926 (let ((adjusted (* (/ (+ column tab-width -
1) tab-width
)
928 (if (< adjusted
(window-width))
929 (setq column adjusted
))))))
930 ;; Don't modify blank lines at start of region.
932 (while (and (< (point) endmark
) (eolp))
934 ;; Add or remove backslashes on all the lines.
935 (while (and (< (point) endmark
)
936 ;; Don't backslashify the last line
937 ;; if the region ends right at the start of the next line.
940 (< (point) endmark
)))
941 (if (not delete-flag
)
942 (makefile-append-backslash column
)
943 (makefile-delete-backslash))
945 (move-marker endmark nil
))))
947 (defun makefile-append-backslash (column)
949 ;; Note that "\\\\" is needed to get one backslash.
950 (if (= (preceding-char) ?
\\)
951 (progn (forward-char -
1)
952 (delete-horizontal-space)
953 (indent-to column
(if makefile-backslash-align nil
1)))
954 (indent-to column
(if makefile-backslash-align nil
1))
957 (defun makefile-delete-backslash ()
962 (if (looking-at "\\\\")
963 (delete-region (1+ (point))
964 (progn (skip-chars-backward " \t") (point)))))))
970 (defun makefile-fill-paragraph (arg)
971 ;; Fill comments, backslashed lines, and variable definitions
977 ;; Found a comment. Set the fill prefix and then fill.
978 (let ((fill-prefix (buffer-substring-no-properties (match-beginning 0)
980 (fill-paragraph-function nil
))
984 ;; Must look for backslashed-region before looking for variable
989 (= (preceding-char) ?
\\)
992 (= (preceding-char) ?
\\))))
993 ;; A backslash region. Find beginning and end, remove
994 ;; backslashes, fill, and then reapply backslahes.
999 (while (= (preceding-char) ?
\\)
1005 (while (= (preceding-char) ?
\\)
1009 (narrow-to-region beginning end
)
1010 (makefile-backslash-region (point-min) (point-max) t
)
1011 (let ((fill-paragraph-function nil
))
1012 (fill-paragraph nil
))
1013 (makefile-backslash-region (point-min) (point-max) nil
)
1014 (goto-char (point-max))
1015 (if (< (skip-chars-backward "\n") 0)
1016 (delete-region (point) (point-max))))))
1018 ((looking-at makefile-macroassign-regex
)
1019 ;; Have a macro assign. Fill just this line, and then backslash
1020 ;; resulting region.
1022 (narrow-to-region (point) (save-excursion
1026 (let ((fill-paragraph-function nil
))
1027 (fill-paragraph nil
))
1028 (makefile-backslash-region (point-min) (point-max) nil
)))))
1030 ;; Always return non-nil so we don't fill anything else.
1035 ;;; ------------------------------------------------------------
1037 ;;; ------------------------------------------------------------
1039 (defun makefile-browser-format-target-line (target selected
)
1041 (concat (make-string makefile-browser-leftmost-column ?\
)
1043 makefile-browser-selected-mark
1044 makefile-browser-unselected-mark
)
1046 target makefile-target-colon
))
1048 (defun makefile-browser-format-macro-line (macro selected
)
1050 (concat (make-string makefile-browser-leftmost-column ?\
)
1052 makefile-browser-selected-mark
1053 makefile-browser-unselected-mark
)
1054 (makefile-format-macro-ref macro
))))
1056 (defun makefile-browser-fill (targets macros
)
1057 (let ((inhibit-read-only t
))
1058 (goto-char (point-min))
1062 (lambda (item) (insert (makefile-browser-format-target-line (car item
) nil
) "\n")))
1067 (lambda (item) (insert (makefile-browser-format-macro-line (car item
) nil
) "\n")))
1070 (sort-lines nil
(point-min) (point-max))
1071 (goto-char (1- (point-max)))
1072 (delete-char 1) ; remove unnecessary newline at eob
1073 (goto-char (point-min))
1074 (forward-char makefile-browser-cursor-column
)))
1077 ;;; Moving up and down in the browser
1080 (defun makefile-browser-next-line ()
1081 "Move the browser selection cursor to the next line."
1083 (if (not (makefile-last-line-p))
1086 (forward-char makefile-browser-cursor-column
))))
1088 (defun makefile-browser-previous-line ()
1089 "Move the browser selection cursor to the previous line."
1091 (if (not (makefile-first-line-p))
1094 (forward-char makefile-browser-cursor-column
))))
1097 ;;; Quitting the browser (returns to client buffer)
1100 (defun makefile-browser-quit ()
1101 "Leave the browser and return to the makefile buffer."
1103 (let ((my-client makefile-browser-client
))
1104 (setq makefile-browser-client nil
) ; we quitted, so NO client!
1105 (set-buffer-modified-p nil
)
1107 (pop-to-buffer my-client
)))
1110 ;;; Toggle state of a browser item
1113 (defun makefile-browser-toggle ()
1114 "Toggle the selection state of the browser item at the cursor position."
1116 (let ((this-line (count-lines (point-min) (point))))
1117 (setq this-line
(max 1 this-line
))
1118 (makefile-browser-toggle-state-for-line this-line
)
1119 (goto-line this-line
)
1120 (let ((inhibit-read-only t
))
1122 (if (makefile-browser-on-macro-line-p)
1123 (let ((macro-name (makefile-browser-this-line-macro-name)))
1124 (delete-region (point) (progn (end-of-line) (point)))
1126 (makefile-browser-format-macro-line
1128 (makefile-browser-get-state-for-line this-line
))))
1129 (let ((target-name (makefile-browser-this-line-target-name)))
1130 (delete-region (point) (progn (end-of-line) (point)))
1132 (makefile-browser-format-target-line
1134 (makefile-browser-get-state-for-line this-line
))))))
1136 (forward-char makefile-browser-cursor-column
)
1137 (if makefile-browser-auto-advance-after-selection-p
1138 (makefile-browser-next-line))))
1141 ;;; Making insertions into the client buffer
1144 (defun makefile-browser-insert-continuation ()
1145 "Insert a makefile continuation.
1146 In the makefile buffer, go to (end-of-line), insert a \'\\\'
1147 character, insert a new blank line, go to that line and indent by one TAB.
1148 This is most useful in the process of creating continued lines when copying
1149 large dependencies from the browser to the client buffer.
1150 \(point) advances accordingly in the client buffer."
1153 (set-buffer makefile-browser-client
)
1157 (defun makefile-browser-insert-selection ()
1158 "Insert all selected targets and/or macros in the makefile buffer.
1159 Insertion takes place at point."
1163 (let ((current-line 1))
1165 (if (makefile-browser-get-state-for-line current-line
)
1166 (makefile-browser-send-this-line-item))
1168 (setq current-line
(1+ current-line
))))))
1170 (defun makefile-browser-insert-selection-and-quit ()
1172 (makefile-browser-insert-selection)
1173 (makefile-browser-quit))
1175 (defun makefile-browser-send-this-line-item ()
1176 (if (makefile-browser-on-macro-line-p)
1178 (let ((macro-name (makefile-browser-this-line-macro-name)))
1179 (set-buffer makefile-browser-client
)
1180 (insert (makefile-format-macro-ref macro-name
) " ")))
1182 (let ((target-name (makefile-browser-this-line-target-name)))
1183 (set-buffer makefile-browser-client
)
1184 (insert target-name
" ")))))
1186 (defun makefile-browser-start-interaction ()
1187 (use-local-map makefile-browser-map
)
1188 (setq buffer-read-only t
))
1190 (defun makefile-browse (targets macros
)
1192 (if (zerop (+ (length targets
) (length macros
)))
1195 (message "No macros or targets to browse! Consider running 'makefile-pickup-everything\'"))
1196 (let ((browser-buffer (get-buffer-create makefile-browser-buffer-name
)))
1197 (pop-to-buffer browser-buffer
)
1198 (make-variable-buffer-local 'makefile-browser-selection-vector
)
1199 (makefile-browser-fill targets macros
)
1200 (shrink-window-if-larger-than-buffer)
1201 (setq makefile-browser-selection-vector
1202 (make-vector (+ (length targets
) (length macros
)) nil
))
1203 (makefile-browser-start-interaction))))
1205 (defun makefile-switch-to-browser ()
1207 (run-hooks 'makefile-browser-hook
)
1208 (setq makefile-browser-client
(current-buffer))
1209 (makefile-pickup-targets)
1210 (makefile-pickup-macros)
1211 (makefile-browse makefile-target-table makefile-macro-table
))
1215 ;;; ------------------------------------------------------------
1216 ;;; Up-to-date overview buffer
1217 ;;; ------------------------------------------------------------
1219 (defun makefile-create-up-to-date-overview ()
1220 "Create a buffer containing an overview of the state of all known targets.
1221 Known targets are targets that are explicitly defined in that makefile;
1222 in other words, all targets that appear on the left hand side of a
1223 dependency in the makefile."
1225 (if (y-or-n-p "Are you sure that the makefile being edited is consistent? ")
1227 ;; The rest of this function operates on a temporary makefile, created by
1228 ;; writing the current contents of the makefile buffer.
1230 (let ((saved-target-table makefile-target-table
)
1231 (this-buffer (current-buffer))
1232 (makefile-up-to-date-buffer
1233 (get-buffer-create makefile-up-to-date-buffer-name
))
1234 (filename (makefile-save-temporary))
1236 ;; Forget the target table because it may contain picked-up filenames
1237 ;; that are not really targets in the current makefile.
1238 ;; We don't want to query these, so get a new target-table with just the
1239 ;; targets that can be found in the makefile buffer.
1240 ;; The 'old' target table will be restored later.
1242 (real-targets (progn
1243 (makefile-pickup-targets)
1244 makefile-target-table
))
1245 (prereqs makefile-has-prereqs
)
1248 (set-buffer makefile-up-to-date-buffer
)
1249 (setq buffer-read-only nil
)
1251 (makefile-query-targets filename real-targets prereqs
)
1252 (if (zerop (buffer-size)) ; if it did not get us anything
1254 (kill-buffer (current-buffer))
1255 (message "No overview created!")))
1256 (set-buffer this-buffer
)
1257 (setq makefile-target-table saved-target-table
)
1258 (if (get-buffer makefile-up-to-date-buffer-name
)
1260 (pop-to-buffer (get-buffer makefile-up-to-date-buffer-name
))
1261 (shrink-window-if-larger-than-buffer)
1262 (sort-lines nil
(point-min) (point-max))
1263 (setq buffer-read-only t
))))))
1265 (defun makefile-save-temporary ()
1266 "Create a temporary file from the current makefile buffer."
1267 (let ((filename (makefile-generate-temporary-filename)))
1268 (write-region (point-min) (point-max) filename nil
0)
1269 filename
)) ; return the filename
1271 (defun makefile-generate-temporary-filename ()
1272 "Create a filename suitable for use in `makefile-save-temporary'.
1273 Be careful to allow brain-dead file systems (DOS, SYSV ...) to cope
1274 with the generated name!"
1275 (let ((my-name (user-login-name))
1276 (my-uid (int-to-string (user-uid))))
1278 (if (> (length my-name
) 3)
1279 (substring my-name
0 3)
1282 (if (> (length my-uid
) 3)
1283 (substring my-uid
0 3)
1286 (defun makefile-query-targets (filename target-table prereq-list
)
1287 "Fill the up-to-date overview buffer.
1288 Checks each target in TARGET-TABLE using `makefile-query-one-target-method'
1289 and generates the overview, one line per target name."
1292 (function (lambda (item)
1293 (let* ((target-name (car item
))
1294 (no-prereqs (not (member target-name prereq-list
)))
1295 (needs-rebuild (or no-prereqs
1297 makefile-query-one-target-method
1302 (cond (no-prereqs " .. has no prerequisites")
1303 (needs-rebuild " .. NEEDS REBUILD")
1304 (t " .. is up to date"))))
1307 (goto-char (point-min))
1308 (delete-file filename
)) ; remove the tmpfile
1310 (defun makefile-query-by-make-minus-q (target &optional filename
)
1312 (call-process makefile-brave-make nil nil nil
1313 "-f" filename
"-q" target
))))
1317 ;;; ------------------------------------------------------------
1318 ;;; Continuation cleanup
1319 ;;; ------------------------------------------------------------
1321 (defun makefile-cleanup-continuations ()
1322 (if (eq major-mode
'makefile-mode
)
1323 (if (and makefile-cleanup-continuations-p
1324 (not buffer-read-only
))
1326 (goto-char (point-min))
1327 (while (re-search-forward "\\\\[ \t]+$" (point-max) t
)
1328 (replace-match "\\" t t
))))))
1331 ;;; ------------------------------------------------------------
1332 ;;; Warn of suspicious lines
1333 ;;; ------------------------------------------------------------
1335 (defun makefile-warn-suspicious-lines ()
1336 (let ((dont-save nil
))
1337 (if (eq major-mode
'makefile-mode
)
1340 (goto-char (point-min))
1342 "\\(^[\t]+$\\)\\|\\(^[ ]+[\t]\\)" (point-max) t
))))
1344 (let ((line-nr (count-lines (point-min) suspicious
)))
1347 (format "Suspicious line %d. Save anyway "
1353 ;;; ------------------------------------------------------------
1354 ;;; GNU make function support
1355 ;;; ------------------------------------------------------------
1357 (defun makefile-insert-gmake-function ()
1358 "Insert a GNU make function call.
1359 Asks for the name of the function to use (with completion).
1360 Then prompts for all required parameters."
1362 (let* ((gm-function-name (completing-read
1364 makefile-gnumake-functions-alist
1366 (gm-function-prompts
1367 (cdr (assoc gm-function-name makefile-gnumake-functions-alist
))))
1368 (if (not (zerop (length gm-function-name
)))
1369 (insert (makefile-format-macro-ref
1370 (concat gm-function-name
" "
1371 (makefile-prompt-for-gmake-funargs
1372 gm-function-name gm-function-prompts
)))
1375 (defun makefile-prompt-for-gmake-funargs (function-name prompt-list
)
1377 (function (lambda (one-prompt)
1378 (read-string (format "[%s] %s: " function-name one-prompt
)
1385 ;;; ------------------------------------------------------------
1386 ;;; Utility functions
1387 ;;; ------------------------------------------------------------
1389 (defun makefile-do-macro-insertion (macro-name)
1390 "Insert a macro reference."
1391 (if (not (zerop (length macro-name
)))
1392 (if (assoc macro-name makefile-runtime-macros-list
)
1393 (insert "$" macro-name
)
1394 (insert (makefile-format-macro-ref macro-name
)))))
1396 (defun makefile-remember-target (target-name &optional has-prereqs
)
1397 "Remember a given target if it is not already remembered for this buffer."
1398 (if (not (zerop (length target-name
)))
1400 (if (not (assoc target-name makefile-target-table
))
1401 (setq makefile-target-table
1402 (cons (list target-name
) makefile-target-table
)))
1404 (setq makefile-has-prereqs
1405 (cons target-name makefile-has-prereqs
))))))
1407 (defun makefile-remember-macro (macro-name)
1408 "Remember a given macro if it is not already remembered for this buffer."
1409 (if (not (zerop (length macro-name
)))
1410 (if (not (assoc macro-name makefile-macro-table
))
1411 (setq makefile-macro-table
1412 (cons (list macro-name
) makefile-macro-table
)))))
1414 (defun makefile-forward-after-target-colon ()
1415 "Move point forward after inserting the terminating colon of a target.
1416 This acts according to the value of `makefile-tab-after-target-colon'."
1417 (if makefile-tab-after-target-colon
1421 (defun makefile-browser-on-macro-line-p ()
1422 "Determine if point is on a macro line in the browser."
1425 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t
)))
1427 (defun makefile-browser-this-line-target-name ()
1428 "Extract the target name from a line in the browser."
1431 (skip-chars-backward "^ \t")
1432 (buffer-substring (point) (1- (makefile-end-of-line-point)))))
1434 (defun makefile-browser-this-line-macro-name ()
1435 "Extract the macro name from a line in the browser."
1438 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t
)
1439 (let ((macro-start (point)))
1440 (skip-chars-forward "^})")
1441 (buffer-substring macro-start
(point)))))
1443 (defun makefile-format-macro-ref (macro-name)
1444 "Format a macro reference.
1445 Uses `makefile-use-curly-braces-for-macros-p'."
1446 (if (or (char-equal ?\
( (string-to-char macro-name
))
1447 (char-equal ?\
{ (string-to-char macro-name
)))
1448 (format "$%s" macro-name
)
1449 (if makefile-use-curly-braces-for-macros-p
1450 (format "${%s}" macro-name
)
1451 (format "$(%s)" macro-name
))))
1453 (defun makefile-browser-get-state-for-line (n)
1454 (aref makefile-browser-selection-vector
(1- n
)))
1456 (defun makefile-browser-set-state-for-line (n to-state
)
1457 (aset makefile-browser-selection-vector
(1- n
) to-state
))
1459 (defun makefile-browser-toggle-state-for-line (n)
1460 (makefile-browser-set-state-for-line n
(not (makefile-browser-get-state-for-line n
))))
1462 (defun makefile-beginning-of-line-point ()
1467 (defun makefile-end-of-line-point ()
1472 (defun makefile-last-line-p ()
1473 (= (makefile-end-of-line-point) (point-max)))
1475 (defun makefile-first-line-p ()
1476 (= (makefile-beginning-of-line-point) (point-min)))
1480 ;;; Support for other packages, like add-log and imenu.
1482 (defun makefile-add-log-defun ()
1483 "Return name of target or variable assignment that point is in.
1484 If it isn't in one, return nil."
1488 ;; Scan back line by line, noticing when we come to a
1489 ;; variable or rule definition, and giving up when we see
1490 ;; a line that is not part of either of those.
1493 ((looking-at makefile-macroassign-regex
)
1494 (setq found
(buffer-substring-no-properties (match-beginning 1)
1496 ((looking-at makefile-dependency-regex
)
1497 (setq found
(buffer-substring-no-properties (match-beginning 1)
1499 ;; Don't keep looking across a blank line or comment. Give up.
1500 ((looking-at "$\\|#")
1503 (setq found
'bobp
)))
1506 (if (stringp found
) found
))))
1508 ;; FIXME it might be nice to have them separated by macro vs target.
1509 (defun makefile-menu-index-function ()
1510 ;; "Generate alist of indices for imenu."
1513 (re (concat makefile-dependency-regex
1515 makefile-macroassign-regex
)))
1516 (imenu-progress-message stupid
0)
1517 (goto-char (point-min))
1518 (while (re-search-forward re nil t
)
1519 (imenu-progress-message stupid
)
1520 (let ((n (if (match-beginning 1) 1 5)))
1522 (cons (buffer-substring (match-beginning n
)
1524 (match-beginning n
))
1526 (imenu-progress-message stupid
100)
1529 ;;; make-mode.el ends here