Commit 08ce70d1 authored by Jim Blandy's avatar Jim Blandy
Browse files

* rect.el (operate-on-rectangle): Use move-to-column's FORCE

	argument instead of implementing it ourselves.
	(rectangle-coerce-tab): No longer used; deleted.

	* rect.el (open-rectangle): Leave point at the upper corner of the
	rectangle just opened, in imitation of open-line.  Fix doc typo.
	(open-rectangle-line): Use skip-chars-backward's LIM argument to
	leave spaces before the line segment's beginning undisturbed.

	* rect.el: Provide 'rect.
parent 04715579
...@@ -45,24 +45,16 @@ Point is at the end of the segment of this line within the rectangle." ...@@ -45,24 +45,16 @@ Point is at the end of the segment of this line within the rectangle."
(forward-line 1) (forward-line 1)
(setq endlinepos (point-marker))) (setq endlinepos (point-marker)))
(if (< endcol startcol) (if (< endcol startcol)
(let ((tem startcol)) (setq startcol (prog1 endcol (setq endcol startcol))))
(setq startcol endcol endcol tem)))
(if (/= endcol startcol) (if (/= endcol startcol)
(save-excursion (save-excursion
(goto-char startlinepos) (goto-char startlinepos)
(while (< (point) endlinepos) (while (< (point) endlinepos)
(let (startpos begextra endextra) (let (startpos begextra endextra)
(move-to-column startcol) (move-to-column startcol coerce-tabs)
(and coerce-tabs
(> (current-column) startcol)
(rectangle-coerce-tab startcol))
(setq begextra (- (current-column) startcol)) (setq begextra (- (current-column) startcol))
(setq startpos (point)) (setq startpos (point))
(move-to-column endcol) (move-to-column endcol coerce-tabs)
(if (> (current-column) endcol)
(if coerce-tabs
(rectangle-coerce-tab endcol)
(forward-char -1)))
(setq endextra (- endcol (current-column))) (setq endextra (- endcol (current-column)))
(if (< begextra 0) (if (< begextra 0)
(setq endextra (+ endextra begextra) (setq endextra (+ endextra begextra)
...@@ -167,11 +159,7 @@ and point is at the lower right corner." ...@@ -167,11 +159,7 @@ and point is at the lower right corner."
(progn (progn
(forward-line 1) (forward-line 1)
(or (bolp) (insert ?\n)) (or (bolp) (insert ?\n))
(move-to-column insertcolumn) (move-to-column insertcolumn t)))
(if (> (current-column) insertcolumn)
(rectangle-coerce-tab insertcolumn))
(if (< (current-column) insertcolumn)
(indent-to insertcolumn))))
(setq first nil) (setq first nil)
(insert (car lines)) (insert (car lines))
(setq lines (cdr lines))))) (setq lines (cdr lines)))))
...@@ -180,9 +168,10 @@ and point is at the lower right corner." ...@@ -180,9 +168,10 @@ and point is at the lower right corner."
(defun open-rectangle (start end) (defun open-rectangle (start end)
"Blank out rectangle with corners at point and mark, shifting text right. "Blank out rectangle with corners at point and mark, shifting text right.
The text previously in the region is not overwritten by the blanks, The text previously in the region is not overwritten by the blanks,
but insted winds up to the right of the rectangle." but instead winds up to the right of the rectangle."
(interactive "r") (interactive "r")
(operate-on-rectangle 'open-rectangle-line start end nil)) (operate-on-rectangle 'open-rectangle-line start end nil)
(goto-char start))
(defun open-rectangle-line (startpos begextra endextra) (defun open-rectangle-line (startpos begextra endextra)
(let ((column (+ (current-column) begextra endextra))) (let ((column (+ (current-column) begextra endextra)))
...@@ -191,7 +180,9 @@ but insted winds up to the right of the rectangle." ...@@ -191,7 +180,9 @@ but insted winds up to the right of the rectangle."
(skip-chars-forward " \t") (skip-chars-forward " \t")
(setq column (+ column (- (current-column) ocol)))) (setq column (+ column (- (current-column) ocol))))
(delete-region (point) (delete-region (point)
(progn (skip-chars-backward " \t") ;; Use skip-chars-backward's LIM argument to leave
;; characters before STARTPOS undisturbed.
(progn (skip-chars-backward " \t" startpos)
(point))) (point)))
(indent-to column))) (indent-to column)))
...@@ -212,11 +203,6 @@ When called from a program, requires two args which specify the corners." ...@@ -212,11 +203,6 @@ When called from a program, requires two args which specify the corners."
(point))) (point)))
(indent-to column))) (indent-to column)))
(defun rectangle-coerce-tab (column) (provide 'rect)
(let ((aftercol (current-column))
(indent-tabs-mode nil))
(delete-char -1)
(indent-to aftercol)
(backward-char (- aftercol column))))
;;; rect.el ends here ;;; rect.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment