can you please help me to write a small emacs function? This is the first lisp function I am writing and I think I am getting confused with point and mark placement.
I want to write a function that yanks text and that than replace parts of it with a regular expression. Example: I have in my killring
TEXT_TEXT
TEXT_TEXT
and I want in my buffer
TEXT_TEXT:10=TEXT_TEXT
TEXT_TEXT:10=TEXT_TEXT
These are the functions I have been writing. query-replace-in-yank
does what I want, exept that I have to press !
every time I use it. replace-in-yank
is what I cant get to work.
(defun replace-in-yank (numstr)
(interactive "sNumber: ")
(let ((repstr (concat "\\1:" numstr "=\\1")))
(let ((startp (point)))
(yank nil)
(let ((endp (point)))
(goto-char startp)
(while (re-search-forward "\\([A-Z\\_]+\\)" endp t)replace-match repstr t nil))))
(newline-and-indent)))
(defun query-replace-in-yank (numstr)
(interactive "sNumber: ")
(let ((repstr (concat "\\1:" numstr "=\\1")))
(yank nil)
(exchange-point-and-mark nil)
(query-replace-regexp "\\([A-Z\\_]+\\)" repstr nil (mark) (point) nil nil))
(newline-and-indent))