I'm working with large, extra wide data files I probably should just be viewing in Excel... but I'd rather stay in Emacs. Is there an elisp function to search (and fontify) just on the current line?

  • 3
    You can select the line, narrow to that region and do the plain old incremental search. Jan 26, 2015 at 22:33
  • @kaushalmodi: Please post that as an answer (a good one). If an answer gets accepted then the question no longer appears among those unanswered. ;-)
    – Drew
    Jan 27, 2015 at 2:09
  • OP: What do you mean by "(and fontify)"?
    – Drew
    Jan 27, 2015 at 2:14
  • @Drew: isearch highlights matches, which is nice, but really slow.
    – wdkrnls
    Jan 27, 2015 at 2:50
  • 1
    Keep in mind that you can tell Isearch how many matches to highlight at a time: option lazy-highlight-max-at-a-time. See also other lazy-highlight-* options. But this highlighting might treat a whole line at once; dunno. If it does, and these options don't help, consider filing an enhancement request: M-x report-emacs-bug.
    – Drew
    Jan 27, 2015 at 15:46

2 Answers 2


Isearch is quite flexible and if you become tired of constantly narrowing the buffer (as was suggested), you may want to have a dedicated command for this, e.g.

(defun isearch-line-forward (&optional regexp-p)
  (interactive "P")
  (let* ((beg (line-beginning-position))
         (end (line-end-position))
         (isearch-message-prefix-add "[Line]")
          `(lambda ()
             (lambda (string &optional bound noerror)
                 (narrow-to-region ,beg ,end)
                 (funcall (isearch-search-fun-default)
                          string bound noerror))))))
    (isearch-forward regexp-p)))
  • Select the current line ( C-a C-SPC C-e )
  • Narrow region ( C-x n n )
  • Perform search using any method
  • Go back to the original buffer by widening ( C-x n w )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.