 	  (if (windowp window)
 	      (set-window-buffer window buffer)
 	    (setq window (display-buffer buffer)))
-    (set-buffer buffer)
-    (if (> line-number 0)
-	(progn
+	  (set-buffer buffer)
+	  (if (> line-number 0)
+	      (progn
 		(setq old-pos (point))
-	  (goto-line line-number)
-	  (set-window-point window (point))
+		(goto-line line-number)
+		(setq old-point (point))
+		(if cscope-adjust-range
+		    (progn
+		      ;; Calculate the length of the line specified by cscope.
+		      (end-of-line)
+		      (setq line-end (point))
+		      (goto-char old-point)
+		      (setq line-length (- line-end old-point))
+
+		      ;; Search forward and backward for the pattern.
+		      (setq forward-point (search-forward
+					   cscope-symbol
+					   (+ old-point
+					      cscope-adjust-range) t))
+		      (goto-char old-point)
+		      (setq backward-point (search-backward
+					    cscope-symbol
+					    (- old-point
+					       cscope-adjust-range) t))
+		      (if forward-point
+			  (progn
+			    (if backward-point
+				(setq new-point
+				      ;; Use whichever of forward-point or
+				      ;; backward-point is closest to old-point.
+				      ;; Give forward-point a line-length advantage
+				      ;; so that if the symbol is on the currrent
+				      ;; line the current line is chosen.
+				      (if (<= (- (- forward-point line-length)
+						 old-point)
+					      (- old-point backward-point))
+					  forward-point
+					backward-point))
+			      (setq new-point forward-point)))
+			(if backward-point
+			    (setq new-point backward-point)
+			  (setq new-point old-point)))
+		      (goto-char new-point)
+		      (beginning-of-line)
+		      (setq new-point (point)))
+		  (setq new-point old-point))
+		(set-window-point window new-point)
 		(if arrow-p
 		    (set-marker overlay-arrow-position (point))
 		  (set-marker overlay-arrow-position nil))
 		(or (not save-mark-p)
 		    (= old-pos (point))
 		    (push-mark old-pos))
-	  ))
+		))
 	  )
       (message "No entry found at point."))
     )

		  (cscope-prompt-for-symbol "Find this egrep pattern: " nil))
		))
  (let ()
    (cscope-call (format "Finding egrep pattern: %s" symbol)
		 (list "-6" symbol) nil 'cscope-process-filter
		 'cscope-process-sentinel)

		(cscope-prompt-for-symbol "Find this global definition: " nil)
		))
  (let ()
    (setq cscope-symbol symbol)
    (cscope-call (format "Finding global definition: %s" symbol)
		 (list "-1" symbol) nil 'cscope-process-filter
		 'cscope-process-sentinel)
