--- replace.el 26 Jul 2007 07:26:32 +0200 1.259 +++ replace.el 24 Sep 2007 18:04:34 +0200 @@ -525,10 +525,15 @@ (defun keep-lines-read-args (prompt) "Read arguments for `keep-lines' and friends. -Prompt for a regexp with PROMPT. +Prompt for a regexp with PROMPT followed by some information and a colon. Value is a list, (REGEXP)." - (list (read-from-minibuffer prompt nil nil nil - 'regexp-history nil t) + (list (read-from-minibuffer (concat prompt + (if (and transient-mark-mode mark-active) + " in the region: " + (if current-prefix-arg + " backward: " + ": "))) + nil nil nil 'regexp-history nil t) nil nil t)) (defun keep-lines (regexp &optional rstart rend interactive) @@ -547,7 +552,8 @@ Interactively, in Transient Mark mode when the mark is active, operate on all lines whose accessible part is entirely contained in the region. -Otherwise, the command applies to all lines starting after point. +Otherwise, the command applies to all lines starting after point (or before +point if a prefix argument is provided). When calling this function from Lisp, you can pretend that it was called interactively by passing a non-nil INTERACTIVE argument. @@ -558,7 +564,7 @@ (interactive (progn (barf-if-buffer-read-only) - (keep-lines-read-args "Keep lines (containing match for regexp): "))) + (keep-lines-read-args "Keep lines (containing match for regexp)"))) (if rstart (progn (goto-char (min rstart rend)) @@ -576,8 +582,8 @@ (unless (or (bolp) (eobp)) (forward-line 0)) (point-marker))) - (setq rstart (point) - rend (point-max-marker))) + (setq rstart (if current-prefix-arg (point-min) (point)) + rend (if current-prefix-arg (point-marker) (point-max-marker)))) (goto-char rstart)) (save-excursion (or (bolp) (forward-line 1)) @@ -620,9 +626,10 @@ 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 accessible portion of) the buffer. When calling this function -from Lisp, you can pretend that it was called interactively by passing -a non-nil INTERACTIVE argument. +end of (the accessible portion of) the buffer (or its beginning if a prefix +argument is provided). +When calling this function from Lisp, you can pretend that it was called +interactively by passing a non-nil INTERACTIVE argument. If a match is split across lines, all the lines it lies in are deleted. They are deleted _before_ looking for the next match. Hence, a match @@ -631,7 +638,7 @@ (interactive (progn (barf-if-buffer-read-only) - (keep-lines-read-args "Flush lines (containing match for regexp): "))) + (keep-lines-read-args "Flush lines (containing match for regexp)"))) (if rstart (progn (goto-char (min rstart rend)) @@ -639,8 +646,8 @@ (if (and interactive transient-mark-mode mark-active) (setq rstart (region-beginning) rend (copy-marker (region-end))) - (setq rstart (point) - rend (point-max-marker))) + (setq rstart (if current-prefix-arg (point-min) (point)) + rend (if current-prefix-arg (point-marker) (point-max-marker)))) (goto-char rstart)) (let ((case-fold-search (and case-fold-search (isearch-no-upper-case-p regexp t)))) @@ -668,14 +675,16 @@ 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 accessible portion of) the buffer. +end of (the accessible portion of) the buffer (or its beginning if a +prefix argument is provided). This function starts looking for the next match from the end of the previous match. Hence, it ignores matches that overlap a previously found match." (interactive - (keep-lines-read-args "How many matches for (regexp): ")) + (keep-lines-read-args "How many matches for (regexp)")) + (save-excursion (if rstart (progn @@ -684,8 +693,8 @@ (if (and interactive transient-mark-mode mark-active) (setq rstart (region-beginning) rend (region-end)) - (setq rstart (point) - rend (point-max))) + (setq rstart (if current-prefix-arg (point-min) (point)) + rend (if current-prefix-arg (point) (point-max)))) (goto-char rstart)) (let ((count 0) opoint