emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#22212: closed (24.5; Odd return behavior of functi


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#22212: closed (24.5; Odd return behavior of function lisp-indent-line (minor))
Date: Mon, 21 Dec 2015 10:06:02 +0000

Your message dated 21 Dec 2015 10:05:08 -0000
with message-id <address@hidden>
and subject line Re: bug#22212: 24.5; Odd return behavior of function 
lisp-indent-line (minor)
has caused the debbugs.gnu.org bug report #22212,
regarding 24.5; Odd return behavior of function lisp-indent-line (minor)
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
22212: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=22212
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: 24.5; Odd return behavior of function lisp-indent-line (minor) Date: Sat, 19 Dec 2015 05:26:25 -0500
(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. 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.

Similar behavior exists for every method I tested of placing
(lisp-indent-line) in a loop, including dolists and recursive functions,
named or anonymous. Furthermore, sometimes you *can*
evaluate

       (setq count (- count (- (point) (lisp-indent-line))))
            
inside a loop! You can evaluate it unless you also use one of a number
of commands that moves the cursor, such as (forward-line), (goto-line),
(back-to-indentation), or (goto-char).

I believe that the nil return value only occurs when 

I think the function comes from common-lisp-indent-line as implemented in
.../lisp/emacs-lisp/cl-indent.el?




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

Configured using:
 `configure --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.5/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.5/site-lisp:/usr/share/emacs/site-lisp
 --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
 --libexecdir=/usr/lib --localstatedir=/var/lib
 --infodir=/usr/share/info --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.5/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.5/site-lisp:/usr/share/emacs/site-lisp
 --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
 'CFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat
 -Werror=format-security -Wall' CPPFLAGS=-D_FORTIFY_SOURCE=2
 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro''

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Emacs-Lisp

Minor modes in effect:
  TeX-PDF-mode: t
  show-paren-mode: t
  pdf-occur-global-minor-mode: t
  image-diredx-async-mode: t
  image-diredx-adjust-mode: t
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
nil
eval: Symbol's function definition is void: current-minor-modes
Making completion list...
Quit [2 times]
Making completion list...
eval: Symbol's function definition is void: mode-local-active-mode
nil
<C-mouse-1> is undefined
Quit
Making completion list...

Load-path shadows:
/usr/share/emacs/24.5/site-lisp/debian-startup hides /usr/share/emacs/site-lisp/debian-startup

Features:
(god-mode eieio-opt speedbar sb-image ezimage dframe find-func shadow
sort face-remap gnus-util mail-extr emacsbug message rfc822 mml mml-sec
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils term disp-table ehelp misearch multi-isearch help-mode debug
warnings easy-mmode smartparens-latex smartparens thingatpt dash cl-macs
gv tex dbus xml crm my-theme-theme paren key-chord pdf-occur ibuf-ext
ibuffer tablist tablist-filter semantic/wisent/comp semantic/wisent
semantic/wisent/wisent semantic/util-modes semantic/util semantic
semantic/tag semantic/lex semantic/fw eieio byte-opt bytecomp
byte-compile cl-extra cconv eieio-core mode-local cedet pdf-isearch
let-alist pdf-misc imenu pdf-tools compile comint ansi-color ring
cus-edit cus-start cus-load wid-edit pdf-view mule-util bookmark pp
jka-compr pdf-cache pdf-info tq pdf-util image-mode edmacro kmacro
tex-site info easymenu image-dired+ image-dired format-spec dired advice
help-fns cl-loaddefs cl-lib package epg-config time-date tooltip
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode prog-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
abbrev minibuffer nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
dbusbind gfilenotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)

Memory information:
((conses 16 265106 81203)
 (symbols 48 33379 0)
 (miscs 40 2053 866)
 (strings 32 65718 4528)
 (string-bytes 1 2079482)
 (vectors 16 34848)
 (vector-slots 8 867195 55107)
 (floats 8 143 510)
 (intervals 56 2286 50)
 (buffers 960 18)
 (heap 1024 46373 8212))


--- End Message ---
--- Begin Message --- Subject: Re: bug#22212: 24.5; Odd return behavior of function lisp-indent-line (minor) Date: 21 Dec 2015 10:05:08 -0000 User-agent: tin/2.3.1-20141224 ("Tallant") (UNIX) (FreeBSD/10.2-RELEASE-p7 (amd64))
Hello, Jonathan.

In article <address@hidden> 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).



--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]