[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: proposal: edit-rectangle
From: |
John Mastro |
Subject: |
Re: proposal: edit-rectangle |
Date: |
Thu, 6 Oct 2016 12:38:50 -0700 |
John Wiegley <address@hidden> 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
- proposal: edit-rectangle, John Wiegley, 2016/10/06
- 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 <=
- Re: proposal: edit-rectangle, Alain Schneble, 2016/10/06
- Re: proposal: edit-rectangle, Stefan Monnier, 2016/10/06
- Re: proposal: edit-rectangle, Alain Schneble, 2016/10/06