Mercurial > emacs
diff lisp/replace.el @ 38040:79be85ef3a31
(keep-lines-read-args): Return just a regexp.
Provide nil for the region args.
(keep-lines, flush-lines, how-many):
Calculate the defaults for the region here, when args are nil.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 14 Jun 2001 20:54:34 +0000 |
parents | 018637678f29 |
children | be5236e1efc7 |
line wrap: on
line diff
--- a/lisp/replace.el Thu Jun 14 15:45:09 2001 +0000 +++ b/lisp/replace.el Thu Jun 14 20:54:34 2001 +0000 @@ -293,23 +293,9 @@ (defun keep-lines-read-args (prompt) "Read arguments for `keep-lines' and friends. Prompt for a regexp with PROMPT. - -Value is a list (REGEXP START END). - -If in Transient Mark mode, and the mark is active, START is the -start of the region, and END is a marker for the end of the region. -Otherwise, START is the current point, and END is the value of -function `point-max-marker'." - (let ((regexp (read-from-minibuffer prompt nil nil nil - 'regexp-history nil t)) - start end) - (if (and transient-mark-mode mark-active) - (setq start (region-beginning) - end (copy-marker (region-end))) - (setq start (point) - end (point-max-marker))) - (list regexp start end))) - +Value is a list, (REGEXP)." + (list (read-from-minibuffer prompt nil nil nil + 'regexp-history nil t))) (defun keep-lines (regexp &optional rstart rend) "Delete all lines except those containing matches for REGEXP. @@ -321,13 +307,20 @@ Second and third arg RSTART and REND specify the region to operate on. -In Transient Mark mode, if the mark is active, operate on the contents -of the region. Otherwise, operate from point to the end of the buffer." +Interactively, in Transient Mark mode when the mark is active, operate +on the contents of the region. Otherwise, operate from point to the +end of the buffer." + (interactive (keep-lines-read-args "Keep lines (containing match for regexp): ")) (if rstart (goto-char (min rstart rend)) - (setq rstart (point) rend (point-max-marker))) + (if (and transient-mark-mode mark-active) + (setq rstart (region-beginning) + rend (copy-marker (region-end))) + (setq rstart (point) + rend (point-max-marker))) + (goto-char rstart)) (save-excursion (or (bolp) (forward-line 1)) (let ((start (point)) @@ -361,13 +354,20 @@ Second and third arg RSTART and REND specify the region to operate on. -In Transient Mark mode, if the mark is active, operate on the contents -of the region. Otherwise, operate from point to the end of the buffer." +Interactively, in Transient Mark mode when the mark is active, operate +on the contents of the region. Otherwise, operate from point to the +end of the buffer." + (interactive (keep-lines-read-args "Flush lines (containing match for regexp): ")) (if rstart (goto-char (min rstart rend)) - (setq rstart (point) rend (point-max-marker))) + (if (and transient-mark-mode mark-active) + (setq rstart (region-beginning) + rend (copy-marker (region-end))) + (setq rstart (point) + rend (point-max-marker))) + (goto-char rstart)) (let ((case-fold-search (and case-fold-search (isearch-no-upper-case-p regexp t)))) (save-excursion @@ -387,14 +387,21 @@ Second and third arg RSTART and REND specify the region to operate on. -In Transient Mark mode, if the mark is active, operate on the contents -of the region. Otherwise, operate from point to the end of the buffer." +Interactively, in Transient Mark mode when the mark is active, operate +on the contents of the region. Otherwise, operate from point to the +end of the buffer." + (interactive (keep-lines-read-args "How many matches for (regexp): ")) (save-excursion (if rstart (goto-char (min rstart rend)) - (setq rstart (point) rend (point-max-marker))) + (if (and transient-mark-mode mark-active) + (setq rstart (region-beginning) + rend (copy-marker (region-end))) + (setq rstart (point) + rend (point-max-marker))) + (goto-char rstart)) (let ((count 0) opoint (case-fold-search (and case-fold-search