8

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?

wdkrnls
  • 3,657
  • 2
  • 27
  • 46
  • 3
    You can select the line, narrow to that region and do the plain old incremental search. – Kaushal Modi Jan 26 '15 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 '15 at 02:09
  • OP: What do you mean by "(and fontify)"? – Drew Jan 27 '15 at 02:14
  • @Drew: isearch highlights matches, which is nice, but really slow. – wdkrnls Jan 27 '15 at 02:50
  • I still don't know what your request "(and fontify)" means. You are apparently looking for some kind of highlighting of matches, but not isearch highlighting. – Drew Jan 27 '15 at 15:43
  • 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 '15 at 15:46
  • I didn't know about these options. Thanks! – wdkrnls Jan 27 '15 at 15:49

2 Answers2

10
  • 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 )
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
8

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]")
         (isearch-search-fun-function
          `(lambda ()
             (lambda (string &optional bound noerror)
               (save-restriction
                 (narrow-to-region ,beg ,end)
                 (funcall (isearch-search-fun-default)
                          string bound noerror))))))
    (isearch-forward regexp-p)))
politza
  • 3,316
  • 14
  • 16