Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Like if you have a buffer containing hel! and paste in lo world after the third letter you get 4 and 11 respectively?

Emacs has many state variables, are there any that could help me in this case?

share|improve this question
Could perhaps read point before a paste command and then count the letters in whatever is pasted. The end would be start point + paste text length. Still hard though. – The Unfun Cat Jan 8 at 19:29
You can read (point), paste and then read (point) again. – Kaushal Modi Jan 8 at 19:32
So after paste you always end up at the end of a paste? Will test... – The Unfun Cat Jan 8 at 19:36
up vote 7 down vote accepted

These are just point and mark right after the yank command. Just see the doc for yank or yank-pop. If you want to conserve these positions you could advice yank. Make sure that you save these values as markers or in buffer-local variables!

One more thing: If you want to see these values just once you can call M-: (mark) and M-: (point) right after the yank command.

share|improve this answer

Here's a quick snippet I came up with that does what you need on brief testing.

(defun my/get-yanked-text-boundaries ()
  "Yank and return the start and end boundaries of the yanked text in the buffer."
  (let ((start (point))
    (call-interactively #'yank)
    (setq end (point))
    (message (format "Start: %0d End: %0d" start end))
    (list start end)))
share|improve this answer
this works but is not the idiomatic way to do it, see Tobias' answer – Joseph Garvin Jan 8 at 20:18
JosephGarvin: That's a very good point. Thanks @Tobias. – Kaushal Modi Jan 8 at 20:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.