(defun zorch-line ()
  "Kill the line the point is on, from anywhere on that line"
  (interactive)
  (save-excursion
    (kill-new "")
    (kill-region (line-beginning-position)
                         (if (= (line-end-position) (point-max))
                                    (line-end-position)
                                    (+ 1 (line-end-position))))
    ))
 
(defun duplicate-line ()
  "Duplicate the line the point is on, moving the point to the duplicate"
  (interactive)
  (save-excursion
    (kill-new (buffer-substring (line-beginning-position) (line-end-position)))
    (end-of-line)
    (newline)
    (yank)
    (rotate-yank-pointer 1)
    )
  (next-line 1)
  )
 
(defun entag (start end tagname)
  "Surround region with HTML tag"
  (interactive "r\nsTag name: ")
  (save-excursion
    (goto-char end)
    (insert "</" tagname ">")
    (goto-char start)
    (insert "<" tagname ">")
    )
  (goto-char (+ start 1 (length tagname)))
)
 
(defun copy-whole-buffer ()
  "Add a new entry to the kill ring containing the entire buffer"
  (interactive)
  (kill-new (buffer-substring (point-min) (point-max)))
  (message "Buffer %s copied to kill ring" (buffer-name)))
 
(defun roll-line-down ()
  "Exchange the line the point is on with the one below it"
  (interactive)
  (let ((col (current-column))
            (yank-ptr-cache kill-ring-yank-pointer))
    (save-excursion
      (zorch-line)
      (next-line 1)
      (yank)
      )
    (next-line 1)
    (forward-char col)
    (setq kill-ring-yank-pointer yank-ptr-cache))
  '())
 
(defun roll-line-up ()
  "Exchange the line the point is on with the one above it"
  (interactive)
  (let ((col (current-column))
            (yank-ptr-cache kill-ring-yank-pointer))
    (save-excursion
      (zorch-line)
      (next-line -1)
      (yank)
      )
    (next-line -2)
    (forward-char col)
    (setq kill-ring-yank-pointer yank-ptr-cache))
  '())
 
(global-set-key [(meta up)] 'roll-line-up)
(global-set-key [(meta down)] 'roll-line-down)
(global-set-key "\M-k" 'zorch-line)
(global-set-key "\M-d" 'duplicate-line)
(global-set-key "\C-e" 'entag)
(global-set-key "\C-a" 'copy-whole-buffer)
