+2005-05-17 Daniel Pfeiffer <occitan@esperanto.org>
+
+ * 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 <Reiner.Steib@gmx.de>
* dired.el (dired-mode): Simplify.
"^ *\\(\\(?: *\\$\\(?:[({]\\(?:\\$\\(?:[({]\\(?:\\$\\(?:[^({]\\|.[^\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.")
(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
(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)))
\f
((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