[Top][All Lists]

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

Re: simple useful functions

From: Tak Ota
Subject: Re: simple useful functions
Date: Tue, 2 Nov 2010 17:38:45 -0700

Don't you like the simplicity?  How about simply adding collect-string
to replace.el instead of trying to associate it with occur in a clumsy


Mon, 1 Nov 2010 19:22:11 -0700: "Stephen J. Turnbull" <address@hidden> wrote:

> Tak Ota writes:
>  > Could you teach me how to perform collect-string equivalent operation
>  > with occur mode?
> I don't know if you can, maybe there's something in Emacs's version of
> `occur' that would allow it.  I didn't understand your requirements,
> that's why I asked.
> Rather than a separate function, I think it would be useful to augment
> occur-mode here, by saving the occur regexp (say to occur-mode-regexp)
> and adding the following command to occur mode (untested):
> (defun occur-mode-matchers-only ()
>   "Leave only text that matches the first group in the occur regexp.
> If there is no group, use the whole match.
> With more than one group, you should use shy groups for the others.
> Be careful with repeated groups; only one of them will be left."
>   (interactive)
>   (save-excursion
>     (toggle-read-only -1)
>     (goto-char (point-min))
>     (save-match-data
>       ;; don't look at this code lest you be turned to stone, bletch
>       (re-search-forward occur-mode-regexp nil t)
>       (let* ((group (if (match-end 1) 1 0))
>              (previous-end (progn (goto-char (match-end group))
>                                   (point-marker)))
>              temp)
>         (delete-region (point-min) (match-beginning group))
>         (while (re-search-forward occur-mode-regexp nil t)
>           (setq temp (progn (goto-char (match-end group)) (point-marker)))
>           (delete-region previous-end (match-beginning group))
>           (goto-char previous-end)
>           (insert ?\n)
>           (setq previous-end temp))
>         (delete-region previous-end (point-max))
>         (insert ?\n)
>         (goto-char (point-max))
>         (insert ?\n)
>         (toggle-read-only 1)))))

reply via email to

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