From: jerry@math.ep.utexas.EDU (Jerry)
Subject: Re: A command to delete to beginning of line?
Organization: Department of Mathematical Sciences--University of Texas at El Paso
Date: Wed, 7 Oct 1992 15:57:24 GMT

C-x C-k is quite natural, whereas C-u - 0 C-k is unwieldy.  From our
site-init.el file:

(define-key ctl-x-map "\C-k" 'backward-kill-line)

(defun backward-kill-line ()
  "Like kill-line, only in reverse.  Kills backward to beginning of line.
If at beginning already, kills previous newline.  Does not accept prefix arg.
Use \\[kill-line-full] (kill-line-full) with negative prefix instead."
  (interactive "*")
  (if (bolp)
      (delete-backward-char 1 t)
  (let ((here (point)))
    (beginning-of-line)
  (kill-region here (point)))))


;; Here's the one I use most often, however.

(define-key esc-map "K" 'kill-line-full)

(defun kill-line-full (arg)
  "Kills entire line that point is on, including the newline at the end.
Positive prefix ARG kills this line plus (arg - 1) lines forward.
Negative prefix ARG kills arg previous lines, but not the current line."
  (interactive "*p")
  (beginning-of-line)
  (let ((beg (point)))
    (forward-line arg)
    (kill-region beg (point))))


;; ---------------- some more funs ----------------

(define-key ctl-x-map "3" 'one-window-or-two)

(defun one-window-or-two (arg)
  "If there is only one window, split-window.  Otherwise, delete-other-windows.
A non-nil prefix ARG runs split-window regardless of the number of windows."
  (interactive "P")
  (if (or (one-window-p) arg)
      (split-window)
    (delete-other-windows)))

(define-key ctl-x-map "6" 'one-window-or-two-horizontal)

(defun one-window-or-two-horizontal (arg)
  "If there is only one window, split-window-vertically.  Otherwise, delete-other-windows.
A non-nil prefix ARG runs split-window-vertically regardless of the number of windows."
  (interactive "P")
  (if (or (one-window-p) arg)
      (split-window-horizontally)
  (delete-other-windows)))

(define-key ctl-x-4-map "B" 'bury-buffer-other-window)

(defun bury-buffer-other-window (arg)
  "Pushes buffer in other window to end of buffer stack
 (making it the least likely to be selected or viewed).
  Prefix ARG pops buffer from bottom of stack making it visible.
If there is only one window, then current buffer is pushed/popped."
  (interactive "P")
  (progn (other-window 1)
	 (if arg (unbury-buffer) (bury-buffer))
	 (other-window -1)))

(define-key esc-map "o" 'open-line-full)

(defun open-line-full (arg)
  "Insert newline at beginning of this line and leave point before it.
Prefix inserts ARG newlines leaving point before all of them."
  (interactive "*p")
  (progn (beginning-of-line) (open-line arg)))

;; This is helpful for grabbing contiguous strings of non-blank characters,
;; such as email addresses.  I use it much more often than mark-word.
(define-key esc-map "H" 'mark-non-whitespace)

(defun mark-non-whitespace ()
  "Mark a block of contiguous non-whitespace.  Like mark-word but ignores punctuation.
  If point is surrounded by whitespace, then the mark is set at current point.
This could be considered a feature."
  (interactive)
  (progn
  (re-search-forward "[ \t\n]" (point-max) 0)
  (backward-char 1)
  (if (looking-at "[ \t\n]")
      (set-mark (point))
    (set-mark (+ (point) 1)))
  (re-search-backward "[ \t\n]" (point-min) 0)
  (if (looking-at "[ \t\n]")
      (forward-char 1))
  (if (not (eq (selected-window) (minibuffer-window)))
      (message "Mark set"))))

(define-key ctl-x-map "B" 'bury-buffer)
(define-key ctl-x-map "U" 'unbury-buffer)

(defun unbury-buffer ()
  "Bring BUFFER from the end of buffer list to the top.  Unlike bury-buffer,
this will find so-called \"hidden buffers\" which begin with a space."
  (interactive)
  (switch-to-buffer (nth (1- (length (buffer-list))) (buffer-list))))


;;; The current transpose command is kinda stupid.  This one makes more sense
(define-key global-map "\C-t" 'transpose-previous-chars)

(defun transpose-previous-chars ()
  "Exchange the two characters before the point without moving point.
If point is at the beginning of the line, then exchange the current line
with the previous line."
  (interactive)
  (if (and (bolp)
	   (null (bobp)))
      (progn
	(transpose-lines 1)
	(next-line -1))
    (if (> (point) 2)
	(progn
	  (forward-char -1)
	  (transpose-subr 'forward-char 1)))))


;; I picked this little gem up from the cis.ohio-state.edu archives.
(define-key ctl-x-4-map "/" 'swap-window-positions)

(defun swap-window-positions ()
  "Swap the positions of this window and the next one."
  (interactive)
  (let ((other-window (next-window (selected-window) 'no-minibuf)))
    (let ((other-window-buffer (window-buffer other-window))
	  (other-window-hscroll (window-hscroll other-window))
	  (other-window-point (window-point other-window))
	  (other-window-start (window-start other-window)))
      (set-window-buffer other-window (current-buffer))
      (set-window-hscroll other-window (window-hscroll (selected-window)))
      (set-window-point other-window (point))
      (set-window-start other-window (window-start (selected-window)))
      (set-window-buffer (selected-window) other-window-buffer)
      (set-window-hscroll (selected-window) other-window-hscroll)
      (set-window-point (selected-window) other-window-point)
      (set-window-start (selected-window) other-window-start))
    (select-window other-window)))

;;-Jerry
;;                             Jerry Graves
;;                          UTEP Math Sysadmin
;;                       jerry@math.ep.utexas.edu
Newsgroups: gnu.emacs.help