Subject: bug#40896: 27.0.91; Moving point fails sometimes in shell-command

From: Michael Albinus <[email-masked]>
Date: Mon, 27 Apr 2020 10:28:03 +0200

Hi,

`shell-command' shall move the point after the output of the command,
unless indicated otherwise by `shell-command-dont-erase-buffer'. This
works almost, but not always. I have extracted three test cases which fail.

--8<---------------cut here---------------start------------->8---
;; Erase if buffer is the current one, but
;; `shell-command-dont-erase-buffer' is set to `erase'.
;; Move point to `point-max'.
(let ((default-directory temporary-file-directory)
      (shell-command-dont-erase-buffer 'erase))
  (with-temp-buffer
    (insert "bar")
    (cl-assert (string-equal "bar" (buffer-string)))
    (cl-assert (= (point) (point-max)))
    (shell-command "echo baz" (current-buffer))
    (cl-assert (string-equal "baz\n" (buffer-string)))
    ;; Point is not moved after the inserted text.
    (cl-assert (= (point) (point-max)) 'show-args)))

;; Don't erase if the buffer is the current one and
;; `shell-command-dont-erase-buffer' is set to `end-last-out'.
;; Move point to `point-max'.
(let ((default-directory temporary-file-directory)
      (shell-command-dont-erase-buffer 'end-last-out))
  (with-temp-buffer
    (insert "bar")
    (cl-assert (string-equal "bar" (buffer-string)))
    (cl-assert (= (point) (point-max)))
    (shell-command "echo baz" (current-buffer))
    (cl-assert (string-equal "barbaz\n" (buffer-string)))
    ;; Point is not moved after the inserted text.
    (cl-assert (= (point) (point-max)) 'show-args)))

;; Don't erase if the buffer is the current one and
;; `shell-command-dont-erase-buffer' is set to a random value.
;; Move point to `point-max'.
(let ((default-directory temporary-file-directory)
      (shell-command-dont-erase-buffer 'random))
  (with-temp-buffer
    (insert "bar")
    (cl-assert (string-equal "bar" (buffer-string)))
    (cl-assert (= (point) (point-max)))
    (shell-command "echo baz" (current-buffer))
    (cl-assert (string-equal "barbaz\n" (buffer-string)))
    ;; Point is not moved after the inserted text.
    (cl-assert (= (point) (point-max)) 'show-args)))
--8<---------------cut here---------------end--------------->8---

If it is undecided where point will be in the first and third case, this
shall be documented at least.

Best regards, Michael.

In GNU Emacs 27.0.91 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.13)
 of 2020-04-26 built on gandalf
Repository revision: 68f4a740a13ee6a1d98079ef655dd42924d24d41
Repository branch: emacs-27
Windowing system distributor 'Fedora Project', version 11.0.12006000
System Description: Fedora 31 (Workstation Edition)

Recent messages:
Reading active file from news via nntp...
Opening nntp server on news...done
Opening connection to imap.gmx.net via tls...
Opening connection to imap.gmx.net...done
Reading active file via nnml...
Reading incoming mail from pop...
nnml: Reading incoming mail (no new mail)...done
Reading active file via nnml...done
Reading active file via nndraft...done
Checking new news...done

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND GPM DBUS GSETTINGS GLIB NOTIFY INOTIFY
ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS PDUMPER LCMS2 GMP

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

Major mode: Group

Minor modes in effect:
  gnus-undo-mode: t
  erc-notify-mode: t
  erc-notifications-mode: t
  display-time-mode: t
  shell-dirtrack-mode: t
  delete-selection-mode: t
  icomplete-mode: t
  show-paren-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-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
  buffer-read-only: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
/home/albinus/src/tramp/lisp/tramp-sh hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-sh
/home/albinus/src/tramp/lisp/tramp-compat hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-compat
/home/albinus/src/tramp/lisp/tramp hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp
/home/albinus/src/tramp/lisp/tramp-rclone hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-rclone
/home/albinus/src/tramp/lisp/tramp-cmds hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-cmds
/home/albinus/src/tramp/lisp/tramp-gvfs hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-gvfs
/home/albinus/src/tramp/lisp/tramp-uu hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-uu
/home/albinus/src/tramp/lisp/tramp-integration hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-integration
/home/albinus/src/tramp/lisp/tramp-archive hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-archive
/home/albinus/src/tramp/lisp/tramp-adb hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-adb
/home/albinus/src/tramp/lisp/trampver hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/trampver
/home/albinus/src/tramp/lisp/tramp-ftp hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-ftp
/home/albinus/src/tramp/lisp/tramp-smb hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-smb
/home/albinus/src/tramp/lisp/tramp-cache hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-cache
/home/albinus/src/tramp/lisp/tramp-sudoedit hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-sudoedit
/home/albinus/src/tramp/lisp/tramp-loaddefs hides /home/albinus/.emacs.d/elpa/tramp-2.4.3.3/tramp-loaddefs
/home/albinus/src/elpa/packages/tramp-theme/tramp-theme-autoloads hides /home/albinus/.emacs.d/elpa/tramp-theme-0.2/tramp-theme-autoloads
/home/albinus/src/elpa/packages/tramp-theme/tramp-theme hides /home/albinus/.emacs.d/elpa/tramp-theme-0.2/tramp-theme
/home/albinus/src/elpa/packages/tramp-theme/tramp-theme-pkg hides /home/albinus/.emacs.d/elpa/tramp-theme-0.2/tramp-theme-pkg
/home/albinus/src/tramp/lisp/tramp-sh hides /home/albinus/src/emacs-27/lisp/net/tramp-sh
/home/albinus/src/tramp/lisp/tramp-cmds hides /home/albinus/src/emacs-27/lisp/net/tramp-cmds
/home/albinus/src/tramp/lisp/tramp-gvfs hides /home/albinus/src/emacs-27/lisp/net/tramp-gvfs
/home/albinus/src/tramp/lisp/tramp-ftp hides /home/albinus/src/emacs-27/lisp/net/tramp-ftp
/home/albinus/src/tramp/lisp/tramp-adb hides /home/albinus/src/emacs-27/lisp/net/tramp-adb
/home/albinus/src/tramp/lisp/tramp hides /home/albinus/src/emacs-27/lisp/net/tramp
/home/albinus/src/tramp/lisp/tramp-cache hides /home/albinus/src/emacs-27/lisp/net/tramp-cache
/home/albinus/src/tramp/lisp/tramp-rclone hides /home/albinus/src/emacs-27/lisp/net/tramp-rclone
/home/albinus/src/tramp/lisp/tramp-compat hides /home/albinus/src/emacs-27/lisp/net/tramp-compat
/home/albinus/src/tramp/lisp/tramp-integration hides /home/albinus/src/emacs-27/lisp/net/tramp-integration
/home/albinus/src/tramp/lisp/tramp-archive hides /home/albinus/src/emacs-27/lisp/net/tramp-archive
~/lisp/dbus hides /home/albinus/src/emacs-27/lisp/net/dbus
/home/albinus/src/tramp/lisp/tramp-sudoedit hides /home/albinus/src/emacs-27/lisp/net/tramp-sudoedit
/home/albinus/src/tramp/lisp/tramp-loaddefs hides /home/albinus/src/emacs-27/lisp/net/tramp-loaddefs
/home/albinus/src/tramp/lisp/tramp-uu hides /home/albinus/src/emacs-27/lisp/net/tramp-uu
/home/albinus/src/tramp/lisp/tramp-smb hides /home/albinus/src/emacs-27/lisp/net/tramp-smb
/home/albinus/src/tramp/lisp/trampver hides /home/albinus/src/emacs-27/lisp/net/trampver

Features:
(shadow sort mail-extr warnings emacsbug pop3 utf-7 nndraft nnmh nnml
gnutls network-stream nsm gnus-agent gnus-srvr gnus-score score-mode
nnvirtual gnus-msg gnus-art mm-uu mml2015 mm-view mml-smime smime dig
gnus-cache gnus-sum url url-proxy url-privacy url-expand url-methods
url-history mailcap shr url-cookie url-domsuf url-util svg dom nnnil
smtpmail sendmail gnus-demon nntp gnus-group gnus-undo gnus-start
gnus-cloud nnimap nnmail mail-source utf7 netrc nnoo gnus-spec gnus-int
gnus-range message rmc puny rfc822 mml mml-sec epa derived epg
epg-config mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader gnus-win gnus nnheader gnus-util rmail
rmail-loaddefs rfc2047 rfc2045 ietf-drums text-property-search
mail-utils mm-util mail-prsvr wid-edit eieio-opt cl-extra speedbar
sb-image ezimage dframe help-fns radix-tree cl-print debug backtrace
help-mode find-func vc vc-dispatcher erc-notify erc-networks
erc-desktop-notifications erc-match notifications dbus xml erc-goodies
erc erc-backend erc-compat thingatpt pp erc-loaddefs cperl-mode time
tramp-sh vagrant-tramp dash term disp-table ehelp tramp tramp-loaddefs
trampver tramp-integration files-x tramp-compat shell pcomplete comint
ansi-color ring parse-time iso8601 time-date ls-lisp format-spec delsel
ido jka-compr icomplete paren dired dired-loaddefs info package easymenu
browse-url url-handlers url-parse auth-source cl-seq eieio eieio-core
cl-macs eieio-loaddefs password-cache json subr-x map url-vars seq
byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib tooltip eldoc
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel term/x-win
x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame minibuffer 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 composite charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray 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 threads dbusbind inotify lcms2 dynamic-setting
system-font-setting font-render-setting move-toolbar gtk x-toolkit x
multi-tty make-network-process emacs)

Memory information:
((conses 16 212745 10654)
 (symbols 48 21733 1)
 (strings 32 66828 3046)
 (string-bytes 1 2267312)
 (vectors 16 31843)
 (vector-slots 8 397198 17284)
 (floats 8 253 37)
 (intervals 56 2268 0)
 (buffers 1000 24))