unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Jonathan Holmes <jonathan.m.holmes@cantab.net>
Cc: 22212-done@debbugs.gnu.org
Subject: bug#22212: 24.5; Odd return behavior of function lisp-indent-line (minor)
Date: 21 Dec 2015 10:05:08 -0000	[thread overview]
Message-ID: <20151221100508.5802.qmail@mail.muc.de> (raw)
In-Reply-To: <mailman.212.1450548248.843.bug-gnu-emacs@gnu.org>

Hello, Jonathan.

In article <mailman.212.1450548248.843.bug-gnu-emacs@gnu.org> 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).






      parent reply	other threads:[~2015-12-21 10:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-19 10:26 bug#22212: 24.5; Odd return behavior of function lisp-indent-line (minor) Jonathan Holmes
     [not found] ` <mailman.212.1450548248.843.bug-gnu-emacs@gnu.org>
2015-12-21 10:05   ` Alan Mackenzie [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151221100508.5802.qmail@mail.muc.de \
    --to=acm@muc.de \
    --cc=22212-done@debbugs.gnu.org \
    --cc=jonathan.m.holmes@cantab.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).