[Top][All Lists]

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


From: Kristof Bastiaensen
Subject: kill-indented-line
Date: Fri, 01 Oct 2004 14:40:07 +0200
User-agent: Pan/ (As She Crawled Across the Table (Debian GNU/Linux))

Hi (X)Emacs users,

I have written a function kill-indented-line, that I find
more comfortable for editing indented text (code).  It 
preserves the indentation better (no need to clean up indentation
after kill-line).

I personally find it an improvement.  I would be interested to
hear you opinion about this.

Here is the code:

(defun kill-indented-line (&optional arg)
  "kill-line for indented text.
preserves indentation and removes extra whitespace"
  (interactive "_P")
  (let ((col (current-column))
        (old-point (point)))
    (cond ((or (and (numberp arg) (< arg 0))
               (and (not (looking-at "[ \t]*$"))
                    (or (not (numberp arg)) (zerop arg))))
           ;use default behavior when calling with a negative argument
           ;or killing (once) from the middle of a line
           (kill-line arg))
          ((and (skip-chars-backward " \t") ;always true
                  (forward-line arg)
                  (not (looking-at "[ \t]*$"))))
           ; killing from an empty line:
           ; preserve indentation of the next line
           (kill-region (point)
                          (forward-line arg)
           (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)
                          (forward-line arg)
                          (skip-chars-forward " \t")


reply via email to

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