From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Klaus Jantzen Newsgroups: gmane.emacs.help Subject: Re: Command in a function Date: Sat, 27 Mar 2010 11:25:36 +0100 Message-ID: <4BADDD20.6030008@t-online.de> References: <4BAA8919.8000502@t-online.de><579E3B8BC2A2420588F857DE9B9AFFAB@us.oracle.com> <4BAB0F68.1090608@t-online.de> <64CA90377F02460FA31510200EF35DFE@us.oracle.com> <4BACD9DE.6080802@t-online.de> <52CFAD1180B1460090347833DE17B97D@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1269685621 23946 80.91.229.12 (27 Mar 2010 10:27:01 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 27 Mar 2010 10:27:01 +0000 (UTC) To: emacs-list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Mar 27 11:26:52 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NvTE9-0001Ke-MC for geh-help-gnu-emacs@m.gmane.org; Sat, 27 Mar 2010 11:26:49 +0100 Original-Received: from localhost ([127.0.0.1]:46397 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NvTE8-0000Or-Vq for geh-help-gnu-emacs@m.gmane.org; Sat, 27 Mar 2010 06:26:49 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NvTDG-0000I1-QC for help-gnu-emacs@gnu.org; Sat, 27 Mar 2010 06:25:54 -0400 Original-Received: from [140.186.70.92] (port=45228 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NvTDE-0000HZ-V6 for help-gnu-emacs@gnu.org; Sat, 27 Mar 2010 06:25:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NvTDD-0004Ei-NA for help-gnu-emacs@gnu.org; Sat, 27 Mar 2010 06:25:52 -0400 Original-Received: from mailout07.t-online.de ([194.25.134.83]:42745) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NvTDD-0004ET-9X for help-gnu-emacs@gnu.org; Sat, 27 Mar 2010 06:25:51 -0400 Original-Received: from fwd03.aul.t-online.de (fwd03.aul.t-online.de ) by mailout07.t-online.de with smtp id 1NvTDA-00040i-HC; Sat, 27 Mar 2010 11:25:48 +0100 Original-Received: from [192.168.2.100] (GW9KWeZYwhGZHtnDZk5OWiZA7hANkECRvRzz7XDeSntvyDwmSVH7IAt8AoC22fvZ03@[87.144.114.14]) by fwd03.aul.t-online.de with esmtp id 1NvTCy-161xBo0; Sat, 27 Mar 2010 11:25:36 +0100 User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090707) In-Reply-To: <52CFAD1180B1460090347833DE17B97D@us.oracle.com> X-ID: GW9KWeZYwhGZHtnDZk5OWiZA7hANkECRvRzz7XDeSntvyDwmSVH7IAt8AoC22fvZ03 X-TOI-MSGID: 6f78fdf9-17a3-4b70-b826-98a5d15b5586 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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:72493 Archived-At: Drew Adams wrote: >> Here is what I want to do: I want to find out, where the cursor is >> before I insert some text: if it is at the end of a line I ensure >> that it is here (end-of-line), write a new line (new-line) go to >> the beginning of that line. This function is supposed to be called >> by those functions that must insert text at the beginning >> line. >> >> (defun g-where () >> "Determines where we are" >> (interactive) >> (if (bolp) ; at the end of a line ? >> () >> ((end-of-line) >> (new-line) >> (beginning-of-line)))) >> >> The code is certainly somewhat crude as it is one of my first >> emacs-functions I wrote. >> > > 1. C-h f if > > ,---- > | if is a special form in `C source code'. > | > | (if COND THEN ELSE...) > | > | If COND yields non-nil, do THEN, else do ELSE... > | Returns the value of THEN or the value of the last of the ELSE's. > | THEN must be one expression, but ELSE... can be zero or more expressions. > | If COND yields nil, and there are no ELSE's, the value is nil. > | > `---- > > You are using (if COND THEN (ELSE...)), not (if COND THEN ELSE...). > > 2. No such function: `new-line'. > > If you just want to insert a newline unless point is at the beginning of the > line (and do nothing otherwise), then just do that: > > (defun foo () > (interactive) > (unless (bolp) (insert "\n"))) > > Or if you want the return value to let you know whether you were at bolp to > begin with, then: > > (defun foo () > (interactive) > (if (bolp) > nil ; We were at bolp > (insert "\n") > t)) ; We weren't at bolp > > Drew, thanks very much for your help. Your last message put me on the right track. Following your suggestions I wrote the function in question as follows: (defun g-where () "Determines where we are" (interactive) (if (not (eolp)) (end-of-line)) (insert "\n")) This moves the cursor to the end of a line if the cursor is at the beginning of line that is not empty or if the cursor is somewhere in a line. Thanks a lot. -- K.D.J.