From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: Command in a function Date: Sat, 27 Mar 2010 07:01:29 -0700 Message-ID: <3A65F8774A74436CB84A4FEE6CB9DAF3@us.oracle.com> 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> <4BADDD20.6030008@t-online.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1269698774 29548 80.91.229.12 (27 Mar 2010 14:06:14 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 27 Mar 2010 14:06:14 +0000 (UTC) To: "'Klaus Jantzen'" , "'emacs-list'" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Mar 27 15:06:09 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 1NvWeP-0008Cm-3b for geh-help-gnu-emacs@m.gmane.org; Sat, 27 Mar 2010 15:06:09 +0100 Original-Received: from localhost ([127.0.0.1]:46096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NvWeO-0001Jk-JY for geh-help-gnu-emacs@m.gmane.org; Sat, 27 Mar 2010 10:06:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NvWbh-00089S-LS for help-gnu-emacs@gnu.org; Sat, 27 Mar 2010 10:03:21 -0400 Original-Received: from [140.186.70.92] (port=58468 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NvWbf-00087c-C4 for help-gnu-emacs@gnu.org; Sat, 27 Mar 2010 10:03:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NvWbc-0003zf-TQ for help-gnu-emacs@gnu.org; Sat, 27 Mar 2010 10:03:19 -0400 Original-Received: from rcsinet11.oracle.com ([148.87.113.123]:22596) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NvWbc-0003zb-OR for help-gnu-emacs@gnu.org; Sat, 27 Mar 2010 10:03:16 -0400 Original-Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by rcsinet11.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id o2RE3EiD021560 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 27 Mar 2010 14:03:15 GMT Original-Received: from acsmt354.oracle.com (acsmt354.oracle.com [141.146.40.154]) by acsinet15.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id o2RDn0Ku028324; Sat, 27 Mar 2010 14:03:13 GMT Original-Received: from abhmt018.oracle.com by acsmt355.oracle.com with ESMTP id 116392491269698491; Sat, 27 Mar 2010 07:01:31 -0700 Original-Received: from dradamslap1 (/141.144.73.76) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 27 Mar 2010 07:01:30 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <4BADDD20.6030008@t-online.de> Thread-Index: AcrNl/BfB8J8zyoeSeSHr7S8Apm8JQAG/HLQ X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Source-IP: acsmt354.oracle.com [141.146.40.154] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090208.4BAE1021.0135:SCFMA4539814,ss=1,fgs=0 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:72495 Archived-At: > > 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. You always insert the newline (`insert' is not inside the `if'). `insert' always returns nil, so your command does too - its return value determines/shows nothing. So your side-effect-only command inserts a newline, moving first to eol if not already there. IOW, it inserts a newline after the current non-empty line. That is not what your doc string says. Your `if' has only one branch (THEN). And you do not use the `if' return value - you use the `if' only for its side effect. To make this single-branch-and-side-effect-only behavior clearer to human readers, it is somewhat conventional to use `when' or `unless': (defun g-where () "Insert a newline after the current line, unless empty." (interactive) (unless (eolp) (end-of-line)) (insert "\n"))