all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Wiegley <jwiegley@gmail.com>
To: Emacs Development <emacs-devel@gnu.org>
Subject: proposal: edit-rectangle
Date: Thu, 06 Oct 2016 10:08:19 -0700	[thread overview]
Message-ID: <m27f9l5rss.fsf@newartisans.com> (raw)

[-- 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 --]

             reply	other threads:[~2016-10-06 17:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-06 17:08 John Wiegley [this message]
2016-10-06 17:34 ` proposal: edit-rectangle 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m27f9l5rss.fsf@newartisans.com \
    --to=jwiegley@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.