emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

keep|flush-lines, how-many to be used backward.


From: Michaël Cadilhac
Subject: keep|flush-lines, how-many to be used backward.
Date: Mon, 24 Sep 2007 18:08:22 +0200
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux)

I've been using this for a few days, and I find it quite useful.  It may
be good to install.

The effect: C-u M-x how-many RET is how-many'ing in the text *before*
point.  Same for C-u M-x keep-lines.

If this is not the right thing to do for such a feature, just say it,
I'll not insist too much.

--- 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

-- 
 |   Michaël `Micha' Cadilhac       |  In a World without Walls and Fences,  |
 |   http://michael.cadilhac.name   |     who needs Windows and Gates?       |
 |   JID/MSN:                       |          -- Dino Esposito              |
 `----  address@hidden  |                                   -  --'

Attachment: pgph_zMSmouPH.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]