Subject: bug#20897: 25.0.50; [python] sexp-movement are confusing

From: Rasmus <[email-masked]>
Date: Thu, 25 Jun 2015 17:53:45 +0200

Hi,

Sexp movement in python.el are very confusing to me.  I know that logical
sexp movements outside lisp are subjective, and I know that the behavior
isn't wrong.  I understand why it does what it does.  The behavior is just
confusing when I use it an practice.

Example, starting from emacs -q:

Open test.py

Insert something like this, ignoring point denoted by "{v,^} {1,...,5}".

4  5   6
v  v   v
def foo(x):
   """return x as one"""

    x = 1;

    return(x)
   ^      ^  ^
   2      3  1

Consider points 1,...,5.  At point 2 forward-sexp will go to point 1, at
point 3 backward-sexp will go to point 2.  At point 1, sexp-backward will
go to 4 rather than point 2 (as I would expect).  Likewise, at point 4,
forward sexp goes to point 1 rather than 5.  At point five, everything is
as I would expect, and {forward,backward}-sexp goes to 6 and 4.

A switch to prefer a closer opening/closing of the "sexp" at point would
be great.

Thanks,
Rasmus

In GNU Emacs 25.0.50.2 (x86_64-unknown-linux-gnu, GTK+ Version 3.16.4)
 of 2015-06-21 on x200s
Repository revision: 821a3633564f36857968c7fe2b8bb6681a895905
Windowing system distributor `The X.Org Foundation', version 11.0.11702000
Configured using:
 `configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --mandir=/usr/share/man
 --pdfdir=/usr/share/doc/emacs/pdf --with-sound=alsa --with-x-toolkit=gtk3
 --with-xft 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe
 -fstack-protector-strong --param=ssp-buffer-size=4'
 CPPFLAGS=-D_FORTIFY_SOURCE=2
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF GSETTINGS
NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3

Important settings:
  value of $LC_MONETARY: en_DK.utf8
  value of $LC_NUMERIC: en_DK.utf8
  value of $LC_TIME: en_DK.utf8
  value of $LANG: en_US.utf8
  locale-coding-system: utf-8-unix

Major mode: Group

Minor modes in effect:
  magit-auto-revert-mode: t
  recentf-mode: t
  shell-dirtrack-mode: t
  pdf-occur-global-minor-mode: t
  gnus-topic-mode: t
  hl-line-mode: t
  cursor-sensor-mode: t
  gnus-undo-mode: t
  nyan-mode: t
  global-company-mode: t
  company-mode: t
  diff-auto-refine-mode: t
  ido-everywhere: t
  global-auto-revert-mode: t
  which-function-mode: t
  winner-mode: t
  delete-selection-mode: t
  show-paren-mode: t
  electric-pair-mode: t
  savehist-mode: t
  save-place-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-layout-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-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
  column-number-mode: t
  line-number-mode: t
  global-visual-line-mode: t
  visual-line-mode: t
  transient-mark-mode: t

Recent messages:
Reading active file via nnnil...done
Reading active file via nndraft...done
Checking new news...done
nnimap read 0k from mail
Checking new news...
Reading active file via nnnil...done
Reading active file via nndraft...done
Checking new news...done
funcall-interactively: Buffer is read-only: #<buffer *Group*>
Quit

Load-path shadows:
/home/rasmus/.emacs.d/lisp/abbrev hides /usr/share/emacs/25.0.50/lisp/abbrev
/usr/share/emacs/site-lisp/org/ox-texinfo hides /usr/share/emacs/25.0.50/lisp/org/ox-texinfo
/usr/share/emacs/site-lisp/org/ox-publish hides /usr/share/emacs/25.0.50/lisp/org/ox-publish
/usr/share/emacs/site-lisp/org/ox-org hides /usr/share/emacs/25.0.50/lisp/org/ox-org
/usr/share/emacs/site-lisp/org/ox-odt hides /usr/share/emacs/25.0.50/lisp/org/ox-odt
/usr/share/emacs/site-lisp/org/ox-md hides /usr/share/emacs/25.0.50/lisp/org/ox-md
/usr/share/emacs/site-lisp/org/ox-man hides /usr/share/emacs/25.0.50/lisp/org/ox-man
/usr/share/emacs/site-lisp/org/ox-latex hides /usr/share/emacs/25.0.50/lisp/org/ox-latex
/usr/share/emacs/site-lisp/org/ox-icalendar hides /usr/share/emacs/25.0.50/lisp/org/ox-icalendar
/usr/share/emacs/site-lisp/org/ox-html hides /usr/share/emacs/25.0.50/lisp/org/ox-html
/usr/share/emacs/site-lisp/org/ox hides /usr/share/emacs/25.0.50/lisp/org/ox
/usr/share/emacs/site-lisp/org/ox-beamer hides /usr/share/emacs/25.0.50/lisp/org/ox-beamer
/usr/share/emacs/site-lisp/org/ox-ascii hides /usr/share/emacs/25.0.50/lisp/org/ox-ascii
/usr/share/emacs/site-lisp/org/org-w3m hides /usr/share/emacs/25.0.50/lisp/org/org-w3m
/usr/share/emacs/site-lisp/org/org-timer hides /usr/share/emacs/25.0.50/lisp/org/org-timer
/usr/share/emacs/site-lisp/org/org-table hides /usr/share/emacs/25.0.50/lisp/org/org-table
/usr/share/emacs/site-lisp/org/org-src hides /usr/share/emacs/25.0.50/lisp/org/org-src
/usr/share/emacs/site-lisp/org/org-rmail hides /usr/share/emacs/25.0.50/lisp/org/org-rmail
/usr/share/emacs/site-lisp/org/org-protocol hides /usr/share/emacs/25.0.50/lisp/org/org-protocol
/usr/share/emacs/site-lisp/org/org-plot hides /usr/share/emacs/25.0.50/lisp/org/org-plot
/usr/share/emacs/site-lisp/org/org-pcomplete hides /usr/share/emacs/25.0.50/lisp/org/org-pcomplete
/usr/share/emacs/site-lisp/org/org-mouse hides /usr/share/emacs/25.0.50/lisp/org/org-mouse
/usr/share/emacs/site-lisp/org/org-mobile hides /usr/share/emacs/25.0.50/lisp/org/org-mobile
/usr/share/emacs/site-lisp/org/org-mhe hides /usr/share/emacs/25.0.50/lisp/org/org-mhe
/usr/share/emacs/site-lisp/org/org-macs hides /usr/share/emacs/25.0.50/lisp/org/org-macs
/usr/share/emacs/site-lisp/org/org-macro hides /usr/share/emacs/25.0.50/lisp/org/org-macro
/usr/share/emacs/site-lisp/org/org-list hides /usr/share/emacs/25.0.50/lisp/org/org-list
/usr/share/emacs/site-lisp/org/org-irc hides /usr/share/emacs/25.0.50/lisp/org/org-irc
/usr/share/emacs/site-lisp/org/org-inlinetask hides /usr/share/emacs/25.0.50/lisp/org/org-inlinetask
/usr/share/emacs/site-lisp/org/org-info hides /usr/share/emacs/25.0.50/lisp/org/org-info
/usr/share/emacs/site-lisp/org/org-indent hides /usr/share/emacs/25.0.50/lisp/org/org-indent
/usr/share/emacs/site-lisp/org/org-id hides /usr/share/emacs/25.0.50/lisp/org/org-id
/usr/share/emacs/site-lisp/org/org-habit hides /usr/share/emacs/25.0.50/lisp/org/org-habit
/usr/share/emacs/site-lisp/org/org-gnus hides /usr/share/emacs/25.0.50/lisp/org/org-gnus
/usr/share/emacs/site-lisp/org/org-footnote hides /usr/share/emacs/25.0.50/lisp/org/org-footnote
/usr/share/emacs/site-lisp/org/org-feed hides /usr/share/emacs/25.0.50/lisp/org/org-feed
/usr/share/emacs/site-lisp/org/org-faces hides /usr/share/emacs/25.0.50/lisp/org/org-faces
/usr/share/emacs/site-lisp/org/org-eshell hides /usr/share/emacs/25.0.50/lisp/org/org-eshell
/usr/share/emacs/site-lisp/org/org-entities hides /usr/share/emacs/25.0.50/lisp/org/org-entities
/usr/share/emacs/site-lisp/org/org-element hides /usr/share/emacs/25.0.50/lisp/org/org-element
/usr/share/emacs/site-lisp/org/org hides /usr/share/emacs/25.0.50/lisp/org/org
/usr/share/emacs/site-lisp/org/org-docview hides /usr/share/emacs/25.0.50/lisp/org/org-docview
/usr/share/emacs/site-lisp/org/org-datetree hides /usr/share/emacs/25.0.50/lisp/org/org-datetree
/usr/share/emacs/site-lisp/org/org-ctags hides /usr/share/emacs/25.0.50/lisp/org/org-ctags
/usr/share/emacs/site-lisp/org/org-crypt hides /usr/share/emacs/25.0.50/lisp/org/org-crypt
/usr/share/emacs/site-lisp/org/org-compat hides /usr/share/emacs/25.0.50/lisp/org/org-compat
/usr/share/emacs/site-lisp/org/org-colview hides /usr/share/emacs/25.0.50/lisp/org/org-colview
/usr/share/emacs/site-lisp/org/org-clock hides /usr/share/emacs/25.0.50/lisp/org/org-clock
/usr/share/emacs/site-lisp/org/org-capture hides /usr/share/emacs/25.0.50/lisp/org/org-capture
/usr/share/emacs/site-lisp/org/org-bibtex hides /usr/share/emacs/25.0.50/lisp/org/org-bibtex
/usr/share/emacs/site-lisp/org/org-bbdb hides /usr/share/emacs/25.0.50/lisp/org/org-bbdb
/usr/share/emacs/site-lisp/org/org-attach hides /usr/share/emacs/25.0.50/lisp/org/org-attach
/usr/share/emacs/site-lisp/org/org-archive hides /usr/share/emacs/25.0.50/lisp/org/org-archive
/usr/share/emacs/site-lisp/org/org-agenda hides /usr/share/emacs/25.0.50/lisp/org/org-agenda
/usr/share/emacs/site-lisp/org/ob-tangle hides /usr/share/emacs/25.0.50/lisp/org/ob-tangle
/usr/share/emacs/site-lisp/org/ob-table hides /usr/share/emacs/25.0.50/lisp/org/ob-table
/usr/share/emacs/site-lisp/org/ob-sqlite hides /usr/share/emacs/25.0.50/lisp/org/ob-sqlite
/usr/share/emacs/site-lisp/org/ob-sql hides /usr/share/emacs/25.0.50/lisp/org/ob-sql
/usr/share/emacs/site-lisp/org/ob-shen hides /usr/share/emacs/25.0.50/lisp/org/ob-shen
/usr/share/emacs/site-lisp/org/ob-screen hides /usr/share/emacs/25.0.50/lisp/org/ob-screen
/usr/share/emacs/site-lisp/org/ob-scheme hides /usr/share/emacs/25.0.50/lisp/org/ob-scheme
/usr/share/emacs/site-lisp/org/ob-scala hides /usr/share/emacs/25.0.50/lisp/org/ob-scala
/usr/share/emacs/site-lisp/org/ob-sass hides /usr/share/emacs/25.0.50/lisp/org/ob-sass
/usr/share/emacs/site-lisp/org/ob-ruby hides /usr/share/emacs/25.0.50/lisp/org/ob-ruby
/usr/share/emacs/site-lisp/org/ob-R hides /usr/share/emacs/25.0.50/lisp/org/ob-R
/usr/share/emacs/site-lisp/org/ob-ref hides /usr/share/emacs/25.0.50/lisp/org/ob-ref
/usr/share/emacs/site-lisp/org/ob-python hides /usr/share/emacs/25.0.50/lisp/org/ob-python
/usr/share/emacs/site-lisp/org/ob-plantuml hides /usr/share/emacs/25.0.50/lisp/org/ob-plantuml
/usr/share/emacs/site-lisp/org/ob-picolisp hides /usr/share/emacs/25.0.50/lisp/org/ob-picolisp
/usr/share/emacs/site-lisp/org/ob-perl hides /usr/share/emacs/25.0.50/lisp/org/ob-perl
/usr/share/emacs/site-lisp/org/ob-org hides /usr/share/emacs/25.0.50/lisp/org/ob-org
/usr/share/emacs/site-lisp/org/ob-octave hides /usr/share/emacs/25.0.50/lisp/org/ob-octave
/usr/share/emacs/site-lisp/org/ob-ocaml hides /usr/share/emacs/25.0.50/lisp/org/ob-ocaml
/usr/share/emacs/site-lisp/org/ob-mscgen hides /usr/share/emacs/25.0.50/lisp/org/ob-mscgen
/usr/share/emacs/site-lisp/org/ob-maxima hides /usr/share/emacs/25.0.50/lisp/org/ob-maxima
/usr/share/emacs/site-lisp/org/ob-matlab hides /usr/share/emacs/25.0.50/lisp/org/ob-matlab
/usr/share/emacs/site-lisp/org/ob-makefile hides /usr/share/emacs/25.0.50/lisp/org/ob-makefile
/usr/share/emacs/site-lisp/org/ob-lob hides /usr/share/emacs/25.0.50/lisp/org/ob-lob
/usr/share/emacs/site-lisp/org/ob-lisp hides /usr/share/emacs/25.0.50/lisp/org/ob-lisp
/usr/share/emacs/site-lisp/org/ob-lilypond hides /usr/share/emacs/25.0.50/lisp/org/ob-lilypond
/usr/share/emacs/site-lisp/org/ob-ledger hides /usr/share/emacs/25.0.50/lisp/org/ob-ledger
/usr/share/emacs/site-lisp/org/ob-latex hides /usr/share/emacs/25.0.50/lisp/org/ob-latex
/usr/share/emacs/site-lisp/org/ob-keys hides /usr/share/emacs/25.0.50/lisp/org/ob-keys
/usr/share/emacs/site-lisp/org/ob-js hides /usr/share/emacs/25.0.50/lisp/org/ob-js
/usr/share/emacs/site-lisp/org/ob-java hides /usr/share/emacs/25.0.50/lisp/org/ob-java
/usr/share/emacs/site-lisp/org/ob-io hides /usr/share/emacs/25.0.50/lisp/org/ob-io
/usr/share/emacs/site-lisp/org/ob-haskell hides /usr/share/emacs/25.0.50/lisp/org/ob-haskell
/usr/share/emacs/site-lisp/org/ob-gnuplot hides /usr/share/emacs/25.0.50/lisp/org/ob-gnuplot
/usr/share/emacs/site-lisp/org/ob-fortran hides /usr/share/emacs/25.0.50/lisp/org/ob-fortran
/usr/share/emacs/site-lisp/org/ob-exp hides /usr/share/emacs/25.0.50/lisp/org/ob-exp
/usr/share/emacs/site-lisp/org/ob-eval hides /usr/share/emacs/25.0.50/lisp/org/ob-eval
/usr/share/emacs/site-lisp/org/ob-emacs-lisp hides /usr/share/emacs/25.0.50/lisp/org/ob-emacs-lisp
/usr/share/emacs/site-lisp/org/ob hides /usr/share/emacs/25.0.50/lisp/org/ob
/usr/share/emacs/site-lisp/org/ob-dot hides /usr/share/emacs/25.0.50/lisp/org/ob-dot
/usr/share/emacs/site-lisp/org/ob-ditaa hides /usr/share/emacs/25.0.50/lisp/org/ob-ditaa
/usr/share/emacs/site-lisp/org/ob-css hides /usr/share/emacs/25.0.50/lisp/org/ob-css
/usr/share/emacs/site-lisp/org/ob-core hides /usr/share/emacs/25.0.50/lisp/org/ob-core
/usr/share/emacs/site-lisp/org/ob-comint hides /usr/share/emacs/25.0.50/lisp/org/ob-comint
/usr/share/emacs/site-lisp/org/ob-clojure hides /usr/share/emacs/25.0.50/lisp/org/ob-clojure
/usr/share/emacs/site-lisp/org/ob-C hides /usr/share/emacs/25.0.50/lisp/org/ob-C
/usr/share/emacs/site-lisp/org/ob-calc hides /usr/share/emacs/25.0.50/lisp/org/ob-calc
/usr/share/emacs/site-lisp/org/ob-awk hides /usr/share/emacs/25.0.50/lisp/org/ob-awk
/usr/share/emacs/site-lisp/org/ob-asymptote hides /usr/share/emacs/25.0.50/lisp/org/ob-asymptote
/usr/share/emacs/site-lisp/org/org-loaddefs hides /usr/share/emacs/25.0.50/lisp/org/org-loaddefs
/usr/share/emacs/site-lisp/org/org-version hides /usr/share/emacs/25.0.50/lisp/org/org-version
/usr/share/emacs/site-lisp/org/org-install hides /usr/share/emacs/25.0.50/lisp/org/org-install
/home/rasmus/.emacs.d/elpa/emms-20150519.736/tq hides /usr/share/emacs/25.0.50/lisp/emacs-lisp/tq

Features:
(shadow emacsbug json-mode json-reformat json-snatcher canlock eieio-opt
speedbar sb-image ezimage dframe cal-iso cal-china lunar solar cal-dst
cal-bahai cal-islam cal-hebrew holidays hol-loaddefs proced browse-url
sh-script smie executable web-mode autoload lisp-mnt url-handlers
tramp-cache magit-key-mode warnings magit view tramp tramp-compat
tramp-loaddefs trampver git-rebase-mode git-commit-mode log-edit pcvs-util
ediff-merg ediff-wind ediff-diff ediff-mult ediff-help ediff-init
ediff-util ediff js skewer-html skewer-mode cache-table js2-mode
simple-httpd sgml-mode rect recentf tree-widget misearch multi-isearch
add-log python find-dired grep dired-aux gnus-dired ffap face-remap
emms-player-mpv emms-info-libtag emms-librefm-stream
emms-librefm-scrobbler emms-playlist-limit emms-volume emms-volume-amixer
emms-i18n emms-history emms-score emms-stream-info emms-metaplaylist-mode
emms-bookmarks emms-cue emms-mode-line-icon emms-browser
emms-playlist-sort emms-last-played emms-player-xine emms-player-mpd
emms-playing-time emms-lyrics emms-url emms-streams emms-tag-editor
emms-mark emms-mode-line emms-cache emms-info-ogginfo emms-info-mp3info
emms-info later-do emms-playlist-mode emms-player-vlc emms-player-mplayer
emms-player-simple emms-source-playlist emms-source-file locate emms-setup
emms emms-compat quail footnote autocap cookie1 flow-fill
gnus-notifications gnus-fun notifications dbus xml cal-move org-bullets
cdlatex texmathp reftex reftex-vars tabify org-table image-file org-rmail
org-mhe org-irc org-info org-gnus org-docview doc-view org-bibtex bibtex
org-bbdb org-element avl-tree org-w3m org-capture ido-completing-read+
smex pdf-sync pdf-annot bbdb-anniv diary-lib diary-loaddefs org-inlinetask
org-indent org-location-google-maps org-agenda google-maps
google-maps-static google-maps-geocode google-maps-base json org org-macro
org-footnote org-pcomplete org-list org-faces org-entities org-version
ob-shell readline-complete shell pcomplete ob-awk ob-org ob-octave
ob-python ob-C ob-emacs-lisp ob-fortran cc-mode cc-fonts cc-guess cc-menus
cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs ob-latex ob-R ob
ob-tangle ob-ref ob-lob ob-table ob-exp org-src ob-keys ob-comint ob-core
ob-eval org-compat org-macs org-loaddefs find-func cal-menu calendar
cal-loaddefs pdf-outline noutline outline pdf-links pdf-history 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 mode-local cedet
pdf-isearch let-alist pdf-misc pdf-tools compile comint cus-edit cus-start
cus-load pdf-view jka-compr pdf-cache pdf-info tq pdf-util image-mode
url-http url-gw url-auth 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 gnus-picon sort smiley ansi-color gnus-cite
mm-archive mail-extr gnus-async gnus-bcklg qp gnus-ml disp-table
gnus-topic hl-line cursor-sensor epa-file epa derived epg gnutls utf-7
network-stream nsm starttls nnnil gnus-demon gnus-harvest bbdb-com crm
bbdb bbdb-site timezone mailalias nnir smtpmail-async smtpmail auth-source
sendmail async gnus-delay gnus-draft gnus-agent gnus-srvr gnus-score
score-mode nnvirtual nntp gnus-cache gnus-msg gnus-art mm-uu mml2015
mm-view mml-smime smime password-cache dig mailcap gnus-sum nndraft nnmh
gnus-group gnus-undo gnus-start gnus-cloud nnimap tls utf7 netrc
parse-time gnus-spec nnmail gnus-int gnus-range mail-source message idna
dired-x dired format-spec rfc822 mml mml-sec mm-decode mm-bodies mm-encode
mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mailabbrev gmm-utils
mailheader gnus-win nnoo gnus gnus-ems nnheader gnus-util mail-utils
mm-util help-fns mail-prsvr wid-edit gnus-switch nyan-mode server paredit
checkdoc help-mode flyspell ispell cap-words superword subword
company-files company-oddmuse company-keywords company-etags etags xref
cl-seq eieio byte-opt bytecomp byte-compile cl-extra seq cconv eieio-core
company-gtags company-dabbrev-code company-dabbrev company-capf
company-cmake company-xcode company-clang company-semantic company-eclim
company-template company-css company-nxml company-bbdb company-c-headers
rx company-jedi thingatpt jedi-core python-environment epc ctable
concurrent deferred cl company vc vc-dispatcher vc-git diff-mode
easy-mmode bookmark pp ido autorevert filenotify which-func imenu winner
ring windmove delsel paren elec-pair savehist saveplace cl-macs time-date
edmacro kmacro cl-loaddefs pcase cl-lib gv finder-inf tex-site advice info
easymenu package epg-config mule-util tooltip eldoc electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame
cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak
czech european ethiopic indian cyrillic chinese charscript case-table
epa-hook jka-cmpr-hook help simple abbrev minibuffer cl-preloaded 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 dbusbind gfilenotify dynamic-setting
system-font-setting font-render-setting move-toolbar gtk x-toolkit x
multi-tty make-network-process emacs)

Memory information:
((conses 16 3221294 73586)
 (symbols 48 71726 114)
 (miscs 40 13038 7141)
 (strings 32 230866 27519)
 (string-bytes 1 12018724)
 (vectors 16 90831)
 (vector-slots 8 2165399 85080)
 (floats 8 4055 3190)
 (intervals 56 43823 10399)
 (buffers 976 278)
 (heap 1024 145052 17505))

-- 
Dung makes an excellent fertilizer