* Re: replace-in-string and backward-delete-char [help request!]
[not found] <mailman.1037600352.29317.help-gnu-emacs@gnu.org>
@ 2002-11-18 19:01 ` Michael Slass
0 siblings, 0 replies; 2+ messages in thread
From: Michael Slass @ 2002-11-18 19:01 UTC (permalink / raw)
Joe Corneli <jcorneli@mail.ma.utexas.edu> writes:
>Hello --
>
>I am running XEmacs version 21.5 (beta4) "bamboo" for
>darwin 6.0. I expect that won't be hugely relevant but
>thought I should mention it before proceeding.
>
>I wrote the following code (below). It has 2 problems. The first
>is that replace-in-string does not seem to have any effect.
>The second is that backward-delete-char copies the deleted stuff
>to the kill ring even though I ask it not to (at least
>I think that I'm interpreting the documentation properly by
>adding an explicit "nil" at the end. -- Behavior is the same
>for me when I put nothing after the "3").
>
>Suggestions? I'm open to someone rewriting the code entirely
>if he or she has a better way to do this. I just want it
>to work....
>
>Thanks,
>Joe Corneli
>
>(defun cite-last-n-words (n)
>"Copy last ARG words to point and wrap with TeX citation markup."
> (interactive "p")
> (backward-kill-word n)
> (yank)
> (insert " \\cite{")
> (kill-new
> ; stuff I can't get to work properly--------
> (replace-in-string
> (replace-in-string
> (prin1-to-string (yank))
> " " "_")
> "[\n]" "_")
> ; --------stuff I can't get to work properly
> )
> (yank)
>
> ;; need to rid of trailing nil... but I don't like it being added to
> ;; kill ring even though I indicate I don't want it there.
> (backward-delete-char 3 nil)
> (delete-horizontal-space)
> (insert "} ")
> )
>
>
>
I'm not sure if you're trying to wrap the current n word in \cite{...}
in place, or trying to place such a string on the kill ring. Here's a
solution for each. The only magic is the (save-excursion ...) form, for
which you should read the docs,
(defun cite-last-n-words (word-count)
"Wrap WORD-COUNT words before the point in TeX \\cite{...}"
(interactive "p")
(insert "}")
(save-excursion
(backward-word word-count)
(insert "\\cite{")))
(defun add-last-n-words-citation-to-kill (word-count)
"Add to kill ring: \"\\cite{<last WORD-COUNT words>}\""
(interactive "p")
(let* ((beg
(save-excursion
(backward-word word-count)
(point)))
(entry (concat "\\cite{"
(buffer-substring beg (point))
"}")))
(kill-new entry)
(message "Created kill ring entry: %s" entry)))
--
Mike Slass
^ permalink raw reply [flat|nested] 2+ messages in thread
* replace-in-string and backward-delete-char [help request!]
@ 2002-11-18 6:06 Joe Corneli
0 siblings, 0 replies; 2+ messages in thread
From: Joe Corneli @ 2002-11-18 6:06 UTC (permalink / raw)
Hello --
I am running XEmacs version 21.5 (beta4) "bamboo" for
darwin 6.0. I expect that won't be hugely relevant but
thought I should mention it before proceeding.
I wrote the following code (below). It has 2 problems. The first
is that replace-in-string does not seem to have any effect.
The second is that backward-delete-char copies the deleted stuff
to the kill ring even though I ask it not to (at least
I think that I'm interpreting the documentation properly by
adding an explicit "nil" at the end. -- Behavior is the same
for me when I put nothing after the "3").
Suggestions? I'm open to someone rewriting the code entirely
if he or she has a better way to do this. I just want it
to work....
Thanks,
Joe Corneli
(defun cite-last-n-words (n)
"Copy last ARG words to point and wrap with TeX citation markup."
(interactive "p")
(backward-kill-word n)
(yank)
(insert " \\cite{")
(kill-new
; stuff I can't get to work properly--------
(replace-in-string
(replace-in-string
(prin1-to-string (yank))
" " "_")
"[\n]" "_")
; --------stuff I can't get to work properly
)
(yank)
;; need to rid of trailing nil... but I don't like it being added to
;; kill ring even though I indicate I don't want it there.
(backward-delete-char 3 nil)
(delete-horizontal-space)
(insert "} ")
)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-11-18 19:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.1037600352.29317.help-gnu-emacs@gnu.org>
2002-11-18 19:01 ` replace-in-string and backward-delete-char [help request!] Michael Slass
2002-11-18 6:06 Joe Corneli
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.