Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6675611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:52:42+00:00 2026-05-26T03:52:42+00:00

I wrote a snippet to copy previous line to point,if I repeat the command,it

  • 0

I wrote a snippet to copy previous line to point,if I repeat the command,it copy more previous line. It’s here:

    (defun my-copy-line (num)
      "copy lines"
      (interactive "p")
      (save-excursion
        (move-end-of-line 1)
        (push-mark)
        (move-beginning-of-line num)
        (kill-ring-save (point) (mark))))


(defvar copy-line-num 1)
(defun my-copy-line-here (num)
  "copy line ahead here"
  (interactive "p")
  (if (eq this-command last-command)
      (setq copy-line-num (+ copy-line-num num)) ;count num lines up
    (setq copy-line-default 1))
  (save-excursion
    (save-excursion                     ;make current line blank
      (move-beginning-of-line 1)
      (push-mark)
      (move-end-of-line 1)
      (kill-region (point) (mark)))     ;不用kill-line,以免删除空白行
    (push-mark)
    (previous-line copy-line-num)
    (my-copy-line 1)
    (exchange-point-and-mark)
    (yank))
  (setq this-command 'my-copy-line-here))

I intended to yank previous line to override current line.If I repeat my-copy-line-here,I’ll yank the 2th previous line,this is accomplished by the test (if (eq this-command last-command).But it failed ,Because every time after executing my-copy-line-here,it sets the last-command to yank,instead my-copy-line-here.I just can’t figure out what’s going on.I need your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:52:43+00:00Added an answer on May 26, 2026 at 3:52 am

    `M-y (yank-pop) works similarly, pasting previous copied lines on repeated calls. Checking its sources, I see two differences with yours:

    ; explicit check for yank 
    (if (not (eq last-command 'yank))
    
    ; setting this command
    (setq this-command 'yank)
    

    Perhaps one or both of these together can be useful. Set this-command after calling yank maybe?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this snippet of code and I assume len is tail-recursive, but a
To help me better understand lambda I wrote this short snippet that rotates and
By code snippet execution, I mean the ability to write a few lines of
I wrote this small snippet to calculate Fibonacci numbers. It works well for numbers
What is the point of the synchronization here? Why not just use mConnectedThread.write(out) ?
I wrote the following snippet to get rid of excessive spaces in slabs of
I have this snippet of code I wrote for fading an element out and
I wrote a snippet to create a own DataTemplate by c# code. And i
I wrote this little snippet that should format money but its failing on the
In the following snippet, you can see my two collatz functions I wrote in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.