1 ;;; make-mode.el --- makefile editing commands for Emacs
3 ;; Copyright (C) 1992, 1994, 1999, 2000 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.
99 ;;; ------------------------------------------------------------
100 ;;; Configurable stuff
101 ;;; ------------------------------------------------------------
103 (defgroup makefile nil
104 "Makefile editing commands for Emacs."
108 (defface makefile-space-face
109 '((((class color
)) (:background
"hotpink"))
110 (t (:reverse-video t
)))
111 "Face to use for highlighting leading spaces in Font-Lock mode."
115 (defcustom makefile-browser-buffer-name
"*Macros and Targets*"
116 "*Name of the macro- and target browser buffer."
120 (defcustom makefile-target-colon
":"
121 "*String to append to all target names inserted by `makefile-insert-target'.
122 \":\" or \"::\" are common values."
126 (defcustom makefile-macro-assign
" = "
127 "*String to append to all macro names inserted by `makefile-insert-macro'.
128 The normal value should be \" = \", since this is what
129 standard make expects. However, newer makes such as dmake
130 allow a larger variety of different macro assignments, so you
131 might prefer to use \" += \" or \" := \" ."
135 (defcustom makefile-electric-keys nil
136 "*If non-nil, Makefile mode should install electric keybindings.
141 (defcustom makefile-use-curly-braces-for-macros-p nil
142 "*Controls the style of generated macro references.
143 Non-nil means macro references should use curly braces, like `${this}'.
144 nil means use parentheses, like `$(this)'."
148 (defcustom makefile-tab-after-target-colon t
149 "*If non-nil, insert a TAB after a target colon.
150 Otherwise, a space is inserted.
155 (defcustom makefile-browser-leftmost-column
10
156 "*Number of blanks to the left of the browser selection mark."
160 (defcustom makefile-browser-cursor-column
10
161 "*Column the cursor goes to when it moves up or down in the Makefile browser."
165 (defcustom makefile-backslash-column
48
166 "*Column in which `makefile-backslash-region' inserts backslashes."
170 (defcustom makefile-backslash-align t
171 "*If non-nil, `makefile-backslash-region' will align backslashes."
175 (defcustom makefile-browser-selected-mark
"+ "
176 "*String used to mark selected entries in the Makefile browser."
180 (defcustom makefile-browser-unselected-mark
" "
181 "*String used to mark unselected entries in the Makefile browser."
185 (defcustom makefile-browser-auto-advance-after-selection-p t
186 "*If non-nil, cursor will move after item is selected in Makefile browser."
190 (defcustom makefile-pickup-everything-picks-up-filenames-p nil
191 "*If non-nil, `makefile-pickup-everything' picks up filenames as targets.
192 This means it calls `makefile-pickup-filenames-as-targets'.
193 Otherwise filenames are omitted."
197 (defcustom makefile-cleanup-continuations-p t
198 "*If non-nil, automatically clean up continuation lines when saving.
199 A line is cleaned up by removing all whitespace following a trailing
200 backslash. This is done silently.
201 IMPORTANT: Please note that enabling this option causes Makefile mode
202 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \"it seems necessary\"."
206 (defcustom makefile-mode-hook nil
207 "*Normal hook run by `makefile-mode'."
211 (defvar makefile-browser-hook
'())
214 ;; Special targets for DMake, Sun's make ...
216 (defcustom makefile-special-targets-list
217 '(("DEFAULT") ("DONE") ("ERROR") ("EXPORT")
218 ("FAILED") ("GROUPEPILOG") ("GROUPPROLOG") ("IGNORE")
219 ("IMPORT") ("INCLUDE") ("INCLUDEDIRS") ("INIT")
220 ("KEEP_STATE") ("MAKEFILES") ("MAKE_VERSION") ("NO_PARALLEL")
221 ("PARALLEL") ("PHONY") ("PRECIOUS") ("REMOVE")
222 ("SCCS_GET") ("SILENT") ("SOURCE") ("SUFFIXES")
223 ("WAIT") ("c.o") ("C.o") ("m.o")
224 ("el.elc") ("y.c") ("s.o"))
225 "*List of special targets.
226 You will be offered to complete on one of those in the minibuffer whenever
227 you enter a \".\" at the beginning of a line in `makefile-mode'."
228 :type
'(repeat (list string
))
231 (defcustom makefile-runtime-macros-list
232 '(("@") ("&") (">") ("<") ("*") ("^") ("+") ("?") ("%") ("$"))
233 "*List of macros that are resolved by make at runtime.
234 If you insert a macro reference using `makefile-insert-macro-ref', the name
235 of the macro is checked against this list. If it can be found its name will
236 not be enclosed in { } or ( )."
237 :type
'(repeat (list string
))
240 ;; Note that the first big subexpression is used by font lock. Note
241 ;; that if you change this regexp you might have to fix the imenu
242 ;; index in makefile-imenu-generic-expression.
243 (defconst makefile-dependency-regex
244 "^ *\\([^ \n\t#:=]+\\([ \t]+\\([^ \t\n#:=]+\\|\\$[({][^ \t\n#})]+[})]\\)\\)*\\)[ \t]*:\\([ \t]*$\\|\\([^=\n].*$\\)\\)"
245 "Regex used to find dependency lines in a makefile.")
247 ;; Note that the first subexpression is used by font lock. Note
248 ;; that if you change this regexp you might have to fix the imenu
249 ;; index in makefile-imenu-generic-expression.
250 (defconst makefile-macroassign-regex
251 "^ *\\([^ \n\t][^:#= \t\n]*\\)[ \t]*[*:+]?[:?]?="
252 "Regex used to find macro assignment lines in a makefile.")
254 (defconst makefile-ignored-files-in-pickup-regex
255 "\\(^\\..*\\)\\|\\(.*~$\\)\\|\\(.*,v$\\)\\|\\(\\.[chy]\\)"
256 "Regex for filenames that will NOT be included in the target list.")
258 (if (fboundp 'facemenu-unlisted-faces
)
259 (add-to-list 'facemenu-unlisted-faces
'makefile-space-face
))
260 (defvar makefile-space-face
'makefile-space-face
261 "Face to use for highlighting leading spaces in Font-Lock mode.")
263 (defconst makefile-font-lock-keywords
266 ;; Do macro assignments. These get the "variable-name" face rather
268 (list makefile-macroassign-regex
1 'font-lock-variable-name-face
)
270 ;; Do dependencies. These get the function name face.
271 (list makefile-dependency-regex
1 'font-lock-function-name-face
)
273 ;; Variable references even in targets/strings/comments:
274 '("\\$[({]\\([-a-zA-Z0-9_.]+\\)[}):]" 1 font-lock-constant-face prepend
)
276 ;; Automatic variable references.
277 '("\\$\\([@%<?^+*]\\)" 1 font-lock-reference-face prepend
)
279 ;; Fontify conditionals and includes.
280 ;; Note that plain `if' is an automake conditional, and not a bug.
282 (concat "^\\(?: [ \t]*\\)?"
283 (regexp-opt '("-include" "-sinclude" "include" "sinclude" "ifeq"
284 "if" "ifneq" "ifdef" "ifndef" "endif" "else") t
)
285 "\\>[ \t]*\\([^: \t\n#]*\\)")
286 '(1 font-lock-keyword-face
) '(2 font-lock-variable-name-face
))
288 ;; Highlight lines that contain just whitespace.
289 ;; They can cause trouble, especially if they start with a tab.
290 '("^[ \t]+$" . makefile-space-face
)
292 ;; Highlight shell comments that Make treats as commands,
293 ;; since these can fool people.
294 '("^\t+#" 0 makefile-space-face t
)
296 ;; Highlight spaces that precede tabs.
297 ;; They can make a tab fail to be effective.
298 '("^\\( +\\)\t" 1 makefile-space-face
)))
300 (defvar makefile-imenu-generic-expression
302 (list "Dependencies" makefile-dependency-regex
1)
303 (list "Macro Assignment" makefile-macroassign-regex
1))
304 "Imenu generic expression for Makefile mode. See `imenu-generic-expression'.")
306 ;;; ------------------------------------------------------------
307 ;;; The following configurable variables are used in the
308 ;;; up-to-date overview .
309 ;;; The standard configuration assumes that your `make' program
310 ;;; can be run in question/query mode using the `-q' option, this
311 ;;; means that the command
315 ;;; should return an exit status of zero if the target `foo' is
316 ;;; up to date and a nonzero exit status otherwise.
317 ;;; Many makes can do this although the docs/manpages do not mention
318 ;;; it. Try it with your favourite one. GNU make, System V make, and
319 ;;; Dennis Vadura's DMake have no problems.
320 ;;; Set the variable `makefile-brave-make' to the name of the
321 ;;; make utility that does this on your system.
322 ;;; To understand what this is all about see the function definition
323 ;;; of `makefile-query-by-make-minus-q' .
324 ;;; ------------------------------------------------------------
326 (defcustom makefile-brave-make
"make"
327 "*How to invoke make, for `makefile-query-targets'.
328 This should identify a `make' command that can handle the `-q' option."
332 (defcustom makefile-query-one-target-method
'makefile-query-by-make-minus-q
333 "*Function to call to determine whether a make target is up to date.
334 The function must satisfy this calling convention:
336 * As its first argument, it must accept the name of the target to
337 be checked, as a string.
339 * As its second argument, it may accept the name of a makefile
340 as a string. Depending on what you're going to do you may
343 * It must return the integer value 0 (zero) if the given target
344 should be considered up-to-date in the context of the given
345 makefile, any nonzero integer value otherwise."
349 (defcustom makefile-up-to-date-buffer-name
"*Makefile Up-to-date overview*"
350 "*Name of the Up-to-date overview buffer."
354 ;;; --- end of up-to-date-overview configuration ------------------
356 (defvar makefile-mode-abbrev-table nil
357 "Abbrev table in use in Makefile buffers.")
358 (if makefile-mode-abbrev-table
360 (define-abbrev-table 'makefile-mode-abbrev-table
()))
362 (defvar makefile-mode-map nil
363 "The keymap that is used in Makefile mode.")
365 (if makefile-mode-map
367 (setq makefile-mode-map
(make-sparse-keymap))
369 (define-key makefile-mode-map
"\C-c:" 'makefile-insert-target-ref
)
370 (if makefile-electric-keys
372 (define-key makefile-mode-map
"$" 'makefile-insert-macro-ref
)
373 (define-key makefile-mode-map
":" 'makefile-electric-colon
)
374 (define-key makefile-mode-map
"=" 'makefile-electric-equal
)
375 (define-key makefile-mode-map
"." 'makefile-electric-dot
)))
376 (define-key makefile-mode-map
"\C-c\C-f" 'makefile-pickup-filenames-as-targets
)
377 (define-key makefile-mode-map
"\C-c\C-b" 'makefile-switch-to-browser
)
378 (define-key makefile-mode-map
"\C-c\C-c" 'comment-region
)
379 (define-key makefile-mode-map
"\C-c\C-p" 'makefile-pickup-everything
)
380 (define-key makefile-mode-map
"\C-c\C-u" 'makefile-create-up-to-date-overview
)
381 (define-key makefile-mode-map
"\C-c\C-i" 'makefile-insert-gmake-function
)
382 (define-key makefile-mode-map
"\C-c\C-\\" 'makefile-backslash-region
)
383 (define-key makefile-mode-map
"\M-p" 'makefile-previous-dependency
)
384 (define-key makefile-mode-map
"\M-n" 'makefile-next-dependency
)
385 (define-key makefile-mode-map
"\e\t" 'makefile-complete
)
388 (define-key makefile-mode-map
[menu-bar makefile-mode
]
389 (cons "Makefile" (make-sparse-keymap "Makefile")))
391 (define-key makefile-mode-map
[menu-bar makefile-mode browse
]
392 '("Pop up Makefile Browser" . makefile-switch-to-browser
))
393 (define-key makefile-mode-map
[menu-bar makefile-mode complete
]
394 '("Complete Target or Macro" . makefile-complete
))
395 (define-key makefile-mode-map
[menu-bar makefile-mode pickup
]
396 '("Find Targets and Macros" . makefile-pickup-everything
))
398 (define-key makefile-mode-map
[menu-bar makefile-mode prev
]
399 '("Move to Previous Dependency" . makefile-previous-dependency
))
400 (define-key makefile-mode-map
[menu-bar makefile-mode next
]
401 '("Move to Next Dependency" . makefile-next-dependency
)))
403 (defvar makefile-browser-map nil
404 "The keymap that is used in the macro- and target browser.")
405 (if makefile-browser-map
407 (setq makefile-browser-map
(make-sparse-keymap))
408 (define-key makefile-browser-map
"n" 'makefile-browser-next-line
)
409 (define-key makefile-browser-map
"\C-n" 'makefile-browser-next-line
)
410 (define-key makefile-browser-map
"p" 'makefile-browser-previous-line
)
411 (define-key makefile-browser-map
"\C-p" 'makefile-browser-previous-line
)
412 (define-key makefile-browser-map
" " 'makefile-browser-toggle
)
413 (define-key makefile-browser-map
"i" 'makefile-browser-insert-selection
)
414 (define-key makefile-browser-map
"I" 'makefile-browser-insert-selection-and-quit
)
415 (define-key makefile-browser-map
"\C-c\C-m" 'makefile-browser-insert-continuation
)
416 (define-key makefile-browser-map
"q" 'makefile-browser-quit
)
417 ;; disable horizontal movement
418 (define-key makefile-browser-map
"\C-b" 'undefined
)
419 (define-key makefile-browser-map
"\C-f" 'undefined
))
422 (defvar makefile-mode-syntax-table nil
)
423 (if makefile-mode-syntax-table
425 (setq makefile-mode-syntax-table
(make-syntax-table))
426 (modify-syntax-entry ?\
( "() " makefile-mode-syntax-table
)
427 (modify-syntax-entry ?\
) ")( " makefile-mode-syntax-table
)
428 (modify-syntax-entry ?\
[ "(] " makefile-mode-syntax-table
)
429 (modify-syntax-entry ?\
] ")[ " makefile-mode-syntax-table
)
430 (modify-syntax-entry ?\
{ "(} " makefile-mode-syntax-table
)
431 (modify-syntax-entry ?\
} "){ " makefile-mode-syntax-table
)
432 (modify-syntax-entry ?
\' "\" " makefile-mode-syntax-table
)
433 (modify-syntax-entry ?\
` "\" " makefile-mode-syntax-table
)
434 (modify-syntax-entry ?
# "< " makefile-mode-syntax-table
)
435 (modify-syntax-entry ?
\n "> " makefile-mode-syntax-table
))
438 ;;; ------------------------------------------------------------
439 ;;; Internal variables.
440 ;;; You don't need to configure below this line.
441 ;;; ------------------------------------------------------------
443 (defvar makefile-target-table nil
444 "Table of all target names known for this buffer.")
446 (defvar makefile-macro-table nil
447 "Table of all macro names known for this buffer.")
449 (defvar makefile-browser-client
450 "A buffer in Makefile mode that is currently using the browser.")
452 (defvar makefile-browser-selection-vector nil
)
453 (defvar makefile-has-prereqs nil
)
454 (defvar makefile-need-target-pickup t
)
455 (defvar makefile-need-macro-pickup t
)
457 (defvar makefile-mode-hook
'())
459 ;; Each element looks like '("GNU MAKE FUNCTION" "ARG" "ARG" ... )
460 ;; Each "ARG" is used as a prompt for a required argument.
461 (defconst makefile-gnumake-functions-alist
464 ("subst" "From" "To" "In")
465 ("patsubst" "Pattern" "Replacement" "In")
467 ("findstring" "Find what" "In")
468 ("filter" "Pattern" "Text")
469 ("filter-out" "Pattern" "Text")
471 ;; Filename functions
476 ("addprefix" "Prefix" "Names")
477 ("addsuffix" "Suffix" "Names")
478 ("join" "List 1" "List 2")
479 ("word" "Index" "Text")
482 ("wildcard" "Pattern")
484 ("foreach" "Variable" "List" "Text")
485 ("origin" "Variable")
486 ("shell" "Command")))
489 ;;; ------------------------------------------------------------
490 ;;; The mode function itself.
491 ;;; ------------------------------------------------------------
494 (defun makefile-mode ()
495 "Major mode for editing Makefiles.
496 This function ends by invoking the function(s) `makefile-mode-hook'.
498 \\{makefile-mode-map}
500 In the browser, use the following keys:
502 \\{makefile-browser-map}
504 Makefile mode can be configured by modifying the following variables:
506 makefile-browser-buffer-name:
507 Name of the macro- and target browser buffer.
509 makefile-target-colon:
510 The string that gets appended to all target names
511 inserted by `makefile-insert-target'.
512 \":\" or \"::\" are quite common values.
514 makefile-macro-assign:
515 The string that gets appended to all macro names
516 inserted by `makefile-insert-macro'.
517 The normal value should be \" = \", since this is what
518 standard make expects. However, newer makes such as dmake
519 allow a larger variety of different macro assignments, so you
520 might prefer to use \" += \" or \" := \" .
522 makefile-tab-after-target-colon:
523 If you want a TAB (instead of a space) to be appended after the
524 target colon, then set this to a non-nil value.
526 makefile-browser-leftmost-column:
527 Number of blanks to the left of the browser selection mark.
529 makefile-browser-cursor-column:
530 Column in which the cursor is positioned when it moves
531 up or down in the browser.
533 makefile-browser-selected-mark:
534 String used to mark selected entries in the browser.
536 makefile-browser-unselected-mark:
537 String used to mark unselected entries in the browser.
539 makefile-browser-auto-advance-after-selection-p:
540 If this variable is set to a non-nil value the cursor
541 will automagically advance to the next line after an item
542 has been selected in the browser.
544 makefile-pickup-everything-picks-up-filenames-p:
545 If this variable is set to a non-nil value then
546 `makefile-pickup-everything' also picks up filenames as targets
547 (i.e. it calls `makefile-pickup-filenames-as-targets'), otherwise
548 filenames are omitted.
550 makefile-cleanup-continuations-p:
551 If this variable is set to a non-nil value then Makefile mode
552 will assure that no line in the file ends with a backslash
553 (the continuation character) followed by any whitespace.
554 This is done by silently removing the trailing whitespace, leaving
555 the backslash itself intact.
556 IMPORTANT: Please note that enabling this option causes Makefile mode
557 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \"it seems necessary\".
559 makefile-browser-hook:
560 A function or list of functions to be called just before the
561 browser is entered. This is executed in the makefile buffer.
563 makefile-special-targets-list:
564 List of special targets. You will be offered to complete
565 on one of those in the minibuffer whenever you enter a `.'.
566 at the beginning of a line in Makefile mode."
569 (kill-all-local-variables)
570 (make-local-variable 'local-write-file-hooks
)
571 (setq local-write-file-hooks
572 '(makefile-cleanup-continuations makefile-warn-suspicious-lines
))
573 (make-local-variable 'makefile-target-table
)
574 (make-local-variable 'makefile-macro-table
)
575 (make-local-variable 'makefile-has-prereqs
)
576 (make-local-variable 'makefile-need-target-pickup
)
577 (make-local-variable 'makefile-need-macro-pickup
)
580 (make-local-variable 'font-lock-defaults
)
581 (setq font-lock-defaults
582 ;; SYNTAX-BEGIN set to backward-paragraph to avoid slow-down
583 ;; near the end of a large buffer, due to parse-partial-sexp's
584 ;; trying to parse all the way till the beginning of buffer.
585 '(makefile-font-lock-keywords nil nil nil backward-paragraph
))
588 (make-local-variable 'add-log-current-defun-function
)
589 (setq add-log-current-defun-function
'makefile-add-log-defun
)
592 (make-local-variable 'imenu-generic-expression
)
593 (setq imenu-generic-expression makefile-imenu-generic-expression
)
596 (make-local-variable 'dabbrev-abbrev-skip-leading-regexp
)
597 (setq dabbrev-abbrev-skip-leading-regexp
"\\$")
600 (setq local-abbrev-table makefile-mode-abbrev-table
)
603 (make-local-variable 'fill-paragraph-function
)
604 (setq fill-paragraph-function
'makefile-fill-paragraph
)
607 (make-local-variable 'comment-start
)
608 (setq comment-start
"#")
609 (make-local-variable 'comment-end
)
610 (setq comment-end
"")
611 (make-local-variable 'comment-start-skip
)
612 (setq comment-start-skip
"#+[ \t]*")
614 ;; become the current major mode
615 (setq major-mode
'makefile-mode
)
616 (setq mode-name
"Makefile")
618 ;; Activate keymap and syntax table.
619 (use-local-map makefile-mode-map
)
620 (set-syntax-table makefile-mode-syntax-table
)
622 ;; Real TABs are important in makefiles
623 (setq indent-tabs-mode t
)
624 (run-hooks 'makefile-mode-hook
))
630 (defun makefile-next-dependency ()
631 "Move point to the beginning of the next dependency line."
633 (let ((here (point)))
635 (if (re-search-forward makefile-dependency-regex
(point-max) t
)
636 (progn (beginning-of-line) t
) ; indicate success
637 (goto-char here
) nil
)))
639 (defun makefile-previous-dependency ()
640 "Move point to the beginning of the previous dependency line."
642 (let ((here (point)))
644 (if (re-search-backward makefile-dependency-regex
(point-min) t
)
645 (progn (beginning-of-line) t
) ; indicate success
646 (goto-char here
) nil
)))
650 ;;; Electric keys. Blech.
652 (defun makefile-electric-dot (arg)
653 "Prompt for the name of a special target to insert.
654 Only does electric insertion at beginning of line.
655 Anywhere else just self-inserts."
658 (makefile-insert-special-target)
659 (self-insert-command arg
)))
661 (defun makefile-insert-special-target ()
662 "Prompt for and insert a special target name.
663 Uses `makefile-special-targets' list."
665 (makefile-pickup-targets)
666 (let ((special-target
667 (completing-read "Special target: "
668 makefile-special-targets-list nil nil nil
)))
669 (if (zerop (length special-target
))
671 (insert "." special-target
":")
672 (makefile-forward-after-target-colon))))
674 (defun makefile-electric-equal (arg)
675 "Prompt for name of a macro to insert.
676 Only does prompting if point is at beginning of line.
677 Anywhere else just self-inserts."
679 (makefile-pickup-macros)
681 (call-interactively 'makefile-insert-macro
)
682 (self-insert-command arg
)))
684 (defun makefile-insert-macro (macro-name)
685 "Prepare definition of a new macro."
686 (interactive "sMacro Name: ")
687 (makefile-pickup-macros)
688 (if (not (zerop (length macro-name
)))
691 (insert macro-name makefile-macro-assign
)
692 (setq makefile-need-macro-pickup t
)
693 (makefile-remember-macro macro-name
))))
695 (defun makefile-insert-macro-ref (macro-name)
696 "Complete on a list of known macros, then insert complete ref at point."
700 (makefile-pickup-macros)
701 (completing-read "Refer to macro: " makefile-macro-table nil nil nil
))))
702 (makefile-do-macro-insertion macro-name
))
704 (defun makefile-insert-target (target-name)
705 "Prepare definition of a new target (dependency line)."
706 (interactive "sTarget: ")
707 (if (not (zerop (length target-name
)))
710 (insert target-name makefile-target-colon
)
711 (makefile-forward-after-target-colon)
713 (setq makefile-need-target-pickup t
)
714 (makefile-remember-target target-name
))))
716 (defun makefile-insert-target-ref (target-name)
717 "Complete on a list of known targets, then insert TARGET-NAME at point."
721 (makefile-pickup-targets)
722 (completing-read "Refer to target: " makefile-target-table nil nil nil
))))
723 (if (not (zerop (length target-name
)))
724 (insert target-name
" ")))
726 (defun makefile-electric-colon (arg)
727 "Prompt for name of new target.
728 Prompting only happens at beginning of line.
729 Anywhere else just self-inserts."
732 (call-interactively 'makefile-insert-target
)
733 (self-insert-command arg
)))
737 ;;; ------------------------------------------------------------
738 ;;; Extracting targets and macros from an existing makefile
739 ;;; ------------------------------------------------------------
741 (defun makefile-pickup-targets ()
742 "Notice names of all target definitions in Makefile."
744 (if (not makefile-need-target-pickup
)
746 (setq makefile-need-target-pickup nil
)
747 (setq makefile-target-table nil
)
748 (setq makefile-has-prereqs nil
)
750 (goto-char (point-min))
751 (while (re-search-forward makefile-dependency-regex
(point-max) t
)
752 (makefile-add-this-line-targets)))
753 (message "Read targets OK.")))
755 (defun makefile-add-this-line-targets ()
758 (let ((done-with-line nil
)
759 (line-number (1+ (count-lines (point-min) (point)))))
760 (while (not done-with-line
)
761 (skip-chars-forward " \t")
762 (if (not (setq done-with-line
(or (eolp)
763 (char-equal (char-after (point)) ?
:))))
765 (let* ((start-of-target-name (point))
768 (skip-chars-forward "^ \t:#")
769 (buffer-substring start-of-target-name
(point))))
771 (not (looking-at ":[ \t]*$"))))
772 (if (makefile-remember-target target-name has-prereqs
)
773 (message "Picked up target \"%s\" from line %d"
774 target-name line-number
)))))))))
776 (defun makefile-pickup-macros ()
777 "Notice names of all macro definitions in Makefile."
779 (if (not makefile-need-macro-pickup
)
781 (setq makefile-need-macro-pickup nil
)
782 (setq makefile-macro-table nil
)
784 (goto-char (point-min))
785 (while (re-search-forward makefile-macroassign-regex
(point-max) t
)
786 (makefile-add-this-line-macro)
788 (message "Read macros OK.")))
790 (defun makefile-add-this-line-macro ()
793 (skip-chars-forward " \t")
795 (let* ((start-of-macro-name (point))
796 (line-number (1+ (count-lines (point-min) (point))))
798 (skip-chars-forward "^ \t:#=*")
799 (buffer-substring start-of-macro-name
(point)))))
800 (if (makefile-remember-macro macro-name
)
801 (message "Picked up macro \"%s\" from line %d"
802 macro-name line-number
))))))
804 (defun makefile-pickup-everything (arg)
805 "Notice names of all macros and targets in Makefile.
806 Prefix arg means force pickups to be redone."
810 (setq makefile-need-target-pickup t
)
811 (setq makefile-need-macro-pickup t
)))
812 (makefile-pickup-macros)
813 (makefile-pickup-targets)
814 (if makefile-pickup-everything-picks-up-filenames-p
815 (makefile-pickup-filenames-as-targets)))
817 (defun makefile-pickup-filenames-as-targets ()
818 "Scan the current directory for filenames to use as targets.
819 Checks each filename against `makefile-ignored-files-in-pickup-regex'
820 and adds all qualifying names to the list of known targets."
822 (let* ((dir (file-name-directory (buffer-file-name)))
823 (raw-filename-list (if dir
824 (file-name-all-completions "" dir
)
825 (file-name-all-completions "" ""))))
826 (mapcar (lambda (name)
827 (if (and (not (file-directory-p name
))
828 (not (string-match makefile-ignored-files-in-pickup-regex
830 (if (makefile-remember-target name
)
831 (message "Picked up file \"%s\" as target" name
))))
838 (defun makefile-complete ()
839 "Perform completion on Makefile construct preceding point.
840 Can complete variable and target names.
841 The context determines which are considered."
843 (let* ((beg (save-excursion
844 (skip-chars-backward "^$(){}:#= \t\n")
846 (try (buffer-substring beg
(point)))
852 (let ((pc (preceding-char)))
854 ;; Beginning of line means anything.
858 ;; Preceding "$" means macros only.
862 ;; Preceding "$(" or "${" means macros only.
869 (= (preceding-char) ?$
))))
870 (setq do-macros t
)))))
873 (let* ((table (append (if do-macros
875 makefile-target-table
)
876 makefile-macro-table
))
877 (completion (try-completion try table
)))
879 ;; Exact match, so insert closing paren or colon.
881 (insert (if do-macros
893 (message "Can't find completion for \"%s\"" try
)
896 ;; Partial completion.
897 ((not (string= try completion
))
898 ;; FIXME it would be nice to supply the closing paren if an
899 ;; exact, unambiguous match were found. That is not possible
900 ;; right now. Ditto closing ":" for targets.
901 (delete-region beg
(point))
903 ;; DO-MACROS means doing macros only. If not that, then check
904 ;; to see if this completion is a macro. Special insertion
905 ;; must be done for macros.
907 (assoc completion makefile-macro-table
))
908 (let ((makefile-use-curly-braces-for-macros-p
910 makefile-use-curly-braces-for-macros-p
)))
911 (delete-backward-char 2)
912 (makefile-do-macro-insertion completion
)
913 (delete-backward-char 1))
915 ;; Just insert targets.
916 (insert completion
)))
918 ;; Can't complete any more, so make completion list. FIXME
919 ;; this doesn't do the right thing when the completion is
920 ;; actually inserted. I don't think there is an easy way to do
923 (message "Making completion list...")
924 (let ((list (all-completions try table
)))
925 (with-output-to-temp-buffer "*Completions*"
926 (display-completion-list list
)))
927 (message "Making completion list...done"))))))
931 ;; Backslashification. Stolen from cc-mode.el.
933 (defun makefile-backslash-region (from to delete-flag
)
934 "Insert, align, or delete end-of-line backslashes on the lines in the region.
935 With no argument, inserts backslashes and aligns existing backslashes.
936 With an argument, deletes the backslashes.
938 This function does not modify the last line of the region if the region ends
939 right at the start of the following line; it does not modify blank lines
940 at the start of the region. So you can put the region around an entire macro
941 definition and conveniently use this command."
945 (let ((column makefile-backslash-column
)
946 (endmark (make-marker)))
947 (move-marker endmark to
)
948 ;; Compute the smallest column number past the ends of all the lines.
949 (if makefile-backslash-align
951 (if (not delete-flag
)
952 (while (< (point) to
)
954 (if (= (preceding-char) ?
\\)
955 (progn (forward-char -
1)
956 (skip-chars-backward " \t")))
957 (setq column
(max column
(1+ (current-column))))
959 ;; Adjust upward to a tab column, if that doesn't push
961 (if (> (% column tab-width
) 0)
962 (let ((adjusted (* (/ (+ column tab-width -
1) tab-width
)
964 (if (< adjusted
(window-width))
965 (setq column adjusted
))))))
966 ;; Don't modify blank lines at start of region.
968 (while (and (< (point) endmark
) (eolp))
970 ;; Add or remove backslashes on all the lines.
971 (while (and (< (point) endmark
)
972 ;; Don't backslashify the last line
973 ;; if the region ends right at the start of the next line.
976 (< (point) endmark
)))
977 (if (not delete-flag
)
978 (makefile-append-backslash column
)
979 (makefile-delete-backslash))
981 (move-marker endmark nil
))))
983 (defun makefile-append-backslash (column)
985 ;; Note that "\\\\" is needed to get one backslash.
986 (if (= (preceding-char) ?
\\)
987 (progn (forward-char -
1)
988 (delete-horizontal-space)
989 (indent-to column
(if makefile-backslash-align nil
1)))
990 (indent-to column
(if makefile-backslash-align nil
1))
993 (defun makefile-delete-backslash ()
998 (if (looking-at "\\\\")
999 (delete-region (1+ (point))
1000 (progn (skip-chars-backward " \t") (point)))))))
1006 (defun makefile-fill-paragraph (arg)
1007 ;; Fill comments, backslashed lines, and variable definitions
1012 ((looking-at "^#+ ")
1013 ;; Found a comment. Set the fill prefix and then fill.
1014 (let ((fill-prefix (buffer-substring-no-properties (match-beginning 0)
1016 (fill-paragraph-function nil
))
1017 (fill-paragraph nil
)
1020 ;; Must look for backslashed-region before looking for variable
1025 (= (preceding-char) ?
\\)
1028 (= (preceding-char) ?
\\))))
1029 ;; A backslash region. Find beginning and end, remove
1030 ;; backslashes, fill, and then reapply backslahes.
1035 (while (= (preceding-char) ?
\\)
1041 (while (= (preceding-char) ?
\\)
1045 (narrow-to-region beginning end
)
1046 (makefile-backslash-region (point-min) (point-max) t
)
1047 (let ((fill-paragraph-function nil
))
1048 (fill-paragraph nil
))
1049 (makefile-backslash-region (point-min) (point-max) nil
)
1050 (goto-char (point-max))
1051 (if (< (skip-chars-backward "\n") 0)
1052 (delete-region (point) (point-max))))))
1054 ((looking-at makefile-macroassign-regex
)
1055 ;; Have a macro assign. Fill just this line, and then backslash
1056 ;; resulting region.
1058 (narrow-to-region (point) (save-excursion
1062 (let ((fill-paragraph-function nil
))
1063 (fill-paragraph nil
))
1064 (makefile-backslash-region (point-min) (point-max) nil
)))))
1066 ;; Always return non-nil so we don't fill anything else.
1071 ;;; ------------------------------------------------------------
1073 ;;; ------------------------------------------------------------
1075 (defun makefile-browser-format-target-line (target selected
)
1077 (concat (make-string makefile-browser-leftmost-column ?\
)
1079 makefile-browser-selected-mark
1080 makefile-browser-unselected-mark
)
1082 target makefile-target-colon
))
1084 (defun makefile-browser-format-macro-line (macro selected
)
1086 (concat (make-string makefile-browser-leftmost-column ?\
)
1088 makefile-browser-selected-mark
1089 makefile-browser-unselected-mark
)
1090 (makefile-format-macro-ref macro
))))
1092 (defun makefile-browser-fill (targets macros
)
1093 (let ((inhibit-read-only t
))
1094 (goto-char (point-min))
1098 (lambda (item) (insert (makefile-browser-format-target-line (car item
) nil
) "\n")))
1103 (lambda (item) (insert (makefile-browser-format-macro-line (car item
) nil
) "\n")))
1106 (sort-lines nil
(point-min) (point-max))
1107 (goto-char (1- (point-max)))
1108 (delete-char 1) ; remove unnecessary newline at eob
1109 (goto-char (point-min))
1110 (forward-char makefile-browser-cursor-column
)))
1113 ;;; Moving up and down in the browser
1116 (defun makefile-browser-next-line ()
1117 "Move the browser selection cursor to the next line."
1119 (if (not (makefile-last-line-p))
1122 (forward-char makefile-browser-cursor-column
))))
1124 (defun makefile-browser-previous-line ()
1125 "Move the browser selection cursor to the previous line."
1127 (if (not (makefile-first-line-p))
1130 (forward-char makefile-browser-cursor-column
))))
1133 ;;; Quitting the browser (returns to client buffer)
1136 (defun makefile-browser-quit ()
1137 "Leave the browser and return to the makefile buffer."
1139 (let ((my-client makefile-browser-client
))
1140 (setq makefile-browser-client nil
) ; we quitted, so NO client!
1141 (set-buffer-modified-p nil
)
1143 (pop-to-buffer my-client
)))
1146 ;;; Toggle state of a browser item
1149 (defun makefile-browser-toggle ()
1150 "Toggle the selection state of the browser item at the cursor position."
1152 (let ((this-line (count-lines (point-min) (point))))
1153 (setq this-line
(max 1 this-line
))
1154 (makefile-browser-toggle-state-for-line this-line
)
1155 (goto-line this-line
)
1156 (let ((inhibit-read-only t
))
1158 (if (makefile-browser-on-macro-line-p)
1159 (let ((macro-name (makefile-browser-this-line-macro-name)))
1160 (delete-region (point) (progn (end-of-line) (point)))
1162 (makefile-browser-format-macro-line
1164 (makefile-browser-get-state-for-line this-line
))))
1165 (let ((target-name (makefile-browser-this-line-target-name)))
1166 (delete-region (point) (progn (end-of-line) (point)))
1168 (makefile-browser-format-target-line
1170 (makefile-browser-get-state-for-line this-line
))))))
1172 (forward-char makefile-browser-cursor-column
)
1173 (if makefile-browser-auto-advance-after-selection-p
1174 (makefile-browser-next-line))))
1177 ;;; Making insertions into the client buffer
1180 (defun makefile-browser-insert-continuation ()
1181 "Insert a makefile continuation.
1182 In the makefile buffer, go to (end-of-line), insert a \'\\\'
1183 character, insert a new blank line, go to that line and indent by one TAB.
1184 This is most useful in the process of creating continued lines when copying
1185 large dependencies from the browser to the client buffer.
1186 \(point) advances accordingly in the client buffer."
1189 (set-buffer makefile-browser-client
)
1193 (defun makefile-browser-insert-selection ()
1194 "Insert all selected targets and/or macros in the makefile buffer.
1195 Insertion takes place at point."
1199 (let ((current-line 1))
1201 (if (makefile-browser-get-state-for-line current-line
)
1202 (makefile-browser-send-this-line-item))
1204 (setq current-line
(1+ current-line
))))))
1206 (defun makefile-browser-insert-selection-and-quit ()
1208 (makefile-browser-insert-selection)
1209 (makefile-browser-quit))
1211 (defun makefile-browser-send-this-line-item ()
1212 (if (makefile-browser-on-macro-line-p)
1214 (let ((macro-name (makefile-browser-this-line-macro-name)))
1215 (set-buffer makefile-browser-client
)
1216 (insert (makefile-format-macro-ref macro-name
) " ")))
1218 (let ((target-name (makefile-browser-this-line-target-name)))
1219 (set-buffer makefile-browser-client
)
1220 (insert target-name
" ")))))
1222 (defun makefile-browser-start-interaction ()
1223 (use-local-map makefile-browser-map
)
1224 (setq buffer-read-only t
))
1226 (defun makefile-browse (targets macros
)
1228 (if (zerop (+ (length targets
) (length macros
)))
1231 (message "No macros or targets to browse! Consider running 'makefile-pickup-everything\'"))
1232 (let ((browser-buffer (get-buffer-create makefile-browser-buffer-name
)))
1233 (pop-to-buffer browser-buffer
)
1234 (makefile-browser-fill targets macros
)
1235 (shrink-window-if-larger-than-buffer)
1236 (set (make-local-variable 'makefile-browser-selection-vector
)
1237 (make-vector (+ (length targets
) (length macros
)) nil
))
1238 (makefile-browser-start-interaction))))
1240 (defun makefile-switch-to-browser ()
1242 (run-hooks 'makefile-browser-hook
)
1243 (setq makefile-browser-client
(current-buffer))
1244 (makefile-pickup-targets)
1245 (makefile-pickup-macros)
1246 (makefile-browse makefile-target-table makefile-macro-table
))
1250 ;;; ------------------------------------------------------------
1251 ;;; Up-to-date overview buffer
1252 ;;; ------------------------------------------------------------
1254 (defun makefile-create-up-to-date-overview ()
1255 "Create a buffer containing an overview of the state of all known targets.
1256 Known targets are targets that are explicitly defined in that makefile;
1257 in other words, all targets that appear on the left hand side of a
1258 dependency in the makefile."
1260 (if (y-or-n-p "Are you sure that the makefile being edited is consistent? ")
1262 ;; The rest of this function operates on a temporary makefile, created by
1263 ;; writing the current contents of the makefile buffer.
1265 (let ((saved-target-table makefile-target-table
)
1266 (this-buffer (current-buffer))
1267 (makefile-up-to-date-buffer
1268 (get-buffer-create makefile-up-to-date-buffer-name
))
1269 (filename (makefile-save-temporary))
1271 ;; Forget the target table because it may contain picked-up filenames
1272 ;; that are not really targets in the current makefile.
1273 ;; We don't want to query these, so get a new target-table with just the
1274 ;; targets that can be found in the makefile buffer.
1275 ;; The 'old' target table will be restored later.
1277 (real-targets (progn
1278 (makefile-pickup-targets)
1279 makefile-target-table
))
1280 (prereqs makefile-has-prereqs
)
1283 (set-buffer makefile-up-to-date-buffer
)
1284 (setq buffer-read-only nil
)
1286 (makefile-query-targets filename real-targets prereqs
)
1287 (if (zerop (buffer-size)) ; if it did not get us anything
1289 (kill-buffer (current-buffer))
1290 (message "No overview created!")))
1291 (set-buffer this-buffer
)
1292 (setq makefile-target-table saved-target-table
)
1293 (if (get-buffer makefile-up-to-date-buffer-name
)
1295 (pop-to-buffer (get-buffer makefile-up-to-date-buffer-name
))
1296 (shrink-window-if-larger-than-buffer)
1297 (sort-lines nil
(point-min) (point-max))
1298 (setq buffer-read-only t
))))))
1300 (defun makefile-save-temporary ()
1301 "Create a temporary file from the current makefile buffer."
1302 (let ((filename (makefile-generate-temporary-filename)))
1303 (write-region (point-min) (point-max) filename nil
0)
1304 filename
)) ; return the filename
1306 (defun makefile-generate-temporary-filename ()
1307 "Create a filename suitable for use in `makefile-save-temporary'.
1308 Be careful to allow brain-dead file systems (DOS, SYSV ...) to cope
1309 with the generated name!"
1310 (let ((my-name (user-login-name))
1311 (my-uid (int-to-string (user-uid))))
1313 (if (> (length my-name
) 3)
1314 (substring my-name
0 3)
1317 (if (> (length my-uid
) 3)
1318 (substring my-uid
0 3)
1321 (defun makefile-query-targets (filename target-table prereq-list
)
1322 "Fill the up-to-date overview buffer.
1323 Checks each target in TARGET-TABLE using `makefile-query-one-target-method'
1324 and generates the overview, one line per target name."
1327 (function (lambda (item)
1328 (let* ((target-name (car item
))
1329 (no-prereqs (not (member target-name prereq-list
)))
1330 (needs-rebuild (or no-prereqs
1332 makefile-query-one-target-method
1337 (cond (no-prereqs " .. has no prerequisites")
1338 (needs-rebuild " .. NEEDS REBUILD")
1339 (t " .. is up to date"))))
1342 (goto-char (point-min))
1343 (delete-file filename
)) ; remove the tmpfile
1345 (defun makefile-query-by-make-minus-q (target &optional filename
)
1347 (call-process makefile-brave-make nil nil nil
1348 "-f" filename
"-q" target
))))
1352 ;;; ------------------------------------------------------------
1353 ;;; Continuation cleanup
1354 ;;; ------------------------------------------------------------
1356 (defun makefile-cleanup-continuations ()
1357 (if (eq major-mode
'makefile-mode
)
1358 (if (and makefile-cleanup-continuations-p
1359 (not buffer-read-only
))
1361 (goto-char (point-min))
1362 (while (re-search-forward "\\\\[ \t]+$" (point-max) t
)
1363 (replace-match "\\" t t
))))))
1366 ;;; ------------------------------------------------------------
1367 ;;; Warn of suspicious lines
1368 ;;; ------------------------------------------------------------
1370 (defun makefile-warn-suspicious-lines ()
1371 ;; Returning non-nil cancels the save operation
1372 (if (eq major-mode
'makefile-mode
)
1374 (goto-char (point-min))
1375 (if (re-search-forward "^\\(\t+$\\| +\t\\)" nil t
)
1377 (format "Suspicious line %d. Save anyway "
1378 (count-lines (point-min) (point)))))))))
1382 ;;; ------------------------------------------------------------
1383 ;;; GNU make function support
1384 ;;; ------------------------------------------------------------
1386 (defun makefile-insert-gmake-function ()
1387 "Insert a GNU make function call.
1388 Asks for the name of the function to use (with completion).
1389 Then prompts for all required parameters."
1391 (let* ((gm-function-name (completing-read
1393 makefile-gnumake-functions-alist
1395 (gm-function-prompts
1396 (cdr (assoc gm-function-name makefile-gnumake-functions-alist
))))
1397 (if (not (zerop (length gm-function-name
)))
1398 (insert (makefile-format-macro-ref
1399 (concat gm-function-name
" "
1400 (makefile-prompt-for-gmake-funargs
1401 gm-function-name gm-function-prompts
)))
1404 (defun makefile-prompt-for-gmake-funargs (function-name prompt-list
)
1406 (function (lambda (one-prompt)
1407 (read-string (format "[%s] %s: " function-name one-prompt
)
1414 ;;; ------------------------------------------------------------
1415 ;;; Utility functions
1416 ;;; ------------------------------------------------------------
1418 (defun makefile-do-macro-insertion (macro-name)
1419 "Insert a macro reference."
1420 (if (not (zerop (length macro-name
)))
1421 (if (assoc macro-name makefile-runtime-macros-list
)
1422 (insert "$" macro-name
)
1423 (insert (makefile-format-macro-ref macro-name
)))))
1425 (defun makefile-remember-target (target-name &optional has-prereqs
)
1426 "Remember a given target if it is not already remembered for this buffer."
1427 (if (not (zerop (length target-name
)))
1429 (if (not (assoc target-name makefile-target-table
))
1430 (setq makefile-target-table
1431 (cons (list target-name
) makefile-target-table
)))
1433 (setq makefile-has-prereqs
1434 (cons target-name makefile-has-prereqs
))))))
1436 (defun makefile-remember-macro (macro-name)
1437 "Remember a given macro if it is not already remembered for this buffer."
1438 (if (not (zerop (length macro-name
)))
1439 (if (not (assoc macro-name makefile-macro-table
))
1440 (setq makefile-macro-table
1441 (cons (list macro-name
) makefile-macro-table
)))))
1443 (defun makefile-forward-after-target-colon ()
1444 "Move point forward after inserting the terminating colon of a target.
1445 This acts according to the value of `makefile-tab-after-target-colon'."
1446 (if makefile-tab-after-target-colon
1450 (defun makefile-browser-on-macro-line-p ()
1451 "Determine if point is on a macro line in the browser."
1454 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t
)))
1456 (defun makefile-browser-this-line-target-name ()
1457 "Extract the target name from a line in the browser."
1460 (skip-chars-backward "^ \t")
1461 (buffer-substring (point) (1- (makefile-end-of-line-point)))))
1463 (defun makefile-browser-this-line-macro-name ()
1464 "Extract the macro name from a line in the browser."
1467 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t
)
1468 (let ((macro-start (point)))
1469 (skip-chars-forward "^})")
1470 (buffer-substring macro-start
(point)))))
1472 (defun makefile-format-macro-ref (macro-name)
1473 "Format a macro reference.
1474 Uses `makefile-use-curly-braces-for-macros-p'."
1475 (if (or (char-equal ?\
( (string-to-char macro-name
))
1476 (char-equal ?\
{ (string-to-char macro-name
)))
1477 (format "$%s" macro-name
)
1478 (if makefile-use-curly-braces-for-macros-p
1479 (format "${%s}" macro-name
)
1480 (format "$(%s)" macro-name
))))
1482 (defun makefile-browser-get-state-for-line (n)
1483 (aref makefile-browser-selection-vector
(1- n
)))
1485 (defun makefile-browser-set-state-for-line (n to-state
)
1486 (aset makefile-browser-selection-vector
(1- n
) to-state
))
1488 (defun makefile-browser-toggle-state-for-line (n)
1489 (makefile-browser-set-state-for-line n
(not (makefile-browser-get-state-for-line n
))))
1491 (defun makefile-beginning-of-line-point ()
1496 (defun makefile-end-of-line-point ()
1501 (defun makefile-last-line-p ()
1502 (= (makefile-end-of-line-point) (point-max)))
1504 (defun makefile-first-line-p ()
1505 (= (makefile-beginning-of-line-point) (point-min)))
1509 ;;; Support for other packages, like add-log.
1511 (defun makefile-add-log-defun ()
1512 "Return name of target or variable assignment that point is in.
1513 If it isn't in one, return nil."
1517 ;; Scan back line by line, noticing when we come to a
1518 ;; variable or rule definition, and giving up when we see
1519 ;; a line that is not part of either of those.
1522 ((looking-at makefile-macroassign-regex
)
1523 (setq found
(buffer-substring-no-properties (match-beginning 1)
1525 ((looking-at makefile-dependency-regex
)
1526 (setq found
(buffer-substring-no-properties (match-beginning 1)
1528 ;; Don't keep looking across a blank line or comment. Give up.
1529 ((looking-at "$\\|#")
1532 (setq found
'bobp
)))
1535 (if (stringp found
) found
))))
1537 ;;; make-mode.el ends here