unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Andreas Röhler" <andreas.roehler@online.de>
To: Tak Ota <Takaaki.Ota@am.sony.com>
Cc: "Stephen J. Turnbull" <stephen@xemacs.org>,
	Stefan Monnier <monnier@IRO.UMontreal.CA>,
	Emacs developers <emacs-devel@gnu.org>
Subject: Re: collect-string (was: simple useful functions)
Date: Fri, 05 Nov 2010 08:52:26 +0100	[thread overview]
Message-ID: <4CD3B7BA.9070004@online.de> (raw)
In-Reply-To: <20101104.132709.29335017.Takaaki.Ota@am.sony.com>

Am 04.11.2010 21:27, schrieb Tak Ota:
> And here is the change log update.
>
> 2010-11-04  Takaaki Ota<Takaaki.Ota@am.sony.com>
>
> 	* replace.el (occur-1): Add string collection feature when NLINES
> 	is zero or negative integer value.
>
> -Tak
>
> Thu, 04 Nov 2010 13:18:20 -0700: Tak Ota<Takaaki.Ota@am.sony.com>  wrote:
>
>> The documentation can be something like this.  I just added the last
>> paragraph below.
>>
>> -Tak
>>
>> `M-x occur'
>>       Prompt for a regexp, and display a list showing each line in the
>>       buffer that contains a match for it.  To limit the search to part
>>       of the buffer, narrow to that part (*note Narrowing::).  A numeric
>>       argument N specifies that N lines of context are to be displayed
>>       before and after each matching line.  Currently, `occur' can not
>>       correctly handle multiline matches.
>>
>>       The buffer `*Occur*' containing the output serves as a menu for
>>       finding the occurrences in their original context.  Click
>>       `Mouse-2' on an occurrence listed in `*Occur*', or position point
>>       there and type<RET>; this switches to the buffer that was
>>       searched and moves point to the original of the chosen occurrence.
>>       `o' and `C-o' display the match in another window; `C-o' does not
>>       select it.
>>
>>       After using `M-x occur', you can use `next-error' to visit the
>>       occurrences found, one by one.  *note Compilation Mode::.
>>
>>       When the numeric argument N is 0 or negative the buffer `*Occur*'
>>       collects all the matched strings.  When N is 0 the entire text
>>       matched is collected.  When N is negative the text in the -Nth
>>       parenthesized expression in the regexp is collected.
>>
>>
>> Thu, 04 Nov 2010 11:36:54 -0700: Tak Ota<Takaaki.Ota@am.sony.com>  wrote:
>>
>>> Thu, 4 Nov 2010 06:58:20 -0700: Stefan Monnier<monnier@iro.umontreal.ca>  wrote:
>>>
>>>>>> How about rename the command as collect-occur instead of
>>>>>> collect-string and document it as next?
>>>>> Wrong namespace.  IMO, the name should *start* with occur (but Stefan
>>>>> and Yidong are final authorities on that).
>>>>
>>>> Agreed, namespace cleanliness is one of my favorite forms of
>>>> anal retentiveness.
>>>>
>>>> The way I see it, the suggested collect-string is a variant of occur
>>>> where the result buffer contains none of the regexp matches's context.
>>>> So it would make sense to integrate it very tightly with `occur',
>>>> i.e. make M-x occur do the job of collect-strings for some particular
>>>> value of its argument NLINES.  Currently, NLINES is assumed to be
>>>> a number and all values of that number have a useful meaning, so we'd
>>>> have to add this new feature via a non-number value of NLINES.
>>>>
>>>> E.g. C-u M-x occur could do the collect-string thingy (which is still an
>>>> incompatible change since some people may like to use C-u M-x occur to get
>>>> 4 lines of context, but you can make omelets without breaking eggs).
>>>>
>>>>
>>>>          Stefan
>>>>
>>>
>>> Now I am convinced.  How about the change below?  In conventional
>>> occur zero or negative value for nlines is meaningless correct?  We
>>> can use that for collection purpose.  i.e. C-u 0 M-x occur does the
>>> collection of the matching pattern.  C-u -1 M-x occur performs the
>>> collection of the recorded pattern 1.
>>>
>>> -Tak
>>>
>>> (defun occur-1 (regexp nlines bufs&optional buf-name)
>>>    (unless (and regexp (not (equal regexp "")))
>>>      (error "Occur doesn't work with the empty regexp"))
>>>    (unless buf-name
>>>      (setq buf-name "*Occur*"))
>>>    (let (occur-buf
>>> 	(active-bufs (delq nil (mapcar #'(lambda (buf)
>>> 					   (when (buffer-live-p buf) buf))
>>> 				       bufs))))
>>>      ;; Handle the case where one of the buffers we're searching is the
>>>      ;; output buffer.  Just rename it.
>>>      (when (member buf-name (mapcar 'buffer-name active-bufs))
>>>        (with-current-buffer (get-buffer buf-name)
>>> 	(rename-uniquely)))
>>>
>>>      ;; Now find or create the output buffer.
>>>      ;; If we just renamed that buffer, we will make a new one here.
>>>      (setq occur-buf (get-buffer-create buf-name))
>>>
>>>      (if (or (null (integerp nlines))
>>> 	    (>  nlines 0))
>>> 	;; nlines is not zero or negative so perform nomal occur
>>> 	(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)))))
>>>        ;; nlines is zero or negative integer perform collect-string
>>>        (with-current-buffer occur-buf
>>> 	(setq nlines (- nlines))
>>> 	(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 nlines)))
>>> 		    (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)))))
>
>
>

Hi Tak,

please permit a consideration, which affects Emacs usability as such:

do you recognise the difference between

;;;;;;;;;;;;;;;;;;;;;
  When the numeric argument N is 0 or negative the buffer `*Occur*'
      collects all the matched strings.  When N is 0 the entire text
      matched is collected.  When N is negative the text in the -Nth
      parenthesized expression in the regexp is collected.
;;;;;;;;;;;;;;;;;;;;

and your original describtion

;;;;;;;;;;;;;;;;;;;
  "Collect strings of REGEXP (or optional NUM paren) from the
current buffer into a collection buffer."
;;;;;;;;;;;;;;;;;;;

Which one would you think is more readable?

Cheers

Andreas








  reply	other threads:[~2010-11-05  7:52 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-28 18:56 simple useful functions Tak Ota
2010-10-29  3:39 ` Stephen J. Turnbull
2010-10-29 18:13   ` Tak Ota
2010-10-29 19:02     ` Drew Adams
2010-10-29 19:26       ` Andreas Schwab
2010-10-29 20:19         ` Drew Adams
2010-10-29 20:47           ` Andreas Schwab
2010-10-29 20:56             ` Chad Brown
2010-10-29 21:23               ` Drew Adams
2010-10-30  9:01       ` Stephen J. Turnbull
2010-10-30 10:55     ` Thierry Volpiatto
2010-11-02  0:40     ` Tak Ota
2010-11-02  2:22       ` Stephen J. Turnbull
2010-11-03  0:38         ` Tak Ota
2010-11-03  5:27           ` Stephen J. Turnbull
2010-11-03  8:09             ` Andreas Röhler
2010-11-03 10:13               ` Stephen J. Turnbull
2010-11-03 18:08                 ` Tak Ota
2010-11-03 18:01             ` Tak Ota
2010-11-04  2:10               ` Stephen J. Turnbull
2010-11-04  2:20                 ` Tak Ota
2010-11-04 13:58                 ` collect-string (was: simple useful functions) Stefan Monnier
2010-11-04 18:36                   ` Tak Ota
2010-11-04 20:18                     ` Tak Ota
2010-11-04 20:27                       ` Tak Ota
2010-11-05  7:52                         ` Andreas Röhler [this message]
2010-11-08 18:36                     ` collect-string Stefan Monnier
2010-11-09  0:18                       ` collect-string Tak Ota
2010-11-09  9:06                         ` collect-string Stephen J. Turnbull
2010-11-10  2:12                       ` collect-string Tak Ota
2010-11-30  2:14                         ` collect-string Tak Ota
2010-11-30  5:27                           ` collect-string Stephen J. Turnbull
2010-12-02  1:59                             ` collect-string Tak Ota
2010-12-02  7:00                               ` collect-string Stephen J. Turnbull
2010-12-02 14:16                         ` collect-string Stefan Monnier
2010-12-03  1:03                           ` collect-string Tak Ota
2010-12-03 19:17                             ` collect-string Stefan Monnier
2010-12-03 22:31                               ` collect-string Tak Ota
2010-12-03 22:40                                 ` collect-string Davis Herring
2010-12-03 22:47                                   ` collect-string Tak Ota
2010-12-03 22:56                                 ` collect-string Stefan Monnier
2010-12-03 23:15                                   ` collect-string Tak Ota
2010-12-04  2:01                                     ` collect-string Stefan Monnier
2010-12-04  2:07                                       ` collect-string Tak Ota
2010-12-04  3:27                                   ` collect-string Glenn Morris
2010-10-29  8:44 ` simple useful functions Andreas Schwab
2010-11-02  7:27 ` Andreas Röhler
2010-12-03 23:37 ` Tak Ota
2010-12-04  2:36   ` Stefan Monnier
2010-12-04  2:58     ` Tak Ota
2010-12-04  4:36       ` Stefan Monnier
2010-12-04  9:10         ` David Kastrup
2010-12-06 14:08         ` René Kyllingstad
2010-12-06 19:31           ` Stefan Monnier
2010-12-06 18:39         ` Tak Ota
2010-12-06 20:23           ` Stefan Monnier
2010-12-06 21:25             ` Tak Ota
2010-12-07  3:24               ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CD3B7BA.9070004@online.de \
    --to=andreas.roehler@online.de \
    --cc=Takaaki.Ota@am.sony.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    --cc=stephen@xemacs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).