Mercurial > emacs
annotate lisp/progmodes/make-mode.el @ 2318:50737ca2fd45
Decide automatically whether to use COFF or ELF.
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Mon, 22 Mar 1993 19:50:35 +0000 |
| parents | 10e417efb12a |
| children | 2cfd22aa6017 |
| rev | line source |
|---|---|
| 809 | 1 ;;; makefile.el --- makefile editing commands for Emacs |
| 2 | |
| 841 | 3 ;; Copyright (C) 1992 Free Software Foundation, Inc. |
| 4 | |
| 809 | 5 ;; Author: Thomas Neumann <tom@smart.bo.open.de> |
| 6 ;; Adapted-By: ESR | |
|
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
809
diff
changeset
|
7 ;; Keywords: unix, tools |
| 809 | 8 |
|
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
9 ;; $Id: makefile.el,v 1.3 1992/07/22 02:13:37 eric Exp eric $ |
| 809 | 10 |
| 11 ;; This file is part of GNU Emacs. | |
| 12 | |
| 13 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 14 ;; it under the terms of the GNU General Public License as published by | |
| 15 ;; the Free Software Foundation; either version 1, or (at your option) | |
| 16 ;; any later version. | |
| 17 | |
| 18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 ;; GNU General Public License for more details. | |
| 22 | |
| 23 ;; You should have received a copy of the GNU General Public License | |
| 24 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
| 25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 26 | |
|
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
27 ;;; Commentary: |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
28 |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
29 ;; A major mode for editing Makefiles. Hairy. Needs more documentation. |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
30 ;; If you get familiar with it, please write some and send it to the GNU |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
31 ;; Emacs maintainers. |
|
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
841
diff
changeset
|
32 |
| 809 | 33 ;;; Code: |
| 34 | |
| 35 (provide 'makefile) | |
| 36 | |
| 37 ;;; ------------------------------------------------------------ | |
| 38 ;;; Configureable stuff | |
| 39 ;;; ------------------------------------------------------------ | |
| 40 | |
| 41 (defvar makefile-mode-name "makefile" | |
| 42 "The \"pretty name\" of makefile-mode, as it | |
| 43 appears in the modeline.") | |
| 44 | |
| 45 (defvar makefile-browser-buffer-name "*Macros and Targets*" | |
| 46 "Name of the macro- and target browser buffer.") | |
| 47 | |
| 48 (defvar makefile-target-colon ":" | |
| 49 "The string that gets appended to all target names | |
| 50 inserted by makefile-insert-target. | |
| 51 \":\" or \"::\" are quite common values.") | |
| 52 | |
| 53 (defvar makefile-macro-assign " = " | |
| 54 "The string that gets appended to all macro names | |
| 55 inserted by makefile-insert-macro. | |
| 56 The normal value should be \" = \", since this is what | |
| 57 standard make expects. However, newer makes such as dmake | |
| 58 allow a larger variety of different macro assignments, so you | |
| 59 might prefer to use \" += \" or \" := \" .") | |
| 60 | |
| 61 (defvar makefile-use-curly-braces-for-macros-p nil | |
| 62 "Set this variable to a non-nil value if you prefer curly braces | |
| 63 in macro-references, so it looks like ${this}. A value of nil | |
| 64 will cause makefile-mode to use parantheses, making macro references | |
| 65 look like $(this) .") | |
| 66 | |
| 67 (defvar makefile-tab-after-target-colon t | |
| 68 "If you want a TAB (instead of a space) to be appended after the | |
| 69 target colon, then set this to a non-nil value.") | |
| 70 | |
| 71 (defvar makefile-browser-leftmost-column 10 | |
| 72 "Number of blanks to the left of the browser selection mark.") | |
| 73 | |
| 74 (defvar makefile-browser-cursor-column 10 | |
| 75 "Column in which the cursor is positioned when it moves | |
| 76 up or down in the browser.") | |
| 77 | |
| 78 (defvar makefile-browser-selected-mark "+ " | |
| 79 "String used to mark selected entries in the browser.") | |
| 80 | |
| 81 (defvar makefile-browser-unselected-mark " " | |
| 82 "String used to mark unselected entries in the browser.") | |
| 83 | |
| 84 (defvar makefile-browser-auto-advance-after-selection-p t | |
| 85 "If this variable is set to a non-nil value the cursor | |
| 86 will automagically advance to the next line after an item | |
| 87 has been selected in the browser.") | |
| 88 | |
| 89 (defvar makefile-find-file-autopickup-p t | |
| 90 "If this variable is set to a non-nil value then finding a file in | |
| 91 a makefile-mode buffer will cause an automatic initial pickup of | |
| 92 all macros and targets from the found file.") | |
| 93 | |
| 94 (defvar makefile-pickup-everything-picks-up-filenames-p nil | |
| 95 "If this variable is set to a non-nil value then | |
| 96 makefile-pickup-everything also picks up filenames as targets | |
| 97 (i.e. it calls makefile-find-filenames-as-targets), otherwise | |
| 98 filenames are omitted.") | |
| 99 | |
| 100 (defvar makefile-cleanup-continuations-p t | |
| 101 "If this variable is set to a non-nil value then makefile-mode | |
| 102 will assure that no line in the file ends with a backslash | |
| 103 (the continuation character) followed by any whitespace. | |
| 104 This is done by silently removing the trailing whitespace, leaving | |
| 105 the backslash itself intact. | |
| 106 IMPORTANT: Please note that enabling this option causes makefile-mode | |
| 107 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \'it seems necessary\'.") | |
| 108 | |
| 109 (defvar makefile-browser-hook '() | |
| 110 "A function or list of functions to be called just before the | |
| 111 browser is entered. This is executed in the makefile buffer, so | |
| 112 you can for example run a makefile-pickup-everything automatically.") | |
| 113 | |
| 114 ;; | |
| 115 ;; Special targets for DMake, Sun's make ... | |
| 116 ;; | |
| 117 (defvar makefile-special-targets-list | |
| 118 '(("DEFAULT") ("DONE") ("ERROR") ("EXPORT") | |
| 119 ("FAILED") ("GROUPEPILOG") ("GROUPPROLOG") ("IGNORE") | |
| 120 ("IMPORT") ("INCLUDE") ("INCLUDEDIRS") ("INIT") | |
| 121 ("KEEP_STATE") ("MAKEFILES") ("MAKE_VERSION") ("NO_PARALLEL") | |
| 122 ("PARALLEL") ("PHONY") ("PRECIOUS") ("REMOVE") | |
| 123 ("SCCS_GET") ("SILENT") ("SOURCE") ("SUFFIXES") | |
| 124 ("WAIT") ("c.o") ("C.o") ("m.o") | |
| 125 ("el.elc") ("y.c") ("s.o")) | |
| 126 "List of special targets. You will be offered to complete | |
| 127 on one of those in the minibuffer whenever you enter a \".\" | |
| 128 at the beginning of a line in makefile-mode.") | |
| 129 | |
| 130 (defvar makefile-runtime-macros-list | |
| 131 '(("@") ("&") (">") ("<") ("*") ("^") ("?") ("%")) | |
| 132 "List of macros that are resolved by make at runtime. | |
| 133 If you insert a macro reference using makefile-insert-macro-ref, the name | |
| 134 of the macro is checked against this list. If it can be found its name will | |
| 135 not be enclosed in { } or ( ).") | |
| 136 | |
| 137 (defconst makefile-dependency-regex | |
| 138 "^[^ \t#:]+\\([ \t]+[^ \t#:]+\\)*[ \t]*:\\($\\|\\([^=].*$\\)\\)" | |
| 139 "Regex used to find dependency lines in a makefile.") | |
| 140 | |
| 141 (defconst makefile-macroassign-regex | |
| 142 "^[^ \t][^:#=]*[\\*:\\+]?:?=.*$" | |
| 143 "Regex used to find macro assignment lines in a makefile.") | |
| 144 | |
| 145 (defconst makefile-ignored-files-in-pickup-regex | |
| 146 "\\(^\\..*\\)\\|\\(.*~$\\)\\|\\(.*,v$\\)" | |
| 147 "Regex for filenames that will NOT be included in the target list.") | |
| 148 | |
| 149 ;;; ------------------------------------------------------------ | |
| 150 ;;; The following configurable variables are used in the | |
| 151 ;;; up-to-date overview . | |
| 152 ;;; The standard configuration assumes that your `make' programm | |
| 153 ;;; can be run in question/query mode using the `-q' option, this | |
| 154 ;;; means that the command | |
| 155 ;;; | |
| 156 ;;; make -q foo | |
| 157 ;;; | |
| 158 ;;; should return an exit status of zero if the target `foo' is | |
| 159 ;;; up to date and a nonzero exit status otherwise. | |
| 160 ;;; Many makes can do this although the docs/manpages do not mention | |
| 161 ;;; it. Try it with your favourite one. GNU make and Dennis Vaduras | |
| 162 ;;; DMake have no problems. | |
| 163 ;;; Set the variable `makefile-brave-make' to the name of the | |
| 164 ;;; make utility that does this on your system. | |
| 165 ;;; To understand what this is all about see the function defintion | |
| 166 ;;; of `makefile-query-by-make-minus-q' . | |
| 167 ;;; ------------------------------------------------------------ | |
| 168 | |
| 169 (defvar makefile-brave-make "gmake" | |
| 170 "A make that can handle the \'-q\' option.") | |
| 171 | |
| 172 (defvar makefile-query-one-target-method 'makefile-query-by-make-minus-q | |
| 173 "A function symbol [one that can be used as the first argument to | |
| 174 funcall] that provides a function that must conform to the following | |
| 175 interface: | |
| 176 | |
| 177 * As its first argument, it must accept the name of the target to | |
| 178 be checked, as a string. | |
| 179 | |
| 180 * As its second argument, it may accept the name of a makefile | |
| 181 as a string. Depending on what you\'re going to do you may | |
| 182 not need this. | |
| 183 | |
| 184 * It must return the integer value 0 (zero) if the given target | |
| 185 should be considered up-to-date in the context of the given | |
| 186 makefile, any nonzero integer value otherwise.") | |
| 187 | |
| 188 (defvar makefile-up-to-date-buffer-name "*Makefile Up-to-date overview*" | |
| 189 "Name of the Up-to-date overview buffer.") | |
| 190 | |
| 191 (defvar makefile-target-needs-rebuild-mark " .. NEEDS REBUILD" | |
| 192 "A string that is appended to the target name in the up-to-date | |
| 193 overview if that target is considered to require a rebuild.") | |
| 194 | |
| 195 (defvar makefile-target-up-to-date-mark " .. is up to date" | |
| 196 "A string that is appenden to the target name in the up-to-date | |
| 197 overview if that target is considered up-to-date.") | |
| 198 | |
| 199 ;;; --- end of up-to-date-overview configuration ------------------ | |
| 200 | |
| 201 | |
| 202 (defvar makefile-mode-map nil | |
| 203 "The keymap that is used in makefile-mode.") | |
| 204 (if makefile-mode-map | |
| 205 () | |
| 206 (setq makefile-mode-map (make-sparse-keymap)) | |
| 207 ;; set up the keymap | |
| 208 (define-key makefile-mode-map "$" 'makefile-insert-macro-ref) | |
| 209 (define-key makefile-mode-map "\C-c:" 'makefile-insert-target-ref) | |
| 210 (define-key makefile-mode-map ":" 'makefile-electric-colon) | |
| 211 (define-key makefile-mode-map "=" 'makefile-electric-equal) | |
| 212 (define-key makefile-mode-map "." 'makefile-electric-dot) | |
| 213 (define-key makefile-mode-map "\C-c\C-t" 'makefile-pickup-targets) | |
| 214 (define-key makefile-mode-map "\C-c\C-m" 'makefile-pickup-macros) | |
| 215 (define-key makefile-mode-map "\C-c\C-f" 'makefile-pickup-filenames-as-targets) | |
| 216 (define-key makefile-mode-map "\C-c\C-0" 'makefile-forget-everything) | |
| 217 (define-key makefile-mode-map "\C-c0" 'makefile-forget-everything) | |
| 218 (define-key makefile-mode-map "\C-c\C-b" 'makefile-switch-to-browser) | |
| 219 (define-key makefile-mode-map "\C-c\C-p" 'makefile-pickup-everything) | |
| 220 (define-key makefile-mode-map "\C-c\C-u" 'makefile-create-up-to-date-overview) | |
| 221 (define-key makefile-mode-map "\C-c\C-i" 'makefile-insert-gmake-function) | |
| 222 (define-key makefile-mode-map "\M-p" 'makefile-previous-dependency) | |
| 223 (define-key makefile-mode-map "\M-n" 'makefile-next-dependency)) | |
| 224 | |
| 225 (defvar makefile-browser-map nil | |
| 226 "The keymap that is used in the macro- and target browser.") | |
| 227 (if makefile-browser-map | |
| 228 () | |
| 229 (setq makefile-browser-map (make-sparse-keymap)) | |
| 230 (define-key makefile-browser-map "n" 'makefile-browser-next-line) | |
| 231 (define-key makefile-browser-map "\C-n" 'makefile-browser-next-line) | |
| 232 (define-key makefile-browser-map "p" 'makefile-browser-previous-line) | |
| 233 (define-key makefile-browser-map "\C-p" 'makefile-browser-previous-line) | |
| 234 (define-key makefile-browser-map " " 'makefile-browser-toggle) | |
| 235 (define-key makefile-browser-map "i" 'makefile-browser-insert-selection) | |
| 236 (define-key makefile-browser-map "I" 'makefile-browser-insert-selection-and-quit) | |
| 237 (define-key makefile-browser-map "\C-c\C-m" 'makefile-browser-insert-continuation) | |
| 238 (define-key makefile-browser-map "q" 'makefile-browser-quit) | |
| 239 ;; disable horizontal movement | |
| 240 (define-key makefile-browser-map "\C-b" 'undefined) | |
| 241 (define-key makefile-browser-map "\C-f" 'undefined)) | |
| 242 | |
| 243 | |
| 244 (defvar makefile-mode-syntax-table nil | |
| 245 "The syntax-table used in makefile mode.") | |
| 246 (if makefile-mode-syntax-table | |
| 247 () | |
| 248 (setq makefile-mode-syntax-table (make-syntax-table)) | |
| 249 (modify-syntax-entry ?\( "() " makefile-mode-syntax-table) | |
| 250 (modify-syntax-entry ?\) ")( " makefile-mode-syntax-table) | |
| 251 (modify-syntax-entry ?\[ "(] " makefile-mode-syntax-table) | |
| 252 (modify-syntax-entry ?\] "([ " makefile-mode-syntax-table) | |
| 253 (modify-syntax-entry ?\{ "(} " makefile-mode-syntax-table) | |
| 254 (modify-syntax-entry ?\} "){ " makefile-mode-syntax-table) | |
| 255 (modify-syntax-entry ?# "< " makefile-mode-syntax-table) | |
| 256 (modify-syntax-entry ?\n "> " makefile-mode-syntax-table)) | |
| 257 | |
| 258 | |
| 259 ;;; ------------------------------------------------------------ | |
| 260 ;;; Internal variables. | |
| 261 ;;; You don't need to configure below this line. | |
| 262 ;;; ------------------------------------------------------------ | |
| 263 | |
| 264 (defvar makefile-target-table nil | |
| 265 "Table of all targets that have been inserted in | |
| 266 this Makefile buffer using makefile-insert-target or picked up | |
| 267 using makefile-pickup-targets.") | |
| 268 | |
| 269 (defvar makefile-macro-table nil | |
| 270 "Table of all macros that have been iserted in | |
| 271 this Makefile buffer using makefile-insert-macro or picked up | |
| 272 using makefile-pickup-macros.") | |
| 273 | |
| 274 (defvar makefile-browser-client | |
| 275 "A buffer in makefile-mode that is currently using the browser.") | |
| 276 | |
| 277 (defvar makefile-browser-selection-vector nil) | |
| 278 | |
| 279 (defvar makefile-mode-hook '()) | |
| 280 | |
| 281 (defconst makefile-gnumake-functions-alist | |
| 282 | |
| 283 '( | |
| 284 ;; Text functions | |
| 285 ("subst" "From" "To" "In") | |
| 286 ("patsubst" "Pattern" "Replacement" "In") | |
| 287 ("strip" "Text") | |
| 288 ("findstring" "Find what" "In") | |
| 289 ("filter" "Pattern" "Text") | |
| 290 ("filter-out" "Pattern" "Text") | |
| 291 ("sort" "List") | |
| 292 ;; Filename functions | |
| 293 ("dir" "Names") | |
| 294 ("notdir" "Names") | |
| 295 ("suffix" "Names") | |
| 296 ("basename" "Names") | |
| 297 ("addsuffix" "Suffix" "Names") | |
| 298 ("join" "List 1" "List 2") | |
| 299 ("word" "Index" "Text") | |
| 300 ("words" "Text") | |
| 301 ("firstword" "Text") | |
| 302 ("wildcard" "Pattern") | |
| 303 ;; Misc functions | |
| 304 ("foreach" "Variable" "List" "Text") | |
| 305 ("origin" "Variable") | |
| 306 ("shell" "Command")) | |
| 307 "A list of GNU make 3.62 function names associated with | |
| 308 the prompts for each function. | |
| 309 This is used in the function makefile-insert-gmake-function .") | |
| 310 | |
| 311 | |
| 312 ;;; ------------------------------------------------------------ | |
| 313 ;;; The mode function itself. | |
| 314 ;;; ------------------------------------------------------------ | |
| 315 | |
| 316 (defun makefile-mode () | |
| 317 "Major mode for editing Makefiles. | |
| 318 Calling this function invokes the function(s) \"makefile-mode-hook\" before | |
| 319 doing anything else. | |
| 320 | |
| 321 \\{makefile-mode-map} | |
| 322 | |
| 323 In the browser, use the following keys: | |
| 324 | |
| 325 \\{makefile-browser-map} | |
| 326 | |
| 327 makefile-mode can be configured by modifying the following | |
| 328 variables: | |
| 329 | |
| 330 makefile-mode-name: | |
| 331 The \"pretty name\" of makefile-mode, as it | |
| 332 appears in the modeline. | |
| 333 | |
| 334 makefile-browser-buffer-name: | |
| 335 Name of the macro- and target browser buffer. | |
| 336 | |
| 337 makefile-target-colon: | |
| 338 The string that gets appended to all target names | |
| 339 inserted by makefile-insert-target. | |
| 340 \":\" or \"::\" are quite common values. | |
| 341 | |
| 342 makefile-macro-assign: | |
| 343 The string that gets appended to all macro names | |
| 344 inserted by makefile-insert-macro. | |
| 345 The normal value should be \" = \", since this is what | |
| 346 standard make expects. However, newer makes such as dmake | |
| 347 allow a larger variety of different macro assignments, so you | |
| 348 might prefer to use \" += \" or \" := \" . | |
| 349 | |
| 350 makefile-tab-after-target-colon: | |
| 351 If you want a TAB (instead of a space) to be appended after the | |
| 352 target colon, then set this to a non-nil value. | |
| 353 | |
| 354 makefile-browser-leftmost-column: | |
| 355 Number of blanks to the left of the browser selection mark. | |
| 356 | |
| 357 makefile-browser-cursor-column: | |
| 358 Column in which the cursor is positioned when it moves | |
| 359 up or down in the browser. | |
| 360 | |
| 361 makefile-browser-selected-mark: | |
| 362 String used to mark selected entries in the browser. | |
| 363 | |
| 364 makefile-browser-unselected-mark: | |
| 365 String used to mark unselected entries in the browser. | |
| 366 | |
| 367 makefile-browser-auto-advance-after-selection-p: | |
| 368 If this variable is set to a non-nil value the cursor | |
| 369 will automagically advance to the next line after an item | |
| 370 has been selected in the browser. | |
| 371 | |
| 372 makefile-find-file-autopickup-p: | |
| 373 If this variable is set to a non-nil value then finding a file in | |
| 374 a makefile-mode buffer will cause an automatic initial pickup of | |
| 375 all macros and targets from the found file. | |
| 376 | |
| 377 makefile-pickup-everything-picks-up-filenames-p: | |
| 378 If this variable is set to a non-nil value then | |
| 379 makefile-pickup-everything also picks up filenames as targets | |
| 380 (i.e. it calls makefile-find-filenames-as-targets), otherwise | |
| 381 filenames are omitted. | |
| 382 | |
| 383 makefile-cleanup-continuations-p: | |
| 384 If this variable is set to a non-nil value then makefile-mode | |
| 385 will assure that no line in the file ends with a backslash | |
| 386 (the continuation character) followed by any whitespace. | |
| 387 This is done by silently removing the trailing whitespace, leaving | |
| 388 the backslash itself intact. | |
| 389 IMPORTANT: Please note that enabling this option causes makefile-mode | |
| 390 to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \'it seems necessary\'. | |
| 391 | |
| 392 makefile-browser-hook: | |
| 393 A function or list of functions to be called just before the | |
| 394 browser is entered. This is executed in the makefile buffer, so | |
| 395 you can for example run a makefile-pickup-everything automatically. | |
| 396 | |
| 397 makefile-special-targets-list: | |
| 398 List of special targets. You will be offered to complete | |
| 399 on one of those in the minibuffer whenever you enter a \".\" | |
| 400 at the beginning of a line in makefile-mode." | |
| 401 (interactive) | |
| 402 (kill-all-local-variables) | |
| 403 (if (not (memq 'makefile-find-file-autopickup find-file-hooks)) | |
| 404 (setq find-file-hooks | |
| 405 (append find-file-hooks (list 'makefile-find-file-autopickup)))) | |
| 406 (if (not (memq 'makefile-cleanup-continuations write-file-hooks)) | |
| 407 (setq write-file-hooks | |
| 408 (append write-file-hooks (list 'makefile-cleanup-continuations)))) | |
| 409 (make-variable-buffer-local 'makefile-target-table) | |
| 410 (make-variable-buffer-local 'makefile-macro-table) | |
| 411 (makefile-forget-all-macros) | |
| 412 (makefile-forget-all-targets) | |
| 413 (setq comment-start "#") | |
| 414 (setq comment-end "") | |
| 415 (setq comment-start-skip "#[ \t]*") | |
| 416 ;; become the current major mode | |
| 417 (setq major-mode 'makefile-mode) | |
| 418 (setq mode-name makefile-mode-name) | |
| 419 ;; activate keymap | |
| 420 (use-local-map makefile-mode-map) | |
| 421 (set-syntax-table makefile-mode-syntax-table) | |
| 422 (run-hooks 'makefile-mode-hook)) | |
| 423 | |
| 424 | |
| 425 (defun makefile-find-file-autopickup () | |
| 426 (if (eq major-mode 'makefile-mode) | |
| 427 (if makefile-find-file-autopickup-p | |
| 428 (makefile-pickup-everything)))) | |
| 429 | |
| 430 (defun makefile-next-dependency () | |
| 431 "Move (point) to the beginning of the next dependency line | |
| 432 below the current position of (point)." | |
| 433 (interactive) | |
| 434 (let ((here (point))) | |
| 435 (end-of-line) | |
| 436 (if (re-search-forward makefile-dependency-regex (point-max) t) | |
| 437 (progn (beginning-of-line) t) ; indicate success | |
| 438 (goto-char here) nil))) | |
| 439 | |
| 440 (defun makefile-previous-dependency () | |
| 441 "Move (point) to the beginning of the next dependency line | |
| 442 above the current position of (point)." | |
| 443 (interactive) | |
| 444 (let ((here (point))) | |
| 445 (beginning-of-line) | |
| 446 (if (re-search-backward makefile-dependency-regex (point-min) t) | |
| 447 (progn (beginning-of-line) t) ; indicate success | |
| 448 (goto-char here) nil))) | |
| 449 | |
| 450 | |
| 451 (defun makefile-electric-dot () | |
| 452 "At (bol), offer completion on makefile-special-targets-list. | |
| 453 Anywhere else just insert a dot." | |
| 454 (interactive) | |
| 455 (if (bolp) | |
| 456 (makefile-insert-special-target) | |
| 457 (insert "."))) | |
| 458 | |
| 459 | |
| 460 (defun makefile-insert-special-target () | |
| 461 "Offer completion on makefile-special-targets-list and insert | |
| 462 the result at (point)." | |
| 463 (interactive) | |
| 464 (let | |
| 465 ((special-target | |
| 466 (completing-read "Special target: " | |
| 467 makefile-special-targets-list nil nil nil))) | |
| 468 (if (zerop (length special-target)) | |
| 469 () | |
| 470 (insert (format ".%s:" special-target)) | |
| 471 (makefile-forward-after-target-colon)))) | |
| 472 | |
| 473 | |
| 474 (defun makefile-electric-equal () | |
| 475 "At (bol) do makefile-insert-macro. Anywhere else just | |
| 476 self-insert." | |
| 477 (interactive) | |
| 478 (if (bolp) | |
| 479 (call-interactively 'makefile-insert-macro) | |
| 480 (insert "="))) | |
| 481 | |
| 482 (defun makefile-insert-macro (macro-name) | |
| 483 "Prepare definition of a new macro." | |
| 484 (interactive "sMacro Name: ") | |
| 485 (if (not (zerop (length macro-name))) | |
| 486 (progn | |
| 487 (beginning-of-line) | |
| 488 (insert (format "%s%s" macro-name makefile-macro-assign)) | |
| 489 (makefile-remember-macro macro-name)))) | |
| 490 | |
| 491 | |
| 492 (defun makefile-insert-macro-ref (macro-name) | |
| 493 "Offer completion on a list of known macros, then | |
| 494 insert complete macro-ref at (point) ." | |
| 495 (interactive | |
| 496 (list | |
| 497 (completing-read "Refer to macro: " makefile-macro-table nil nil nil))) | |
| 498 (if (not (zerop (length macro-name))) | |
| 499 (if (assoc macro-name makefile-runtime-macros-list) | |
| 500 (insert (format "$%s " macro-name)) | |
| 501 (insert (makefile-format-macro-ref macro-name) " ")))) | |
| 502 | |
| 503 | |
| 504 (defun makefile-insert-target (target-name) | |
| 505 "Prepare definition of a new target (dependency line)." | |
| 506 (interactive "sTarget: ") | |
| 507 (if (not (zerop (length target-name))) | |
| 508 (progn | |
| 509 (beginning-of-line) | |
| 510 (insert (format "%s%s" target-name makefile-target-colon)) | |
| 511 (makefile-forward-after-target-colon) | |
| 512 (end-of-line) | |
| 513 (makefile-remember-target target-name)))) | |
| 514 | |
| 515 | |
| 516 (defun makefile-insert-target-ref (target-name) | |
| 517 "Offer completion on a list of known targets, then | |
| 518 insert complete target-ref at (point) ." | |
| 519 (interactive | |
| 520 (list | |
| 521 (completing-read "Refer to target: " makefile-target-table nil nil nil))) | |
| 522 (if (not (zerop (length target-name))) | |
| 523 (progn | |
| 524 (insert (format "%s " target-name))))) | |
| 525 | |
| 526 (defun makefile-electric-colon () | |
| 527 "At (bol) defines a new target, anywhere else just self-insert ." | |
| 528 (interactive) | |
| 529 (if (bolp) | |
| 530 (call-interactively 'makefile-insert-target) | |
| 531 (insert ":"))) | |
| 532 | |
| 533 | |
| 534 ;;; ------------------------------------------------------------ | |
| 535 ;;; Extracting targets and macros from an existing makefile | |
| 536 ;;; ------------------------------------------------------------ | |
| 537 | |
| 538 (defun makefile-pickup-targets () | |
| 539 "Scan a buffer that contains a makefile for target definitions (dependencies) | |
| 540 and add them to the list of known targets." | |
| 541 (interactive) | |
| 542 (save-excursion | |
| 543 (goto-char (point-min)) | |
| 544 (while (re-search-forward makefile-dependency-regex (point-max) t) | |
| 545 (makefile-add-this-line-targets)))) | |
| 546 ; (forward-line 1)))) | |
| 547 | |
| 548 (defun makefile-add-this-line-targets () | |
| 549 (save-excursion | |
| 550 (beginning-of-line) | |
| 551 (let ((done-with-line nil)) | |
| 552 (while (not done-with-line) | |
| 553 (skip-chars-forward " \t") | |
| 554 (if (not (setq done-with-line (or (eolp) | |
| 555 (char-equal (char-after (point)) ?:)))) | |
| 556 (progn | |
| 557 (let* ((start-of-target-name (point)) | |
| 558 (target-name | |
| 559 (progn | |
| 560 (skip-chars-forward "^ \t:#") | |
| 561 (buffer-substring start-of-target-name (point))))) | |
| 562 (if (makefile-remember-target target-name) | |
| 563 (message "Picked up target \"%s\"" target-name))))))))) | |
| 564 | |
| 565 | |
| 566 (defun makefile-pickup-macros () | |
| 567 "Scan a buffer that contains a makefile for macro definitions | |
| 568 and add them to the list of known macros." | |
| 569 (interactive) | |
| 570 (save-excursion | |
| 571 (goto-char (point-min)) | |
| 572 (while (re-search-forward makefile-macroassign-regex (point-max) t) | |
| 573 (makefile-add-this-line-macro) | |
| 574 (forward-line 1)))) | |
| 575 | |
| 576 (defun makefile-add-this-line-macro () | |
| 577 (save-excursion | |
| 578 (beginning-of-line) | |
| 579 (skip-chars-forward " \t") | |
| 580 (if (not (eolp)) | |
| 581 (let* ((start-of-macro-name (point)) | |
| 582 (macro-name (progn | |
| 583 (skip-chars-forward "^ \t:#=*") | |
| 584 (buffer-substring start-of-macro-name (point))))) | |
| 585 (if (makefile-remember-macro macro-name) | |
| 586 (message "Picked up macro \"%s\"" macro-name)))))) | |
| 587 | |
| 588 | |
| 589 (defun makefile-pickup-everything () | |
| 590 "Calls makefile-pickup-targets and makefile-pickup-macros. | |
| 591 See their documentation for what they do." | |
| 592 (interactive) | |
| 593 (makefile-pickup-macros) | |
| 594 (makefile-pickup-targets) | |
| 595 (if makefile-pickup-everything-picks-up-filenames-p | |
| 596 (makefile-pickup-filenames-as-targets))) | |
| 597 | |
| 598 | |
| 599 (defun makefile-pickup-filenames-as-targets () | |
| 600 "Scan the current directory for filenames, check each filename | |
| 601 against makefile-ignored-files-in-pickup-regex and add all qualifying | |
| 602 names to the list of known targets." | |
| 603 (interactive) | |
| 604 (let* ((dir (file-name-directory (buffer-file-name))) | |
| 605 (raw-filename-list (if dir | |
| 606 (file-name-all-completions "" dir) | |
| 607 (file-name-all-completions "" "")))) | |
| 608 (mapcar '(lambda (name) | |
| 609 (if (and (not (file-directory-p name)) | |
| 610 (not (string-match makefile-ignored-files-in-pickup-regex | |
| 611 name))) | |
| 612 (if (makefile-remember-target name) | |
| 613 (message "Picked up file \"%s\" as target" name)))) | |
| 614 raw-filename-list))) | |
| 615 | |
| 616 ;;; ------------------------------------------------------------ | |
| 617 ;;; The browser window | |
| 618 ;;; ------------------------------------------------------------ | |
| 619 | |
| 620 | |
| 621 (defun makefile-browser-format-target-line (target selected) | |
| 622 (format | |
| 623 (concat (make-string makefile-browser-leftmost-column ?\ ) | |
| 624 (if selected | |
| 625 makefile-browser-selected-mark | |
| 626 makefile-browser-unselected-mark) | |
| 627 "%s%s") | |
| 628 target makefile-target-colon)) | |
| 629 | |
| 630 (defun makefile-browser-format-macro-line (macro selected) | |
| 631 (format | |
| 632 (concat (make-string makefile-browser-leftmost-column ?\ ) | |
| 633 (if selected | |
| 634 makefile-browser-selected-mark | |
| 635 makefile-browser-unselected-mark) | |
| 636 (makefile-format-macro-ref macro)))) | |
| 637 | |
| 638 (defun makefile-browser-fill (targets macros) | |
| 639 (setq buffer-read-only nil) | |
| 640 (goto-char (point-min)) | |
| 641 (erase-buffer) | |
| 642 (mapconcat | |
| 643 (function | |
| 644 (lambda (item) (insert (makefile-browser-format-target-line (car item) nil) "\n"))) | |
| 645 targets | |
| 646 "") | |
| 647 (mapconcat | |
| 648 (function | |
| 649 (lambda (item) (insert (makefile-browser-format-macro-line (car item) nil) "\n"))) | |
| 650 macros | |
| 651 "") | |
| 652 (sort-lines nil (point-min) (point-max)) | |
| 653 (goto-char (1- (point-max))) | |
| 654 (delete-char 1) ; remove unnecessary newline at eob | |
| 655 (goto-char (point-min)) | |
| 656 (forward-char makefile-browser-cursor-column) | |
| 657 (setq buffer-read-only t)) | |
| 658 | |
| 659 | |
| 660 ;;; | |
| 661 ;;; Moving up and down in the browser | |
| 662 ;;; | |
| 663 | |
| 664 (defun makefile-browser-next-line () | |
| 665 "Move the browser selection cursor to the next line." | |
| 666 (interactive) | |
| 667 (if (not (makefile-last-line-p)) | |
| 668 (progn | |
| 669 (forward-line 1) | |
| 670 (forward-char makefile-browser-cursor-column)))) | |
| 671 | |
| 672 (defun makefile-browser-previous-line () | |
| 673 "Move the browser selection cursor to the previous line." | |
| 674 (interactive) | |
| 675 (if (not (makefile-first-line-p)) | |
| 676 (progn | |
| 677 (forward-line -1) | |
| 678 (forward-char makefile-browser-cursor-column)))) | |
| 679 | |
| 680 ;;; | |
| 681 ;;; Quitting the browser (returns to client buffer) | |
| 682 ;;; | |
| 683 | |
| 684 (defun makefile-browser-quit () | |
| 685 "Leave the makefile-browser-buffer and return to the buffer | |
| 686 from that it has been entered." | |
| 687 (interactive) | |
| 688 (let ((my-client makefile-browser-client)) | |
| 689 (setq makefile-browser-client nil) ; we quitted, so NO client! | |
| 690 (set-buffer-modified-p nil) | |
| 691 (kill-buffer (current-buffer)) | |
| 692 (pop-to-buffer my-client))) | |
| 693 | |
| 694 ;;; | |
| 695 ;;; Toggle state of a browser item | |
| 696 ;;; | |
| 697 | |
| 698 (defun makefile-browser-toggle () | |
| 699 "Toggle the selection state of the browser item at the cursor position." | |
| 700 (interactive) | |
| 701 (let ((this-line (count-lines (point-min) (point)))) | |
| 702 (setq this-line (max 1 this-line)) | |
| 703 (makefile-browser-toggle-state-for-line this-line) | |
| 704 (goto-line this-line) | |
| 705 (setq buffer-read-only nil) | |
| 706 (beginning-of-line) | |
| 707 (if (makefile-browser-on-macro-line-p) | |
| 708 (let ((macro-name (makefile-browser-this-line-macro-name))) | |
| 709 (kill-line) | |
| 710 (insert | |
| 711 (makefile-browser-format-macro-line | |
| 712 macro-name | |
| 713 (makefile-browser-get-state-for-line this-line)))) | |
| 714 (let ((target-name (makefile-browser-this-line-target-name))) | |
| 715 (kill-line) | |
| 716 (insert | |
| 717 (makefile-browser-format-target-line | |
| 718 target-name | |
| 719 (makefile-browser-get-state-for-line this-line))))) | |
| 720 (setq buffer-read-only t) | |
| 721 (beginning-of-line) | |
| 722 (forward-char makefile-browser-cursor-column) | |
| 723 (if makefile-browser-auto-advance-after-selection-p | |
| 724 (makefile-browser-next-line)))) | |
| 725 | |
| 726 ;;; | |
| 727 ;;; Making insertions into the client buffer | |
| 728 ;;; | |
| 729 | |
| 730 (defun makefile-browser-insert-continuation () | |
| 731 "In the browser\'s client buffer, go to (end-of-line), insert a \'\\\' | |
| 732 character, insert a new blank line, go to that line and indent by one TAB. | |
| 733 This is most useful in the process of creating continued lines when 'sending' large | |
| 734 dependencies from the browser to the client buffer. | |
| 735 (point) advances accordingly in the client buffer." | |
| 736 (interactive) | |
| 737 (save-excursion | |
| 738 (set-buffer makefile-browser-client) | |
| 739 (end-of-line) | |
| 740 (insert "\\\n\t"))) | |
| 741 | |
| 742 (defun makefile-browser-insert-selection () | |
| 743 "Insert all browser-selected targets and/or macros in the browser\'s | |
| 744 client buffer. | |
| 745 Insertion takes place at (point)." | |
| 746 (interactive) | |
| 747 (save-excursion | |
| 748 (goto-line 1) | |
| 749 (let ((current-line 1)) | |
| 750 (while (not (eobp)) | |
| 751 (if (makefile-browser-get-state-for-line current-line) | |
| 752 (makefile-browser-send-this-line-item)) | |
| 753 (forward-line 1) | |
| 754 (setq current-line (1+ current-line)))))) | |
| 755 | |
| 756 (defun makefile-browser-insert-selection-and-quit () | |
| 757 (interactive) | |
| 758 (makefile-browser-insert-selection) | |
| 759 (makefile-browser-quit)) | |
| 760 | |
| 761 (defun makefile-browser-send-this-line-item () | |
| 762 (if (makefile-browser-on-macro-line-p) | |
| 763 (save-excursion | |
| 764 (let ((macro-name (makefile-browser-this-line-macro-name))) | |
| 765 (set-buffer makefile-browser-client) | |
| 766 (insert (makefile-format-macro-ref macro-name) " "))) | |
| 767 (save-excursion | |
| 768 (let ((target-name (makefile-browser-this-line-target-name))) | |
| 769 (set-buffer makefile-browser-client) | |
| 770 (insert target-name " "))))) | |
| 771 | |
| 772 | |
| 773 (defun makefile-browser-start-interaction () | |
| 774 (use-local-map makefile-browser-map) | |
| 775 (setq buffer-read-only t)) | |
| 776 | |
| 777 | |
| 778 (defun makefile-browse (targets macros) | |
| 779 (interactive) | |
| 780 (if (zerop (+ (length targets) (length macros))) | |
| 781 (progn | |
| 782 (beep) | |
| 783 (message "No macros or targets to browse! Consider running 'makefile-pickup-everything\'")) | |
| 784 (let ((browser-buffer (get-buffer-create makefile-browser-buffer-name))) | |
| 785 (pop-to-buffer browser-buffer) | |
| 786 (make-variable-buffer-local 'makefile-browser-selection-vector) | |
| 787 (makefile-browser-fill targets macros) | |
| 788 (setq makefile-browser-selection-vector | |
| 789 (make-vector (+ (length targets) (length macros)) nil)) | |
| 790 (makefile-browser-start-interaction)))) | |
| 791 | |
| 792 | |
| 793 (defun makefile-switch-to-browser () | |
| 794 (interactive) | |
| 795 (run-hooks 'makefile-browser-hook) | |
| 796 (setq makefile-browser-client (current-buffer)) | |
| 797 (makefile-browse makefile-target-table makefile-macro-table)) | |
| 798 | |
| 799 | |
| 800 ;;; ------------------------------------------------------------ | |
| 801 ;;; Up-to-date overview buffer | |
| 802 ;;; ------------------------------------------------------------ | |
| 803 | |
| 804 (defun makefile-create-up-to-date-overview () | |
| 805 "Create a buffer containing an overview of the state of all | |
| 806 known targets from the makefile that is currently being edited. | |
| 807 Known targets are targets that are explicitly defined in that makefile; | |
| 808 in other words, all targets that appear on the left hand side of a | |
| 809 dependency in the makefile." | |
| 810 (interactive) | |
| 811 (if (y-or-n-p "Are you sure that the makefile being edited is consistent? ") | |
| 812 ;; | |
| 813 ;; The rest of this function operates on a temporary makefile, created by | |
| 814 ;; writing the current contents of the makefile buffer. | |
| 815 ;; | |
| 816 (let ((saved-target-table makefile-target-table) | |
| 817 (this-buffer (current-buffer)) | |
| 818 (makefile-up-to-date-buffer | |
| 819 (get-buffer-create makefile-up-to-date-buffer-name)) | |
| 820 (filename (makefile-save-temporary)) | |
| 821 ;; | |
| 822 ;; Forget the target table because it may contain picked-up filenames | |
| 823 ;; that are not really targets in the current makefile. | |
| 824 ;; We don't want to query these, so get a new target-table with just the | |
| 825 ;; targets that can be found in the makefile buffer. | |
| 826 ;; The 'old' target table will be restored later. | |
| 827 ;; | |
| 828 (real-targets (progn | |
| 829 (makefile-forget-all-targets) | |
| 830 (makefile-pickup-targets) | |
| 831 makefile-target-table))) | |
| 832 | |
| 833 (set-buffer makefile-up-to-date-buffer) | |
| 834 (setq buffer-read-only nil) | |
| 835 (erase-buffer) | |
| 836 (makefile-query-targets filename real-targets) | |
| 837 (if (zerop (buffer-size)) ; if it did not get us anything | |
| 838 (progn | |
| 839 (kill-buffer (current-buffer)) | |
| 840 (message "No overview created!"))) | |
| 841 (set-buffer this-buffer) | |
| 842 (setq makefile-target-table saved-target-table) | |
| 843 (if (get-buffer makefile-up-to-date-buffer-name) | |
| 844 (progn | |
| 845 (pop-to-buffer (get-buffer makefile-up-to-date-buffer-name)) | |
| 846 (sort-lines nil (point-min) (point-max)) | |
| 847 (setq buffer-read-only t)))))) | |
| 848 | |
| 849 | |
| 850 | |
| 851 (defun makefile-save-temporary () | |
| 852 "Create a temporary file from the current makefile buffer." | |
| 853 (let ((filename (makefile-generate-temporary-filename))) | |
| 854 (write-region (point-min) (point-max) filename nil 0) | |
| 855 filename)) ; return the filename | |
| 856 | |
| 857 (defun makefile-generate-temporary-filename () | |
| 858 "Create a filename suitable for use in makefile-save-temporary. | |
| 859 Be careful to allow brain-dead file systems (DOS, SYSV ...) to cope | |
| 860 with the generated name !" | |
| 861 (let ((my-name (user-login-name)) | |
| 862 (my-uid (int-to-string (user-uid)))) | |
| 863 (concat "mktmp" | |
| 864 (if (> (length my-name) 3) | |
| 865 (substring my-name 0 3) | |
| 866 my-name) | |
| 867 "." | |
| 868 (if (> (length my-uid) 3) | |
| 869 (substring my-uid 0 3) | |
| 870 my-uid)))) | |
| 871 | |
| 872 (defun makefile-query-targets (filename target-table) | |
| 873 "This function fills the up-to-date-overview-buffer. | |
| 874 It checks each target in target-table using makefile-query-one-target-method | |
| 875 and generates the overview, one line per target name." | |
| 876 (insert | |
| 877 (mapconcat '(lambda (item) | |
| 878 (let ((target-name (car item))) | |
| 879 (makefile-format-up-to-date-buffer-entry | |
| 880 (funcall makefile-query-one-target-method | |
| 881 target-name filename) target-name))) | |
| 882 target-table "\n")) | |
| 883 (goto-char (point-min)) | |
| 884 (delete-file filename)) ; remove the tmpfile | |
| 885 | |
| 886 (defun makefile-query-by-make-minus-q (target &optional filename) | |
| 887 (not (zerop (call-process makefile-brave-make nil nil nil "-f" filename "-q" target)))) | |
| 888 | |
| 889 (defun makefile-format-up-to-date-buffer-entry (needs-rebuild target) | |
| 890 (format "\t%s%s" | |
| 891 target | |
| 892 (if needs-rebuild | |
| 893 makefile-target-needs-rebuild-mark | |
| 894 makefile-target-up-to-date-mark))) | |
| 895 | |
| 896 | |
| 897 ;;; ------------------------------------------------------------ | |
| 898 ;;; Continuation cleanup | |
| 899 ;;; ------------------------------------------------------------ | |
| 900 | |
| 901 (defun makefile-cleanup-continuations () | |
| 902 (if (eq major-mode 'makefile-mode) | |
| 903 (if (and makefile-cleanup-continuations-p | |
| 904 (not buffer-read-only)) | |
| 905 (save-excursion | |
| 906 (goto-char (point-min)) | |
| 907 (while (re-search-forward "\\\\[ \t]+$" (point-max) t) | |
| 908 (replace-match "\\" t t)))))) | |
| 909 | |
| 910 ;;; ------------------------------------------------------------ | |
| 911 ;;; GNU make function support | |
| 912 ;;; ------------------------------------------------------------ | |
| 913 | |
| 914 (defun makefile-insert-gmake-function () | |
| 915 "This function is intended to help you using the numerous | |
| 916 macro-like \'function calls\' of GNU make. | |
| 917 It will ask you for the name of the function you wish to | |
| 918 use (with completion), then, after you selected the function, | |
| 919 it will prompt you for all required parameters. | |
| 920 This function \'knows\' about the required parameters of every | |
| 921 GNU make function and will use meaningfull prompts for the | |
| 922 various args, making it much easier to take advantage of this | |
| 923 powerfull GNU make feature." | |
| 924 (interactive) | |
| 925 (let* ((gm-function-name (completing-read | |
| 926 "Function: " | |
| 927 makefile-gnumake-functions-alist | |
| 928 nil t nil)) | |
| 929 (gm-function-prompts | |
| 930 (cdr (assoc gm-function-name makefile-gnumake-functions-alist)))) | |
| 931 (if (not (zerop (length gm-function-name))) | |
| 932 (insert (makefile-format-macro-ref | |
| 933 (concat gm-function-name " " | |
| 934 (makefile-prompt-for-gmake-funargs | |
| 935 gm-function-name gm-function-prompts))) | |
| 936 " ")))) | |
| 937 | |
| 938 (defun makefile-prompt-for-gmake-funargs (function-name prompt-list) | |
| 939 (mapconcat | |
| 940 (function (lambda (one-prompt) | |
| 941 (read-string (format "[%s] %s: " function-name one-prompt) nil))) | |
| 942 prompt-list | |
| 943 ",")) | |
| 944 | |
| 945 | |
| 946 | |
| 947 ;;; ------------------------------------------------------------ | |
| 948 ;;; Utility functions | |
| 949 ;;; ------------------------------------------------------------ | |
| 950 | |
| 951 (defun makefile-forget-all-targets () | |
| 952 "Clear the target-table for this buffer." | |
| 953 (interactive) | |
| 954 (setq makefile-target-table '())) | |
| 955 | |
| 956 (defun makefile-forget-all-macros () | |
| 957 "Clear the macro-table for this buffer." | |
| 958 (interactive) | |
| 959 (setq makefile-macro-table '())) | |
| 960 | |
| 961 | |
| 962 (defun makefile-forget-everything () | |
| 963 "Clear the macro-table AND the target-table for this buffer." | |
| 964 (interactive) | |
| 965 (if (y-or-n-p "Really forget all macro- and target information ? ") | |
| 966 (progn | |
| 967 (makefile-forget-all-targets) | |
| 968 (makefile-forget-all-macros) | |
| 969 (if (get-buffer makefile-browser-buffer-name) | |
| 970 (kill-buffer makefile-browser-buffer-name)) | |
| 971 (message "Cleared macro- and target tables.")))) | |
| 972 | |
| 973 (defun makefile-remember-target (target-name) | |
| 974 "Remember a given target if it is not already remembered for this buffer." | |
| 975 (if (not (zerop (length target-name))) | |
| 976 (if (not (assoc target-name makefile-target-table)) | |
| 977 (setq makefile-target-table | |
| 978 (cons (list target-name) makefile-target-table))))) | |
| 979 | |
| 980 (defun makefile-remember-macro (macro-name) | |
| 981 "Remember a given macro if it is not already remembered for this buffer." | |
| 982 (if (not (zerop (length macro-name))) | |
| 983 (if (not (assoc macro-name makefile-macro-table)) | |
| 984 (setq makefile-macro-table | |
| 985 (cons (list macro-name) makefile-macro-table))))) | |
| 986 | |
| 987 (defun makefile-forward-after-target-colon () | |
| 988 "Move point forward after the terminating colon | |
| 989 of a target has been inserted. | |
| 990 This accts according to the value of makefile-tab-after-target-colon ." | |
| 991 (if makefile-tab-after-target-colon | |
| 992 (insert "\t") | |
| 993 (insert " "))) | |
| 994 | |
| 995 (defun makefile-browser-on-macro-line-p () | |
| 996 "Determine if point is on a macro line in the browser." | |
| 997 (save-excursion | |
| 998 (beginning-of-line) | |
| 999 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t))) | |
| 1000 | |
| 1001 (defun makefile-browser-this-line-target-name () | |
| 1002 "Extract the target name from a line in the browser." | |
| 1003 (save-excursion | |
| 1004 (end-of-line) | |
| 1005 (skip-chars-backward "^ \t") | |
| 1006 (buffer-substring (point) (1- (makefile-end-of-line-point))))) | |
| 1007 | |
| 1008 (defun makefile-browser-this-line-macro-name () | |
| 1009 "Extract the macro name from a line in the browser." | |
| 1010 (save-excursion | |
| 1011 (beginning-of-line) | |
| 1012 (re-search-forward "\\$[{(]" (makefile-end-of-line-point) t) | |
| 1013 (let ((macro-start (point))) | |
| 1014 (skip-chars-forward "^})") | |
| 1015 (buffer-substring macro-start (point))))) | |
| 1016 | |
| 1017 (defun makefile-format-macro-ref (macro-name) | |
| 1018 "Format a macro reference according to the value of the | |
| 1019 configuration variable makefile-use-curly-braces-for-macros-p ." | |
| 1020 (if makefile-use-curly-braces-for-macros-p | |
| 1021 (format "${%s}" macro-name) | |
| 1022 (format "$(%s)" macro-name))) | |
| 1023 | |
| 1024 (defun makefile-browser-get-state-for-line (n) | |
| 1025 (aref makefile-browser-selection-vector (1- n))) | |
| 1026 | |
| 1027 (defun makefile-browser-set-state-for-line (n to-state) | |
| 1028 (aset makefile-browser-selection-vector (1- n) to-state)) | |
| 1029 | |
| 1030 (defun makefile-browser-toggle-state-for-line (n) | |
| 1031 (makefile-browser-set-state-for-line n (not (makefile-browser-get-state-for-line n)))) | |
| 1032 | |
| 1033 (defun makefile-beginning-of-line-point () | |
| 1034 (save-excursion | |
| 1035 (beginning-of-line) | |
| 1036 (point))) | |
| 1037 | |
| 1038 (defun makefile-end-of-line-point () | |
| 1039 (save-excursion | |
| 1040 (end-of-line) | |
| 1041 (point))) | |
| 1042 | |
| 1043 (defun makefile-last-line-p () | |
| 1044 (= (makefile-end-of-line-point) (point-max))) | |
| 1045 | |
| 1046 (defun makefile-first-line-p () | |
| 1047 (= (makefile-beginning-of-line-point) (point-min))) | |
| 1048 | |
| 1049 ;; makefile.el ends here |
