diff options
Diffstat (limited to 'lisp/progmodes/make-mode.el')
-rw-r--r-- | lisp/progmodes/make-mode.el | 168 |
1 files changed, 68 insertions, 100 deletions
diff --git a/lisp/progmodes/make-mode.el b/lisp/progmodes/make-mode.el index 36130ff2f48..22e5d2f7c5c 100644 --- a/lisp/progmodes/make-mode.el +++ b/lisp/progmodes/make-mode.el @@ -1,7 +1,6 @@ ;;; make-mode.el --- makefile editing commands for Emacs -;; Copyright (C) 1992, 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, -;; 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. +;; Copyright (C) 1992, 1994, 1999-2011 Free Software Foundation, Inc. ;; Author: Thomas Neumann <tom@smart.bo.open.de> ;; Eric S. Raymond <esr@snark.thyrsus.com> @@ -281,8 +280,7 @@ not be enclosed in { } or ( )." "Regex used to highlight makepp rule action lines in font lock mode.") (defconst makefile-bsdmake-rule-action-regex - (progn (string-match "-@" makefile-rule-action-regex) - (replace-match "-+@" t t makefile-rule-action-regex)) + (replace-regexp-in-string "-@" "-+@" makefile-rule-action-regex) "Regex used to highlight BSD rule action lines in font lock mode.") ;; Note that the first and second subexpression is used by font lock. Note @@ -345,7 +343,7 @@ not be enclosed in { } or ( )." (defun makefile-make-font-lock-keywords (var keywords space &optional negation - &rest font-lock-keywords) + &rest fl-keywords) `(;; Do macro assignments. These get the "variable-name" face. (,makefile-macroassign-regex (1 font-lock-variable-name-face) @@ -395,7 +393,7 @@ not be enclosed in { } or ( )." ;; They can make a tab fail to be effective. ("^\\( +\\)\t" 1 makefile-space))) - ,@font-lock-keywords + ,@fl-keywords ;; Do dependencies. (makefile-match-dependency @@ -493,7 +491,7 @@ not be enclosed in { } or ( )." '("^[ \t]*\\.for[ \t].+[ \t]\\(in\\)\\>" 1 font-lock-keyword-face))) (defconst makefile-imake-font-lock-keywords - (append + (append (makefile-make-font-lock-keywords makefile-var-use-regex makefile-statements @@ -506,40 +504,41 @@ not be enclosed in { } or ( )." cpp-font-lock-keywords)) -(defconst makefile-font-lock-syntactic-keywords - ;; From sh-script.el. - ;; A `#' begins a comment in sh when it is unquoted and at the beginning - ;; of a word. In the shell, words are separated by metacharacters. - ;; The list of special chars is taken from the single-unix spec of the - ;; shell command language (under `quoting') but with `$' removed. - '(("[^|&;<>()`\\\"' \t\n]\\(#+\\)" 1 "_") - ;; Change the syntax of a quoted newline so that it does not end a comment. - ("\\\\\n" 0 "."))) +(defconst makefile-syntax-propertize-function + (syntax-propertize-rules + ;; From sh-script.el. + ;; A `#' begins a comment in sh when it is unquoted and at the beginning + ;; of a word. In the shell, words are separated by metacharacters. + ;; The list of special chars is taken from the single-unix spec of the + ;; shell command language (under `quoting') but with `$' removed. + ("[^|&;<>()`\\\"' \t\n]\\(#+\\)" (1 "_")) + ;; Change the syntax of a quoted newline so that it does not end a comment. + ("\\\\\n" (0 ".")))) (defvar makefile-imenu-generic-expression `(("Dependencies" makefile-previous-dependency 1) ("Macro Assignment" ,makefile-macroassign-regex 1)) "Imenu generic expression for Makefile mode. See `imenu-generic-expression'.") -;;; ------------------------------------------------------------ -;;; The following configurable variables are used in the -;;; up-to-date overview . -;;; The standard configuration assumes that your `make' program -;;; can be run in question/query mode using the `-q' option, this -;;; means that the command -;;; -;;; make -q foo -;;; -;;; should return an exit status of zero if the target `foo' is -;;; up to date and a nonzero exit status otherwise. -;;; Many makes can do this although the docs/manpages do not mention -;;; it. Try it with your favourite one. GNU make, System V make, and -;;; Dennis Vadura's DMake have no problems. -;;; Set the variable `makefile-brave-make' to the name of the -;;; make utility that does this on your system. -;;; To understand what this is all about see the function definition -;;; of `makefile-query-by-make-minus-q' . -;;; ------------------------------------------------------------ +;; ------------------------------------------------------------ +;; The following configurable variables are used in the +;; up-to-date overview . +;; The standard configuration assumes that your `make' program +;; can be run in question/query mode using the `-q' option, this +;; means that the command +;; +;; make -q foo +;; +;; should return an exit status of zero if the target `foo' is +;; up to date and a nonzero exit status otherwise. +;; Many makes can do this although the docs/manpages do not mention +;; it. Try it with your favourite one. GNU make, System V make, and +;; Dennis Vadura's DMake have no problems. +;; Set the variable `makefile-brave-make' to the name of the +;; make utility that does this on your system. +;; To understand what this is all about see the function definition +;; of `makefile-query-by-make-minus-q' . +;; ------------------------------------------------------------ (defcustom makefile-brave-make "make" "*How to invoke make, for `makefile-query-targets'. @@ -574,11 +573,8 @@ The function must satisfy this calling convention: ;;; --- end of up-to-date-overview configuration ------------------ -(defvar makefile-mode-abbrev-table nil +(define-abbrev-table 'makefile-mode-abbrev-table () "Abbrev table in use in Makefile buffers.") -(if makefile-mode-abbrev-table - () - (define-abbrev-table 'makefile-mode-abbrev-table ())) (defvar makefile-mode-map (let ((map (make-sparse-keymap)) @@ -706,15 +702,13 @@ The function must satisfy this calling convention: (modify-syntax-entry ?\n "> " st) st)) -(defvar makefile-imake-mode-syntax-table (copy-syntax-table - makefile-mode-syntax-table)) -(if makefile-imake-mode-syntax-table - () - (modify-syntax-entry ?/ ". 14" makefile-imake-mode-syntax-table) - (modify-syntax-entry ?* ". 23" makefile-imake-mode-syntax-table) - (modify-syntax-entry ?# "'" makefile-imake-mode-syntax-table) - (modify-syntax-entry ?\n ". b" makefile-imake-mode-syntax-table)) - +(defvar makefile-imake-mode-syntax-table + (let ((st (make-syntax-table makefile-mode-syntax-table))) + (modify-syntax-entry ?/ ". 14" st) + (modify-syntax-entry ?* ". 23" st) + (modify-syntax-entry ?# "'" st) + (modify-syntax-entry ?\n ". b" st) + st)) ;;; ------------------------------------------------------------ ;;; Internal variables. @@ -774,7 +768,7 @@ The function must satisfy this calling convention: ;;; ------------------------------------------------------------ ;;;###autoload -(defun makefile-mode () +(define-derived-mode makefile-mode prog-mode "Makefile" "Major mode for editing standard Makefiles. If you are editing a file for a different make, try one of the @@ -858,9 +852,6 @@ Makefile mode can be configured by modifying the following variables: List of special targets. You will be offered to complete on one of those in the minibuffer whenever you enter a `.'. at the beginning of a line in Makefile mode." - - (interactive) - (kill-all-local-variables) (add-hook 'write-file-functions 'makefile-warn-suspicious-lines nil t) (add-hook 'write-file-functions @@ -874,59 +865,44 @@ Makefile mode can be configured by modifying the following variables: (make-local-variable 'makefile-need-macro-pickup) ;; Font lock. - (make-local-variable 'font-lock-defaults) - (setq font-lock-defaults - ;; SYNTAX-BEGIN set to backward-paragraph to avoid slow-down - ;; near the end of a large buffer, due to parse-partial-sexp's - ;; trying to parse all the way till the beginning of buffer. - '(makefile-font-lock-keywords - nil nil - ((?$ . ".")) - backward-paragraph - (font-lock-syntactic-keywords - . makefile-font-lock-syntactic-keywords))) + (set (make-local-variable 'font-lock-defaults) + ;; SYNTAX-BEGIN set to backward-paragraph to avoid slow-down + ;; near the end of a large buffer, due to parse-partial-sexp's + ;; trying to parse all the way till the beginning of buffer. + '(makefile-font-lock-keywords + nil nil + ((?$ . ".")) + backward-paragraph)) + (set (make-local-variable 'syntax-propertize-function) + makefile-syntax-propertize-function) ;; Add-log. - (make-local-variable 'add-log-current-defun-function) - (setq add-log-current-defun-function 'makefile-add-log-defun) + (set (make-local-variable 'add-log-current-defun-function) + 'makefile-add-log-defun) ;; Imenu. - (make-local-variable 'imenu-generic-expression) - (setq imenu-generic-expression makefile-imenu-generic-expression) + (set (make-local-variable 'imenu-generic-expression) + makefile-imenu-generic-expression) ;; Dabbrev. - (make-local-variable 'dabbrev-abbrev-skip-leading-regexp) - (setq dabbrev-abbrev-skip-leading-regexp "\\$") + (set (make-local-variable 'dabbrev-abbrev-skip-leading-regexp) "\\$") ;; Other abbrevs. (setq local-abbrev-table makefile-mode-abbrev-table) ;; Filling. - (make-local-variable 'fill-paragraph-function) - (setq fill-paragraph-function 'makefile-fill-paragraph) + (set (make-local-variable 'fill-paragraph-function) 'makefile-fill-paragraph) ;; Comment stuff. - (make-local-variable 'comment-start) - (setq comment-start "#") - (make-local-variable 'comment-end) - (setq comment-end "") - (make-local-variable 'comment-start-skip) - (setq comment-start-skip "#+[ \t]*") + (set (make-local-variable 'comment-start) "#") + (set (make-local-variable 'comment-end) "") + (set (make-local-variable 'comment-start-skip) "#+[ \t]*") ;; Make sure TAB really inserts \t. (set (make-local-variable 'indent-line-function) 'indent-to-left-margin) - ;; become the current major mode - (setq major-mode 'makefile-mode) - (setq mode-name "Makefile") - - ;; Activate keymap and syntax table. - (use-local-map makefile-mode-map) - (set-syntax-table makefile-mode-syntax-table) - ;; Real TABs are important in makefiles - (setq indent-tabs-mode t) - (run-mode-hooks 'makefile-mode-hook)) + (setq indent-tabs-mode t)) ;; These should do more than just differentiate font-lock. ;;;###autoload @@ -967,15 +943,9 @@ Makefile mode can be configured by modifying the following variables: (define-derived-mode makefile-imake-mode makefile-mode "Imakefile" "An adapted `makefile-mode' that knows about imake." :syntax-table makefile-imake-mode-syntax-table - (let ((base `(makefile-imake-font-lock-keywords ,@(cdr font-lock-defaults))) - new) - ;; Remove `font-lock-syntactic-keywords' entry from font-lock-defaults. - (mapc (lambda (elt) - (unless (and (consp elt) - (eq (car elt) 'font-lock-syntactic-keywords)) - (setq new (cons elt new)))) - base) - (setq font-lock-defaults (nreverse new)))) + (set (make-local-variable 'syntax-propertize-function) nil) + (setq font-lock-defaults + `(makefile-imake-font-lock-keywords ,@(cdr font-lock-defaults)))) @@ -1185,7 +1155,6 @@ The context determines which are considered." (let* ((beg (save-excursion (skip-chars-backward "^$(){}:#= \t\n") (point))) - (try (buffer-substring beg (point))) (paren nil) (do-macros (save-excursion @@ -1292,7 +1261,7 @@ definition and conveniently use this command." ;; Filling -(defun makefile-fill-paragraph (arg) +(defun makefile-fill-paragraph (_arg) ;; Fill comments, backslashed lines, and variable definitions ;; specially. (save-excursion @@ -1710,7 +1679,7 @@ Then prompts for all required parameters." ;;; Utility functions ;;; ------------------------------------------------------------ -(defun makefile-match-function-end (end) +(defun makefile-match-function-end (_end) "To be called as an anchored matcher by font-lock. The anchor must have matched the opening parens in the first group." (let ((s (match-string-no-properties 1))) @@ -1868,5 +1837,4 @@ If it isn't in one, return nil." (provide 'make-mode) -;; arch-tag: bd23545a-de91-44fb-b1b2-feafbb2635a0 ;;; make-mode.el ends here |