]> code.delx.au - gnu-emacs/blobdiff - lisp/rect.el
Auto-commit of generated files.
[gnu-emacs] / lisp / rect.el
index ad914cab7d2beba096baebcbc3eea1247a660201..ec234b6514f5d46bfd9c04a9bd2a0164c0d27d2f 100644 (file)
@@ -1,6 +1,6 @@
 ;;; rect.el --- rectangle functions for GNU Emacs
 
-;; Copyright (C) 1985, 1999-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1999-2013 Free Software Foundation, Inc.
 
 ;; Maintainer: Didier Verna <didier@xemacs.org>
 ;; Keywords: internal
 ;; ### NOTE: this file was almost completely rewritten by Didier Verna
 ;; <didier@xemacs.org> in July 1999.
 
-;;; Global key bindings
-
-;;;###autoload (define-key ctl-x-r-map "c" 'clear-rectangle)
-;;;###autoload (define-key ctl-x-r-map "k" 'kill-rectangle)
-;;;###autoload (define-key ctl-x-r-map "d" 'delete-rectangle)
-;;;###autoload (define-key ctl-x-r-map "y" 'yank-rectangle)
-;;;###autoload (define-key ctl-x-r-map "o" 'open-rectangle)
-;;;###autoload (define-key ctl-x-r-map "t" 'string-rectangle)
-;;;###autoload (define-key ctl-x-r-map "N" 'rectangle-number-lines)
-
 ;;; Code:
 
 ;; FIXME: this function should be replaced by `apply-on-rectangle'
@@ -93,8 +83,9 @@ Point is at the end of the segment of this line within the rectangle."
   "Call FUNCTION for each line of rectangle with corners at START, END.
 FUNCTION is called with two arguments: the start and end columns of the
 rectangle, plus ARGS extra arguments.  Point is at the beginning of line when
-the function is called."
-  (let (startcol startpt endcol endpt)
+the function is called.
+The final point after the last operation will be returned."
+  (let (startcol startpt endcol endpt final-point)
     (save-excursion
       (goto-char start)
       (setq startcol (current-column))
@@ -112,8 +103,9 @@ the function is called."
       (goto-char startpt)
       (while (< (point) endpt)
        (apply function startcol endcol args)
+       (setq final-point (point))
        (forward-line 1)))
-    ))
+    final-point))
 
 (defun delete-rectangle-line (startcol endcol fill)
   (when (= (move-to-column startcol (if fill t 'coerce)) startcol)
@@ -227,12 +219,22 @@ even beep.)"
   (condition-case nil
       (setq killed-rectangle (delete-extract-rectangle start end fill))
     ((buffer-read-only text-read-only)
+     (setq deactivate-mark t)
      (setq killed-rectangle (extract-rectangle start end))
      (if kill-read-only-ok
         (progn (message "Read only text copied to kill ring") nil)
        (barf-if-buffer-read-only)
        (signal 'text-read-only (list (current-buffer)))))))
 
+;;;###autoload
+(defun copy-rectangle-as-kill (start end)
+  "Copy the region-rectangle and save it as the last killed one."
+  (interactive "r")
+  (setq killed-rectangle (extract-rectangle start end))
+  (setq deactivate-mark t)
+  (if (called-interactively-p 'interactive)
+      (indicate-copied-region (length (car killed-rectangle)))))
+
 ;;;###autoload
 (defun yank-rectangle ()
   "Yank the last killed rectangle with upper left corner at point."
@@ -323,7 +325,8 @@ Called from a program, takes three args; START, END and STRING."
                                (or (car string-rectangle-history) ""))
                        nil 'string-rectangle-history
                        (car string-rectangle-history)))))
-  (apply-on-rectangle 'string-rectangle-line start end string t))
+  (goto-char
+   (apply-on-rectangle 'string-rectangle-line start end string t)))
 
 ;;;###autoload
 (defalias 'replace-rectangle 'string-rectangle)