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.
281 '("^[ \t]*\\(-?include\\|if\\(n?eq\\|n?def\\)?\\)[ \t]+\\([^: \t\n#]+\\)"
282 (1 font-lock-warning-face
) (3 font-lock-variable-name-face
))
284 ;; Fontify endif and else.
285 '("^[ \t]*\\(else\\|endif\\)[ \t]*\\(#.*$\\)?"
286 (1 font-lock-warning-face
))
288 ;; Fontify conditionals and includes.
289 ;; Note that plain `if' is an automake conditional, and not a bug.
290 '("^[ \t]*\\(-?include\\|if\\(n?eq\\|n?def\\)?\\)[ \t]+\\([^: \t\n#]+\\)"
291 (1 font-lock-reference-face
) (3 font-lock-variable-name-face
))
293 ;; Fontify endif and else.
294 '("^[ \t]*\\(else\\|endif\\)[ \t]*\\(#.*$\\)?"
295 (1 font-lock-reference-face
))
297 ;; Highlight lines that contain just whitespace.
298 ;; They can cause trouble, especially if they start with a tab.
299 '("^[ \t]+$" . makefile-space-face
)
301 ;; Highlight shell comments that Make treats as commands,
302 ;; since these can fool people.
303 '("^\t+#" 0 makefile-space-face t
)
305 ;; Highlight spaces that precede tabs.
306 ;; They can make a tab fail to be effective.
307 '("^\\( +\\)\t" 1 makefile-space-face
)))
309 (defvar makefile-imenu-generic-expression
311 (list "Dependencies" makefile-dependency-regex
1)
312 (list "Macro Assignment" makefile-macroassign-regex
1))
313 "Imenu generic expression for Makefile mode. See `imenu-generic-expression'.")
315 ;;; ------------------------------------------------------------
316 ;;; The following configurable variables are used in the
317 ;;; up-to-date overview .
318 ;;; The standard configuration assumes that your `make' program
319 ;;; can be run in question/query mode using the `-q' option, this
320 ;;; means that the command
324 ;;; should return an exit status of zero if the target `foo' is
325 ;;; up to date and a nonzero exit status otherwise.
326 ;;; Many makes can do this although the docs/manpages do not mention
327 ;;; it. Try it with your favourite one. GNU make, System V make, and
328 ;;; Dennis Vadura's DMake have no problems.
329 ;;; Set the variable `makefile-brave-make' to the name of the
330 ;;; make utility that does this on your system.
331 ;;; To understand what this is all about see the function definition
332 ;;; of `makefile-query-by-make-minus-q' .
333 ;;; ------------------------------------------------------------
335 (defcustom makefile-brave-make
"make"
336 "*How to invoke make, for `makefile-query-targets'.
337 This should identify a `make' command that can handle the `-q' option."
341 (defcustom makefile-query-one-target-method
'makefile-query-by-make-minus-q
342 "*Function to call to determine whether a make target is up to date.
343 The function must satisfy this calling convention:
345 * As its first argument, it must accept the name of the target to
346 be checked, as a string.
348 * As its second argument, it may accept the name of a makefile
349 as a string. Depending on what you're going to do you may
352 * It must return the integer value 0 (zero) if the given target
353 should be considered up-to-date in the context of the given
354 makefile, any nonzero integer value otherwise."
358 (defcustom makefile-up-to-date-buffer-name
"*Makefile Up-to-date overview*"
359 "*Name of the Up-to-date overview buffer."
363 ;;; --- end of up-to-date-overview configuration ------------------
365 (defvar makefile-mode-abbrev-table nil
366 "Abbrev table in use in Makefile buffers.")
367 (if makefile-mode-abbrev-table
369 (define-abbrev-table 'makefile-mode-abbrev-table
()))
371 (defvar makefile-mode-map nil
372 "The keymap that is used in Makefile mode.")
374 (if makefile-mode-map
376 (setq makefile-mode-map
(make-sparse-keymap))
378 (define-key makefile-mode-map
"\C-c:" 'makefile-insert-target-ref
)
379 (if makefile-electric-keys
381 (define-key makefile-mode-map
"$" 'makefile-insert-macro-ref
)
382 (define-key makefile-mode-map
":" 'makefile-electric-colon
)
383 (define-key makefile-mode-map
"=" 'makefile-electric-equal
)
384 (define-key makefile-mode-map
"." 'makefile-electric-dot
)))
385 (define-key makefile-mode-map
"\C-c\C-f" 'makefile-pickup-filenames-as-targets
)
386 (define-key makefile-mode-map
"\C-c\C-b" 'makefile-switch-to-browser
)
387 (define-key makefile-mode-map
"\C-c\C-c" 'comment-region
)
388 (define-key makefile-mode-map
"\C-c\C-p" 'makefile-pickup-everything
)
389 (define-key makefile-mode-map
"\C-c\C-u" 'makefile-create-up-to-date-overview
)
390 (define-key makefile-mode-map
"\C-c\C-i" 'makefile-insert-gmake-function
)
391 (define-key makefile-mode-map
"\C-c\C-\\" 'makefile-backslash-region
)
392 (define-key makefile-mode-map
"\M-p" 'makefile-previous-dependency
)
393 (define-key makefile-mode-map
"\M-n" 'makefile-next-dependency
)
394 (define-key makefile-mode-map
"\e\t" 'makefile-complete
)
397 (define-key makefile-mode-map
[menu-bar makefile-mode
]
398 (cons "Makefile" (make-sparse-keymap "Makefile")))
400 (define-key makefile-mode-map
[menu-bar makefile-mode browse
]
401 '("Pop up Makefile Browser" . makefile-switch-to-browser
))
402 (define-key makefile-mode-map
[menu-bar makefile-mode complete
]
403 '("Complete Target or Macro" . makefile-complete
))
404 (define-key makefile-mode-map
[menu-bar makefile-mode pickup
]
405 '("Find Targets and Macros" . makefile-pickup-everything
))
407 (define-key makefile-mode-map
[menu-bar makefile-mode prev
]
408 '("Move to Previous Dependency" . makefile-previous-dependency
))
409 (define-key makefile-mode-map
[menu-bar makefile-mode next
]
410 '("Move to Next Dependency" . makefile-next-dependency
)))
412 (defvar makefile-browser-map nil
413 "The keymap that is used in the macro- and target browser.")
414 (if makefile-browser-map
416 (setq makefile-browser-map
(make-sparse-keymap))
417 (define-key makefile-browser-map
"n" 'makefile-browser-next-line
)
418 (define-key makefile-browser-map
"\C-n" 'makefile-browser-next-line
)
419 (define-key makefile-browser-map
"p" 'makefile-browser-previous-line
)
420 (define-key makefile-browser-map
"\C-p" 'makefile-browser-previous-line
)
421 (define-key makefile-browser-map
" " 'makefile-browser-toggle
)
422 (define-key makefile-browser-map
"i" 'makefile-browser-insert-selection
)
423 (define-key makefile-browser-map
"I" 'makefile-browser-insert-selection-and-quit
)
424 (define-key makefile-browser-map
"\C-c\C-m" 'makefile-browser-insert-continuation
)
425 (define-key makefile-browser-map
"q" 'makefile-browser-quit
)
426 ;; disable horizontal movement
427 (define-key makefile-browser-map
"\C-b" 'undefined
)
428 (define-key makefile-browser-map
"\C-f" 'undefined
))
431 (defvar makefile-mode-syntax-table nil
)
432 (if makefile-mode-syntax-table
434 (setq makefile-mode-syntax-table
(make-syntax-table))
435 (modify-syntax-entry ?\
( "() " makefile-mode-syntax-table
)
436 (modify-syntax-entry ?\
) ")( " makefile-mode-syntax-table
)
437 (modify-syntax-entry ?\
[ "(] " makefile-mode-syntax-table
)
438 (modify-syntax-entry ?\
] ")[ " makefile-mode-syntax-table
)
439 (modify-syntax-entry ?\
{ "(} " makefile-mode-syntax-table
)
440 (modify-syntax-entry ?\
} "){ " makefile-mode-syntax-table
)
441 (modify-syntax-entry ?
\' "\" " makefile-mode-syntax-table
)
442 (modify-syntax-entry ?\
` "\" " makefile-mode-syntax-table
)
443 (modify-syntax-entry ?
# "< " makefile-mode-syntax-table
)
444 (modify-syntax-entry ?
\n "> " makefile-mode-syntax-table
))
447 ;;; ------------------------------------------------------------
448 ;;; Internal variables.
449 ;;; You don't need to configure below this line.
450 ;;; ------------------------------------------------------------
452 (defvar makefile-target-table nil
453 "Table of all target names known for this buffer.")
455 (defvar makefile-macro-table nil
456 "Table of all macro names known for this buffer.")
458 (defvar makefile-browser-client
459 "A buffer in Makefile mode that is currently using the browser.")
461 (defvar makefile-browser-selection-vector nil
)
462 (defvar makefile-has-prereqs nil
)
463 (defvar makefile-need-target-pickup t
)
464 (defvar makefile-need-macro-pickup t
)
466 (defvar makefile-mode-hook
'())
468 ;; Each element looks like '("GNU MAKE FUNCTION" "ARG" "ARG" ... )
469 ;; Each "ARG" is used as a prompt for a required argument.
470 (defconst makefile-gnumake-functions-alist
473 ("subst" "From" "To" "In")
474 ("patsubst" "Pattern" "Replacement" "In")
476 ("findstring" "Find what" "In")
477 ("filter" "Pattern" "Text")
478 ("filter-out" "Pattern" "Text")
480 ;; Filename functions
485 ("addprefix" "Prefix" "Names")
486 ("addsuffix" "Suffix" "Names")
487 ("join" "List 1" "List 2")
488 ("word" "Index" "Text")
491 ("wildcard" "Pattern")
493 ("foreach" "Variable" "List" "Text")
494 ("origin" "Variable")
495 ("shell" "Command")))
498 ;;; ------------------------------------------------------------
499 ;;; The mode function itself.
500 ;;; ------------------------------------------------------------
503 (defun makefile-mode ()
504 "Major mode for editing Makefiles.
505 This function ends by invoking the function(s) `makefile-mode-hook'.
507 \\{makefile-mode-map}
509 In the browser, use the following keys:
511 \\{makefile-browser-map}
513 Makefile mode can be configured by modifying the following variables:
515 makefile-browser-buffer-name:
516 Name of the macro- and target browser buffer.
518 makefile-target-colon:
519 The string that gets appended to all target names
520 inserted by `makefile-insert-target'.
521 \":\" or \"::\" are quite common values.
523 makefile-macro-assign:
524 The string that gets appended to all macro names
525 inserted by `makefile-insert-macro'.
526 The normal value should be \" = \", since this is what
527 standard make expects. However, newer makes such as dmake
528 allow a larger variety of different macro assignments, so you
529 might prefer to use \" += \" or \" := \" .
531 makefile-tab-after-target-colon:
532 If you want a TAB (instead of a space) to be appended after the
533 target colon, then set this to a non-nil value.
535 makefile-browser-leftmost-column:
536 Number of blanks to the left of the browser selection mark.
538 makefile-browser-cursor-column:
539 Column in which the cursor is positioned when it moves
540 up or down in the browser.
542 makefile-browser-selected-mark:
543 String used to mark selected entries in the browser.
545 makefile-browser-unselected-mark:
546 String used to mark unselected entries in the browser.
548 makefile-browser-auto-advance-after-selection-p:
549 If this variable is set to a non-nil value the cursor
550 will automagically advance to the next line after an item
551 has been selected in the browser.
553 makefile-pickup-everything-picks-up-filenames-p:
554 If this variable is set to a non-nil value then
555 `makefile-pickup-everything' also picks up filenames as targets
556 (i.e. it calls `makefile-pickup-filenames-as-targets'), otherwise
557 filenames are omitted.
559 makefile-cleanup-continuations-p:
560 If this variable is set to a non-nil value then Makefile mode
561 will assure that no line in the file ends with a backslash
562 (the continuation character) followed by any whitespace.
563 This is done by silently removing the trailing whitespace, leaving
564 the backslash itself intact.
565 IMPORTANT: Please note that enabling this option causes Makefile mode
566 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \"it seems necessary\".
568 makefile-browser-hook:
569 A function or list of functions to be called just before the
570 browser is entered. This is executed in the makefile buffer.
572 makefile-special-targets-list:
573 List of special targets. You will be offered to complete
574 on one of those in the minibuffer whenever you enter a `.'.
575 at the beginning of a line in Makefile mode."
578 (kill-all-local-variables)
579 (make-local-variable 'local-write-file-hooks
)
580 (setq local-write-file-hooks
581 '(makefile-cleanup-continuations makefile-warn-suspicious-lines
))
582 (make-local-variable 'makefile-target-table
)
583 (make-local-variable 'makefile-macro-table
)
584 (make-local-variable 'makefile-has-prereqs
)
585 (make-local-variable 'makefile-need-target-pickup
)
586 (make-local-variable 'makefile-need-macro-pickup
)
589 (make-local-variable 'font-lock-defaults
)
590 (setq font-lock-defaults
'(makefile-font-lock-keywords))
593 (make-local-variable 'add-log-current-defun-function
)
594 (setq add-log-current-defun-function
'makefile-add-log-defun
)
597 (make-local-variable 'imenu-generic-expression
)
598 (setq imenu-generic-expression makefile-imenu-generic-expression
)
601 (make-local-variable 'dabbrev-abbrev-skip-leading-regexp
)
602 (setq dabbrev-abbrev-skip-leading-regexp
"\\$")
605 (setq local-abbrev-table makefile-mode-abbrev-table
)
608 (make-local-variable 'fill-paragraph-function
)
609 (setq fill-paragraph-function
'makefile-fill-paragraph
)
612 (make-local-variable 'comment-start
)
613 (setq comment-start
"#")
614 (make-local-variable 'comment-end
)
615 (setq comment-end
"")
616 (make-local-variable 'comment-start-skip
)
617 (setq comment-start-skip
"#+[ \t]*")
619 ;; become the current major mode
620 (setq major-mode
'makefile-mode
)
621 (setq mode-name
"Makefile")
623 ;; Activate keymap and syntax table.
624 (use-local-map makefile-mode-map
)
625 (set-syntax-table makefile-mode-syntax-table
)
627 ;; Real TABs are important in makefiles
628 (setq indent-tabs-mode t
)
629 (run-hooks 'makefile-mode-hook
))
635 (defun makefile-next-dependency ()
636 "Move point to the beginning of the next dependency line."
638 (let ((here (point)))
640 (if (re-search-forward makefile-dependency-regex
(point-max) t
)
641 (progn (beginning-of-line) t
) ; indicate success
642 (goto-char here
) nil
)))
644 (defun makefile-previous-dependency ()
645 "Move point to the beginning of the previous dependency line."
647 (let ((here (point)))
649 (if (re-search-backward makefile-dependency-regex
(point-min) t
)
650 (progn (beginning-of-line) t
) ; indicate success
651 (goto-char here
) nil
)))
655 ;;; Electric keys. Blech.
657 (defun makefile-electric-dot (arg)
658 "Prompt for the name of a special target to insert.
659 Only does electric insertion at beginning of line.
660 Anywhere else just self-inserts."
663 (makefile-insert-special-target)
664 (self-insert-command arg
)))
666 (defun makefile-insert-special-target ()
667 "Prompt for and insert a special target name.
668 Uses `makefile-special-targets' list."
670 (makefile-pickup-targets)
671 (let ((special-target
672 (completing-read "Special target: "
673 makefile-special-targets-list nil nil nil
)))
674 (if (zerop (length special-target
))
676 (insert "." special-target
":")
677 (makefile-forward-after-target-colon))))
679 (defun makefile-electric-equal (arg)
680 "Prompt for name of a macro to insert.
681 Only does prompting if point is at beginning of line.
682 Anywhere else just self-inserts."
684 (makefile-pickup-macros)
686 (call-interactively 'makefile-insert-macro
)
687 (self-insert-command arg
)))
689 (defun makefile-insert-macro (macro-name)
690 "Prepare definition of a new macro."
691 (interactive "sMacro Name: ")
692 (makefile-pickup-macros)
693 (if (not (zerop (length macro-name
)))
696 (insert macro-name makefile-macro-assign
)
697 (setq makefile-need-macro-pickup t
)
698 (makefile-remember-macro macro-name
))))
700 (defun makefile-insert-macro-ref (macro-name)
701 "Complete on a list of known macros, then insert complete ref at point."
705 (makefile-pickup-macros)
706 (completing-read "Refer to macro: " makefile-macro-table nil nil nil
))))
707 (makefile-do-macro-insertion macro-name
))
709 (defun makefile-insert-target (target-name)
710 "Prepare definition of a new target (dependency line)."
711 (interactive "sTarget: ")
712 (if (not (zerop (length target-name
)))
715 (insert target-name makefile-target-colon
)
716 (makefile-forward-after-target-colon)
718 (setq makefile-need-target-pickup t
)
719 (makefile-remember-target target-name
))))
721 (defun makefile-insert-target-ref (target-name)
722 "Complete on a list of known targets, then insert TARGET-NAME at point."
726 (makefile-pickup-targets)
727 (completing-read "Refer to target: " makefile-target-table nil nil nil
))))
728 (if (not (zerop (length target-name
)))
729 (insert target-name
" ")))
731 (defun makefile-electric-colon (arg)
732 "Prompt for name of new target.
733 Prompting only happens at beginning of line.
734 Anywhere else just self-inserts."
737 (call-interactively 'makefile-insert-target
)
738 (self-insert-command arg
)))
742 ;;; ------------------------------------------------------------
743 ;;; Extracting targets and macros from an existing makefile
744 ;;; ------------------------------------------------------------
746 (defun makefile-pickup-targets ()
747 "Notice names of all target definitions in Makefile."
749 (if (not makefile-need-target-pickup
)
751 (setq makefile-need-target-pickup nil
)
752 (setq makefile-target-table nil
)
753 (setq makefile-has-prereqs nil
)
755 (goto-char (point-min))
756 (while (re-search-forward makefile-dependency-regex
(point-max) t
)
757 (makefile-add-this-line-targets)))
758 (message "Read targets OK.")))
760 (defun makefile-add-this-line-targets ()
763 (let ((done-with-line nil
)
764 (line-number (1+ (count-lines (point-min) (point)))))
765 (while (not done-with-line
)
766 (skip-chars-forward " \t")
767 (if (not (setq done-with-line
(or (eolp)
768 (char-equal (char-after (point)) ?
:))))
770 (let* ((start-of-target-name (point))
773 (skip-chars-forward "^ \t:#")
774 (buffer-substring start-of-target-name
(point))))
776 (not (looking-at ":[ \t]*$"))))
777 (if (makefile-remember-target target-name has-prereqs
)
778 (message "Picked up target \"%s\" from line %d"
779 target-name line-number
)))))))))
781 (defun makefile-pickup-macros ()
782 "Notice names of all macro definitions in Makefile."
784 (if (not makefile-need-macro-pickup
)
786 (setq makefile-need-macro-pickup nil
)
787 (setq makefile-macro-table nil
)
789 (goto-char (point-min))
790 (while (re-search-forward makefile-macroassign-regex
(point-max) t
)
791 (makefile-add-this-line-macro)
793 (message "Read macros OK.")))
795 (defun makefile-add-this-line-macro ()
798 (skip-chars-forward " \t")
800 (let* ((start-of-macro-name (point))
801 (line-number (1+ (count-lines (point-min) (point))))
803 (skip-chars-forward "^ \t:#=*")
804 (buffer-substring start-of-macro-name
(point)))))
805 (if (makefile-remember-macro macro-name
)
806 (message "Picked up macro \"%s\" from line %d"
807 macro-name line-number
))))))
809 (defun makefile-pickup-everything (arg)
810 "Notice names of all macros and targets in Makefile.
811 Prefix arg means force pickups to be redone."
815 (setq makefile-need-target-pickup t
)
816 (setq makefile-need-macro-pickup t
)))
817 (makefile-pickup-macros)
818 (makefile-pickup-targets)
819 (if makefile-pickup-everything-picks-up-filenames-p
820 (makefile-pickup-filenames-as-targets)))
822 (defun makefile-pickup-filenames-as-targets ()
823 "Scan the current directory for filenames to use as targets.
824 Checks each filename against `makefile-ignored-files-in-pickup-regex'
825 and adds all qualifying names to the list of known targets."
827 (let* ((dir (file-name-directory (buffer-file-name)))
828 (raw-filename-list (if dir
829 (file-name-all-completions "" dir
)
830 (file-name-all-completions "" ""))))
831 (mapcar (lambda (name)
832 (if (and (not (file-directory-p name
))
833 (not (string-match makefile-ignored-files-in-pickup-regex
835 (if (makefile-remember-target name
)
836 (message "Picked up file \"%s\" as target" name
))))
843 (defun makefile-complete ()
844 "Perform completion on Makefile construct preceding point.
845 Can complete variable and target names.
846 The context determines which are considered."
848 (let* ((beg (save-excursion
849 (skip-chars-backward "^$(){}:#= \t\n")
851 (try (buffer-substring beg
(point)))
857 (let ((pc (preceding-char)))
859 ;; Beginning of line means anything.
863 ;; Preceding "$" means macros only.
867 ;; Preceding "$(" or "${" means macros only.
874 (= (preceding-char) ?$
))))
875 (setq do-macros t
)))))
878 (let* ((table (append (if do-macros
880 makefile-target-table
)
881 makefile-macro-table
))
882 (completion (try-completion try table
)))
884 ;; Exact match, so insert closing paren or colon.
886 (insert (if do-macros
898 (message "Can't find completion for \"%s\"" try
)
901 ;; Partial completion.
902 ((not (string= try completion
))
903 ;; FIXME it would be nice to supply the closing paren if an
904 ;; exact, unambiguous match were found. That is not possible
905 ;; right now. Ditto closing ":" for targets.
906 (delete-region beg
(point))
908 ;; DO-MACROS means doing macros only. If not that, then check
909 ;; to see if this completion is a macro. Special insertion
910 ;; must be done for macros.
912 (assoc completion makefile-macro-table
))
913 (let ((makefile-use-curly-braces-for-macros-p
915 makefile-use-curly-braces-for-macros-p
)))
916 (delete-backward-char 2)
917 (makefile-do-macro-insertion completion
)
918 (delete-backward-char 1))
920 ;; Just insert targets.
921 (insert completion
)))
923 ;; Can't complete any more, so make completion list. FIXME
924 ;; this doesn't do the right thing when the completion is
925 ;; actually inserted. I don't think there is an easy way to do
928 (message "Making completion list...")
929 (let ((list (all-completions try table
)))
930 (with-output-to-temp-buffer "*Completions*"
931 (display-completion-list list
)))
932 (message "Making completion list...done"))))))
936 ;; Backslashification. Stolen from cc-mode.el.
938 (defun makefile-backslash-region (from to delete-flag
)
939 "Insert, align, or delete end-of-line backslashes on the lines in the region.
940 With no argument, inserts backslashes and aligns existing backslashes.
941 With an argument, deletes the backslashes.
943 This function does not modify the last line of the region if the region ends
944 right at the start of the following line; it does not modify blank lines
945 at the start of the region. So you can put the region around an entire macro
946 definition and conveniently use this command."
950 (let ((column makefile-backslash-column
)
951 (endmark (make-marker)))
952 (move-marker endmark to
)
953 ;; Compute the smallest column number past the ends of all the lines.
954 (if makefile-backslash-align
956 (if (not delete-flag
)
957 (while (< (point) to
)
959 (if (= (preceding-char) ?
\\)
960 (progn (forward-char -
1)
961 (skip-chars-backward " \t")))
962 (setq column
(max column
(1+ (current-column))))
964 ;; Adjust upward to a tab column, if that doesn't push
966 (if (> (% column tab-width
) 0)
967 (let ((adjusted (* (/ (+ column tab-width -
1) tab-width
)
969 (if (< adjusted
(window-width))
970 (setq column adjusted
))))))
971 ;; Don't modify blank lines at start of region.
973 (while (and (< (point) endmark
) (eolp))
975 ;; Add or remove backslashes on all the lines.
976 (while (and (< (point) endmark
)
977 ;; Don't backslashify the last line
978 ;; if the region ends right at the start of the next line.
981 (< (point) endmark
)))
982 (if (not delete-flag
)
983 (makefile-append-backslash column
)
984 (makefile-delete-backslash))
986 (move-marker endmark nil
))))
988 (defun makefile-append-backslash (column)
990 ;; Note that "\\\\" is needed to get one backslash.
991 (if (= (preceding-char) ?
\\)
992 (progn (forward-char -
1)
993 (delete-horizontal-space)
994 (indent-to column
(if makefile-backslash-align nil
1)))
995 (indent-to column
(if makefile-backslash-align nil
1))
998 (defun makefile-delete-backslash ()
1003 (if (looking-at "\\\\")
1004 (delete-region (1+ (point))
1005 (progn (skip-chars-backward " \t") (point)))))))
1011 (defun makefile-fill-paragraph (arg)
1012 ;; Fill comments, backslashed lines, and variable definitions
1017 ((looking-at "^#+ ")
1018 ;; Found a comment. Set the fill prefix and then fill.
1019 (let ((fill-prefix (buffer-substring-no-properties (match-beginning 0)
1021 (fill-paragraph-function nil
))
1022 (fill-paragraph nil
)
1025 ;; Must look for backslashed-region before looking for variable
1030 (= (preceding-char) ?
\\)
1033 (= (preceding-char) ?
\\))))
1034 ;; A backslash region. Find beginning and end, remove
1035 ;; backslashes, fill, and then reapply backslahes.
1040 (while (= (preceding-char) ?
\\)
1046 (while (= (preceding-char) ?
\\)
1050 (narrow-to-region beginning end
)
1051 (makefile-backslash-region (point-min) (point-max) t
)
1052 (let ((fill-paragraph-function nil
))
1053 (fill-paragraph nil
))
1054 (makefile-backslash-region (point-min) (point-max) nil
)
1055 (goto-char (point-max))
1056 (if (< (skip-chars-backward "\n") 0)
1057 (delete-region (point) (point-max))))))
1059 ((looking-at makefile-macroassign-regex
)
1060 ;; Have a macro assign. Fill just this line, and then backslash
1061 ;; resulting region.
1063 (narrow-to-region (point) (save-excursion
1067 (let ((fill-paragraph-function nil
))
1068 (fill-paragraph nil
))
1069 (makefile-backslash-region (point-min) (point-max) nil
)))))
1071 ;; Always return non-nil so we don't fill anything else.
1076 ;;; ------------------------------------------------------------
1078 ;;; ------------------------------------------------------------
1080 (defun makefile-browser-format-target-line (target selected
)
1082 (concat (make-string makefile-browser-leftmost-column ?\
)
1084 makefile-browser-selected-mark
1085 makefile-browser-unselected-mark
)
1087 target makefile-target-colon
))
1089 (defun makefile-browser-format-macro-line (macro selected
)
1091 (concat (make-string makefile-browser-leftmost-column ?\
)
1093 makefile-browser-selected-mark
1094 makefile-browser-unselected-mark
)
1095 (makefile-format-macro-ref macro
))))
1097 (defun makefile-browser-fill (targets macros
)
1098 (let ((inhibit-read-only t
))
1099 (goto-char (point-min))
1103 (lambda (item) (insert (makefile-browser-format-target-line (car item
) nil
) "\n")))
1108 (lambda (item) (insert (makefile-browser-format-macro-line (car item
) nil
) "\n")))
1111 (sort-lines nil
(point-min) (point-max))
1112 (goto-char (1- (point-max)))
1113 (delete-char 1) ; remove unnecessary newline at eob
1114 (goto-char (point-min))
1115 (forward-char makefile-browser-cursor-column
)))
1118 ;;; Moving up and down in the browser
1121 (defun makefile-browser-next-line ()
1122 "Move the browser selection cursor to the next line."
1124 (if (not (makefile-last-line-p))
1127 (forward-char makefile-browser-cursor-column
))))
1129 (defun makefile-browser-previous-line ()
1130 "Move the browser selection cursor to the previous line."
1132 (if (not (makefile-first-line-p))
1135 (forward-char makefile-browser-cursor-column
))))
1138 ;;; Quitting the browser (returns to client buffer)
1141 (defun makefile-browser-quit ()
1142 "Leave the browser and return to the makefile buffer."
1144 (let ((my-client makefile-browser-client
))
1145 (setq makefile-browser-client nil
) ; we quitted, so NO client!
1146 (set-buffer-modified-p nil
)
1148 (pop-to-buffer my-client
)))
1151 ;;; Toggle state of a browser item
1154 (defun makefile-browser-toggle ()
1155 "Toggle the selection state of the browser item at the cursor position."
1157 (let ((this-line (count-lines (point-min) (point))))
1158 (setq this-line
(max 1 this-line
))
1159 (makefile-browser-toggle-state-for-line this-line
)
1160 (goto-line this-line
)
1161 (let ((inhibit-read-only t
))
1163 (if (makefile-browser-on-macro-line-p)
1164 (let ((macro-name (makefile-browser-this-line-macro-name)))
1165 (delete-region (point) (progn (end-of-line) (point)))
1167 (makefile-browser-format-macro-line
1169 (makefile-browser-get-state-for-line this-line
))))
1170 (let ((target-name (makefile-browser-this-line-target-name)))
1171 (delete-region (point) (progn (end-of-line) (point)))
1173 (makefile-browser-format-target-line
1175 (makefile-browser-get-state-for-line this-line
))))))
1177 (forward-char makefile-browser-cursor-column
)
1178 (if makefile-browser-auto-advance-after-selection-p
1179 (makefile-browser-next-line))))
1182 ;;; Making insertions into the client buffer
1185 (defun makefile-browser-insert-continuation ()
1186 "Insert a makefile continuation.
1187 In the makefile buffer, go to (end-of-line), insert a \'\\\'
1188 character, insert a new blank line, go to that line and indent by one TAB.
1189 This is most useful in the process of creating continued lines when copying
1190 large dependencies from the browser to the client buffer.
1191 \(point) advances accordingly in the client buffer."
1194 (set-buffer makefile-browser-client
)
1198 (defun makefile-browser-insert-selection ()
1199 "Insert all selected targets and/or macros in the makefile buffer.
1200 Insertion takes place at point."
1204 (let ((current-line 1))
1206 (if (makefile-browser-get-state-for-line current-line
)
1207 (makefile-browser-send-this-line-item))
1209 (setq current-line
(1+ current-line
))))))
1211 (defun makefile-browser-insert-selection-and-quit ()
1213 (makefile-browser-insert-selection)
1214 (makefile-browser-quit))
1216 (defun makefile-browser-send-this-line-item ()
1217 (if (makefile-browser-on-macro-line-p)
1219 (let ((macro-name (makefile-browser-this-line-macro-name)))
1220 (set-buffer makefile-browser-client
)
1221 (insert (makefile-format-macro-ref macro-name
) " ")))
1223 (let ((target-name (makefile-browser-this-line-target-name)))
1224 (set-buffer makefile-browser-client
)
1225 (insert target-name
" ")))))
1227 (defun makefile-browser-start-interaction ()
1228 (use-local-map makefile-browser-map
)
1229 (setq buffer-read-only t
))
1231 (defun makefile-browse (targets macros
)
1233 (if (zerop (+ (length targets
) (length macros
)))
1236 (message "No macros or targets to browse! Consider running 'makefile-pickup-everything\'"))
1237 (let ((browser-buffer (get-buffer-create makefile-browser-buffer-name
)))
1238 (pop-to-buffer browser-buffer
)
1239 (make-variable-buffer-local 'makefile-browser-selection-vector
)
1240 (makefile-browser-fill targets macros
)
1241 (shrink-window-if-larger-than-buffer)
1242 (setq makefile-browser-selection-vector
1243 (make-vector (+ (length targets
) (length macros
)) nil
))
1244 (makefile-browser-start-interaction))))
1246 (defun makefile-switch-to-browser ()
1248 (run-hooks 'makefile-browser-hook
)
1249 (setq makefile-browser-client
(current-buffer))
1250 (makefile-pickup-targets)
1251 (makefile-pickup-macros)
1252 (makefile-browse makefile-target-table makefile-macro-table
))
1256 ;;; ------------------------------------------------------------
1257 ;;; Up-to-date overview buffer
1258 ;;; ------------------------------------------------------------
1260 (defun makefile-create-up-to-date-overview ()
1261 "Create a buffer containing an overview of the state of all known targets.
1262 Known targets are targets that are explicitly defined in that makefile;
1263 in other words, all targets that appear on the left hand side of a
1264 dependency in the makefile."
1266 (if (y-or-n-p "Are you sure that the makefile being edited is consistent? ")
1268 ;; The rest of this function operates on a temporary makefile, created by
1269 ;; writing the current contents of the makefile buffer.
1271 (let ((saved-target-table makefile-target-table
)
1272 (this-buffer (current-buffer))
1273 (makefile-up-to-date-buffer
1274 (get-buffer-create makefile-up-to-date-buffer-name
))
1275 (filename (makefile-save-temporary))
1277 ;; Forget the target table because it may contain picked-up filenames
1278 ;; that are not really targets in the current makefile.
1279 ;; We don't want to query these, so get a new target-table with just the
1280 ;; targets that can be found in the makefile buffer.
1281 ;; The 'old' target table will be restored later.
1283 (real-targets (progn
1284 (makefile-pickup-targets)
1285 makefile-target-table
))
1286 (prereqs makefile-has-prereqs
)
1289 (set-buffer makefile-up-to-date-buffer
)
1290 (setq buffer-read-only nil
)
1292 (makefile-query-targets filename real-targets prereqs
)
1293 (if (zerop (buffer-size)) ; if it did not get us anything
1295 (kill-buffer (current-buffer))
1296 (message "No overview created!")))
1297 (set-buffer this-buffer
)
1298 (setq makefile-target-table saved-target-table
)
1299 (if (get-buffer makefile-up-to-date-buffer-name
)
1301 (pop-to-buffer (get-buffer makefile-up-to-date-buffer-name
))
1302 (shrink-window-if-larger-than-buffer)
1303 (sort-lines nil
(point-min) (point-max))
1304 (setq buffer-read-only t
))))))
1306 (defun makefile-save-temporary ()
1307 "Create a temporary file from the current makefile buffer."
1308 (let ((filename (makefile-generate-temporary-filename)))
1309 (write-region (point-min) (point-max) filename nil
0)
1310 filename
)) ; return the filename
1312 (defun makefile-generate-temporary-filename ()
1313 "Create a filename suitable for use in `makefile-save-temporary'.
1314 Be careful to allow brain-dead file systems (DOS, SYSV ...) to cope
1315 with the generated name!"
1316 (let ((my-name (user-login-name))
1317 (my-uid (int-to-string (user-uid))))
1319 (if (> (length my-name
) 3)
1320 (substring my-name
0 3)
1323 (if (> (length my-uid
) 3)
1324 (substring my-uid
0 3)
1327 (defun makefile-query-targets (filename target-table prereq-list
)
1328 "Fill the up-to-date overview buffer.
1329 Checks each target in TARGET-TABLE using `makefile-query-one-target-method'
1330 and generates the overview, one line per target name."
1333 (function (lambda (item)
1334 (let* ((target-name (car item
))
1335 (no-prereqs (not (member target-name prereq-list
)))
1336 (needs-rebuild (or no-prereqs
1338 makefile-query-one-target-method
1343 (cond (no-prereqs " .. has no prerequisites")
1344 (needs-rebuild " .. NEEDS REBUILD")
1345 (t " .. is up to date"))))
1348 (goto-char (point-min))
1349 (delete-file filename
)) ; remove the tmpfile
1351 (defun makefile-query-by-make-minus-q (target &optional filename
)
1353 (call-process makefile-brave-make nil nil nil
1354 "-f" filename
"-q" target
))))
1358 ;;; ------------------------------------------------------------
1359 ;;; Continuation cleanup
1360 ;;; ------------------------------------------------------------
1362 (defun makefile-cleanup-continuations ()
1363 (if (eq major-mode
'makefile-mode
)
1364 (if (and makefile-cleanup-continuations-p
1365 (not buffer-read-only
))
1367 (goto-char (point-min))
1368 (while (re-search-forward "\\\\[ \t]+$" (point-max) t
)
1369 (replace-match "\\" t t
))))))
1372 ;;; ------------------------------------------------------------
1373 ;;; Warn of suspicious lines
1374 ;;; ------------------------------------------------------------
1376 (defun makefile-warn-suspicious-lines ()
1377 ;; Returning non-nil cancels the save operation
1378 (if (eq major-mode
'makefile-mode
)
1380 (goto-char (point-min))
1381 (if (re-search-forward "^\\(\t+$\\| +\t\\)" nil t
)
1383 (format "Suspicious line %d. Save anyway "
1384 (count-lines (point-min) (point)))))))))
1388 ;;; ------------------------------------------------------------
1389 ;;; GNU make function support
1390 ;;; ------------------------------------------------------------
1392 (defun makefile-insert-gmake-function ()
1393 "Insert a GNU make function call.
1394 Asks for the name of the function to use (with completion).
1395 Then prompts for all required parameters."
1397 (let* ((gm-function-name (completing-read
1399 makefile-gnumake-functions-alist
1401 (gm-function-prompts
1402 (cdr (assoc gm-function-name makefile-gnumake-functions-alist
))))
1403 (if (not (zerop (length gm-function-name
)))
1404 (insert (makefile-format-macro-ref
1405 (concat gm-function-name
" "
1406 (makefile-prompt-for-gmake-funargs
1407 gm-function-name gm-function-prompts
)))
1410 (defun makefile-prompt-for-gmake-funargs (function-name prompt-list
)
1412 (function (lambda (one-prompt)
1413 (read-string (format "[%s] %s: " function-name one-prompt
)
1420 ;;; ------------------------------------------------------------
1421 ;;; Utility functions
1422 ;;; ------------------------------------------------------------
1424 (defun makefile-do-macro-insertion (macro-name)
1425 "Insert a macro reference."
1426 (if (not (zerop (length macro-name
)))
1427 (if (assoc macro-name makefile-runtime-macros-list
)
1428 (insert "$" macro-name
)
1429 (insert (makefile-format-macro-ref macro-name
)))))
1431 (defun makefile-remember-target (target-name &optional has-prereqs
)
1432 "Remember a given target if it is not already remembered for this buffer."
1433 (if (not (zerop (length target-name
)))
1435 (if (not (assoc target-name makefile-target-table
))
1436 (setq makefile-target-table
1437 (cons (list target-name
) makefile-target-table
)))
1439 (setq makefile-has-prereqs
1440 (cons target-name makefile-has-prereqs
))))))
1442 (defun makefile-remember-macro (macro-name)
1443 "Remember a given macro if it is not already remembered for this buffer."
1444 (if (not (zerop (length macro-name
)))
1445 (if (not (assoc macro-name makefile-macro-table
))
1446 (setq makefile-macro-table
1447 (cons (list macro-name
) makefile-macro-table
)))))
1449 (defun makefile-forward-after-target-colon ()
1450 "Move point forward after inserting the terminating colon of a target.
1451 This acts according to the value of `makefile-tab-after-target-colon'."
1452 (if makefile-tab-after-target-colon
1456 (defun makefile-browser-on-macro-line-p ()
1457 "Determine if point is on a macro line in the browser."
1460 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t
)))
1462 (defun makefile-browser-this-line-target-name ()
1463 "Extract the target name from a line in the browser."
1466 (skip-chars-backward "^ \t")
1467 (buffer-substring (point) (1- (makefile-end-of-line-point)))))
1469 (defun makefile-browser-this-line-macro-name ()
1470 "Extract the macro name from a line in the browser."
1473 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t
)
1474 (let ((macro-start (point)))
1475 (skip-chars-forward "^})")
1476 (buffer-substring macro-start
(point)))))
1478 (defun makefile-format-macro-ref (macro-name)
1479 "Format a macro reference.
1480 Uses `makefile-use-curly-braces-for-macros-p'."
1481 (if (or (char-equal ?\
( (string-to-char macro-name
))
1482 (char-equal ?\
{ (string-to-char macro-name
)))
1483 (format "$%s" macro-name
)
1484 (if makefile-use-curly-braces-for-macros-p
1485 (format "${%s}" macro-name
)
1486 (format "$(%s)" macro-name
))))
1488 (defun makefile-browser-get-state-for-line (n)
1489 (aref makefile-browser-selection-vector
(1- n
)))
1491 (defun makefile-browser-set-state-for-line (n to-state
)
1492 (aset makefile-browser-selection-vector
(1- n
) to-state
))
1494 (defun makefile-browser-toggle-state-for-line (n)
1495 (makefile-browser-set-state-for-line n
(not (makefile-browser-get-state-for-line n
))))
1497 (defun makefile-beginning-of-line-point ()
1502 (defun makefile-end-of-line-point ()
1507 (defun makefile-last-line-p ()
1508 (= (makefile-end-of-line-point) (point-max)))
1510 (defun makefile-first-line-p ()
1511 (= (makefile-beginning-of-line-point) (point-min)))
1515 ;;; Support for other packages, like add-log.
1517 (defun makefile-add-log-defun ()
1518 "Return name of target or variable assignment that point is in.
1519 If it isn't in one, return nil."
1523 ;; Scan back line by line, noticing when we come to a
1524 ;; variable or rule definition, and giving up when we see
1525 ;; a line that is not part of either of those.
1528 ((looking-at makefile-macroassign-regex
)
1529 (setq found
(buffer-substring-no-properties (match-beginning 1)
1531 ((looking-at makefile-dependency-regex
)
1532 (setq found
(buffer-substring-no-properties (match-beginning 1)
1534 ;; Don't keep looking across a blank line or comment. Give up.
1535 ((looking-at "$\\|#")
1538 (setq found
'bobp
)))
1541 (if (stringp found
) found
))))
1543 ;;; make-mode.el ends here