unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: John Mastro <john.b.mastro@gmail.com>
To: Emacs Development <emacs-devel@gnu.org>
Subject: Re: proposal: edit-rectangle
Date: Thu, 6 Oct 2016 12:38:50 -0700	[thread overview]
Message-ID: <CAOj2CQSCHdN+SX1W0xbkWfKGzWkbfyO3QM2fwc4r-xa6hCrYPA@mail.gmail.com> (raw)
In-Reply-To: <m27f9l5rss.fsf@newartisans.com>

John Wiegley <jwiegley@gmail.com> wrote:
> 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.

Neat idea, I like it.

> --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))

Instead of mark and point, should this use the start and end arguments?

Also, since the number of live markers has performance implications, I
think you should (set-marker <marker> nil) once you're done with it in
`restore-rectangle'.

>         (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)

You could use `setq-local' here.

>       (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---

The results are a bit awkward if you `restore-rectangle' with more lines
than you started with, but I don't have any ideas offhand for
obviously better behavior.

        John



  parent reply	other threads:[~2016-10-06 19:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=CAOj2CQSCHdN+SX1W0xbkWfKGzWkbfyO3QM2fwc4r-xa6hCrYPA@mail.gmail.com \
    --to=john.b.mastro@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 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).