[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: DWIM region
From: |
Philipp Stephani |
Subject: |
Re: DWIM region |
Date: |
Fri, 05 Jan 2018 23:18:30 +0000 |
Stefan Monnier <monnier@iro.umontreal.ca> schrieb am Do., 4. Jan. 2018 um
23:19 Uhr:
> > (defun count-regexp-hits (regexp)
> > (interactive "sregexp: ")
> > (let*((region (if mark-active
> > `(,(region-beginning) ,(region-end))
> > `(,(point-min) ,(point-max)) ))
>
> 2 "errors":
> - you should check `use-region-p` instead of `mark-active`.
> - `region` should be an argument, so the use-region-p check is performed
> in the interactive spec rather than in the body of the function:
>
> (defun count-regexp-hits (regexp start end)
> (interactive
> ;; The "s" thingy from `interactive` corresponds to `read-string`
> ;; but we might as well use `read-regexp` here since we can.
> (let ((re (read-regexp "regexp: ")))
> (if (use-region-p)
> (list re (region-beginning) (region-end))
> (list re (point-min) (point-max)))))
> (count-matches regexp start end t))
>
Since this pattern seems to be very common, would it make sense to add an
interactive specifier 'R' that behaves like 'r' if `use-region-p` returns
true and otherwise adds `nil, nil`?
- count regexp hits, Emanuel Berg, 2018/01/03
- RE: count regexp hits, Drew Adams, 2018/01/04
- Message not available
- Re: count regexp hits, Emanuel Berg, 2018/01/04
- Re: DWIM region (was: Re: count regexp hits), Kaushal Modi, 2018/01/04
- Message not available
- Re: DWIM region (was: Re: count regexp hits), Emanuel Berg, 2018/01/04
- Re: DWIM region (was: Re: count regexp hits), Kaushal Modi, 2018/01/04
- Message not available
- Re: DWIM region (was: Re: count regexp hits), Emanuel Berg, 2018/01/04
- advice vs hooks in org (was DWIM region), Rusi, 2018/01/08
- Message not available
- Re: DWIM region, Emanuel Berg, 2018/01/04
- Re: DWIM region, Stefan Monnier, 2018/01/04
- Message not available
- Re: DWIM region, Emanuel Berg, 2018/01/04
- Re: DWIM region, Emanuel Berg, 2018/01/04
- Message not available
- Re: DWIM region, Emanuel Berg, 2018/01/05