From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Newsgroups: gmane.emacs.help Subject: Re: Copying a whole line using kill-ring-save in emacs 24.3.1 Date: Tue, 19 Mar 2013 16:07:58 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8f3ba4c7701a9e04d84ca9c0 X-Trace: ger.gmane.org 1363723704 13320 80.91.229.3 (19 Mar 2013 20:08:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 19 Mar 2013 20:08:24 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Le Wang Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 19 21:08:47 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UI2py-0000gq-0E for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Mar 2013 21:08:46 +0100 Original-Received: from localhost ([::1]:51649 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UI2pa-0007iv-Ad for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Mar 2013 16:08:22 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UI2pL-0007h3-3X for help-gnu-emacs@gnu.org; Tue, 19 Mar 2013 16:08:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UI2pD-0006TZ-GE for help-gnu-emacs@gnu.org; Tue, 19 Mar 2013 16:08:07 -0400 Original-Received: from mail-ia0-x22c.google.com ([2607:f8b0:4001:c02::22c]:56422) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UI2pD-0006TQ-AA for help-gnu-emacs@gnu.org; Tue, 19 Mar 2013 16:07:59 -0400 Original-Received: by mail-ia0-f172.google.com with SMTP id l29so759935iag.17 for ; Tue, 19 Mar 2013 13:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=2ifflRSXlFi2cTkBP72o67u4S9ose5mUiHzFkDLcvZY=; b=STjXdhJVw3VsTYyF+zY6Q3oM2xOw8qrvsbdsyzhJKfVTe2Bnkr3TNx4cYtspDPAhly 7o00Z62LiDaHJoYBFG4QAP2JfR4Z6AVKpvLPH26KNcZiVUu1a9vhNruLvL4cdgU5TSpv 85pmieDY98aoFL99lRP2kn1fh0+S0/Qza3XWjSaC0INlE4LnW0Lq9g61rTmpuQUW1rS0 vdTf2pfLRtySMpAmaRsIEj9MiJk6CdjFpL4L0L2wKEUcz+vrMsHE8AWMk2OFFzBIKy2W 0AnEh7ho2GvCmrP7+Qm+fz7i2gnefx2NhbWfoeNYToswoBe2FqGcxVxfMJMksgO3sjZj VbLg== X-Received: by 10.50.100.167 with SMTP id ez7mr2937635igb.3.1363723678650; Tue, 19 Mar 2013 13:07:58 -0700 (PDT) Original-Received: by 10.64.34.8 with HTTP; Tue, 19 Mar 2013 13:07:58 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c02::22c X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89599 Archived-At: --e89a8f3ba4c7701a9e04d84ca9c0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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 wrote: > On Sun, Mar 17, 2013 at 4:01 PM, Alan 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 erro= r: > > =93Wrong type argument: integer-or-marker-p, nil=94, although it does > > successfully copy the line. However, further =93meta-w=94 presses copy = from > the > > current position to the last mark, regardless of whether the region is > > highlighted. > > > > Any thoughts on getting the =93Meta-w=94 to work? Thanks. > > It looks like functionality has been added to highlight the region that w= as > 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 > --e89a8f3ba4c7701a9e04d84ca9c0 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable
Thanks so much for your help. Your code wor= ks. 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 ha= d in emacs version 24.2.1. In 24.2.1, when I hit "M-w", the curso= r would bounce to the beginning of the line, then back to its original posi= tion 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 be= havior?

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

(put 'kill-region 'interactive-form     =20
     '(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&g= t; wrote:
On S= un, 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 wh= ole line:
>
> (put 'kill-ring-save 'interactive-form
> =A0 =A0 =A0'(interactive
> =A0 =A0 =A0 =A0(if (use-region-p)
> =A0 =A0 =A0 =A0 =A0 =A0(list (region-beginning) (region-end))
> =A0 =A0 =A0 =A0 =A0(list (line-beginning-position) (line-beginning-pos= ition 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.<= br> > (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 g= et the error:
> =93Wrong type argument: integer-or-marker-p, nil=94, although it does<= br> > successfully copy the line. However, further =93meta-w=94 presses copy= from the
> current position to the last mark, regardless of whether the region is=
> highlighted.
>
> Any thoughts on getting the =93Meta-w=94 to work? Thanks.

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

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



--
Le

--e89a8f3ba4c7701a9e04d84ca9c0--