emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: collect-string


From: Stefan Monnier
Subject: Re: collect-string
Date: Thu, 02 Dec 2010 09:16:16 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

>> > Now I am convinced.  How about the change below?
>> Could you send it as a context patch?
> How about this?

IIUC the new arg `collect' overrides `lines' in the sense that when
collect is non-nil lines is simply unused.  So I suggest to just use
a single argument instead (`lines') and simply give additional semantics
to values that weren't supported until now.
E.g. if (numberp lines) then do as before, but if (consp lines) then
only keep the actual match, where (car lines) could specify which
submatch to keep.

>     (list (read-regexp "List lines matching regexp"
>                    (car regexp-history))
>       (when current-prefix-arg
> !       (prefix-numeric-value current-prefix-arg))
> !     (and current-prefix-arg
> !          (listp current-prefix-arg)
> !          (setq last-collect-number
> !                (read-number "Collect" last-collect-number)))))

I recommend you first check (with regexp-opt-depth) whether there is
a submatch, and if not, don't `read-number'.  It's likely to be a very
common case.

> !     (if collect
> !     (with-current-buffer occur-buf
> !       (fundamental-mode)
> !       (let ((inhibit-read-only t)
> !             (buffer-undo-list t))
> !         (erase-buffer)
> !         (while active-bufs
> !           (with-current-buffer (car active-bufs)
> !             (save-excursion
> !               (goto-char (point-min))
> !               (while (re-search-forward regexp nil t)
> !                 (let ((str (match-string collect)))
> !                   (if str
> !                       (with-current-buffer occur-buf
> !                         (insert str)
> !                         (or (zerop (current-column))
> !                             (insert "\n"))))))))
> !           (setq active-bufs (cdr active-bufs))))
> !       (display-buffer occur-buf))
> !       (with-current-buffer occur-buf
> !     (occur-mode)
> !     (let ((inhibit-read-only t)
> !           ;; Don't generate undo entries for creation of the initial 
> contents.
> !           (buffer-undo-list t))
> !       (erase-buffer)
> !       (let ((count (occur-engine
> !                     regexp active-bufs occur-buf
> !                     (or nlines list-matching-lines-default-context-lines)
> !                     (if (and case-fold-search search-upper-case)
> !                         (isearch-no-upper-case-p regexp t)
> !                       case-fold-search)
> !                     list-matching-lines-buffer-name-face
> !                     nil list-matching-lines-face
> !                     (not (eq occur-excluded-properties t)))))
> !         (let* ((bufcount (length active-bufs))
> !                (diff (- (length bufs) bufcount)))
> !           (message "Searched %d buffer%s%s; %s match%s for `%s'"
> !                    bufcount (if (= bufcount 1) "" "s")
> !                    (if (zerop diff) "" (format " (%d killed)" diff))
> !                    (if (zerop count) "no" (format "%d" count))
> !                    (if (= count 1) "" "es")
> !                    regexp))
> !         (setq occur-revert-arguments (list regexp nlines bufs))
> !         (if (= count 0)
> !             (kill-buffer occur-buf)
> !           (display-buffer occur-buf)
> !           (setq next-error-last-buffer occur-buf)
> !           (setq buffer-read-only t)
> !           (set-buffer-modified-p nil)
> !           (run-hooks 'occur-hook))))))))

The "if collect" test should probably not be placed so far out: the
`collect' case should output the same message, run the same hooks, etc
as the non-collect case.


        Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]