🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #87843

rect.el

#87843
From: Kenichi Handa
Date: Mon, 29 Aug 1994 07:14
109 lines
4580 bytes
In GNU Emacs 19.25 on etlken (sparc-sun-sunos),
`kill-rectangle' causes an error of:
	Args out of range: ["" " " "  "...
when killing a rectangle which covers part of multi-column
characters.  More precisely, when you have a buffer which contains
	+--------------
	|a
	|\200
	|bc
	|
(where \200 is a character produced by C-q 2 0 0), setting
region at after `a' and after `c' and doing M-x
kill-rectangle causes this error.

The debugger information is as follows:
------------------------------------------------------------
Signalling: (args-out-of-range ["" " " "  " "   " "    " "     " "      " "       " "        "] -2)
  spaces-string(-2)
  extract-rectangle-line(4 3 -2)
  delete-extract-rectangle-line(4 3 -2)
  operate-on-rectangle(delete-extract-rectangle-line 2 7 t)
  delete-extract-rectangle(2 7)
  kill-rectangle(2 7)
  call-interactively(kill-rectangle)
  execute-extended-command(nil)
  call-interactively(execute-extended-command)
------------------------------------------------------------

The reason is that the current code in rect.el is quite
naive about multi-column characters except for TAB.  A patch 
is attached at the tail of this mail.

---
Ken'ichi HANDA
handa@etl.go.jp

--- /usr/share/src/emacs-19.25/lisp/rect.el	Wed May  4 07:46:13 1994
+++ rect.el	Mon Aug 29 15:54:10 1994
@@ -55,14 +55,30 @@
      (goto-char startlinepos)
      (while (< (point) endlinepos)
        (let (startpos begextra endextra)
-	 (move-to-column startcol coerce-tabs)
+	 (move-to-column startcol)
 	 (setq begextra (- (current-column) startcol))
+	 (if (and coerce-tabs (> begextra 0))
+	     (progn
+	       (delete-char -1)
+	       (insert-char ?  (+ begextra (- startcol (current-column))))
+	       (forward-char (- begextra))
+	       (setq begextra 0)))
 	 (setq startpos (point))
-	 (move-to-column endcol coerce-tabs)
+	 (move-to-column endcol)
 	 (setq endextra (- endcol (current-column)))
+	 (if (and coerce-tabs (< endextra 0))
+	     (progn
+	       (delete-char -1)
+	       (insert-char ?  (- (- endcol (current-column)) endextra))
+	       (forward-char endextra)
+	       (setq endextra 0)))
 	 (if (< begextra 0)
 	     (setq endextra (+ endextra begextra)
-		   begextra 0))
+		   begextra 0)
+	   (if (< endextra 0)
+	       (progn
+		 (forward-char -1)
+		 (setq endextra (- endcol (current-column))))))
 	 (funcall function startpos begextra endextra))
        (forward-line 1)))
     (- endcol startcol)))
@@ -76,20 +92,22 @@
   (delete-region startdelpos (point)))
 
 (defun extract-rectangle-line (startdelpos begextra endextra)
-  (let ((line (buffer-substring startdelpos (point)))
-	(end (point)))
-    (goto-char startdelpos)
-    (while (search-forward "\t" end t)
-      (let ((width (- (current-column)
-		      (save-excursion (forward-char -1)
-				      (current-column)))))
-	(setq line (concat (substring line 0 (- (point) end 1))
-			   (spaces-string width)
-			   (substring line (+ (length line) (- (point) end)))))))
-    (if (or (> begextra 0) (> endextra 0))
-	(setq line (concat (spaces-string begextra)
-			   line
-			   (spaces-string endextra))))
+  (let (line (end (point)))
+    (if (> startdelpos end)
+	(setq line (make-string (- begextra endextra) ? ))
+      (setq line (buffer-substring startdelpos end))
+      (goto-char startdelpos)
+      (while (search-forward "\t" end t)
+	(let ((width (- (current-column)
+			(save-excursion (forward-char -1)
+					(current-column)))))
+	  (setq line (concat (substring line 0 (- (point) end 1))
+			     (spaces-string width)
+			     (substring line (+ (length line) (- (point) end)))))))
+      (if (or (> begextra 0) (> endextra 0))
+	  (setq line (concat (spaces-string begextra)
+			     line
+			     (spaces-string endextra)))))
     (setq lines (cons line lines))))
 
 (defconst spaces-strings
Technical Details
Message-ID: <9408290704.AA13269@etlken.etl.go.jp>
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!redstone.interpath.net!ddsw1!news.kei.com!eff!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!etlken.etl.go.JP!handa

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,d11227113ed101da,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1994-08-29 00:22:30 PST
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!redstone.interpath.net!ddsw1!news.kei.com!eff!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!etlken.etl.go.JP!handa
From: handa@etlken.etl.go.JP (Kenichi Handa)
Newsgroups: gnu.emacs.bug
Subject: rect.el
Date: 29 Aug 1994 03:14:43 -0400
Organization: GNUs Not Usenet
Lines: 109
Sender: daemon@cis.ohio-state.edu
Approved: bug-gnu-emacs@prep.ai.mit.edu
Distribution: gnu
Message-ID: <9408290704.AA13269@etlken.etl.go.jp>