[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
proposal: edit-rectangle
From: |
John Wiegley |
Subject: |
proposal: edit-rectangle |
Date: |
Thu, 06 Oct 2016 10:08:19 -0700 |
User-agent: |
Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.1.50 (darwin) |
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
signature.asc
Description: PGP signature
- proposal: edit-rectangle,
John Wiegley <=
- Re: proposal: edit-rectangle, Thierry Volpiatto, 2016/10/06
- Re: proposal: edit-rectangle, Thierry Volpiatto, 2016/10/06
- Re: proposal: edit-rectangle, Dmitri Paduchikh, 2016/10/06
- Re: proposal: edit-rectangle, John Mastro, 2016/10/06
- Re: proposal: edit-rectangle, Alain Schneble, 2016/10/06