Subject: bug#23809: 24.5; Positive argument to 'posn-at-point' throws erros as being negative

From: Lluís Vilanova <[email-masked]>
Date: Mon, 20 Jun 2016 18:30:51 +0200

To reproduce:

* Open a PDF on a separate window on the same frame using pdf-tools.
* Select that window.
* Scroll a bit down the first page of the PDF.
* Use windmove to move from the pdf-view-mode buffer to the first one.

With these steps, I get this backtrace:

  Debugger entered--Lisp error: (wrong-type-argument wholenump -14)
    posn-at-point(619194 #)
    (nth 2 (posn-at-point (window-point window) window))
    (let ((posn-cons (nth 2 (posn-at-point (window-point window) window)))) (if hor (+ (or (cdr posn-cons) 1) (window-pixel-top window)) (+ (or (car posn-cons) 1) (window-pixel-left window))))
    (cond ((and (numberp sign) (< sign 0)) (if hor (1- (+ (window-pixel-top window) (window-pixel-height window))) (1- (+ (window-pixel-left window) (window-pixel-width window))))) ((and (numberp sign) (> sign 0)) (if hor (window-pixel-top window) (window-pixel-left window))) ((let ((posn-cons (nth 2 (posn-at-point (window-point window) window)))) (if hor (+ (or (cdr posn-cons) 1) (window-pixel-top window)) (+ (or (car posn-cons) 1) (window-pixel-left window))))))
    (let* ((frame (window-frame window)) (hor (memq direction (quote (left right)))) (first (if hor (window-pixel-left window) (window-pixel-top window))) (last (+ first (window-size window hor t))) (posn (cond ((and (numberp sign) (< sign 0)) (if hor (1- (+ ... ...)) (1- (+ ... ...)))) ((and (numberp sign) (> sign 0)) (if hor (window-pixel-top window) (window-pixel-left window))) ((let ((posn-cons ...)) (if hor (+ ... ...) (+ ... ...)))))) (best-edge (cond ((eq direction (quote below)) (frame-pixel-height frame)) ((eq direction (quote right)) (frame-pixel-width frame)) (t -1))) (best-edge-2 best-edge) (best-diff-2 (if hor (frame-pixel-height frame) (frame-pixel-width frame))) best best-2 best-diff-2-new) (walk-window-tree (function (lambda (w) (let* ((w-top (window-pixel-top w)) (w-left (window-pixel-left w))) (cond ((or ... ...)) (hor (cond ... ...)) ((and ... ...) (if ... ...)) ((and ... ... ...) (setq best-edge-2 w-top) (setq best-diff-2 best-diff-2-new) (setq best-2 w)))))) frame nil (and mini t)) (or best best-2))
    window-in-direction(left nil nil nil nil t)
    windmove-find-other-window(left nil nil)
    windmove-do-window-select(left nil)
    windmove-left(nil)
    #(windmove-left nil nil)
    ad-Advice-call-interactively(# windmove-left nil nil)
    apply(ad-Advice-call-interactively # (windmove-left nil nil))
    call-interactively(windmove-left nil nil)
    command-execute(windmove-left)

Note how the argument to posn-at-point (returned by window-point) is actually
positive (619194), but the error raised by Emacs complains about the number
being negative (-14).

Thanks,
  Lluis

Auto-gathered information:

In GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9)
 of 2016-04-08 on binet, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11803000
System Description:	Debian GNU/Linux testing (stretch)

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-strong -Wformat -Werror=format-security -Wall'
 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' LDFLAGS=-Wl,-z,relro'

Important settings:
  value of $LANG: ca_ES.UTF-8
  locale-coding-system: utf-8

Major mode: Debugger

Minor modes in effect:
  pdf-occur-global-minor-mode: t
  TeX-PDF-mode: 1
  diff-auto-refine-mode: t
  magit-auto-revert-mode: t
  global-git-commit-mode: t
  async-bytecomp-package-mode: t
  recentf-mode: t
  ogc:--org-gnome-calendar-mode: t
  global-org-gnome-calendar-mode: t
  change-cursor-mode: t
  which-key-mode: t
  global-flycheck-mode: t
  global-semantic-idle-breadcrumbs-mode: t
  global-ede-mode: t
  shell-dirtrack-mode: t
  savehist-mode: t
  desktop-save-mode: t
  icomplete-mode: t
  flx-ido-mode: t
  ido-ubiquitous-mode: t
  global-undo-tree-mode: t
  undo-tree-mode: t
  global-hungry-delete-mode: t
  hungry-delete-mode: t
  global-auto-revert-mode: t
  global-anzu-mode: t
  anzu-mode: t
  show-smartparens-global-mode: t
  smartparens-global-mode: t
  cua-mode: t
  delete-selection-mode: t
  winner-mode: t
  ido-everywhere: t
  display-time-mode: t
  override-global-mode: t
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  global-prettify-symbols-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
Guessed variable 'css-indent-offset' (2)
Ispell process killed
Starting new Ispell process aspell with default dictionary...
Winner undo (1 / 7)
1238378 (#o4562552, #x12e56a)
Type "q" in help window to restore its previous buffer.
Mark set [2 times]
Quit
(#<window 529 on *Backtrace*> 1 (0 . 0) 0 nil 1 (0 . 0) nil (0 . 0) (8 . 14))
nil [3 times]

Load-path shadows:
/home/lluis/.cache/emacs/elpa/dash-20160510.1127/dash hides /home/lluis/.cache/emacs/el-get/dash/dash
/home/lluis/.cache/emacs/elpa/s-20160508.2357/s hides /home/lluis/.cache/emacs/el-get/s/s
/home/lluis/.cache/emacs/elpa/avy-20160512.2252/avy hides /home/lluis/.cache/emacs/el-get/avy/avy
/home/lluis/.cache/emacs/el-get/hydra/lv hides /home/lluis/.cache/emacs/el-get/lv/lv
/home/lluis/.cache/emacs/elpa/diminish-20151215.915/diminish hides /usr/share/emacs24/site-lisp/emacs-goodies-el/diminish
/home/lluis/.cache/emacs/elpa/dedicated-20090428.1231/dedicated hides /usr/share/emacs24/site-lisp/emacs-goodies-el/dedicated
/usr/share/emacs/24.5/site-lisp/debian-startup hides /usr/share/emacs/site-lisp/debian-startup
/home/lluis/.config/emacs/loaddefs hides /usr/share/emacs/24.5/lisp/loaddefs
/home/lluis/.config/emacs/custom hides /usr/share/emacs/24.5/lisp/custom
/usr/share/emacs24/site-lisp/latex-cjk-thai/thai-word hides /usr/share/emacs/24.5/lisp/language/thai-word

Features:
(shadow emacsbug pdf-sync pdf-annot pdf-outline pdf-links pdf-history pdf-occur
tablist tablist-filter semantic/wisent/comp pdf-isearch pdf-misc pdf-tools
pdf-view bookmark pdf-cache pdf-info tq pdf-util doc-view image-mode texmathp
preview prv-emacs tex-buf font-latex latex tex-style tex smartparens-latex
tex-mode latexenc tabify imenu man debug asm-mode eww mm-url log-view cua-rect
pylint semantic/wisent/python semantic/wisent/python-wy semantic/wisent
semantic/wisent/wisent smartparens-python python gnus-dup vc-bzr vc-sccs vc-svn
vc-cvs vc-rcs god-mode xterm supercite regi tramp-cache sh-script smie
executable dedicated wgrep find-dired grep ede/project-am ede/autoconf-edit
autoconf autoconf-mode ede/makefile-edit make-mode flow-fill dired-filter f s
ucs-normalize dired-hacks-utils dired-aux ede/dired dired-x gnutls url-queue
two-column iso-transl ibuf-ext semantic/db-file data-debug cedet-files
ede/locate semantic/tag-file semantic/edit narrow-or-widen-dwim fancy-narrow
iedit help-macro iedit-lib multiple-cursors-core rect aggressive-indent
elisp-slime-nav etags tar-mode url-handlers misearch multi-isearch
highlight-symbol auto-dictionary em-smart em-unix em-term em-script em-prompt
em-ls em-hist em-pred em-glob em-dirs em-cmpl em-basic em-banner em-alias
esh-var esh-io esh-cmd esh-opt esh-ext esh-proc esh-arg eldoc esh-groups eshell
esh-module esh-mode esh-util ffap copyright magit-stgit linum magit-blame
magit-stash magit-bisect magit-remote magit-commit magit-sequence magit
magit-apply magit-wip magit-log magit-diff smerge-mode diff-mode magit-core
magit-autorevert magit-process magit-popup magit-mode magit-git crm
magit-section magit-utils git-commit log-edit pcvs-util add-log with-editor
async-bytecomp async tramp-sh vc vc-dispatcher semantic/bovine/c
semantic/decorate/include hideif semantic/bovine/c-by semantic/lex-spp
semantic/bovine/gcc semantic/dep semantic/bovine semantic/analyze/refs
semantic/analyze semantic/scope semantic/analyze/fcn macrostep-c cmacexp
macrostep fic-ext-mode cpp disaster doc-mode xcscope outshine outshine-org-cmds
outorg highlight-parentheses guess-style filladapt cc-langs recentf tree-widget
windmove shr-color bbdb-hooks sort url-http url-gw url-auth gnus-cite smiley
gnus-gravatar gravatar url-cache url url-proxy url-privacy url-expand
url-methods url-history url-cookie url-domsuf url-util url-parse url-vars shr
browse-url mm-archive gnus-bcklg qp gnus-async gnus-ml ede/linux ede/make
ede/cpp-root ede/emacs vc-git gnus-topic gnus-mlspl nndraft nnmh utf-7
network-stream starttls nnimap parse-time tls utf7 netrc nnfolder bbdb-gnus
bbdb-snarf mail-extr bbdb-com warnings nnnil gnus-agent gnus-srvr gnus-score
score-mode nnvirtual gnus-msg gnus-cache gnus-demon nntp nnir gnus-notifications
gnus-fun gnus-art mm-uu mml2015 mm-view mml-smime smime dig mailcap gnus-sum
nnoo gnus-group gnus-undo nnmail mail-source notifications gnus-start gnus-spec
gnus-int gnus-range message sendmail rfc822 mml mml-sec mm-decode mm-bodies
mm-encode mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mailabbrev gmm-utils
mailheader gnus-win org-gnome-calendar dbus hl-line+ hl-line ace-link avy xml
cursor-chg smart-mode-line-powerline-theme powerline powerline-separators color
powerline-themes smart-mode-line rich-minority which-key server flycheck derived
json rx subr-x seq seq-24 pcase jka-compr compile let-alist info tex-site
my-personal my-bindings hydra lv my-mail bbdb timezone my-org ob-screen ob-R
ob-python ob-perl ob-octave ob-latex ob-gnuplot ob-dot ob-ditaa ob-C cc-mode
cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs
my-programming ede/generic ede/shell eieio-opt semantic/sb semantic/sort
inversion semantic/db-global semantic/symref/global semantic/symref
semantic/db-find semantic/db-ref cedet-global semantic/mru-bookmark
semantic/db-mode semantic/db semantic/idle semantic/format semantic/ctxt
semantic/decorate/mode semantic/tag-ls semantic/find semantic/decorate pulse
semantic/util-modes semantic/util semantic semantic/tag semantic/lex semantic/fw
mode-local my-writing my-writing-latex flyspell ispell my-ide ede/speedbar
ede/files ede ede/base ede/auto ede/source eieio-base eieio-speedbar speedbar
sb-image ezimage dframe eieio-custom cedet my-behaviour ediff-merg ediff-wind
ediff-diff ediff-mult ediff-help ediff-init ediff-util ediff fuzzy cssh tramp
tramp-compat auth-source eieio eieio-core password-cache tramp-loaddefs trampver
shell term disp-table ehelp ibuffer savehist desktop frameset time-stamp
browse-kill-ring icomplete flx-ido flx ido-ubiquitous ido-completing-read+
cus-edit cus-start cus-load key-chord gnus gnus-ems nnheader gnus-util
mail-utils mm-util mail-prsvr wid-edit org org-macro org-footnote org-pcomplete
pcomplete org-list org-faces org-entities noutline outline org-version
ob-emacs-lisp ob ob-tangle ob-ref ob-lob ob-table ob-exp org-src ob-keys
ob-comint comint ansi-color ob-core ob-eval org-compat org-macs org-loaddefs
format-spec find-func cal-menu calendar cal-loaddefs undo-tree diff
hungry-delete autorevert filenotify whitespace anzu mule-util saveplace
smartparens-config smartparens thingatpt dash cua-base delsel winner ring smex
ido byte-opt my-appearance time time-date my-theme my-cmdline my-misc edmacro
kmacro cl-macs my-package use-package diminish bind-key finder-inf .loaddefs
advice el-get el-get-autoloading el-get-list-packages el-get-dependencies
el-get-build el-get-status pp el-get-methods el-get-fossil el-get-svn
el-get-pacman el-get-github-zip el-get-github-tar el-get-http-zip
el-get-http-tar el-get-hg el-get-go el-get-git-svn el-get-fink el-get-emacswiki
el-get-http el-get-notify help-mode easymenu el-get-emacsmirror el-get-github
el-get-git el-get-elpa package epg-config el-get-darcs el-get-cvs el-get-bzr
el-get-brew el-get-builtin el-get-apt-get el-get-recipes el-get-byte-compile
el-get-custom el-get-core autoload help-fns lisp-mnt bytecomp byte-compile
cl-extra cconv cl gv cl-loaddefs cl-lib dired debian-el debian-el-loaddefs
emacs-goodies-el emacs-goodies-custom emacs-goodies-loaddefs easy-mmode
dpkg-dev-el dpkg-dev-el-loaddefs bbdb-autoloads 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 2406107 245774)
 (symbols 48 81875 64)
 (miscs 40 30275 9176)
 (strings 32 289550 44816)
 (string-bytes 1 17523205)
 (vectors 16 229225)
 (vector-slots 8 6260146 165024)
 (floats 8 41178 7977)
 (intervals 56 93999 1175)
 (buffers 960 489)
 (heap 1024 198499 22150))