From 0b11ce59ee4b7635e207466badfcbff97da80848 Mon Sep 17 00:00:00 2001 From: Daniel Pfeiffer Date: Tue, 17 May 2005 20:45:26 +0000 Subject: [PATCH] (makefile-dependency-skip): New variable. (makefile-previous-dependency): Inline the new matcher, because it is too complex to work in both directions. (makefile-match-dependency): Eliminate `backward' arg (see above). Completely reimplemented so as to not sometimes go into an endless loop. It should also be more efficient, because first it only searches for `:', instead of applying the very complex regexp. --- lisp/ChangeLog | 10 +++++++++ lisp/progmodes/make-mode.el | 41 +++++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2cbb9196005..e9b5ddc832d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,13 @@ +2005-05-17 Daniel Pfeiffer + + * progmodes/make-mode.el (makefile-dependency-skip): New variable. + (makefile-previous-dependency): Inline the new matcher, because it + is too complex to work in both directions. + (makefile-match-dependency): Eliminate `backward' arg (see above). + Completely reimplemented so as to not sometimes go into an endless + loop. It should also be more efficient, because first it only + searches for `:', instead of applying the very complex regexp. + 2005-05-17 Reiner Steib * dired.el (dired-mode): Simplify. diff --git a/lisp/progmodes/make-mode.el b/lisp/progmodes/make-mode.el index 8467310d1da..399f5376d58 100644 --- a/lisp/progmodes/make-mode.el +++ b/lisp/progmodes/make-mode.el @@ -262,6 +262,9 @@ not be enclosed in { } or ( )." "^ *\\(\\(?: *\\$\\(?:[({]\\(?:\\$\\(?:[({]\\(?:\\$\\(?:[^({]\\|.[^\n$#})]+?[})]\\)\\|[^\n$#)}]\\)+?[})]\\|[^({]\\)\\|[^\n$#)}]\\)+?[})]\\|[^({]\\)\\| *[^ \n$#:=]+\\)+?\\)[ \t]*\\(:\\)\\(?:[ \t]*$\\|[^=\n]\\(?:[^#\n]*?;[ \t]*\\(.+\\)\\)?\\)" "Regex used to find dependency lines in a makefile.") +(defvar makefile-dependency-skip "^:" + "Characters to skip to find a line that might be a dependency.") + (defvar makefile-rule-action-regex "^\t[ \t]*\\([-@]*\\)[ \t]*\\(\\(?:.+\\\\\n\\)*.+\\)" "Regex used to highlight rule action lines in font lock mode.") @@ -857,6 +860,7 @@ Makefile mode can be configured by modifying the following variables: (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-dependency-skip) "^:!") (set (make-local-variable 'makefile-rule-action-regex) "^\t[ \t]*\\([-+@]*\\)[ \t]*\\(\\(?:.+\\\\\n\\)*.+\\)") (setq font-lock-defaults @@ -874,18 +878,26 @@ Makefile mode can be configured by modifying the following variables: (interactive) (let ((here (point))) (end-of-line) - (if (makefile-match-dependency (point-max)) + (if (makefile-match-dependency nil) (progn (beginning-of-line) t) ; indicate success (goto-char here) nil))) (defun makefile-previous-dependency () "Move point to the beginning of the previous dependency line." (interactive) - (let ((here (point))) + (let ((pt (point))) (beginning-of-line) - (if (makefile-match-dependency (point-min) t) - (progn (beginning-of-line) t) ; indicate success - (goto-char here) nil))) + ;; makefile-match-dependency done backwards: + (catch 'found + (while (and (< (skip-chars-backward makefile-dependency-skip) 0) + (not (bobp))) + (backward-char) + (or (get-text-property (point) 'face) + (beginning-of-line) + (if (looking-at makefile-dependency-regex) + (throw 'found t)))) + (goto-char pt) + nil))) @@ -1683,16 +1695,23 @@ The anchor must have matched the opening parens in the first group." ((string= s "{{") "\\(.*?\\)[ \t]*}}"))) (if s (looking-at s)))) -(defun makefile-match-dependency (bound &optional backward) +(defun makefile-match-dependency (bound) "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))))) + (let ((pt (point))) + (while (and (> (skip-chars-forward makefile-dependency-skip bound) 0) + (not (eobp))) + (forward-char) + (or (get-text-property (1- (point)) 'face) + (when (save-excursion + (beginning-of-line) + (looking-at makefile-dependency-regex)) + (end-of-line) + (throw 'found (point))))) + (goto-char pt)) + nil)) (defun makefile-match-action (bound) (catch 'found -- 2.39.2