comparison lisp/modes/make-mode.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children 9ee227acff29
comparison
equal deleted inserted replaced
1:c0c6a60d29db 2:ac2d302a0011
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 ;; General Public License for more details. 25 ;; General Public License for more details.
26 26
27 ;; You should have received a copy of the GNU General Public License 27 ;; You should have received a copy of the GNU General Public License
28 ;; along with XEmacs; see the file COPYING. If not, write to the Free 28 ;; along with XEmacs; see the file COPYING. If not, write to the Free
29 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 29 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
30 30 ;; 02111-1307, USA.
31 ;;; Synched up with: FSF 19.30. 31
32 ;;; Synched up with: FSF 19.34.
32 33
33 ;;; Commentary: 34 ;;; Commentary:
34 35
35 ;; A major mode for editing makefiles. The mode knows about Makefile 36 ;; 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. 37 ;; syntax and defines M-n and M-p to move to next and previous productions.
91 ;;; Code: 92 ;;; Code:
92 93
93 (provide 'makefile) 94 (provide 'makefile)
94 95
95 ;; Sadly we need this for a macro. 96 ;; Sadly we need this for a macro.
96 ;(eval-when-compile 97 (eval-when-compile
97 ; (require 'imenu)) 98 (require 'imenu))
98 99
99 ;;; ------------------------------------------------------------ 100 ;;; ------------------------------------------------------------
100 ;;; Configurable stuff 101 ;;; Configurable stuff
101 ;;; ------------------------------------------------------------ 102 ;;; ------------------------------------------------------------
102 103
177 "List of special targets. 178 "List of special targets.
178 You will be offered to complete on one of those in the minibuffer whenever 179 You will be offered to complete on one of those in the minibuffer whenever
179 you enter a \".\" at the beginning of a line in makefile-mode.") 180 you enter a \".\" at the beginning of a line in makefile-mode.")
180 181
181 (defvar makefile-runtime-macros-list 182 (defvar makefile-runtime-macros-list
182 '(("@") ("&") (">") ("<") ("*") ("^") ("?") ("%") ("$")) 183 '(("@") ("&") (">") ("<") ("*") ("^") ("+") ("?") ("%") ("$"))
183 "List of macros that are resolved by make at runtime. 184 "List of macros that are resolved by make at runtime.
184 If you insert a macro reference using makefile-insert-macro-ref, the name 185 If you insert a macro reference using makefile-insert-macro-ref, the name
185 of the macro is checked against this list. If it can be found its name will 186 of the macro is checked against this list. If it can be found its name will
186 not be enclosed in { } or ( ).") 187 not be enclosed in { } or ( ).")
187 188
204 "Regex for filenames that will NOT be included in the target list.") 205 "Regex for filenames that will NOT be included in the target list.")
205 206
206 ;#### 207 ;####
207 ;(add-to-list 'facemenu-unlisted-faces 'makefile-space-face) 208 ;(add-to-list 'facemenu-unlisted-faces 'makefile-space-face)
208 ; Bogus FSFmacs crap. 209 ; Bogus FSFmacs crap.
209 (defvar makefile-space-face 'makefile-space-face) 210 (defvar makefile-space-face 'makefile-space-face
210 ; "Face to use for highlighting leading spaces in Font-Lock mode.") 211 "Face to use for highlighting leading spaces in Font-Lock mode.")
211 212
212 ;Older version of same. 213 ;Older version of same.
213 ;(defconst makefile-font-lock-keywords (purecopy 214 ;(defconst makefile-font-lock-keywords (purecopy
214 ; (list 215 ; (list
215 ; '("^#.*$" . font-lock-comment-face) 216 ; '("^#.*$" . font-lock-comment-face)
232 ;; Do macro assignments. These get the "variable-name" face rather 233 ;; Do macro assignments. These get the "variable-name" face rather
233 ;; arbitrarily. 234 ;; arbitrarily.
234 (list makefile-macroassign-regex 1 'font-lock-variable-name-face) 235 (list makefile-macroassign-regex 1 'font-lock-variable-name-face)
235 ;; 236 ;;
236 ;; Variable references even in targets/strings/comments: 237 ;; Variable references even in targets/strings/comments:
237 '("\\$[({]\\([a-zA-Z0-9_]+\\)[})]" 1 font-lock-reference-face t) 238 '("\\$[({]\\([a-zA-Z0-9_]+\\)[})]" 1 font-lock-reference-face prepend)
238 ;; 239 ;;
239 ;; Do dependencies. These get the function name face. 240 ;; Do dependencies. These get the function name face.
240 (list makefile-dependency-regex 1 'font-lock-function-name-face) 241 (list makefile-dependency-regex 1 'font-lock-function-name-face 'prepend)
241 242
242 ;; Highlight lines that contain just whitespace. 243 ;; Highlight lines that contain just whitespace.
243 ;; They can cause trouble, especially if they start with a tab. 244 ;; They can cause trouble, especially if they start with a tab.
244 '("^[ \t]+$" . makefile-space-face) 245 '("^[ \t]+$" . makefile-space-face)
245 246
246 ;; Highlight shell comments that Make treats as commands, 247 ;; Highlight shell comments that Make treats as commands,
247 ;; since these can fool people. 248 ;; since these can fool people.
248 '("^\t+#" makefile-space-face t) 249 '("^\t+#" 0 makefile-space-face t)
249 250
250 ;; Highlight spaces that precede tabs. 251 ;; Highlight spaces that precede tabs.
251 ;; They can make a tab fail to be effective. 252 ;; They can make a tab fail to be effective.
252 '("^\\( +\\)\t" 1 makefile-space-face))) 253 '("^\\( +\\)\t" 1 makefile-space-face)))
253 "Additional expressions to highlight in makefiles") 254 "Additional expressions to highlight in makefiles")
319 (define-key makefile-mode-map "\C-c\C-\\" 'makefile-backslash-region) 320 (define-key makefile-mode-map "\C-c\C-\\" 'makefile-backslash-region)
320 (define-key makefile-mode-map "\M-p" 'makefile-previous-dependency) 321 (define-key makefile-mode-map "\M-p" 'makefile-previous-dependency)
321 (define-key makefile-mode-map "\M-n" 'makefile-next-dependency) 322 (define-key makefile-mode-map "\M-n" 'makefile-next-dependency)
322 (define-key makefile-mode-map "\e\t" 'makefile-complete)) 323 (define-key makefile-mode-map "\e\t" 'makefile-complete))
323 324
325 ;; XEmacs change
324 (defconst makefile-menubar-menu 326 (defconst makefile-menubar-menu
325 (purecopy 327 (purecopy
326 '("Makefile" 328 '("Makefile"
327 ["Move to Next Dependency" makefile-next-dependency t] 329 ["Move to Next Dependency" makefile-next-dependency t]
328 ["Move to Previous Dependency" makefile-previous-dependency t] 330 ["Move to Previous Dependency" makefile-previous-dependency t]
329 "---" 331 "---"
330 ["Find Targets and Macros" makefile-pickup-everything t] 332 ["Find Targets and Macros" makefile-pickup-everything t]
331 ["Complete Target or Macro" makefile-complete t] 333 ["Complete Target or Macro" makefile-complete t]
332 ["Pop up Makefile Browser" makefile-switch-to-browser t]))) 334 ["Pop up Makefile Browser" makefile-switch-to-browser t])))
333 335
336 ;; XEmacs change
334 (defconst makefile-popup-menu 337 (defconst makefile-popup-menu
335 (purecopy 338 (purecopy
336 (cons "Makefile Mode Commands" 339 (cons "Makefile Mode Commands"
337 (cdr makefile-menubar-menu)))) 340 (cdr makefile-menubar-menu))))
338 341
407 ;; Filename functions 410 ;; Filename functions
408 ("dir" "Names") 411 ("dir" "Names")
409 ("notdir" "Names") 412 ("notdir" "Names")
410 ("suffix" "Names") 413 ("suffix" "Names")
411 ("basename" "Names") 414 ("basename" "Names")
415 ("addprefix" "Prefix" "Names")
412 ("addsuffix" "Suffix" "Names") 416 ("addsuffix" "Suffix" "Names")
413 ("join" "List 1" "List 2") 417 ("join" "List 1" "List 2")
414 ("word" "Index" "Text") 418 ("word" "Index" "Text")
415 ("words" "Text") 419 ("words" "Text")
416 ("firstword" "Text") 420 ("firstword" "Text")
510 (make-local-variable 'makefile-has-prereqs) 514 (make-local-variable 'makefile-has-prereqs)
511 (make-local-variable 'makefile-need-target-pickup) 515 (make-local-variable 'makefile-need-target-pickup)
512 (make-local-variable 'makefile-need-macro-pickup) 516 (make-local-variable 'makefile-need-macro-pickup)
513 517
514 ;; Font lock. 518 ;; Font lock.
515 (if (fboundp 'makefile-define-space-face) 519 (if (fboundp 'make-face)
516 (makefile-define-space-face)) 520 (makefile-define-space-face))
521 (make-local-variable 'font-lock-defaults)
522 (setq font-lock-defaults '(makefile-font-lock-keywords))
517 523
518 ;; Add-log. 524 ;; Add-log.
519 (make-local-variable 'add-log-current-defun-function) 525 (make-local-variable 'add-log-current-defun-function)
520 (setq add-log-current-defun-function 'makefile-add-log-defun) 526 (setq add-log-current-defun-function 'makefile-add-log-defun)
521 527
522 ; ;; Imenu. 528 ;; Imenu.
523 ; (make-local-variable 'imenu-create-index-function) 529 (make-local-variable 'imenu-create-index-function)
524 ; (setq imenu-create-index-function 'makefile-menu-index-function) 530 (setq imenu-create-index-function 'makefile-menu-index-function)
525 531
526 ;; Dabbrev. 532 ;; Dabbrev.
527 (make-local-variable 'dabbrev-abbrev-skip-leading-regexp) 533 (make-local-variable 'dabbrev-abbrev-skip-leading-regexp)
528 (setq dabbrev-abbrev-skip-leading-regexp "\\$") 534 (setq dabbrev-abbrev-skip-leading-regexp "\\$")
529 535
542 ;; Activate keymap and syntax table. 548 ;; Activate keymap and syntax table.
543 (use-local-map makefile-mode-map) 549 (use-local-map makefile-mode-map)
544 (set-syntax-table makefile-mode-syntax-table) 550 (set-syntax-table makefile-mode-syntax-table)
545 551
546 ;; Set menu 552 ;; Set menu
553 ;; XEmacs addition
547 (setq mode-popup-menu makefile-popup-menu) 554 (setq mode-popup-menu makefile-popup-menu)
548 (if (featurep 'menubar) 555 (if (featurep 'menubar)
549 (progn 556 (progn
550 ;; make a local copy of the menubar, so our modes don't 557 ;; make a local copy of the menubar, so our modes don't
551 ;; change the global menubar 558 ;; change the global menubar
891 (delete-region (point) saved))))))) 898 (delete-region (point) saved)))))))
892 899
893 (defun makefile-backslash-region (beg end arg) 900 (defun makefile-backslash-region (beg end arg)
894 "Insert backslashes at end of every line in region. 901 "Insert backslashes at end of every line in region.
895 Useful for defining multi-line rules. 902 Useful for defining multi-line rules.
896 If called with a prefix argument, trailing backslahes are removed." 903 If called with a prefix argument, trailing backslashes are removed."
897 (interactive "r\nP") 904 (interactive "r\nP")
898 (save-excursion 905 (save-excursion
899 (let ((do-lastline-p (progn (goto-char end) (not (bolp))))) 906 (let ((do-lastline-p (progn (goto-char end) (not (bolp)))))
900 (save-restriction 907 (save-restriction
901 (narrow-to-region beg end) 908 (narrow-to-region beg end)
998 (goto-line this-line) 1005 (goto-line this-line)
999 (let ((inhibit-read-only t)) 1006 (let ((inhibit-read-only t))
1000 (beginning-of-line) 1007 (beginning-of-line)
1001 (if (makefile-browser-on-macro-line-p) 1008 (if (makefile-browser-on-macro-line-p)
1002 (let ((macro-name (makefile-browser-this-line-macro-name))) 1009 (let ((macro-name (makefile-browser-this-line-macro-name)))
1003 (kill-line) 1010 (delete-region (point) (progn (end-of-line) (point)))
1004 (insert 1011 (insert
1005 (makefile-browser-format-macro-line 1012 (makefile-browser-format-macro-line
1006 macro-name 1013 macro-name
1007 (makefile-browser-get-state-for-line this-line)))) 1014 (makefile-browser-get-state-for-line this-line))))
1008 (let ((target-name (makefile-browser-this-line-target-name))) 1015 (let ((target-name (makefile-browser-this-line-target-name)))
1009 (kill-line) 1016 (delete-region (point) (progn (end-of-line) (point)))
1010 (insert 1017 (insert
1011 (makefile-browser-format-target-line 1018 (makefile-browser-format-target-line
1012 target-name 1019 target-name
1013 (makefile-browser-get-state-for-line this-line)))))) 1020 (makefile-browser-get-state-for-line this-line))))))
1014 (beginning-of-line) 1021 (beginning-of-line)
1357 1364
1358 1365
1359 ;;; Support for other packages, like add-log and imenu. 1366 ;;; Support for other packages, like add-log and imenu.
1360 1367
1361 (defun makefile-add-log-defun () 1368 (defun makefile-add-log-defun ()
1362 ;; "Return name of target or macro point is in, or nil." 1369 "Return name of target or variable assignment that point is in.
1370 If it isn't in one, return nil."
1363 (save-excursion 1371 (save-excursion
1364 (beginning-of-line) 1372 (let (found)
1365 (cond 1373 (beginning-of-line)
1366 ((looking-at makefile-macroassign-regex) 1374 ;; Scan back line by line, noticing when we come to a
1367 (buffer-substring (match-beginning 1) 1375 ;; variable or rule definition, and giving up when we see
1368 (match-end 1))) 1376 ;; a line that is not part of either of those.
1369 ((progn 1377 (while (not found)
1370 (or (eobp) (forward-char)) 1378 (cond
1371 (re-search-backward makefile-dependency-regex nil t)) 1379 ((looking-at makefile-macroassign-regex)
1372 (buffer-substring (match-beginning 1) 1380 (setq found (buffer-substring-no-properties (match-beginning 1)
1373 (match-end 1))) 1381 (match-end 1))))
1374 (t nil)))) 1382 ((looking-at makefile-dependency-regex)
1375 1383 (setq found (buffer-substring-no-properties (match-beginning 1)
1376 ;;; FIXME it might be nice to have them separated by macro vs target. 1384 (match-end 1))))
1377 ;(defun makefile-menu-index-function () 1385 ;; Don't keep looking across a blank line or comment. Give up.
1378 ; ;; "Generate alist of indices for imenu." 1386 ((looking-at "$\\|#")
1379 ; (let (alist 1387 (setq found 'bobp))
1380 ; stupid 1388 ((bobp)
1381 ; (re (concat makefile-dependency-regex 1389 (setq found 'bobp)))
1382 ; "\\|" 1390 (or found
1383 ; makefile-macroassign-regex))) 1391 (forward-line -1)))
1384 ; (imenu-progress-message stupid 0) 1392 (if (stringp found) found))))
1385 ; (goto-char (point-min)) 1393
1386 ; (while (re-search-forward re nil t) 1394 ;; FIXME it might be nice to have them separated by macro vs target.
1387 ; (imenu-progress-message stupid) 1395 (defun makefile-menu-index-function ()
1388 ; (let ((n (if (match-beginning 1) 1 5))) 1396 ;; "Generate alist of indices for imenu."
1389 ; (setq alist (cons 1397 (let (alist
1390 ; (cons (buffer-substring (match-beginning n) 1398 stupid
1391 ; (match-end n)) 1399 (re (concat makefile-dependency-regex
1392 ; (match-beginning n)) 1400 "\\|"
1393 ; alist)))) 1401 makefile-macroassign-regex)))
1394 ; (imenu-progress-message stupid 100) 1402 (imenu-progress-message stupid 0)
1395 ; (nreverse alist))) 1403 (goto-char (point-min))
1404 (while (re-search-forward re nil t)
1405 (imenu-progress-message stupid)
1406 (let ((n (if (match-beginning 1) 1 5)))
1407 (setq alist (cons
1408 (cons (buffer-substring (match-beginning n)
1409 (match-end n))
1410 (match-beginning n))
1411 alist))))
1412 (imenu-progress-message stupid 100)
1413 (nreverse alist)))
1396 1414
1397 (defun makefile-define-space-face () 1415 (defun makefile-define-space-face ()
1398 (make-face 'makefile-space-face) 1416 (make-face 'makefile-space-face)
1417 ;; XEmacs change
1399 (let* ((light-bg t)) ; #### 1418 (let* ((light-bg t)) ; ####
1400 (set-face-background 'makefile-space-face 1419 (set-face-background 'makefile-space-face
1401 (if light-bg "black" "white") 1420 (if light-bg "black" "white")
1402 nil 1421 nil
1403 '(mono x) 1422 '(mono x)