[climacs-devel] A nicer transpose-lines

Lawrence Mitchell wencel at gmail.com
Sun Jan 2 18:06:44 UTC 2005


Here's (what I think) is a slightly nicer transpose-lines:


(define-named-command com-transpose-lines ()
  (let ((point (point (win *application-frame*))))
    (beginning-of-line point)
    (unless (beginning-of-buffer-p point)
      (previous-line point))
    (let* ((bol (offset point))
           (eol (progn (end-of-line point)
                       (offset point)))
           (line (buffer-sequence (buffer point) bol eol)))
      (delete-region bol point)
      ;; Remove newline at end of line as well.
      (unless (end-of-buffer-p point)
        (delete-range point))
      ;; If the current line is at the end of the buffer, we want to
      ;; be able to insert past it, so we need to get an extra line
      ;; at the end.
      (when (progn (end-of-line point)
                   (end-of-buffer-p point))
        (insert-object point #\Newline))
      (next-line point)
      (insert-sequence point line)
      (insert-object point #\Newline))))


-- 
Lawrence Mitchell



More information about the climacs-devel mailing list