unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How do we copy rectangular selected region
@ 2019-05-05  7:21 Budi
  2019-05-05 13:22 ` Óscar Fuentes
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Budi @ 2019-05-05  7:21 UTC (permalink / raw)
  To: help-gnu-emacs

How can we copy  rectangular selected region on latest emacs
we paste it as line region instead
how do such by script elisp.. thanks in advance



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How do we copy rectangular selected region
  2019-05-05  7:21 How do we copy rectangular selected region Budi
@ 2019-05-05 13:22 ` Óscar Fuentes
  2019-05-06 10:50 ` Michael Heerdegen
  2019-05-10  8:40 ` mickbert
  2 siblings, 0 replies; 6+ messages in thread
From: Óscar Fuentes @ 2019-05-05 13:22 UTC (permalink / raw)
  To: help-gnu-emacs

Budi <budikusasi@gmail.com> writes:

> How can we copy  rectangular selected region on latest emacs
> we paste it as line region instead
> how do such by script elisp.. thanks in advance

Does `copy-rectangle-as-kill' what you want? If not, please give more
details.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How do we copy rectangular selected region
  2019-05-05  7:21 How do we copy rectangular selected region Budi
  2019-05-05 13:22 ` Óscar Fuentes
@ 2019-05-06 10:50 ` Michael Heerdegen
  2019-05-07  6:27   ` Budi
  2019-05-10  8:40 ` mickbert
  2 siblings, 1 reply; 6+ messages in thread
From: Michael Heerdegen @ 2019-05-06 10:50 UTC (permalink / raw)
  To: Budi; +Cc: help-gnu-emacs

Budi <budikusasi@gmail.com> writes:

> How can we copy  rectangular selected region on latest emacs
> we paste it as line region instead
> how do such by script elisp.. thanks in advance

Dunno if I understand correctly.  What I sometimes want is that a yanked
rectangle moves the text after the insertion point completely after the
inserted rectangle text, instead of merging the rectangle into the text.
I do it like following.  Maybe I'm missing something and it can be done
with Emacs ways, dunno.

Anyway, the code modifies the command 'yank-rectangle' to get the
alternative insertion behavior by calling it with a prefix arg.

#+begin_src emacs-lisp
(defun my-insert-rectangle-with-newlines (rectangle)
  "Like `insert-rectangle', but (insert ?\\n) is used to change lines."
  (let ((lines rectangle)
	(insertcolumn (current-column))
	(first t))
    (push-mark)
    (while lines
      (or first
	  (progn
	    (insert ?\n)
	    (or (bolp) (insert ?\n))
	    (move-to-column insertcolumn t)))
      (setq first nil)
      (insert (car lines))
      (setq lines (cdr lines)))
    (save-excursion (insert ?\n))))

(eval-when-compile (require 'rect))

(defun my-yank-rectangle (&optional insert-newlines)
  "The optional argument INSERT-NEWLINES specifies if
`forward-line' or (insert ?\\n) is used to change lines.
A value of nil means that `forward-line' will be used and text after
point will occur beside the inserted rectangle. With any other value,
newlines will be inserted instead, with the effect that any following
text will remain after the inserted rectangle."
  (interactive "*P")
  (funcall (if insert-newlines
	       #'my-insert-rectangle-with-newlines
	     #'insert-rectangle)
           killed-rectangle))

(advice-add 'yank-rectangle :override #'my-yank-rectangle)
#+end_src


Michael.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How do we copy rectangular selected region
  2019-05-06 10:50 ` Michael Heerdegen
@ 2019-05-07  6:27   ` Budi
  0 siblings, 0 replies; 6+ messages in thread
From: Budi @ 2019-05-07  6:27 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

Michael, I am sorry, I did mail the amended question but someone still
got the obsolete one.
The rectangle selected region question is replaced with " symbol's
function definition is void : t " error problem as calling a function

the copy into clipboard function is meant to save to kill-ring with or
without a selected region, if it exist then save that region otherwise
make up a full line region and save that
but got symbol's function definition is void : t  error above


(defun copy (b e)
  (interactive "r")
  (if (use-region-p) (call-interactively 'kill-ring-save)
  (beginning-of-line)
  (push-mark (line-end-position))
  (activate-mark)
  (call-interactively 'kill-ring-save)
  (deactivate-mark)
  (pop-mark)))
(global-set-key (kbd "C-c") 'copy)

invaluable thanks to anyone help me out.

On 5/6/19, Michael Heerdegen <michael_heerdegen@web.de> wrote:
> Budi <budikusasi@gmail.com> writes:
>
>> How can we copy  rectangular selected region on latest emacs
>> we paste it as line region instead
>> how do such by script elisp.. thanks in advance
>
> Dunno if I understand correctly.  What I sometimes want is that a yanked
> rectangle moves the text after the insertion point completely after the
> inserted rectangle text, instead of merging the rectangle into the text.
> I do it like following.  Maybe I'm missing something and it can be done
> with Emacs ways, dunno.
>
> Anyway, the code modifies the command 'yank-rectangle' to get the
> alternative insertion behavior by calling it with a prefix arg.
>
> #+begin_src emacs-lisp
> (defun my-insert-rectangle-with-newlines (rectangle)
>   "Like `insert-rectangle', but (insert ?\\n) is used to change lines."
>   (let ((lines rectangle)
> 	(insertcolumn (current-column))
> 	(first t))
>     (push-mark)
>     (while lines
>       (or first
> 	  (progn
> 	    (insert ?\n)
> 	    (or (bolp) (insert ?\n))
> 	    (move-to-column insertcolumn t)))
>       (setq first nil)
>       (insert (car lines))
>       (setq lines (cdr lines)))
>     (save-excursion (insert ?\n))))
>
> (eval-when-compile (require 'rect))
>
> (defun my-yank-rectangle (&optional insert-newlines)
>   "The optional argument INSERT-NEWLINES specifies if
> `forward-line' or (insert ?\\n) is used to change lines.
> A value of nil means that `forward-line' will be used and text after
> point will occur beside the inserted rectangle. With any other value,
> newlines will be inserted instead, with the effect that any following
> text will remain after the inserted rectangle."
>   (interactive "*P")
>   (funcall (if insert-newlines
> 	       #'my-insert-rectangle-with-newlines
> 	     #'insert-rectangle)
>            killed-rectangle))
>
> (advice-add 'yank-rectangle :override #'my-yank-rectangle)
> #+end_src
>
>
> Michael.
>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How do we copy rectangular selected region
  2019-05-05  7:21 How do we copy rectangular selected region Budi
  2019-05-05 13:22 ` Óscar Fuentes
  2019-05-06 10:50 ` Michael Heerdegen
@ 2019-05-10  8:40 ` mickbert
  2019-05-10  9:08   ` YUE Daian
  2 siblings, 1 reply; 6+ messages in thread
From: mickbert @ 2019-05-10  8:40 UTC (permalink / raw)
  To: help-gnu-emacs

On 05.05.2019 09:21, Budi wrote:
> How can we copy  rectangular selected region on latest emacs
> we paste it as line region instead
> how do such by script elisp.. thanks in advance

I use a temporary buffer, (like "*scratch*", but anything else is the 
same):
- select rectangle and copy it: M-x copy-rectangle-as-kill
- yank rectangle in in temporary buffer: C-x r y
- select what has just been yanked: C-x C-x
- move it in the kill-ring: C-w
- go to destination buffer and yank: C-y

I didn't know the command copy-rectangle-as-kill before; I used to kill 
the rectangle then re-yank, or undo, every time!
--
Mick



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How do we copy rectangular selected region
  2019-05-10  8:40 ` mickbert
@ 2019-05-10  9:08   ` YUE Daian
  0 siblings, 0 replies; 6+ messages in thread
From: YUE Daian @ 2019-05-10  9:08 UTC (permalink / raw)
  To: help-gnu-emacs

On 2019-05-10 10:40, mickbert@posteo.net wrote:
> On 05.05.2019 09:21, Budi wrote:
>> How can we copy  rectangular selected region on latest emacs
>> we paste it as line region instead
>> how do such by script elisp.. thanks in advance
>
> I use a temporary buffer, (like "*scratch*", but anything else is the 
> same):
> - select rectangle and copy it: M-x copy-rectangle-as-kill
> - yank rectangle in in temporary buffer: C-x r y
> - select what has just been yanked: C-x C-x
> - move it in the kill-ring: C-w
> - go to destination buffer and yank: C-y
>
> I didn't know the command copy-rectangle-as-kill before; I used to kill 
> the rectangle then re-yank, or undo, every time!
> --
> Mick

Emacs also provides a mode to select rectangle in a more user-friendly
way, named `rectangle-mark-mode`.
It is bound to `C-x SPC` by default.

It *only* selects a rectangle so you may copy/yank using trivial `M-w`.

Hope it helps.

Danny



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-05-10  9:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-05  7:21 How do we copy rectangular selected region Budi
2019-05-05 13:22 ` Óscar Fuentes
2019-05-06 10:50 ` Michael Heerdegen
2019-05-07  6:27   ` Budi
2019-05-10  8:40 ` mickbert
2019-05-10  9:08   ` YUE Daian

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