emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/progmodes/make-mode.el


From: Daniel Pfeiffer
Subject: [Emacs-diffs] Changes to emacs/lisp/progmodes/make-mode.el
Date: Mon, 16 May 2005 16:13:09 -0400

Index: emacs/lisp/progmodes/make-mode.el
diff -c emacs/lisp/progmodes/make-mode.el:1.90 
emacs/lisp/progmodes/make-mode.el:1.91
*** emacs/lisp/progmodes/make-mode.el:1.90      Fri May 13 07:51:15 2005
--- emacs/lisp/progmodes/make-mode.el   Mon May 16 20:13:09 2005
***************
*** 257,282 ****
  ;; Note that the first big subexpression is used by font lock.  Note
  ;; that if you change this regexp you might have to fix the imenu
  ;; index in makefile-imenu-generic-expression.
! (defconst makefile-dependency-regex
!   ;; Allow for one nested level $($(var:a=b):c=d)
!   ;; Scan non-$ constructs char by char, so we don't miss a $ while allowing 
$$.
!   ;; Since we must allow space between targets, I then don't know how to 
evite a command starting with :.
!   "^ *\\(\\(?:\\$[({]\\(?:\\$[({][^ 
\t\n#})]+?[})]\\|[^\n#]\\)+?[})]\\|[^\n#:=]\\)+?\\)[ \t]*:\\(?:[ 
\t]*$\\|[^=\n].*$\\)"
    "Regex used to find dependency lines in a makefile.")
  
! (defconst makefile-rule-action-regex
!   "^\t[ \t]*\\(address@hidden)[ \t]*\\(.+\\)"
    "Regex used to highlight rule action lines in font lock mode.")
  
  ;; Note that the first and second subexpression is used by font lock.  Note
  ;; that if you change this regexp you might have to fix the imenu index in
  ;; makefile-imenu-generic-expression.
  (defconst makefile-macroassign-regex
!   "^ *\\([^ \n\t][^:#= \t\n]*\\)[ \t]*\\(?:!=[ \t]*\\(.*\\)\\|[*:+]?[:?]?=\\)"
    "Regex used to find macro assignment lines in a makefile.")
  
  (defconst makefile-var-use-regex
!   "[^$]\\$[({]\\([-a-zA-Z0-9_.]+\\|address@hidden<?^+*][FD]?\\)[}):]"
    "Regex used to find $(macro) uses in a makefile.")
  
  (defconst makefile-ignored-files-in-pickup-regex
--- 257,280 ----
  ;; Note that the first big subexpression is used by font lock.  Note
  ;; that if you change this regexp you might have to fix the imenu
  ;; index in makefile-imenu-generic-expression.
! (defvar makefile-dependency-regex
!   ;; Allow for two nested levels $(v1:$(v2:$(v3:a=b)=c)=d)
!   "^ *\\(\\(?: 
*\\$\\(?:[({]\\(?:\\$\\(?:[({]\\(?:\\$\\(?:[^({]\\|.[^\n$#})]+?[})]\\)\\|[^\n$#)}]\\)+?[})]\\|[^({]\\)\\|[^\n$#)}]\\)+?[})]\\|[^({]\\)\\|
 *[^ \n$#:=]+\\)+?\\)[ \t]*\\(:\\)\\(?:[ \t]*$\\|[^=\n]\\(?:[^#\n]*?;[ 
\t]*\\(.+\\)\\)?\\)"
    "Regex used to find dependency lines in a makefile.")
  
! (defvar makefile-rule-action-regex
!   "^\t[ \t]*\\(address@hidden)[ \t]*\\(\\(?:.+\\\\\n\\)*.+\\)"
    "Regex used to highlight rule action lines in font lock mode.")
  
  ;; Note that the first and second subexpression is used by font lock.  Note
  ;; that if you change this regexp you might have to fix the imenu index in
  ;; makefile-imenu-generic-expression.
  (defconst makefile-macroassign-regex
!   "^ *\\([^ \n\t][^:#= \t\n]*\\)[ \t]*\\(?:!=[ 
\t]*\\(\\(?:.+\\\\\n\\)*.+\\)\\|[*:+]?[:?]?=\\)"
    "Regex used to find macro assignment lines in a makefile.")
  
  (defconst makefile-var-use-regex
!   "[^$]\\$[({]\\([-a-zA-Z0-9_.]+\\|address@hidden<?^+*][FD]?\\)"
    "Regex used to find $(macro) uses in a makefile.")
  
  (defconst makefile-ignored-files-in-pickup-regex
***************
*** 323,342 ****
      ".endif" ".for" ".if" ".ifdef" ".ifmake" ".ifndef" ".ifnmake" ".undef")
    "List of keywords understood by BSD make.")
  
! (defun makefile-make-font-lock-keywords (dependency action var keywords space
!                                                   &optional negation
!                                                   &rest font-lock-keywords)
    `(;; Do macro assignments.  These get the "variable-name" face.
      (,makefile-macroassign-regex
       (1 font-lock-variable-name-face)
       ;; This is for after !=
       (2 'makefile-shell-face prepend t))
  
-     ;; Do dependencies.
-     (,dependency 1 'makefile-targets-face prepend)
- 
      ;; Rule actions.
!     (,action
       (1 font-lock-type-face)
       (2 'makefile-shell-face prepend)
       ;; Only makepp has builtin commands.
--- 321,337 ----
      ".endif" ".for" ".if" ".ifdef" ".ifmake" ".ifndef" ".ifnmake" ".undef")
    "List of keywords understood by BSD make.")
  
! (defun makefile-make-font-lock-keywords (var keywords space
!                                            &optional negation
!                                            &rest font-lock-keywords)
    `(;; Do macro assignments.  These get the "variable-name" face.
      (,makefile-macroassign-regex
       (1 font-lock-variable-name-face)
       ;; This is for after !=
       (2 'makefile-shell-face prepend t))
  
      ;; Rule actions.
!     (makefile-match-action
       (1 font-lock-type-face)
       (2 'makefile-shell-face prepend)
       ;; Only makepp has builtin commands.
***************
*** 359,367 ****
              "\\>[ \t]*\\([^: \t\n#]*\\)")
       (1 font-lock-keyword-face) (2 font-lock-variable-name-face))
  
!     ,(if negation
!        `(,negation (1 font-lock-negation-char-face prepend)
!                    (2 font-lock-negation-char-face prepend t)))
  
      ,@(if space
          '(;; Highlight lines that contain just whitespace.
--- 354,362 ----
              "\\>[ \t]*\\([^: \t\n#]*\\)")
       (1 font-lock-keyword-face) (2 font-lock-variable-name-face))
  
!     ,@(if negation
!        `((,negation (1 font-lock-negation-char-face prepend)
!                     (2 font-lock-negation-char-face prepend t))))
  
      ,@(if space
          '(;; Highlight lines that contain just whitespace.
***************
*** 376,403 ****
            ;; They can make a tab fail to be effective.
            ("^\\( +\\)\t" 1 makefile-space-face)))
  
!     ,@font-lock-keywords))
  
  (defconst makefile-font-lock-keywords
    (makefile-make-font-lock-keywords
-    makefile-dependency-regex
-    makefile-rule-action-regex
     makefile-var-use-regex
     makefile-statements
     t))
  
  (defconst makefile-automake-font-lock-keywords
    (makefile-make-font-lock-keywords
-    makefile-dependency-regex
-    makefile-rule-action-regex
     makefile-var-use-regex
     makefile-automake-statements
     t))
  
  (defconst makefile-gmake-font-lock-keywords
    (makefile-make-font-lock-keywords
-    makefile-dependency-regex
-    makefile-rule-action-regex
     makefile-var-use-regex
     makefile-gmake-statements
     t
--- 371,397 ----
            ;; They can make a tab fail to be effective.
            ("^\\( +\\)\t" 1 makefile-space-face)))
  
!     ,@font-lock-keywords
! 
!     ;; Do dependencies.
!     (makefile-match-dependency
!      (1 'makefile-targets-face prepend)
!      (3 'makefile-shell-face prepend t))))
  
  (defconst makefile-font-lock-keywords
    (makefile-make-font-lock-keywords
     makefile-var-use-regex
     makefile-statements
     t))
  
  (defconst makefile-automake-font-lock-keywords
    (makefile-make-font-lock-keywords
     makefile-var-use-regex
     makefile-automake-statements
     t))
  
  (defconst makefile-gmake-font-lock-keywords
    (makefile-make-font-lock-keywords
     makefile-var-use-regex
     makefile-gmake-statements
     t
***************
*** 407,414 ****
       1 'makefile-targets-face prepend)
  
     ;; $(function ...) ${function ...}
!    '("[^$]\\$[({]\\(\\S +\\s \\)"
!      1 font-lock-function-name-face)
  
     ;; $(shell ...) ${shell ...}
     '("[^$]\\$\\([({]\\)shell[ \t]+"
--- 401,408 ----
       1 'makefile-targets-face prepend)
  
     ;; $(function ...) ${function ...}
!    '("[^$]\\$[({]\\([-a-zA-Z0-9_.]+\\s \\)"
!      1 font-lock-function-name-face prepend)
  
     ;; $(shell ...) ${shell ...}
     '("[^$]\\$\\([({]\\)shell[ \t]+"
***************
*** 417,440 ****
  
  (defconst makefile-makepp-font-lock-keywords
    (makefile-make-font-lock-keywords
-    makefile-dependency-regex
-    ;; Don't care about initial tab, but I don't know how to font-lock 
correctly without.
-    "^\t[ \t]*\\(\\(?:[ \t]*noecho\\>\\|[ \t]*ignore[-_]error\\>\\|[ 
address@hidden)*\\)[ \t]*\\(\\(&\\S +\\)?.+\\)"
     makefile-var-use-regex
     makefile-makepp-statements
     nil
     "^\\(?: [ \t]*\\)?\\(?:and[ \t]+\\|else[ \t]+\\|or[ 
\t]+\\)?if\\(n\\)\\(?:def\\|eq\\|sys\\)\\>"
  
!    '("[^$]\\(\\$[({]\\(?:target\\|output\\)s?[})]\\)"
       1 'makefile-targets-face prepend)
  
     ;; Colon modifier keywords.
!    '(":\\s 
*\\(build_c\\(?:ache\\|heck\\)\\|env\\(?:ironment\\)?\\|foreach\\|signature\\|scanner\\|quickscan\\|smartscan\\)\\>"
!      1 font-lock-keyword-face t)
  
     ;; $(function ...) $((function ...)) ${function ...} ${{function ...}}
!    '("[^$]\\$\\(((?\\|{{?\\)\\(\\S +\\s \\)"
!      2 font-lock-function-name-face)
  
     ;; $(shell ...) $((shell ...)) ${shell ...} ${{shell ...}}
     '("[^$]\\$\\(((?\\|{{?\\)shell\\(?:[-_]\\(?:global[-_]\\)?once\\)?[ \t]+"
--- 411,433 ----
  
  (defconst makefile-makepp-font-lock-keywords
    (makefile-make-font-lock-keywords
     makefile-var-use-regex
     makefile-makepp-statements
     nil
     "^\\(?: [ \t]*\\)?\\(?:and[ \t]+\\|else[ \t]+\\|or[ 
\t]+\\)?if\\(n\\)\\(?:def\\|eq\\|sys\\)\\>"
  
!    '("[^$]\\(\\$[({]\\(?:target\\|output\\)s?\\_>.*?[})]\\)"
       1 'makefile-targets-face prepend)
  
     ;; Colon modifier keywords.
!    '("\\(:\\s 
*\\)\\(build_c\\(?:ache\\|heck\\)\\|env\\(?:ironment\\)?\\|foreach\\|signature\\|scanner\\|quickscan\\|smartscan\\)\\>\\([^:\n]*\\)"
!      (1 font-lock-type-face t)
!      (2 font-lock-keyword-face t)
!      (3 font-lock-variable-name-face t))
  
     ;; $(function ...) $((function ...)) ${function ...} ${{function ...}}
!    '("[^$]\\$\\(?:((?\\|{{?\\)\\([-a-zA-Z0-9_.]+\\s \\)"
!      1 font-lock-function-name-face prepend)
  
     ;; $(shell ...) $((shell ...)) ${shell ...} ${{shell ...}}
     '("[^$]\\$\\(((?\\|{{?\\)shell\\(?:[-_]\\(?:global[-_]\\)?once\\)?[ \t]+"
***************
*** 466,476 ****
     '("perl[-_]begin\\s *\\(?:\\s #.*\\)?\n\\(\\(?:.*\n\\)+?\\)\\s 
*perl[-_]end\\>"
       1 'makefile-makepp-perl-face t)))
  
- ;; A lot more could be done for variables here:
  (defconst makefile-bsdmake-font-lock-keywords
    (makefile-make-font-lock-keywords
!    "^ 
*\\(\\(?:\\$[({]\\(?:\\$[({][^\n#})]+?[})]\\|[^\n#]\\)+?[})]\\|[^\n#:=]\\)+?\\)[
 \t]*[:!]\\(?:[ \t]*$\\|[^=\n].*$\\)"
!    "^\t[ \t]*\\(address@hidden)[ \t]*\\(.+\\)"
     makefile-var-use-regex
     makefile-bsdmake-statements
     t
--- 459,467 ----
     '("perl[-_]begin\\s *\\(?:\\s #.*\\)?\n\\(\\(?:.*\n\\)+?\\)\\s 
*perl[-_]end\\>"
       1 'makefile-makepp-perl-face t)))
  
  (defconst makefile-bsdmake-font-lock-keywords
    (makefile-make-font-lock-keywords
!    ;; A lot more could be done for variables here:
     makefile-var-use-regex
     makefile-bsdmake-statements
     t
***************
*** 489,497 ****
      ("\\\\\n" 0 ".")))
  
  (defvar makefile-imenu-generic-expression
!   (list
!    (list "Dependencies" makefile-dependency-regex  1)
!    (list "Macro Assignment" makefile-macroassign-regex 1))
    "Imenu generic expression for Makefile mode.  See 
`imenu-generic-expression'.")
  
  ;;; ------------------------------------------------------------
--- 480,487 ----
      ("\\\\\n" 0 ".")))
  
  (defvar makefile-imenu-generic-expression
!   `(("Dependencies" ,makefile-dependency-regex 1)
!     ("Macro Assignment" ,makefile-macroassign-regex 1))
    "Imenu generic expression for Makefile mode.  See 
`imenu-generic-expression'.")
  
  ;;; ------------------------------------------------------------
***************
*** 695,700 ****
--- 685,695 ----
  it is *.mk.  This function ends by invoking the function(s)
  `makefile-mode-hook'.
  
+ It is strongly recommended to use `font-lock-mode', because that
+ provides additional parsing information.  This is used for
+ example to see that a rule action `echo foo: bar' is a not rule
+ dependency, despite the colon.
+ 
  \\{makefile-mode-map}
  
  In the browser, use the following keys:
***************
*** 849,862 ****
  ;;;###autoload
  (define-derived-mode makefile-makepp-mode makefile-mode "Makeppfile"
    "An adapted `makefile-mode' that knows about makepp."
    (setq font-lock-defaults
        `(makefile-makepp-font-lock-keywords ,@(cdr font-lock-defaults))))
  
  ;;;###autoload
  (define-derived-mode makefile-bsdmake-mode makefile-mode "BSDmakefile"
    "An adapted `makefile-mode' that knows about BSD make."
    (setq font-lock-defaults
!       `(makefile-bsdmake-font-lock-keywords ,@(cdr font-lock-defaults))))
  
  
  
--- 844,869 ----
  ;;;###autoload
  (define-derived-mode makefile-makepp-mode makefile-mode "Makeppfile"
    "An adapted `makefile-mode' that knows about makepp."
+    (set (make-local-variable 'makefile-rule-action-regex)
+       ;; Don't care about initial tab, but I don't know how to font-lock 
correctly without.
+       "^\t[ \t]*\\(\\(?:\\(?:noecho\\|ignore[-_]error\\|address@hidden)[ 
\t]*\\)*\\)\\(\\(&\\S +\\)?\\(?:.+\\\\\n\\)*.+\\)")
+ 
    (setq font-lock-defaults
        `(makefile-makepp-font-lock-keywords ,@(cdr font-lock-defaults))))
  
  ;;;###autoload
  (define-derived-mode makefile-bsdmake-mode makefile-mode "BSDmakefile"
    "An adapted `makefile-mode' that knows about BSD make."
+   (set (make-local-variable 'makefile-dependency-regex)
+        ;; Identical to default, except allows `!' instead of `:'.
+        "^ *\\(\\(?: 
*\\$\\(?:[({]\\(?:\\$\\(?:[({]\\(?:\\$\\(?:[^({]\\|.[^\n$#})]+?[})]\\)\\|[^\n$#)}]\\)+?[})]\\|[^({]\\)\\|[^\n$#)}]\\)+?[})]\\|[^({]\\)\\|
 *[^ \n$#:=]+\\)+?\\)[ \t]*\\([:!]\\)\\(?:[ \t]*$\\|[^=\n]\\(?:[^#\n]*?;[ 
\t]*\\(.+\\)\\)?\\)")
+   (set (make-local-variable 'makefile-rule-action-regex)
+        "^\t[ \t]*\\(address@hidden)[ \t]*\\(\\(?:.+\\\\\n\\)*.+\\)")
    (setq font-lock-defaults
!       `(makefile-bsdmake-font-lock-keywords ,@(cdr font-lock-defaults))
!       imenu-generic-expression
!       `(("Dependencies" ,makefile-dependency-regex 1)
!         ,@(cdr imenu-generic-expression))))
  
  
  
***************
*** 867,873 ****
    (interactive)
    (let ((here (point)))
      (end-of-line)
!     (if (re-search-forward makefile-dependency-regex (point-max) t)
        (progn (beginning-of-line) t)   ; indicate success
        (goto-char here) nil)))
  
--- 874,880 ----
    (interactive)
    (let ((here (point)))
      (end-of-line)
!     (if (makefile-match-dependency (point-max))
        (progn (beginning-of-line) t)   ; indicate success
        (goto-char here) nil)))
  
***************
*** 876,882 ****
    (interactive)
    (let ((here (point)))
      (beginning-of-line)
!     (if (re-search-backward makefile-dependency-regex (point-min) t)
        (progn (beginning-of-line) t)   ; indicate success
        (goto-char here) nil)))
  
--- 883,889 ----
    (interactive)
    (let ((here (point)))
      (beginning-of-line)
!     (if (makefile-match-dependency (point-min) t)
        (progn (beginning-of-line) t)   ; indicate success
        (goto-char here) nil)))
  
***************
*** 983,989 ****
      (setq makefile-has-prereqs nil)
      (save-excursion
        (goto-char (point-min))
!       (while (re-search-forward makefile-dependency-regex nil t)
        (makefile-add-this-line-targets)))
      (message "Read targets OK.")))
  
--- 990,996 ----
      (setq makefile-has-prereqs nil)
      (save-excursion
        (goto-char (point-min))
!       (while (makefile-match-dependency nil)
        (makefile-add-this-line-targets)))
      (message "Read targets OK.")))
  
***************
*** 1676,1681 ****
--- 1683,1705 ----
                  ((string= s "{{") "\\(.*?\\)[ \t]*}}")))
      (if s (looking-at s))))
  
+ (defun makefile-match-dependency (bound &optional backward)
+   "Search for `makefile-dependency-regex' up to BOUND.
+ Optionally search BACKWARD.
+ Checks that the colon has not already been fontified, else we
+ matched in a rule action."
+   (catch 'found
+     (while (funcall (if backward 're-search-backward 're-search-forward)
+                   makefile-dependency-regex bound t)
+       (or (get-text-property (match-beginning 2) 'face)
+         (throw 'found t)))))
+ 
+ (defun makefile-match-action (bound)
+   (catch 'found
+     (while (re-search-forward makefile-rule-action-regex bound t)
+       (or (eq ?\\ (char-after (- (match-beginning 0) 2)))
+         (throw 'found t)))))
+ 
  (defun makefile-do-macro-insertion (macro-name)
    "Insert a macro reference."
    (if (not (zerop (length macro-name)))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]