Subject: bug#12742: 24.2; [PATCH] flymake cannot goto errors correctly in narrowed buffers

From: Leo <[email-masked]>
Date: Sat, 27 Oct 2012 17:25:35 +0800

In a narrowed buffer, both flymake-goto-next-error and
flymake-goto-prev-error stop working correctly. Any objection to install
the attached fix in the emacs-24 branch?

(ChangeLog change omitted for now).

Leo

>From 09158f75e02a5e1814f2f00d0083dfc80e8f0bc1 Mon Sep 17 00:00:00 2001
From: Leo Liu <[email-masked]>
Date: Sat, 27 Oct 2012 17:14:42 +0800
Subject: [PATCH] Fix flymake error navigation in narrowed buffers

---
 lisp/progmodes/flymake.el | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 2614af9f..8ef09466 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -1262,7 +1262,9 @@ (defun flymake-on-timer-event (buffer)
 
 (defun flymake-current-line-no ()
   "Return number of current line in current buffer."
-  (count-lines (point-min) (if (eobp) (point) (1+ (point)))))
+  (save-restriction
+    (widen)
+    (count-lines (point-min) (if (eobp) (point) (1+ (point))))))
 
 (defun flymake-count-lines ()
   "Return number of lines in buffer BUFFER."
@@ -1491,16 +1493,13 @@ (defun flymake-get-prev-err-line-no (err-info-list line-no)
       (if (> count 0)
 	  (flymake-er-get-line (nth (1- count) err-info-list))))))
 
-(defun flymake-skip-whitespace ()
-  "Move forward until non-whitespace is reached."
-  (while (looking-at "[ \t]")
-    (forward-char)))
-
 (defun flymake-goto-line (line-no)
   "Go to line LINE-NO, then skip whitespace."
-  (goto-char (point-min))
-  (forward-line (1- line-no))
-  (flymake-skip-whitespace))
+  (save-restriction
+    (widen)
+    (goto-char (point-min))
+    (forward-line (1- line-no))
+    (skip-chars-forward "[[:blank:]]")))
 
 (defun flymake-goto-next-error ()
   "Go to next error in err ring."
-- 
1.8.0