all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Copying a whole line using kill-ring-save in emacs 24.3.1
@ 2013-03-17  8:01 Alan
  2013-03-18 15:30 ` Le Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Alan @ 2013-03-17  8:01 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 987 bytes --]

Hi,

I've used the following code, from
http://www.emacswiki.org/emacs/WholeLineOrRegion, to copy a whole line:

(put 'kill-ring-save 'interactive-form
     '(interactive
       (if (use-region-p)
           (list (region-beginning) (region-end))
         (list (line-beginning-position) (line-beginning-position 2)))))


Basically, it allows the use of "meta-w" to copy the entire line where the
cursor is currently located, as long as no text is visually selected.
(Transient Mark Mode must be enabled for this to work.) However, after
upgrading to emacs version 24.3.1 (from 24.2.1), this fails to work.

When I visit a file for the first time and hit "meta-w", I get the error:
“Wrong type argument: integer-or-marker-p, nil”, although it does
successfully copy the line. However, further “meta-w” presses copy from the
current position to the last mark, regardless of whether the region is
highlighted.

Any thoughts on getting the “Meta-w” to work? Thanks.

[-- Attachment #2: Type: text/html, Size: 1209 bytes --]

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

* Re: Copying a whole line using kill-ring-save in emacs 24.3.1
  2013-03-17  8:01 Copying a whole line using kill-ring-save in emacs 24.3.1 Alan
@ 2013-03-18 15:30 ` Le Wang
  2013-03-19 20:07   ` Alan
  0 siblings, 1 reply; 3+ messages in thread
From: Le Wang @ 2013-03-18 15:30 UTC (permalink / raw)
  To: Alan; +Cc: help-gnu-emacs

On Sun, Mar 17, 2013 at 4:01 PM, Alan <bowl.of.petunias@gmail.com> wrote:
> Hi,
>
> I've used the following code, from
> http://www.emacswiki.org/emacs/WholeLineOrRegion, to copy a whole line:
>
> (put 'kill-ring-save 'interactive-form
>      '(interactive
>        (if (use-region-p)
>            (list (region-beginning) (region-end))
>          (list (line-beginning-position) (line-beginning-position 2)))))
>
>
> Basically, it allows the use of "meta-w" to copy the entire line where the
> cursor is currently located, as long as no text is visually selected.
> (Transient Mark Mode must be enabled for this to work.) However, after
> upgrading to emacs version 24.3.1 (from 24.2.1), this fails to work.
>
> When I visit a file for the first time and hit "meta-w", I get the error:
> “Wrong type argument: integer-or-marker-p, nil”, although it does
> successfully copy the line. However, further “meta-w” presses copy from the
> current position to the last mark, regardless of whether the region is
> highlighted.
>
> Any thoughts on getting the “Meta-w” to work? Thanks.

It looks like functionality has been added to highlight the region that was
copied.  The problem is your snippet relies on the implementation instead of
the API.  It's better to define your own command and remap.

(defun my-kill-ring-save (beg end)
  (interactive (if (use-region-p)
                   (list (region-beginning) (region-end))
                 (list (line-beginning-position) (line-beginning-position 2))))
  (kill-ring-save beg end))
(global-set-key [remap kill-ring-save] 'my-kill-ring-save)



-- 
Le



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

* Re: Copying a whole line using kill-ring-save in emacs 24.3.1
  2013-03-18 15:30 ` Le Wang
@ 2013-03-19 20:07   ` Alan
  0 siblings, 0 replies; 3+ messages in thread
From: Alan @ 2013-03-19 20:07 UTC (permalink / raw)
  To: Le Wang; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2863 bytes --]

Thanks so much for your help. Your code works. I just have a couple follow
up questions:

1. Although your code does copy the line, the behavior is a little
different from what I had in emacs version 24.2.1. In 24.2.1, when I hit
"M-w", the cursor would bounce to the beginning of the line, then back to
its original position while copying. It's just a visual thing, but I like
it because it tells me the line was definitely copied. Is there some way to
mimic that behavior?

2. This is less relevant, but in the original wiki page from which I copied
the code, http://www.emacswiki.org/emacs/WholeLineOrRegion, there lists
another function that kills the current line:

(put 'kill-region 'interactive-form
     '(interactive
       (if (use-region-p)
           (list (region-beginning) (region-end))
         (list (line-beginning-position) (line-beginning-position 2)))))


This code works for me in the newest emacs version of 24.3.1. How come this
code works and not the "copy whole line" code in my original message?

Thanks.


On Mon, Mar 18, 2013 at 11:30 AM, Le Wang <l26wang@gmail.com> wrote:

> On Sun, Mar 17, 2013 at 4:01 PM, Alan <bowl.of.petunias@gmail.com> wrote:
> > Hi,
> >
> > I've used the following code, from
> > http://www.emacswiki.org/emacs/WholeLineOrRegion, to copy a whole line:
> >
> > (put 'kill-ring-save 'interactive-form
> >      '(interactive
> >        (if (use-region-p)
> >            (list (region-beginning) (region-end))
> >          (list (line-beginning-position) (line-beginning-position 2)))))
> >
> >
> > Basically, it allows the use of "meta-w" to copy the entire line where
> the
> > cursor is currently located, as long as no text is visually selected.
> > (Transient Mark Mode must be enabled for this to work.) However, after
> > upgrading to emacs version 24.3.1 (from 24.2.1), this fails to work.
> >
> > When I visit a file for the first time and hit "meta-w", I get the error:
> > “Wrong type argument: integer-or-marker-p, nil”, although it does
> > successfully copy the line. However, further “meta-w” presses copy from
> the
> > current position to the last mark, regardless of whether the region is
> > highlighted.
> >
> > Any thoughts on getting the “Meta-w” to work? Thanks.
>
> It looks like functionality has been added to highlight the region that was
> copied.  The problem is your snippet relies on the implementation instead
> of
> the API.  It's better to define your own command and remap.
>
> (defun my-kill-ring-save (beg end)
>   (interactive (if (use-region-p)
>                    (list (region-beginning) (region-end))
>                  (list (line-beginning-position) (line-beginning-position
> 2))))
>   (kill-ring-save beg end))
> (global-set-key [remap kill-ring-save] 'my-kill-ring-save)
>
>
>
> --
> Le
>

[-- Attachment #2: Type: text/html, Size: 3769 bytes --]

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

end of thread, other threads:[~2013-03-19 20:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-17  8:01 Copying a whole line using kill-ring-save in emacs 24.3.1 Alan
2013-03-18 15:30 ` Le Wang
2013-03-19 20:07   ` Alan

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.