From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mathias Dahl Newsgroups: gmane.emacs.help Subject: Re: Newbie: Unable to write a custom function Date: Mon, 04 Dec 2006 10:03:35 +0100 Message-ID: References: <1165094606.836594.304590@j72g2000cwa.googlegroups.com> NNTP-Posting-Host: dough.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1165225437 5256 80.91.229.10 (4 Dec 2006 09:43:57 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 4 Dec 2006 09:43:57 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 04 10:43:55 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by dough.gmane.org with esmtp (Exim 4.50) id 1GrAMd-0002ju-NE for geh-help-gnu-emacs@m.gmane.org; Mon, 04 Dec 2006 10:43:55 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GrAMd-0004z8-B1 for geh-help-gnu-emacs@m.gmane.org; Mon, 04 Dec 2006 04:43:55 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 22 Original-X-Trace: individual.net oQOfT9GxNo9b49lLYMmgwgM4W1kDERu2q0W5UcIMLblXoKKizk User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.90 (windows-nt) Cancel-Lock: sha1:ZZ+0aT9BxbO/zWT/OVvi/exy7yY= Original-Xref: shelby.stanford.edu gnu.emacs.help:143640 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:39242 Archived-At: "deech" writes: > ;;Search backwards from a point for a string. If found delete > ;;all characters from that string to the point. > ;;Eg Given the argument 't', 'alligator' becomes 'alliga' > (defun isearch-backward-tophrase () > (set-mark-command ()) > (isearch-backward ) > (kill-region ()()) > ) Maybe this is what you want: (defun del-back-to-string (str) (interactive "sString: ") (let ((start (point))) (if (search-backward str nil t) (kill-region (point) start)))) Also, you don't have to restart Emacs to test your new command; just place point after the last parenthesis and type C-x C-e (`eval-last-sexp') and it will be evaluated and ready to be used.