[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: proposal: edit-rectangle

From: Thierry Volpiatto
Subject: Re: proposal: edit-rectangle
Date: Thu, 06 Oct 2016 20:19:47 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

John Wiegley <address@hidden> writes:

> This is functionality I'd like to add to rect.el. It allows you to specify a
> rectangular region, and then edit just the contents of that rectangle in a
> separate buffer. When finished (C-c C-c), it replaces the old rectangle using
> insert-rectangle with the new contents.
> I'd appreciate comments on usability, fitness, etc.

Looks cool, what about a more lexical variant (not tested) ?

--8<---------------cut here---------------start------------->8---
(defun edit-rectangle (&optional start end)
  (interactive "r")
  (let ((strs   (delete-extract-rectangle start end))
        (mode   major-mode)
        (here   (copy-marker (min (mark) (point)) t))
        (config (current-window-configuration)))
    (with-current-buffer (generate-new-buffer "*Rectangle*")
      (funcall mode)
      (local-set-key (kbd "C-c C-c") (lambda ()
                                       (restore-rectangle-1 here config)))
      (mapc (lambda (x) (insert x ?\n)) strs)
      (goto-char (point-min))
      (pop-to-buffer (current-buffer)))))

(defun restore-rectangle-1 (origin config)
  (let ((content (split-string (buffer-string) "\n")))
    (with-current-buffer (marker-buffer origin)
      (goto-char origin)
      (insert-rectangle content))
    (kill-buffer (current-buffer))
    (set-window-configuration config)))
--8<---------------cut here---------------end--------------->8---

Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]