[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
way?
-Tak
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)))))
>
- Re: simple useful functions, Tak Ota, 2010/11/01
- Re: simple useful functions, Stephen J. Turnbull, 2010/11/01
- Re: simple useful functions,
Tak Ota <=
- Re: simple useful functions, Tak Ota, 2010/11/03
- Re: simple useful functions, Stephen J. Turnbull, 2010/11/03
- Re: simple useful functions, Tak Ota, 2010/11/03
- collect-string (was: simple useful functions), Stefan Monnier, 2010/11/04
- Re: collect-string (was: simple useful functions), Tak Ota, 2010/11/04
- Re: collect-string (was: simple useful functions), Tak Ota, 2010/11/04