unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: proposal: edit-rectangle
Date: Thu, 06 Oct 2016 17:07:07 -0400	[thread overview]
Message-ID: <jwvr37txkvp.fsf-monnier+gmane.emacs.devel@gnu.org> (raw)
In-Reply-To: m27f9l5rss.fsf@newartisans.com

> (defvar edit-rectangle-origin)
> (defvar edit-rectangle-saved-window-config)

Since they're internal, I'd name them with a "rectangle--" prefix.
I'd also give them a docstring.

> (defun edit-rectangle (&optional start end)
>   (interactive "r")
>   (let ((strs (delete-extract-rectangle start end))

I would leave the original rectangle untouched until the user hits C-c C-c.

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

You can use setq-local here.

>       (local-set-key (kbd "C-c C-c") #'restore-rectangle)

This modifies the local keymap, i.e. the major mode's keymap (shared
by all other buffers using this major mode).

You could use (use-local-map `(keymap . ,(current-local-map))), but
I think I'd vote for a minor-mode map and actually define a matching
minor mode.  And make it (along with the above buffer-local vars)
permanent-local, so the user can switch major-mode.

>       (mapc #'(lambda (x) (insert x ?\n)) strs)

    (dolist (x strs) (insert x ?\n))

Indents better, runs faster, and might even generate more compact code
(haven't bothered to check, tho).  It only works if `strs` is a list
(whereas the `mapc` version also works for arrays).

> (defun restore-rectangle ()

"restore" makes it sound like you're reverting to an older state.
How 'bout `rectangle-edit-done` ?

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

I don't like window-configurations, so I'd rather just use something
like bury-buffer.  One of the reasons is that in my kind of setup the
above code will fail: edit-rectangle's pop-to-buffer will have a created
a new frame, so calling set-window-configuration in that new frame at
best makes little sense, and in practice signals an error because
window-configs can only be applied to their original frame.


        Stefan




  parent reply	other threads:[~2016-10-06 21:07 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
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 [this message]
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=jwvr37txkvp.fsf-monnier+gmane.emacs.devel@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --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).