emacs-devel
[Top][All Lists]
Advanced

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

address@hidden: Re: kill-indented-line]


From: Richard Stallman
Subject: address@hidden: Re: kill-indented-line]
Date: Mon, 11 Oct 2004 02:18:17 -0400

Would people like to try out this patch and see if they like it?

------- Start of forwarded message -------
X-Authentication-Warning: mail.dirkl.nl: apache set sender to address@hidden 
using -f
In-Reply-To: <address@hidden>
Date: Tue, 5 Oct 2004 02:10:59 +0200 (CEST)
Subject: Re: kill-indented-line
From: address@hidden
To: address@hidden
X-Spam-Status: No, hits=-1.6 required=5.0
        tests=IN_REP_TO,NO_REAL_NAME,PATCH_UNIFIED_DIFF,
              QUOTED_EMAIL_TEXT,RCVD_IN_ORBS,REFERENCES,
              REPLY_WITH_QUOTES,USER_AGENT,X_AUTH_WARNING
        version=2.55
X-Spam-Level: 
X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp)

- ------=_20041005021059_18684
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

>     * killing from the end of a line (only whitespace after point):
>       - if the line is only whitespace: just erase this line
>       - otherwise kill all whitespace from point upto
>       the first nonwhitespace character on the next line.
>
> It sounds like an interesting idea to try.
> Could you send me a patch that would change kill-line to do this?
>

Ok.  I have created a patch against simple.el that works with the cvs
version of emacs.

Regards,
Kristof Bastiaensen
- ------=_20041005021059_18684
Content-Type: text/x-patch; name="simple.el.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="simple.el.patch"

Index: simple.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/simple.el,v
retrieving revision 1.661
diff -u -r1.661 simple.el
- --- simple.el 19 Sep 2004 00:02:44 -0000      1.661
+++ simple.el   5 Oct 2004 00:47:51 -0000
@@ -2476,30 +2476,51 @@
 \(If the variable `kill-read-only-ok' is non-nil, then this won't
 even beep.)"
   (interactive "P")
- -  (kill-region (point)
- -            ;; It is better to move point to the other end of the kill
- -            ;; before killing.  That way, in a read-only buffer, point
- -            ;; moves across the text that is copied to the kill ring.
- -            ;; The choice has no effect on undo now that undo records
- -            ;; the value of point from before the command was run.
- -            (progn
- -              (if arg
- -                  (forward-visible-line (prefix-numeric-value arg))
- -                (if (eobp)
- -                    (signal 'end-of-buffer nil))
- -                (let ((end
- -                       (save-excursion
- -                         (end-of-visible-line) (point))))
- -                  (if (or (save-excursion
- -                            ;; If trailing whitespace is visible,
- -                            ;; don't treat it as nothing.
- -                            (unless show-trailing-whitespace
- -                              (skip-chars-forward " \t" end))
- -                            (= (point) end))
- -                          (and kill-whole-line (bolp)))
- -                      (forward-visible-line 1)
- -                    (goto-char end))))
- -              (point))))
+  (let ((col (current-column))
+       (old-point (point))
+       (arg (if arg (prefix-numeric-value arg)))
+       (go-forward (lambda (arg)
+                     (if arg (forward-visible-line arg)
+                       (forward-visible-line 1)))))
+    (cond ((or (and arg (<= arg 0))
+              (and (not (looking-at (if show-trailing-whitespace
+                                        "$" "[ \t]*$")))
+                   (not arg)))
+          ; kill without adjusting indentation
+          (kill-region (point)
+                       ;; It is better to move point to the other end of the 
kill
+                       ;; before killing.  That way, in a read-only buffer, 
point
+                       ;; moves across the text that is copied to the kill 
ring.
+                       ;; The choice has no effect on undo now that undo 
records
+                       ;; the value of point from before the command was run.
+                       (progn
+                         (if arg (forward-visible-line arg)
+                           (if (eobp) (signal 'end-of-buffer nil))
+                           (if (and kill-whole-line (bolp))
+                               (forward-visible-line 1)
+                             (end-of-visible-line)))
+                         (point))))
+         ((and (skip-chars-backward " \t") ;always true
+               (bolp)
+               (save-excursion
+                 (funcall go-forward arg)
+                 (not (looking-at "[ \t]*$"))))
+          ; killing from an empty line:
+          ; preserve indentation of the next line
+          (kill-region (point)
+                       (save-excursion
+                         (funcall go-forward arg)
+                         (point)))
+          (skip-chars-forward " \t")
+          (if (> (current-column) col)
+              (move-to-column col)))
+         (t ; killing from not empty line:
+            ; kill all indentation
+          (goto-char old-point)
+          (kill-region (point)
+                       (progn (funcall go-forward arg)
+                              (skip-chars-forward " \t")
+                              (point)))))))
 
 (defun kill-whole-line (&optional arg)
   "Kill current line.
- ------=_20041005021059_18684--
------- End of forwarded message -------




reply via email to

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