From c2f9aec8b46cfa648c9768a0e6574d43d604eb2c Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Thu, 7 Jul 2011 06:35:43 -0400 Subject: [PATCH] Fix bugs finding grep hits in Rmail buffers. --- lisp/ChangeLog | 8 ++++++++ lisp/mail/rmail.el | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 42c1686e9d5..99db8f7962c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2011-07-07 Richard Stallman + + * mail/rmail.el (rmail-next-error-move): Use `compilation-message' + property, and handle its changed format. + Look for the correct line number. + Use file's line contents (but not past first =) to find + correct line in message. + 2011-07-07 Kenichi Handa * international/characters.el (build-unicode-category-table): diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el index 900eedfef84..c43ec9e5611 100644 --- a/lisp/mail/rmail.el +++ b/lisp/mail/rmail.el @@ -3025,9 +3025,13 @@ or forward if N is negative." MSG-POS is a marker pointing at the error message in the grep buffer. BAD-MARKER is a marker that ought to point at where to move to, but probably is garbage." - (let* ((message (car (get-text-property msg-pos 'message (marker-buffer msg-pos)))) - (column (car message)) - (linenum (cadr message)) + + (let* ((message-loc (compilation--message->loc + (get-text-property msg-pos 'compilation-message + (marker-buffer msg-pos)))) + (column (car message-loc)) + (linenum (cadr message-loc)) + line-text pos msgnum msgbeg msgend header-field @@ -3041,10 +3045,18 @@ but probably is garbage." (save-excursion ;; Find the line that the error message points at. (goto-char (point-min)) - (forward-line linenum) + (forward-line (1- linenum)) (setq pos (point)) - ;; Find which message that's in, + ;; Find the text at the start of the line, + ;; before the first = sign. + ;; This text has a good chance of being also in the + ;; decoded message. + (save-excursion + (skip-chars-forward "^=\n") + (setq line-text (buffer-substring pos (point)))) + + ;; Find which message this position is in, ;; and the limits of that message. (setq msgnum (rmail-what-message pos)) (setq msgbeg (rmail-msgbeg msgnum)) @@ -3071,11 +3083,23 @@ but probably is garbage." (rmail-show-message msgnum) ;; Move to the right position within the displayed message. + ;; Or at least try. The decoded message's lines may not + ;; correspond to the lines in the inbox file. + (goto-char (point-min)) (if header-field - (re-search-forward (concat "^" (regexp-quote header-field)) nil t) - (search-forward "\n\n" nil t)) - (forward-line line-number-within) - (forward-char column))) + (progn + (re-search-forward (concat "^" (regexp-quote header-field)) nil t) + (forward-line line-number-within)) + (search-forward "\n\n" nil t) + (if (re-search-forward (concat "^" (regexp-quote line-text)) nil t) + (goto-char (match-beginning 0)))) + (if (eobp) + ;; If the decoded message doesn't have enough lines, + ;; go to the beginning rather than the end. + (goto-char (point-min)) + ;; Otherwise, go to the right column. + (if column + (forward-char column))))) (defun rmail-what-message (&optional pos) "Return message number POS (or point) is in." -- 2.39.5