From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#22212: 24.5; Odd return behavior of function lisp-indent-line (minor) Date: 21 Dec 2015 10:05:08 -0000 Organization: muc.de e.V. Message-ID: <20151221100508.5802.qmail@mail.muc.de> References: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1450692390 3245 80.91.229.3 (21 Dec 2015 10:06:30 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 21 Dec 2015 10:06:30 +0000 (UTC) Cc: 22212-done@debbugs.gnu.org To: Jonathan Holmes Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 21 11:06:17 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aAxM5-0003eI-3B for geb-bug-gnu-emacs@m.gmane.org; Mon, 21 Dec 2015 11:06:13 +0100 Original-Received: from localhost ([::1]:43817 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAxM4-0003Ke-Hi for geb-bug-gnu-emacs@m.gmane.org; Mon, 21 Dec 2015 05:06:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44654) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAxM0-0003J7-KE for bug-gnu-emacs@gnu.org; Mon, 21 Dec 2015 05:06:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aAxLu-0000MT-Oo for bug-gnu-emacs@gnu.org; Mon, 21 Dec 2015 05:06:08 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:50942) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aAxLu-0000MO-MD for bug-gnu-emacs@gnu.org; Mon, 21 Dec 2015 05:06:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aAxLu-0000Sp-HT for bug-gnu-emacs@gnu.org; Mon, 21 Dec 2015 05:06:02 -0500 Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Dec 2015 10:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 22212 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 22212@debbugs.gnu.org, acm@muc.de, jonathan.m.holmes@cantab.net Original-Received: via spool by 22212-done@debbugs.gnu.org id=D22212.14506923121685 (code D ref 22212); Mon, 21 Dec 2015 10:06:02 +0000 Original-Received: (at 22212-done) by debbugs.gnu.org; 21 Dec 2015 10:05:12 +0000 Original-Received: from localhost ([127.0.0.1]:58544 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aAxL6-0000R6-4H for submit@debbugs.gnu.org; Mon, 21 Dec 2015 05:05:12 -0500 Original-Received: from mail.muc.de ([193.149.48.3]:41299) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aAxL3-0000Qv-Dc for 22212-done@debbugs.gnu.org; Mon, 21 Dec 2015 05:05:09 -0500 Original-Received: (qmail 5804 invoked by uid 3782); 21 Dec 2015 10:05:08 -0000 In-Reply-To: X-Newsgroups: gnu.emacs.bug User-Agent: tin/2.3.1-20141224 ("Tallant") (UNIX) (FreeBSD/10.2-RELEASE-p7 (amd64)) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:110233 Archived-At: Hello, Jonathan. In article you wrote: > [-- text/plain, encoding 7bit, charset: UTF-8, 160 lines --] > (lisp-indent-line) generally has an [undocumented] return value of > (point), but when embedded in structures with a number of commands that move > the point, it may return nil instead. I learned about the return value > of (point) from experimentatal evaluation, and then tried to use this to > write the following function: > (defun lisp-indent-lines (lnum1 lnum2) > (let ((count 0) > (pos (point))) > (goto-char 0) (forward-line (- lnum1 1)) > (while (<= lnum1 lnum2) > (back-to-indentation) > (setq count (- count (- (point) (lisp-indent-line)))) > (forward-line) (cl-incf lnum1)) > (goto-char (+ pos count)))) > This exits with a type error because > (lisp-indent-line) > returns nil. But if you execute > (setq count 0) > (setq count (- count (- (point) (lisp-indent-line)))) > outside of a loop or recursion and outside of let/let* bindings, > it has no problem. The only problem with > (lisp-indent-line) > is the inconsistent return value, so this isa very minor bug, > unless it is some kind of esoteric feature used > in emacs at some phase. lisp-indent-line's return value is random: it has no significance. The function performs its actions, and the value returned is just that of the last form in lisp-indent-line which happened to be executed. > The setq statement is not related to the nil value, though it's the > subtraction by nil in that statement that causes the error -- it will > also evaluate to nil in working functions that avoid relying on its > return value. Can I suggest you actually look at the source code for lisp-indent-line? It's not difficult to read. In Emacs 24.5, it's in emacs/lisp/emacs-lisp/lisp-mode.el at line 1253. The very last two lines contain an `if' form: this `if' triggers when point was originally to the right of the indentation whitespace, and it restores the original position of point with a `goto-char' form, hence the apparent return value of point. If the `if' doesn't trigger (when point started in the indentation), nil is returned. Just to emphasise, you cannot rely on the return value of this function. Instead, you must explicitly use `(point)'. [ .... ] Thanks for taking the trouble to report this. But it isn't really a bug at all, so I'm closing it. > In GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.8) > of 2015-08-20 on lgw01-16, modified by Debian > Windowing system distributor `The X.Org Foundation', version 11.0.11501000 > System Description: Ubuntu 14.04.3 LTS -- Alan Mackenzie (Nuremberg, Germany).