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 (defcustom makefile-mode-hook nil
205 "Normal hook run by `makefile-mode'."
209 (defvar makefile-browser-hook
'())
212 ;; Special targets for DMake, Sun's make ...
214 (defcustom makefile-special-targets-list
215 '(("DEFAULT") ("DONE") ("ERROR") ("EXPORT")
216 ("FAILED") ("GROUPEPILOG") ("GROUPPROLOG") ("IGNORE")
217 ("IMPORT") ("INCLUDE") ("INCLUDEDIRS") ("INIT")
218 ("KEEP_STATE") ("MAKEFILES") ("MAKE_VERSION") ("NO_PARALLEL")
219 ("PARALLEL") ("PHONY") ("PRECIOUS") ("REMOVE")
220 ("SCCS_GET") ("SILENT") ("SOURCE") ("SUFFIXES")
221 ("WAIT") ("c.o") ("C.o") ("m.o")
222 ("el.elc") ("y.c") ("s.o"))
223 "List of special targets.
224 You will be offered to complete on one of those in the minibuffer whenever
225 you enter a \".\" at the beginning of a line in makefile-mode."
226 :type
'(repeat (list string
))
229 (defcustom makefile-runtime-macros-list
230 '(("@") ("&") (">") ("<") ("*") ("^") ("+") ("?") ("%") ("$"))
231 "List of macros that are resolved by make at runtime.
232 If you insert a macro reference using `makefile-insert-macro-ref', the name
233 of the macro is checked against this list. If it can be found its name will
234 not be enclosed in { } or ( )."
235 :type
'(repeat (list string
))
238 ;; Note that the first big subexpression is used by font lock. Note
239 ;; that if you change this regexp you might have to fix the imenu
240 ;; index in makefile-imenu-generic-expression.
241 (defconst makefile-dependency-regex
242 "^ *\\([^ \n\t#:=]+\\([ \t]+\\([^ \t\n#:=]+\\|\\$[({][^ \t\n#})]+[})]\\)\\)*\\)[ \t]*:\\([ \t]*$\\|\\([^=\n].*$\\)\\)"
243 "Regex used to find dependency lines in a makefile.")
245 ;; Note that the first subexpression is used by font lock. Note
246 ;; that if you change this regexp you might have to fix the imenu
247 ;; index in makefile-imenu-generic-expression.
248 (defconst makefile-macroassign-regex
249 "^ *\\([^ \n\t][^:#= \t\n]*\\)[ \t]*[*:+]?:?="
250 "Regex used to find macro assignment lines in a makefile.")
252 (defconst makefile-ignored-files-in-pickup-regex
253 "\\(^\\..*\\)\\|\\(.*~$\\)\\|\\(.*,v$\\)\\|\\(\\.[chy]\\)"
254 "Regex for filenames that will NOT be included in the target list.")
256 (if (fboundp 'facemenu-unlisted-faces
)
257 (add-to-list 'facemenu-unlisted-faces
'makefile-space-face
))
258 (defvar makefile-space-face
'makefile-space-face
259 "Face to use for highlighting leading spaces in Font-Lock mode.")
261 (defconst makefile-font-lock-keywords
263 ;; Do macro assignments. These get the "variable-name" face rather
265 (list makefile-macroassign-regex
1 'font-lock-variable-name-face
)
267 ;; Do dependencies. These get the function name face.
268 (list makefile-dependency-regex
1 'font-lock-function-name-face
)
270 ;; Variable references even in targets/strings/comments:
271 '("\\$[({]\\([-a-zA-Z0-9_.]+\\)[}):]" 1 font-lock-constant-face prepend
)
273 ;; Automatic variable references.
274 '("\\$\\([@%<?^+*]\\)" 1 font-lock-reference-face prepend
)
276 ;; Highlight lines that contain just whitespace.
277 ;; They can cause trouble, especially if they start with a tab.
278 '("^[ \t]+$" . makefile-space-face
)
280 ;; Highlight shell comments that Make treats as commands,
281 ;; since these can fool people.
282 '("^\t+#" 0 makefile-space-face t
)
284 ;; Highlight spaces that precede tabs.
285 ;; They can make a tab fail to be effective.
286 '("^\\( +\\)\t" 1 makefile-space-face
)))
288 (defvar makefile-imenu-generic-expression
290 (list "Dependencies" makefile-dependency-regex
1)
291 (list "Macro Assignment" makefile-macroassign-regex
1))
292 "Imenu generic expression for Makefile mode. See `imenu-generic-expression'.")
294 ;;; ------------------------------------------------------------
295 ;;; The following configurable variables are used in the
296 ;;; up-to-date overview .
297 ;;; The standard configuration assumes that your `make' program
298 ;;; can be run in question/query mode using the `-q' option, this
299 ;;; means that the command
303 ;;; should return an exit status of zero if the target `foo' is
304 ;;; up to date and a nonzero exit status otherwise.
305 ;;; Many makes can do this although the docs/manpages do not mention
306 ;;; it. Try it with your favourite one. GNU make, System V make, and
307 ;;; Dennis Vadura's DMake have no problems.
308 ;;; Set the variable `makefile-brave-make' to the name of the
309 ;;; make utility that does this on your system.
310 ;;; To understand what this is all about see the function definition
311 ;;; of `makefile-query-by-make-minus-q' .
312 ;;; ------------------------------------------------------------
314 (defcustom makefile-brave-make
"make"
315 "How to invoke make, for `makefile-query-targets'.
316 This should identify a `make' command that can handle the `-q' option."
320 (defcustom makefile-query-one-target-method
'makefile-query-by-make-minus-q
321 "Function to call to determine whether a make target is up to date.
322 The function must satisfy this calling convention:
324 * As its first argument, it must accept the name of the target to
325 be checked, as a string.
327 * As its second argument, it may accept the name of a makefile
328 as a string. Depending on what you're going to do you may
331 * It must return the integer value 0 (zero) if the given target
332 should be considered up-to-date in the context of the given
333 makefile, any nonzero integer value otherwise."
337 (defcustom makefile-up-to-date-buffer-name
"*Makefile Up-to-date overview*"
338 "Name of the Up-to-date overview buffer."
342 ;;; --- end of up-to-date-overview configuration ------------------
344 (defvar makefile-mode-map nil
345 "The keymap that is used in Makefile mode.")
347 (if makefile-mode-map
349 (setq makefile-mode-map
(make-sparse-keymap))
351 (define-key makefile-mode-map
"\C-c:" 'makefile-insert-target-ref
)
352 (if makefile-electric-keys
354 (define-key makefile-mode-map
"$" 'makefile-insert-macro-ref
)
355 (define-key makefile-mode-map
":" 'makefile-electric-colon
)
356 (define-key makefile-mode-map
"=" 'makefile-electric-equal
)
357 (define-key makefile-mode-map
"." 'makefile-electric-dot
)))
358 (define-key makefile-mode-map
"\C-c\C-f" 'makefile-pickup-filenames-as-targets
)
359 (define-key makefile-mode-map
"\C-c\C-b" 'makefile-switch-to-browser
)
360 (define-key makefile-mode-map
"\C-c\C-c" 'comment-region
)
361 (define-key makefile-mode-map
"\C-c\C-p" 'makefile-pickup-everything
)
362 (define-key makefile-mode-map
"\C-c\C-u" 'makefile-create-up-to-date-overview
)
363 (define-key makefile-mode-map
"\C-c\C-i" 'makefile-insert-gmake-function
)
364 (define-key makefile-mode-map
"\C-c\C-\\" 'makefile-backslash-region
)
365 (define-key makefile-mode-map
"\M-p" 'makefile-previous-dependency
)
366 (define-key makefile-mode-map
"\M-n" 'makefile-next-dependency
)
367 (define-key makefile-mode-map
"\e\t" 'makefile-complete
)
370 (define-key makefile-mode-map
[menu-bar makefile-mode
]
371 (cons "Makefile" (make-sparse-keymap "Makefile")))
373 (define-key makefile-mode-map
[menu-bar makefile-mode browse
]
374 '("Pop up Makefile Browser" . makefile-switch-to-browser
))
375 (define-key makefile-mode-map
[menu-bar makefile-mode complete
]
376 '("Complete Target or Macro" . makefile-complete
))
377 (define-key makefile-mode-map
[menu-bar makefile-mode pickup
]
378 '("Find Targets and Macros" . makefile-pickup-everything
))
380 (define-key makefile-mode-map
[menu-bar makefile-mode prev
]
381 '("Move to Previous Dependency" . makefile-previous-dependency
))
382 (define-key makefile-mode-map
[menu-bar makefile-mode next
]
383 '("Move to Next Dependency" . makefile-next-dependency
)))
385 (defvar makefile-browser-map nil
386 "The keymap that is used in the macro- and target browser.")
387 (if makefile-browser-map
389 (setq makefile-browser-map
(make-sparse-keymap))
390 (define-key makefile-browser-map
"n" 'makefile-browser-next-line
)
391 (define-key makefile-browser-map
"\C-n" 'makefile-browser-next-line
)
392 (define-key makefile-browser-map
"p" 'makefile-browser-previous-line
)
393 (define-key makefile-browser-map
"\C-p" 'makefile-browser-previous-line
)
394 (define-key makefile-browser-map
" " 'makefile-browser-toggle
)
395 (define-key makefile-browser-map
"i" 'makefile-browser-insert-selection
)
396 (define-key makefile-browser-map
"I" 'makefile-browser-insert-selection-and-quit
)
397 (define-key makefile-browser-map
"\C-c\C-m" 'makefile-browser-insert-continuation
)
398 (define-key makefile-browser-map
"q" 'makefile-browser-quit
)
399 ;; disable horizontal movement
400 (define-key makefile-browser-map
"\C-b" 'undefined
)
401 (define-key makefile-browser-map
"\C-f" 'undefined
))
404 (defvar makefile-mode-syntax-table nil
)
405 (if makefile-mode-syntax-table
407 (setq makefile-mode-syntax-table
(make-syntax-table))
408 (modify-syntax-entry ?\
( "() " makefile-mode-syntax-table
)
409 (modify-syntax-entry ?\
) ")( " makefile-mode-syntax-table
)
410 (modify-syntax-entry ?\
[ "(] " makefile-mode-syntax-table
)
411 (modify-syntax-entry ?\
] ")[ " makefile-mode-syntax-table
)
412 (modify-syntax-entry ?\
{ "(} " makefile-mode-syntax-table
)
413 (modify-syntax-entry ?\
} "){ " makefile-mode-syntax-table
)
414 (modify-syntax-entry ?
\' "\" " makefile-mode-syntax-table
)
415 (modify-syntax-entry ?\
` "\" " makefile-mode-syntax-table
)
416 (modify-syntax-entry ?
# "< " makefile-mode-syntax-table
)
417 (modify-syntax-entry ?
\n "> " makefile-mode-syntax-table
))
420 ;;; ------------------------------------------------------------
421 ;;; Internal variables.
422 ;;; You don't need to configure below this line.
423 ;;; ------------------------------------------------------------
425 (defvar makefile-target-table nil
426 "Table of all target names known for this buffer.")
428 (defvar makefile-macro-table nil
429 "Table of all macro names known for this buffer.")
431 (defvar makefile-browser-client
432 "A buffer in Makefile mode that is currently using the browser.")
434 (defvar makefile-browser-selection-vector nil
)
435 (defvar makefile-has-prereqs nil
)
436 (defvar makefile-need-target-pickup t
)
437 (defvar makefile-need-macro-pickup t
)
439 (defvar makefile-mode-hook
'())
441 ;; Each element looks like '("GNU MAKE FUNCTION" "ARG" "ARG" ... )
442 ;; Each "ARG" is used as a prompt for a required argument.
443 (defconst makefile-gnumake-functions-alist
446 ("subst" "From" "To" "In")
447 ("patsubst" "Pattern" "Replacement" "In")
449 ("findstring" "Find what" "In")
450 ("filter" "Pattern" "Text")
451 ("filter-out" "Pattern" "Text")
453 ;; Filename functions
458 ("addprefix" "Prefix" "Names")
459 ("addsuffix" "Suffix" "Names")
460 ("join" "List 1" "List 2")
461 ("word" "Index" "Text")
464 ("wildcard" "Pattern")
466 ("foreach" "Variable" "List" "Text")
467 ("origin" "Variable")
468 ("shell" "Command")))
471 ;;; ------------------------------------------------------------
472 ;;; The mode function itself.
473 ;;; ------------------------------------------------------------
476 (defun makefile-mode ()
477 "Major mode for editing Makefiles.
478 This function ends by invoking the function(s) `makefile-mode-hook'.
480 \\{makefile-mode-map}
482 In the browser, use the following keys:
484 \\{makefile-browser-map}
486 Makefile mode can be configured by modifying the following variables:
488 makefile-browser-buffer-name:
489 Name of the macro- and target browser buffer.
491 makefile-target-colon:
492 The string that gets appended to all target names
493 inserted by `makefile-insert-target'.
494 \":\" or \"::\" are quite common values.
496 makefile-macro-assign:
497 The string that gets appended to all macro names
498 inserted by `makefile-insert-macro'.
499 The normal value should be \" = \", since this is what
500 standard make expects. However, newer makes such as dmake
501 allow a larger variety of different macro assignments, so you
502 might prefer to use \" += \" or \" := \" .
504 makefile-tab-after-target-colon:
505 If you want a TAB (instead of a space) to be appended after the
506 target colon, then set this to a non-nil value.
508 makefile-browser-leftmost-column:
509 Number of blanks to the left of the browser selection mark.
511 makefile-browser-cursor-column:
512 Column in which the cursor is positioned when it moves
513 up or down in the browser.
515 makefile-browser-selected-mark:
516 String used to mark selected entries in the browser.
518 makefile-browser-unselected-mark:
519 String used to mark unselected entries in the browser.
521 makefile-browser-auto-advance-after-selection-p:
522 If this variable is set to a non-nil value the cursor
523 will automagically advance to the next line after an item
524 has been selected in the browser.
526 makefile-pickup-everything-picks-up-filenames-p:
527 If this variable is set to a non-nil value then
528 `makefile-pickup-everything' also picks up filenames as targets
529 (i.e. it calls `makefile-pickup-filenames-as-targets'), otherwise
530 filenames are omitted.
532 makefile-cleanup-continuations-p:
533 If this variable is set to a non-nil value then Makefile mode
534 will assure that no line in the file ends with a backslash
535 (the continuation character) followed by any whitespace.
536 This is done by silently removing the trailing whitespace, leaving
537 the backslash itself intact.
538 IMPORTANT: Please note that enabling this option causes Makefile mode
539 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \"it seems necessary\".
541 makefile-browser-hook:
542 A function or list of functions to be called just before the
543 browser is entered. This is executed in the makefile buffer.
545 makefile-special-targets-list:
546 List of special targets. You will be offered to complete
547 on one of those in the minibuffer whenever you enter a `.'.
548 at the beginning of a line in Makefile mode."
551 (kill-all-local-variables)
552 (make-local-variable 'local-write-file-hooks
)
553 (setq local-write-file-hooks
554 '(makefile-cleanup-continuations makefile-warn-suspicious-lines
))
555 (make-local-variable 'makefile-target-table
)
556 (make-local-variable 'makefile-macro-table
)
557 (make-local-variable 'makefile-has-prereqs
)
558 (make-local-variable 'makefile-need-target-pickup
)
559 (make-local-variable 'makefile-need-macro-pickup
)
562 (make-local-variable 'font-lock-defaults
)
563 (setq font-lock-defaults
'(makefile-font-lock-keywords))
566 (make-local-variable 'add-log-current-defun-function
)
567 (setq add-log-current-defun-function
'makefile-add-log-defun
)
570 (make-local-variable 'imenu-generic-expression
)
571 (setq imenu-generic-expression makefile-imenu-generic-expression
)
574 (make-local-variable 'dabbrev-abbrev-skip-leading-regexp
)
575 (setq dabbrev-abbrev-skip-leading-regexp
"\\$")
578 (make-local-variable 'fill-paragraph-function
)
579 (setq fill-paragraph-function
'makefile-fill-paragraph
)
582 (make-local-variable 'comment-start
)
583 (setq comment-start
"#")
584 (make-local-variable 'comment-end
)
585 (setq comment-end
"")
586 (make-local-variable 'comment-start-skip
)
587 (setq comment-start-skip
"#+[ \t]*")
589 ;; become the current major mode
590 (setq major-mode
'makefile-mode
)
591 (setq mode-name
"Makefile")
593 ;; Activate keymap and syntax table.
594 (use-local-map makefile-mode-map
)
595 (set-syntax-table makefile-mode-syntax-table
)
597 ;; Real TABs are important in makefiles
598 (setq indent-tabs-mode t
)
599 (run-hooks 'makefile-mode-hook
))
605 (defun makefile-next-dependency ()
606 "Move point to the beginning of the next dependency line."
608 (let ((here (point)))
610 (if (re-search-forward makefile-dependency-regex
(point-max) t
)
611 (progn (beginning-of-line) t
) ; indicate success
612 (goto-char here
) nil
)))
614 (defun makefile-previous-dependency ()
615 "Move point to the beginning of the previous dependency line."
617 (let ((here (point)))
619 (if (re-search-backward makefile-dependency-regex
(point-min) t
)
620 (progn (beginning-of-line) t
) ; indicate success
621 (goto-char here
) nil
)))
625 ;;; Electric keys. Blech.
627 (defun makefile-electric-dot (arg)
628 "Prompt for the name of a special target to insert.
629 Only does electric insertion at beginning of line.
630 Anywhere else just self-inserts."
633 (makefile-insert-special-target)
634 (self-insert-command arg
)))
636 (defun makefile-insert-special-target ()
637 "Prompt for and insert a special target name.
638 Uses `makefile-special-targets' list."
640 (makefile-pickup-targets)
641 (let ((special-target
642 (completing-read "Special target: "
643 makefile-special-targets-list nil nil nil
)))
644 (if (zerop (length special-target
))
646 (insert "." special-target
":")
647 (makefile-forward-after-target-colon))))
649 (defun makefile-electric-equal (arg)
650 "Prompt for name of a macro to insert.
651 Only does prompting if point is at beginning of line.
652 Anywhere else just self-inserts."
654 (makefile-pickup-macros)
656 (call-interactively 'makefile-insert-macro
)
657 (self-insert-command arg
)))
659 (defun makefile-insert-macro (macro-name)
660 "Prepare definition of a new macro."
661 (interactive "sMacro Name: ")
662 (makefile-pickup-macros)
663 (if (not (zerop (length macro-name
)))
666 (insert macro-name makefile-macro-assign
)
667 (setq makefile-need-macro-pickup t
)
668 (makefile-remember-macro macro-name
))))
670 (defun makefile-insert-macro-ref (macro-name)
671 "Complete on a list of known macros, then insert complete ref at point."
675 (makefile-pickup-macros)
676 (completing-read "Refer to macro: " makefile-macro-table nil nil nil
))))
677 (makefile-do-macro-insertion macro-name
))
679 (defun makefile-insert-target (target-name)
680 "Prepare definition of a new target (dependency line)."
681 (interactive "sTarget: ")
682 (if (not (zerop (length target-name
)))
685 (insert target-name makefile-target-colon
)
686 (makefile-forward-after-target-colon)
688 (setq makefile-need-target-pickup t
)
689 (makefile-remember-target target-name
))))
691 (defun makefile-insert-target-ref (target-name)
692 "Complete on a list of known targets, then insert TARGET-NAME at point."
696 (makefile-pickup-targets)
697 (completing-read "Refer to target: " makefile-target-table nil nil nil
))))
698 (if (not (zerop (length target-name
)))
699 (insert target-name
" ")))
701 (defun makefile-electric-colon (arg)
702 "Prompt for name of new target.
703 Prompting only happens at beginning of line.
704 Anywhere else just self-inserts."
707 (call-interactively 'makefile-insert-target
)
708 (self-insert-command arg
)))
712 ;;; ------------------------------------------------------------
713 ;;; Extracting targets and macros from an existing makefile
714 ;;; ------------------------------------------------------------
716 (defun makefile-pickup-targets ()
717 "Notice names of all target definitions in Makefile."
719 (if (not makefile-need-target-pickup
)
721 (setq makefile-need-target-pickup nil
)
722 (setq makefile-target-table nil
)
723 (setq makefile-has-prereqs nil
)
725 (goto-char (point-min))
726 (while (re-search-forward makefile-dependency-regex
(point-max) t
)
727 (makefile-add-this-line-targets)))
728 (message "Read targets OK.")))
730 (defun makefile-add-this-line-targets ()
733 (let ((done-with-line nil
)
734 (line-number (1+ (count-lines (point-min) (point)))))
735 (while (not done-with-line
)
736 (skip-chars-forward " \t")
737 (if (not (setq done-with-line
(or (eolp)
738 (char-equal (char-after (point)) ?
:))))
740 (let* ((start-of-target-name (point))
743 (skip-chars-forward "^ \t:#")
744 (buffer-substring start-of-target-name
(point))))
746 (not (looking-at ":[ \t]*$"))))
747 (if (makefile-remember-target target-name has-prereqs
)
748 (message "Picked up target \"%s\" from line %d"
749 target-name line-number
)))))))))
751 (defun makefile-pickup-macros ()
752 "Notice names of all macro definitions in Makefile."
754 (if (not makefile-need-macro-pickup
)
756 (setq makefile-need-macro-pickup nil
)
757 (setq makefile-macro-table nil
)
759 (goto-char (point-min))
760 (while (re-search-forward makefile-macroassign-regex
(point-max) t
)
761 (makefile-add-this-line-macro)
763 (message "Read macros OK.")))
765 (defun makefile-add-this-line-macro ()
768 (skip-chars-forward " \t")
770 (let* ((start-of-macro-name (point))
771 (line-number (1+ (count-lines (point-min) (point))))
773 (skip-chars-forward "^ \t:#=*")
774 (buffer-substring start-of-macro-name
(point)))))
775 (if (makefile-remember-macro macro-name
)
776 (message "Picked up macro \"%s\" from line %d"
777 macro-name line-number
))))))
779 (defun makefile-pickup-everything (arg)
780 "Notice names of all macros and targets in Makefile.
781 Prefix arg means force pickups to be redone."
785 (setq makefile-need-target-pickup t
)
786 (setq makefile-need-macro-pickup t
)))
787 (makefile-pickup-macros)
788 (makefile-pickup-targets)
789 (if makefile-pickup-everything-picks-up-filenames-p
790 (makefile-pickup-filenames-as-targets)))
792 (defun makefile-pickup-filenames-as-targets ()
793 "Scan the current directory for filenames to use as targets.
794 Checks each filename against `makefile-ignored-files-in-pickup-regex'
795 and adds all qualifying names to the list of known targets."
797 (let* ((dir (file-name-directory (buffer-file-name)))
798 (raw-filename-list (if dir
799 (file-name-all-completions "" dir
)
800 (file-name-all-completions "" ""))))
801 (mapcar '(lambda (name)
802 (if (and (not (file-directory-p name
))
803 (not (string-match makefile-ignored-files-in-pickup-regex
805 (if (makefile-remember-target name
)
806 (message "Picked up file \"%s\" as target" name
))))
813 (defun makefile-complete ()
814 "Perform completion on Makefile construct preceding point.
815 Can complete variable and target names.
816 The context determines which are considered."
818 (let* ((beg (save-excursion
819 (skip-chars-backward "^$(){}:#= \t\n")
821 (try (buffer-substring beg
(point)))
827 (let ((pc (preceding-char)))
829 ;; Beginning of line means anything.
833 ;; Preceding "$" means macros only.
837 ;; Preceding "$(" or "${" means macros only.
844 (= (preceding-char) ?$
))))
845 (setq do-macros t
)))))
848 (let* ((table (append (if do-macros
850 makefile-target-table
)
851 makefile-macro-table
))
852 (completion (try-completion try table
)))
854 ;; Exact match, so insert closing paren or colon.
856 (insert (if do-macros
868 (message "Can't find completion for \"%s\"" try
)
871 ;; Partial completion.
872 ((not (string= try completion
))
873 ;; FIXME it would be nice to supply the closing paren if an
874 ;; exact, unambiguous match were found. That is not possible
875 ;; right now. Ditto closing ":" for targets.
876 (delete-region beg
(point))
878 ;; DO-MACROS means doing macros only. If not that, then check
879 ;; to see if this completion is a macro. Special insertion
880 ;; must be done for macros.
882 (assoc completion makefile-macro-table
))
883 (let ((makefile-use-curly-braces-for-macros-p
885 makefile-use-curly-braces-for-macros-p
)))
886 (delete-backward-char 2)
887 (makefile-do-macro-insertion completion
)
888 (delete-backward-char 1))
890 ;; Just insert targets.
891 (insert completion
)))
893 ;; Can't complete any more, so make completion list. FIXME
894 ;; this doesn't do the right thing when the completion is
895 ;; actually inserted. I don't think there is an easy way to do
898 (message "Making completion list...")
899 (let ((list (all-completions try table
)))
900 (with-output-to-temp-buffer "*Completions*"
901 (display-completion-list list
)))
902 (message "Making completion list...done"))))))
906 ;; Backslashification. Stolen from cc-mode.el.
908 (defun makefile-backslash-region (from to delete-flag
)
909 "Insert, align, or delete end-of-line backslashes on the lines in the region.
910 With no argument, inserts backslashes and aligns existing backslashes.
911 With an argument, deletes the backslashes.
913 This function does not modify the last line of the region if the region ends
914 right at the start of the following line; it does not modify blank lines
915 at the start of the region. So you can put the region around an entire macro
916 definition and conveniently use this command."
920 (let ((column makefile-backslash-column
)
921 (endmark (make-marker)))
922 (move-marker endmark to
)
923 ;; Compute the smallest column number past the ends of all the lines.
924 (if makefile-backslash-align
926 (if (not delete-flag
)
927 (while (< (point) to
)
929 (if (= (preceding-char) ?
\\)
930 (progn (forward-char -
1)
931 (skip-chars-backward " \t")))
932 (setq column
(max column
(1+ (current-column))))
934 ;; Adjust upward to a tab column, if that doesn't push
936 (if (> (% column tab-width
) 0)
937 (let ((adjusted (* (/ (+ column tab-width -
1) tab-width
)
939 (if (< adjusted
(window-width))
940 (setq column adjusted
))))))
941 ;; Don't modify blank lines at start of region.
943 (while (and (< (point) endmark
) (eolp))
945 ;; Add or remove backslashes on all the lines.
946 (while (and (< (point) endmark
)
947 ;; Don't backslashify the last line
948 ;; if the region ends right at the start of the next line.
951 (< (point) endmark
)))
952 (if (not delete-flag
)
953 (makefile-append-backslash column
)
954 (makefile-delete-backslash))
956 (move-marker endmark nil
))))
958 (defun makefile-append-backslash (column)
960 ;; Note that "\\\\" is needed to get one backslash.
961 (if (= (preceding-char) ?
\\)
962 (progn (forward-char -
1)
963 (delete-horizontal-space)
964 (indent-to column
(if makefile-backslash-align nil
1)))
965 (indent-to column
(if makefile-backslash-align nil
1))
968 (defun makefile-delete-backslash ()
973 (if (looking-at "\\\\")
974 (delete-region (1+ (point))
975 (progn (skip-chars-backward " \t") (point)))))))
981 (defun makefile-fill-paragraph (arg)
982 ;; Fill comments, backslashed lines, and variable definitions
988 ;; Found a comment. Set the fill prefix and then fill.
989 (let ((fill-prefix (buffer-substring-no-properties (match-beginning 0)
991 (fill-paragraph-function nil
))
995 ;; Must look for backslashed-region before looking for variable
1000 (= (preceding-char) ?
\\)
1003 (= (preceding-char) ?
\\))))
1004 ;; A backslash region. Find beginning and end, remove
1005 ;; backslashes, fill, and then reapply backslahes.
1010 (while (= (preceding-char) ?
\\)
1016 (while (= (preceding-char) ?
\\)
1020 (narrow-to-region beginning end
)
1021 (makefile-backslash-region (point-min) (point-max) t
)
1022 (let ((fill-paragraph-function nil
))
1023 (fill-paragraph nil
))
1024 (makefile-backslash-region (point-min) (point-max) nil
)
1025 (goto-char (point-max))
1026 (if (< (skip-chars-backward "\n") 0)
1027 (delete-region (point) (point-max))))))
1029 ((looking-at makefile-macroassign-regex
)
1030 ;; Have a macro assign. Fill just this line, and then backslash
1031 ;; resulting region.
1033 (narrow-to-region (point) (save-excursion
1037 (let ((fill-paragraph-function nil
))
1038 (fill-paragraph nil
))
1039 (makefile-backslash-region (point-min) (point-max) nil
)))))
1041 ;; Always return non-nil so we don't fill anything else.
1046 ;;; ------------------------------------------------------------
1048 ;;; ------------------------------------------------------------
1050 (defun makefile-browser-format-target-line (target selected
)
1052 (concat (make-string makefile-browser-leftmost-column ?\
)
1054 makefile-browser-selected-mark
1055 makefile-browser-unselected-mark
)
1057 target makefile-target-colon
))
1059 (defun makefile-browser-format-macro-line (macro selected
)
1061 (concat (make-string makefile-browser-leftmost-column ?\
)
1063 makefile-browser-selected-mark
1064 makefile-browser-unselected-mark
)
1065 (makefile-format-macro-ref macro
))))
1067 (defun makefile-browser-fill (targets macros
)
1068 (let ((inhibit-read-only t
))
1069 (goto-char (point-min))
1073 (lambda (item) (insert (makefile-browser-format-target-line (car item
) nil
) "\n")))
1078 (lambda (item) (insert (makefile-browser-format-macro-line (car item
) nil
) "\n")))
1081 (sort-lines nil
(point-min) (point-max))
1082 (goto-char (1- (point-max)))
1083 (delete-char 1) ; remove unnecessary newline at eob
1084 (goto-char (point-min))
1085 (forward-char makefile-browser-cursor-column
)))
1088 ;;; Moving up and down in the browser
1091 (defun makefile-browser-next-line ()
1092 "Move the browser selection cursor to the next line."
1094 (if (not (makefile-last-line-p))
1097 (forward-char makefile-browser-cursor-column
))))
1099 (defun makefile-browser-previous-line ()
1100 "Move the browser selection cursor to the previous line."
1102 (if (not (makefile-first-line-p))
1105 (forward-char makefile-browser-cursor-column
))))
1108 ;;; Quitting the browser (returns to client buffer)
1111 (defun makefile-browser-quit ()
1112 "Leave the browser and return to the makefile buffer."
1114 (let ((my-client makefile-browser-client
))
1115 (setq makefile-browser-client nil
) ; we quitted, so NO client!
1116 (set-buffer-modified-p nil
)
1118 (pop-to-buffer my-client
)))
1121 ;;; Toggle state of a browser item
1124 (defun makefile-browser-toggle ()
1125 "Toggle the selection state of the browser item at the cursor position."
1127 (let ((this-line (count-lines (point-min) (point))))
1128 (setq this-line
(max 1 this-line
))
1129 (makefile-browser-toggle-state-for-line this-line
)
1130 (goto-line this-line
)
1131 (let ((inhibit-read-only t
))
1133 (if (makefile-browser-on-macro-line-p)
1134 (let ((macro-name (makefile-browser-this-line-macro-name)))
1135 (delete-region (point) (progn (end-of-line) (point)))
1137 (makefile-browser-format-macro-line
1139 (makefile-browser-get-state-for-line this-line
))))
1140 (let ((target-name (makefile-browser-this-line-target-name)))
1141 (delete-region (point) (progn (end-of-line) (point)))
1143 (makefile-browser-format-target-line
1145 (makefile-browser-get-state-for-line this-line
))))))
1147 (forward-char makefile-browser-cursor-column
)
1148 (if makefile-browser-auto-advance-after-selection-p
1149 (makefile-browser-next-line))))
1152 ;;; Making insertions into the client buffer
1155 (defun makefile-browser-insert-continuation ()
1156 "Insert a makefile continuation.
1157 In the makefile buffer, go to (end-of-line), insert a \'\\\'
1158 character, insert a new blank line, go to that line and indent by one TAB.
1159 This is most useful in the process of creating continued lines when copying
1160 large dependencies from the browser to the client buffer.
1161 \(point) advances accordingly in the client buffer."
1164 (set-buffer makefile-browser-client
)
1168 (defun makefile-browser-insert-selection ()
1169 "Insert all selected targets and/or macros in the makefile buffer.
1170 Insertion takes place at point."
1174 (let ((current-line 1))
1176 (if (makefile-browser-get-state-for-line current-line
)
1177 (makefile-browser-send-this-line-item))
1179 (setq current-line
(1+ current-line
))))))
1181 (defun makefile-browser-insert-selection-and-quit ()
1183 (makefile-browser-insert-selection)
1184 (makefile-browser-quit))
1186 (defun makefile-browser-send-this-line-item ()
1187 (if (makefile-browser-on-macro-line-p)
1189 (let ((macro-name (makefile-browser-this-line-macro-name)))
1190 (set-buffer makefile-browser-client
)
1191 (insert (makefile-format-macro-ref macro-name
) " ")))
1193 (let ((target-name (makefile-browser-this-line-target-name)))
1194 (set-buffer makefile-browser-client
)
1195 (insert target-name
" ")))))
1197 (defun makefile-browser-start-interaction ()
1198 (use-local-map makefile-browser-map
)
1199 (setq buffer-read-only t
))
1201 (defun makefile-browse (targets macros
)
1203 (if (zerop (+ (length targets
) (length macros
)))
1206 (message "No macros or targets to browse! Consider running 'makefile-pickup-everything\'"))
1207 (let ((browser-buffer (get-buffer-create makefile-browser-buffer-name
)))
1208 (pop-to-buffer browser-buffer
)
1209 (make-variable-buffer-local 'makefile-browser-selection-vector
)
1210 (makefile-browser-fill targets macros
)
1211 (shrink-window-if-larger-than-buffer)
1212 (setq makefile-browser-selection-vector
1213 (make-vector (+ (length targets
) (length macros
)) nil
))
1214 (makefile-browser-start-interaction))))
1216 (defun makefile-switch-to-browser ()
1218 (run-hooks 'makefile-browser-hook
)
1219 (setq makefile-browser-client
(current-buffer))
1220 (makefile-pickup-targets)
1221 (makefile-pickup-macros)
1222 (makefile-browse makefile-target-table makefile-macro-table
))
1226 ;;; ------------------------------------------------------------
1227 ;;; Up-to-date overview buffer
1228 ;;; ------------------------------------------------------------
1230 (defun makefile-create-up-to-date-overview ()
1231 "Create a buffer containing an overview of the state of all known targets.
1232 Known targets are targets that are explicitly defined in that makefile;
1233 in other words, all targets that appear on the left hand side of a
1234 dependency in the makefile."
1236 (if (y-or-n-p "Are you sure that the makefile being edited is consistent? ")
1238 ;; The rest of this function operates on a temporary makefile, created by
1239 ;; writing the current contents of the makefile buffer.
1241 (let ((saved-target-table makefile-target-table
)
1242 (this-buffer (current-buffer))
1243 (makefile-up-to-date-buffer
1244 (get-buffer-create makefile-up-to-date-buffer-name
))
1245 (filename (makefile-save-temporary))
1247 ;; Forget the target table because it may contain picked-up filenames
1248 ;; that are not really targets in the current makefile.
1249 ;; We don't want to query these, so get a new target-table with just the
1250 ;; targets that can be found in the makefile buffer.
1251 ;; The 'old' target table will be restored later.
1253 (real-targets (progn
1254 (makefile-pickup-targets)
1255 makefile-target-table
))
1256 (prereqs makefile-has-prereqs
)
1259 (set-buffer makefile-up-to-date-buffer
)
1260 (setq buffer-read-only nil
)
1262 (makefile-query-targets filename real-targets prereqs
)
1263 (if (zerop (buffer-size)) ; if it did not get us anything
1265 (kill-buffer (current-buffer))
1266 (message "No overview created!")))
1267 (set-buffer this-buffer
)
1268 (setq makefile-target-table saved-target-table
)
1269 (if (get-buffer makefile-up-to-date-buffer-name
)
1271 (pop-to-buffer (get-buffer makefile-up-to-date-buffer-name
))
1272 (shrink-window-if-larger-than-buffer)
1273 (sort-lines nil
(point-min) (point-max))
1274 (setq buffer-read-only t
))))))
1276 (defun makefile-save-temporary ()
1277 "Create a temporary file from the current makefile buffer."
1278 (let ((filename (makefile-generate-temporary-filename)))
1279 (write-region (point-min) (point-max) filename nil
0)
1280 filename
)) ; return the filename
1282 (defun makefile-generate-temporary-filename ()
1283 "Create a filename suitable for use in `makefile-save-temporary'.
1284 Be careful to allow brain-dead file systems (DOS, SYSV ...) to cope
1285 with the generated name!"
1286 (let ((my-name (user-login-name))
1287 (my-uid (int-to-string (user-uid))))
1289 (if (> (length my-name
) 3)
1290 (substring my-name
0 3)
1293 (if (> (length my-uid
) 3)
1294 (substring my-uid
0 3)
1297 (defun makefile-query-targets (filename target-table prereq-list
)
1298 "Fill the up-to-date overview buffer.
1299 Checks each target in TARGET-TABLE using `makefile-query-one-target-method'
1300 and generates the overview, one line per target name."
1303 (function (lambda (item)
1304 (let* ((target-name (car item
))
1305 (no-prereqs (not (member target-name prereq-list
)))
1306 (needs-rebuild (or no-prereqs
1308 makefile-query-one-target-method
1313 (cond (no-prereqs " .. has no prerequisites")
1314 (needs-rebuild " .. NEEDS REBUILD")
1315 (t " .. is up to date"))))
1318 (goto-char (point-min))
1319 (delete-file filename
)) ; remove the tmpfile
1321 (defun makefile-query-by-make-minus-q (target &optional filename
)
1323 (call-process makefile-brave-make nil nil nil
1324 "-f" filename
"-q" target
))))
1328 ;;; ------------------------------------------------------------
1329 ;;; Continuation cleanup
1330 ;;; ------------------------------------------------------------
1332 (defun makefile-cleanup-continuations ()
1333 (if (eq major-mode
'makefile-mode
)
1334 (if (and makefile-cleanup-continuations-p
1335 (not buffer-read-only
))
1337 (goto-char (point-min))
1338 (while (re-search-forward "\\\\[ \t]+$" (point-max) t
)
1339 (replace-match "\\" t t
))))))
1342 ;;; ------------------------------------------------------------
1343 ;;; Warn of suspicious lines
1344 ;;; ------------------------------------------------------------
1346 (defun makefile-warn-suspicious-lines ()
1347 (let ((dont-save nil
))
1348 (if (eq major-mode
'makefile-mode
)
1351 (goto-char (point-min))
1353 "\\(^[\t]+$\\)\\|\\(^[ ]+[\t]\\)" (point-max) t
))))
1355 (let ((line-nr (count-lines (point-min) suspicious
)))
1358 (format "Suspicious line %d. Save anyway "
1364 ;;; ------------------------------------------------------------
1365 ;;; GNU make function support
1366 ;;; ------------------------------------------------------------
1368 (defun makefile-insert-gmake-function ()
1369 "Insert a GNU make function call.
1370 Asks for the name of the function to use (with completion).
1371 Then prompts for all required parameters."
1373 (let* ((gm-function-name (completing-read
1375 makefile-gnumake-functions-alist
1377 (gm-function-prompts
1378 (cdr (assoc gm-function-name makefile-gnumake-functions-alist
))))
1379 (if (not (zerop (length gm-function-name
)))
1380 (insert (makefile-format-macro-ref
1381 (concat gm-function-name
" "
1382 (makefile-prompt-for-gmake-funargs
1383 gm-function-name gm-function-prompts
)))
1386 (defun makefile-prompt-for-gmake-funargs (function-name prompt-list
)
1388 (function (lambda (one-prompt)
1389 (read-string (format "[%s] %s: " function-name one-prompt
)
1396 ;;; ------------------------------------------------------------
1397 ;;; Utility functions
1398 ;;; ------------------------------------------------------------
1400 (defun makefile-do-macro-insertion (macro-name)
1401 "Insert a macro reference."
1402 (if (not (zerop (length macro-name
)))
1403 (if (assoc macro-name makefile-runtime-macros-list
)
1404 (insert "$" macro-name
)
1405 (insert (makefile-format-macro-ref macro-name
)))))
1407 (defun makefile-remember-target (target-name &optional has-prereqs
)
1408 "Remember a given target if it is not already remembered for this buffer."
1409 (if (not (zerop (length target-name
)))
1411 (if (not (assoc target-name makefile-target-table
))
1412 (setq makefile-target-table
1413 (cons (list target-name
) makefile-target-table
)))
1415 (setq makefile-has-prereqs
1416 (cons target-name makefile-has-prereqs
))))))
1418 (defun makefile-remember-macro (macro-name)
1419 "Remember a given macro if it is not already remembered for this buffer."
1420 (if (not (zerop (length macro-name
)))
1421 (if (not (assoc macro-name makefile-macro-table
))
1422 (setq makefile-macro-table
1423 (cons (list macro-name
) makefile-macro-table
)))))
1425 (defun makefile-forward-after-target-colon ()
1426 "Move point forward after inserting the terminating colon of a target.
1427 This acts according to the value of `makefile-tab-after-target-colon'."
1428 (if makefile-tab-after-target-colon
1432 (defun makefile-browser-on-macro-line-p ()
1433 "Determine if point is on a macro line in the browser."
1436 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t
)))
1438 (defun makefile-browser-this-line-target-name ()
1439 "Extract the target name from a line in the browser."
1442 (skip-chars-backward "^ \t")
1443 (buffer-substring (point) (1- (makefile-end-of-line-point)))))
1445 (defun makefile-browser-this-line-macro-name ()
1446 "Extract the macro name from a line in the browser."
1449 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t
)
1450 (let ((macro-start (point)))
1451 (skip-chars-forward "^})")
1452 (buffer-substring macro-start
(point)))))
1454 (defun makefile-format-macro-ref (macro-name)
1455 "Format a macro reference.
1456 Uses `makefile-use-curly-braces-for-macros-p'."
1457 (if (or (char-equal ?\
( (string-to-char macro-name
))
1458 (char-equal ?\
{ (string-to-char macro-name
)))
1459 (format "$%s" macro-name
)
1460 (if makefile-use-curly-braces-for-macros-p
1461 (format "${%s}" macro-name
)
1462 (format "$(%s)" macro-name
))))
1464 (defun makefile-browser-get-state-for-line (n)
1465 (aref makefile-browser-selection-vector
(1- n
)))
1467 (defun makefile-browser-set-state-for-line (n to-state
)
1468 (aset makefile-browser-selection-vector
(1- n
) to-state
))
1470 (defun makefile-browser-toggle-state-for-line (n)
1471 (makefile-browser-set-state-for-line n
(not (makefile-browser-get-state-for-line n
))))
1473 (defun makefile-beginning-of-line-point ()
1478 (defun makefile-end-of-line-point ()
1483 (defun makefile-last-line-p ()
1484 (= (makefile-end-of-line-point) (point-max)))
1486 (defun makefile-first-line-p ()
1487 (= (makefile-beginning-of-line-point) (point-min)))
1491 ;;; Support for other packages, like add-log.
1493 (defun makefile-add-log-defun ()
1494 "Return name of target or variable assignment that point is in.
1495 If it isn't in one, return nil."
1499 ;; Scan back line by line, noticing when we come to a
1500 ;; variable or rule definition, and giving up when we see
1501 ;; a line that is not part of either of those.
1504 ((looking-at makefile-macroassign-regex
)
1505 (setq found
(buffer-substring-no-properties (match-beginning 1)
1507 ((looking-at makefile-dependency-regex
)
1508 (setq found
(buffer-substring-no-properties (match-beginning 1)
1510 ;; Don't keep looking across a blank line or comment. Give up.
1511 ((looking-at "$\\|#")
1514 (setq found
'bobp
)))
1517 (if (stringp found
) found
))))
1519 ;;; make-mode.el ends here