From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Michael Slass Newsgroups: gmane.emacs.help Subject: Re: replace-in-string and backward-delete-char [help request!] Date: Mon, 18 Nov 2002 19:01:52 GMT Organization: AT&T Broadband Sender: help-gnu-emacs-admin@gnu.org Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1037647367 6651 80.91.224.249 (18 Nov 2002 19:22:47 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 18 Nov 2002 19:22:47 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18DrTp-0001it-00 for ; Mon, 18 Nov 2002 20:22:45 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 18DrUy-0004Q6-00; Mon, 18 Nov 2002 14:23:56 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!paloalto-snf1.gtei.net!crtntx1-snh1.gtei.net!nycmny1-snh1.gtei.net!news.gtei.net!newsfeed.mathworks.com!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_feed4!attbi.com!sccrnsc02.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Original-Lines: 81 Original-NNTP-Posting-Host: 12.228.27.239 Original-X-Complaints-To: abuse@attbi.com Original-X-Trace: sccrnsc02 1037646112 12.228.27.239 (Mon, 18 Nov 2002 19:01:52 GMT) Original-NNTP-Posting-Date: Mon, 18 Nov 2002 19:01:52 GMT Original-Xref: shelby.stanford.edu gnu.emacs.help:107166 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:3718 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:3718 Joe Corneli 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{}\"" (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