[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: DWIM region
From: |
Stefan Monnier |
Subject: |
Re: DWIM region |
Date: |
Thu, 04 Jan 2018 17:18:26 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
> (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))
-- Stefan
- 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