unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* proposal: edit-rectangle
@ 2016-10-06 17:08 John Wiegley
  2016-10-06 17:34 ` Kaushal Modi
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: John Wiegley @ 2016-10-06 17:08 UTC (permalink / raw)
  To: Emacs Development

[-- Attachment #1: Type: text/plain, Size: 1739 bytes --]

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.

--8<---------------cut here---------------start------------->8---
(defvar edit-rectangle-origin)
(defvar edit-rectangle-saved-window-config)

(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)
      (set (make-local-variable 'edit-rectangle-origin) here)
      (set (make-local-variable 'edit-rectangle-saved-window-config) config)
      (local-set-key (kbd "C-c C-c") #'restore-rectangle)
      (mapc #'(lambda (x) (insert x ?\n)) strs)
      (goto-char (point-min))
      (pop-to-buffer (current-buffer)))))

(defun restore-rectangle ()
  (interactive)
  (let ((content (split-string (buffer-string) "\n"))
        (origin edit-rectangle-origin)
        (config edit-rectangle-saved-window-config))
    (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---

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 629 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-10-07 20:31 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-06 17:08 proposal: edit-rectangle John Wiegley
2016-10-06 17:34 ` Kaushal Modi
2016-10-06 18:08   ` John Wiegley
2016-10-06 20:49     ` Stefan Monnier
2016-10-06 21:00       ` Kaushal Modi
2016-10-06 18:19 ` Thierry Volpiatto
2016-10-06 18:44 ` Thierry Volpiatto
2016-10-07 20:31   ` Richard Stallman
2016-10-06 19:17 ` Dmitri Paduchikh
2016-10-06 19:38 ` John Mastro
2016-10-06 20:23 ` Alain Schneble
2016-10-06 20:26   ` Kaushal Modi
2016-10-06 20:31   ` John Wiegley
2016-10-06 21:07 ` Stefan Monnier
2016-10-06 21:42 ` Alain Schneble
2016-10-06 21:53   ` Alain Schneble

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).