unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#40896: 27.0.91; Moving point fails sometimes in shell-command
@ 2020-04-27  8:28 Michael Albinus
  2020-04-27 14:43 ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Albinus @ 2020-04-27  8:28 UTC (permalink / raw)
  To: 40896; +Cc: Tino Calancha


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))





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#40896: 27.0.91; Moving point fails sometimes in shell-command
  2020-04-27  8:28 bug#40896: 27.0.91; Moving point fails sometimes in shell-command Michael Albinus
@ 2020-04-27 14:43 ` Eli Zaretskii
  2020-04-27 17:50   ` Michael Albinus
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2020-04-27 14:43 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 40896, tino.calancha

> From: Michael Albinus <michael.albinus@gmx.de>
> Date: Mon, 27 Apr 2020 10:28:03 +0200
> Cc: Tino Calancha <tino.calancha@gmail.com>
> 
> `shell-command' shall move the point after the output of the command,
> unless indicated otherwise by `shell-command-dont-erase-buffer'.

Which part(s) of the documentation caused this interpretation?  AFAIK,
the truth is that the output is inserted at point (i.e. point is left
_before_ the output), unless indicated otherwise by
shell-command-dont-erase-buffer.  So if something we say tricks you to
think otherwise, we need to fix that text.

Thanks.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#40896: 27.0.91; Moving point fails sometimes in shell-command
  2020-04-27 14:43 ` Eli Zaretskii
@ 2020-04-27 17:50   ` Michael Albinus
  2020-04-28 11:32     ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Albinus @ 2020-04-27 17:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 40896, tino.calancha

Eli Zaretskii <eliz@gnu.org> writes:

Hi Eli,

>> `shell-command' shall move the point after the output of the command,
>> unless indicated otherwise by `shell-command-dont-erase-buffer'.
>
> Which part(s) of the documentation caused this interpretation?  AFAIK,
> the truth is that the output is inserted at point (i.e. point is left
> _before_ the output), unless indicated otherwise by
> shell-command-dont-erase-buffer.  So if something we say tricks you to
> think otherwise, we need to fix that text.

Hmm, maybe I have been biased with the Tramp behaviour. But still,
there's suspicious behaviour with shell-command:

--8<---------------cut here---------------start------------->8---
;; Don't erase if the buffer is not the current one and
;; `shell-command-dont-erase-buffer' is set to `save-point'.
;; Check point.
(let ((default-directory temporary-file-directory)
      (shell-command-dont-erase-buffer 'save-point)
      buffer point)
  (with-temp-buffer
    (setq buffer (current-buffer))
    (insert "foobar")
    (goto-char (- (point-max) 3))
    (setq point (point))
    (cl-assert (string-equal "foobar" (buffer-string)))
    (cl-assert (string-equal "foo" (buffer-substring (point-min) (point))))
    (cl-assert (string-equal "bar" (buffer-substring (point) (point-max))))
    (cl-assert (= (point) (- (point-max) 3)))
    (with-temp-buffer
      (shell-command "echo baz" buffer))
    ;; The shell command output should be inserted between "foo" and "bar".
    (cl-assert (string-equal "foobaz\nbar" (buffer-string)) 'show-args)
    (cl-assert (= point (point)) 'show-args)))

;; Don't erase if the buffer is not the current one and
;; `shell-command-dont-erase-buffer' is set to a non-nil value.
;; Point should be before shell command output.
(let ((default-directory temporary-file-directory)
      (shell-command-dont-erase-buffer 'random)
      buffer point)
  (with-temp-buffer
    (setq buffer (current-buffer))
    (insert "foobar")
    (setq point (point))
    (cl-assert (string-equal "foobar" (buffer-string)))
    (cl-assert (= (point) (point-max)))
    (with-temp-buffer
      (shell-command "echo baz" buffer))
    (cl-assert (string-equal "foobarbaz\n" (buffer-string)) 'show-args)
    ;; Point should be the same.
    (cl-assert (= point (point)) 'show-args)))
--8<---------------cut here---------------end--------------->8---

Unless I still misunderstand something, these cases should be checked. I
will work on Tramp when clarified.

> Thanks.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#40896: 27.0.91; Moving point fails sometimes in shell-command
  2020-04-27 17:50   ` Michael Albinus
@ 2020-04-28 11:32     ` Eli Zaretskii
  2020-04-28 14:22       ` Michael Albinus
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2020-04-28 11:32 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 40896, tino.calancha

> From: Michael Albinus <michael.albinus@gmx.de>
> Cc: 40896@debbugs.gnu.org,  tino.calancha@gmail.com
> Date: Mon, 27 Apr 2020 19:50:57 +0200
> 
> Hmm, maybe I have been biased with the Tramp behaviour. But still,
> there's suspicious behaviour with shell-command:

I think these also behave as intended.  In general, all the non-nil
values of shell-command-dont-erase-buffer are set up to accumulate
output of several consecutive commands.  Once again, perhaps the
documentation needs to be clarified.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#40896: 27.0.91; Moving point fails sometimes in shell-command
  2020-04-28 11:32     ` Eli Zaretskii
@ 2020-04-28 14:22       ` Michael Albinus
  2020-04-30 13:45         ` Michael Albinus
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Albinus @ 2020-04-28 14:22 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 40896, tino.calancha

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Michael Albinus <michael.albinus@gmx.de>
>> Cc: 40896@debbugs.gnu.org,  tino.calancha@gmail.com
>> Date: Mon, 27 Apr 2020 19:50:57 +0200
>> 
>> Hmm, maybe I have been biased with the Tramp behaviour. But still,
>> there's suspicious behaviour with shell-command:
>
> I think these also behave as intended.  In general, all the non-nil
> values of shell-command-dont-erase-buffer are set up to accumulate
> output of several consecutive commands.  Once again, perhaps the
> documentation needs to be clarified.

Whatever shell-command-dont-erase-buffer says, shell-command output in
non-interactive mode shall be inserted at point, possibly after erasing
the buffer first. The first example I gave shows that this doesn't happen:

--8<---------------cut here---------------start------------->8---
;; Don't erase if the buffer is not the current one and
;; `shell-command-dont-erase-buffer' is set to `save-point'.
;; Check point.
(let ((default-directory temporary-file-directory)
      (shell-command-dont-erase-buffer 'save-point)
      buffer point)
  (with-temp-buffer
    (setq buffer (current-buffer))
    (insert "foobar")
    (goto-char (- (point-max) 3))
    (setq point (point))
    (cl-assert (string-equal "foobar" (buffer-string)))
    (cl-assert (string-equal "foo" (buffer-substring (point-min) (point))))
    (cl-assert (string-equal "bar" (buffer-substring (point) (point-max))))
    (cl-assert (= (point) (- (point-max) 3)))
    (with-temp-buffer
      (shell-command "echo baz" buffer))
    ;; The shell command output should be inserted between "foo" and "bar".
    (cl-assert (string-equal "foobaz\nbar" (buffer-string)) 'show-args)
    (cl-assert (= point (point)) 'show-args)))
--8<---------------cut here---------------end--------------->8---

Note that in case the buffer the output has to be inserted in is the
current one, this test succeeds. You can achieve this be replacing
'(with-temp-buffer (shell-command "echo baz" buffer))' by
'(shell-command "echo baz" buffer)'. This is inconsistent, isn't it? And
I haven't found any indication, that in case the buffer is not the
current one, shell command is inserted at the end of the buffer instead
of being inserted at point.

The second test case I've shown indicates, that a random value of
shell-command-dont-erase-buffer (I use the symbol 'random' here) doesn't
behave as expected. The docstring of that user option is not clear to
me: could it be, that the special symbols 'beg-last-out', 'end-last-out'
and ‘save-point’ indicate only setting the point if the buffer is the
current one? Why that? It's inconsistent in my eyes.

Maybe all of this is irrelevant in real life. But I'm fighting with
Tramp, in order to let its shell-command implementation behave like in
the local case.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#40896: 27.0.91; Moving point fails sometimes in shell-command
  2020-04-28 14:22       ` Michael Albinus
@ 2020-04-30 13:45         ` Michael Albinus
  2020-05-02  9:40           ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Albinus @ 2020-04-30 13:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 40896, tino.calancha

Michael Albinus <michael.albinus@gmx.de> writes:

Hi Eli,

> Maybe all of this is irrelevant in real life. But I'm fighting with
> Tramp, in order to let its shell-command implementation behave like in
> the local case.

In order to understand the situation better, I have enhanced my test
code to cover all different values of shell-command-dont-erase-buffer,
and whether the OUTPUT-BUFFER argument of shell-command is the current
buffer, or not. Here's the code:

--8<---------------cut here---------------start------------->8---
(progn
  (message "   s-c-d-e-b current-buffer buffer-string point")
  (message "===============================================")

  (let ((default-directory temporary-file-directory)
	buffer)
    ;; These are the possible values of `shell-command-dont-erase-buffer'.
    ;; `random' is taken as non-nil value without special meaning.
    (dolist (shell-command-dont-erase-buffer
	     '(nil erase beg-last-out end-last-out save-point random))
      ;; `shell-command' might work over the current buffer, or not.
      (dolist (current '(t nil))
	(with-temp-buffer
	  ;; We insert the string "foobar" into an empty buffer.
	  ;; Point is set between "foo" and "bar".
	  (setq buffer (current-buffer))
	  (insert "foobar")
	  (goto-char (- (point) 3))

	  ;; Apply `shell-command'.  It shall output the string
	  ;; "bazz".  Messages in the *Messages* buffer are
	  ;; suppressed.
          (let (message-log-max)
	    (if current
		(shell-command "echo -n bazz" (current-buffer))
	      (with-temp-buffer (shell-command "echo -n bazz" buffer))))

	  ;; Print result.
	  (message
	   "%12s %14s %13s %5d"
	   shell-command-dont-erase-buffer current (buffer-string) (point))))
      (message "-----------------------------------------------"))))
--8<---------------cut here---------------end--------------->8---

In a temporary buffer, the string "foobar" is inserted. Point is set
between "foo" and "bar". Then, shell-command is called, which outputs
the string "bazz".

The result can be seen in the *Messages* buffer. Honestly, I cannot say
whether this is conform to the docstring of shell-command (I have read
it several times), because it describes too many cases, and it is not
always clear how the combination of the cases is meant. But at least, I
would say the results look inconsistent.

A first observation is, that the output is inserted at (point) if
OUTPUT-BUFFER is the current buffer, and it is appended at (point-max)
if OUTPUT-BUFFER is not the current buffer. The fact, that the output is
appended at the end of the buffer, isn't mentioned anywhere in the doc AFAICT.

Now, let's see the details:

--8<---------------cut here---------------start------------->8---
   s-c-d-e-b current-buffer buffer-string point
===============================================
         nil              t    foobazzbar     4
         nil            nil          bazz     5
--8<---------------cut here---------------end--------------->8---

shell-command-dont-erase-buffer is nil. In case OUTPUT-BUFFER is the
current one, "bazz" is inserted at (point), and (point) is
preserved. Fine. In case OUTPUT-BUFFER is not the current one, the
buffer is erased, which as OK. However, (point) is NOT preserved, but
moved to the end of the shell command output. That doesn't sound right.

--8<---------------cut here---------------start------------->8---
       erase              t          bazz     1
       erase            nil          bazz     5
--8<---------------cut here---------------end--------------->8---

shell-command-dont-erase-buffer is erase. In both cases of
OUTPUT-BUFFER, the buffer is erased (as expected), but again, in case
OUTPUT-BUFFER is not the current one, (point) is moved after the shell
command output.

--8<---------------cut here---------------start------------->8---
beg-last-out              t    foobazzbar     4
beg-last-out            nil    foobarbazz     7
--8<---------------cut here---------------end--------------->8---

shell-command-dont-erase-buffer is beg-last-out. Shell command output is
inserted in case OUTPUT-BUFFER is the current one, and it is appended
otherwise. (point) is moved in both cases to the begin of the shell
command output, which is consistent, but I don't still see why the
output is either inserted, or appended.

--8<---------------cut here---------------start------------->8---
end-last-out              t    foobazzbar     4
end-last-out            nil    foobazzbar    11
--8<---------------cut here---------------end--------------->8---

shell-command-dont-erase-buffer is end-last-out. In case OUTPUT-BUFFER
is the current one everything looks as expected. But in the other case,
OUTPUT-BUFFER is not the current buffer, the result is irritating. Shell
command is inserted in this case at (point), and (point) is not moved to the
end of the shell command output, but to the end of the buffer. Strange!

--8<---------------cut here---------------start------------->8---
  save-point              t    foobazzbar     4
  save-point            nil    foobarbazz     4
--8<---------------cut here---------------end--------------->8---

shell-command-dont-erase-buffer is save-point. And indeed, (point) is
saved in both cases. But again, shell command output is appended at the
end of the buffer, instead of being inserted at (point).

--8<---------------cut here---------------start------------->8---
      random              t    foobazzbar     4
      random            nil    foobazzbar    11
--8<---------------cut here---------------end--------------->8---

shell-command-dont-erase-buffer is random, which stands for a non-nil
value which has no special meaning. It behaves like end-last-out. I
don't know whether this is intended; if yes, it shall be documented.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#40896: 27.0.91; Moving point fails sometimes in shell-command
  2020-04-30 13:45         ` Michael Albinus
@ 2020-05-02  9:40           ` Eli Zaretskii
  2020-05-02 13:12             ` Michael Albinus
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2020-05-02  9:40 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 40896, tino.calancha

> From: Michael Albinus <michael.albinus@gmx.de>
> Cc: 40896@debbugs.gnu.org,  tino.calancha@gmail.com
> Date: Thu, 30 Apr 2020 15:45:38 +0200
> 
> In order to understand the situation better, I have enhanced my test
> code to cover all different values of shell-command-dont-erase-buffer,
> and whether the OUTPUT-BUFFER argument of shell-command is the current
> buffer, or not. Here's the code:

AFAIU, the use case of OUTPUT-BUFFER being different from the current
buffer is meant for the case where subsequent commands accumulate the
output in that buffer, which is why the output is appended in that
case.

Does what you see make more sense now?





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#40896: 27.0.91; Moving point fails sometimes in shell-command
  2020-05-02  9:40           ` Eli Zaretskii
@ 2020-05-02 13:12             ` Michael Albinus
  2022-01-28 15:34               ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Albinus @ 2020-05-02 13:12 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 40896, tino.calancha

[-- Attachment #1: Type: text/plain, Size: 863 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

Hi Eli,

>> In order to understand the situation better, I have enhanced my test
>> code to cover all different values of shell-command-dont-erase-buffer,
>> and whether the OUTPUT-BUFFER argument of shell-command is the current
>> buffer, or not. Here's the code:
>
> AFAIU, the use case of OUTPUT-BUFFER being different from the current
> buffer is meant for the case where subsequent commands accumulate the
> output in that buffer, which is why the output is appended in that
> case.
>
> Does what you see make more sense now?

Almost. But it is not documented. Maybe we shall apply the appended
patch. And if shell-command-dont-erase-buffer is end-last-out with
output buffer not being the current one, the behavior is simply
wrong, see my previous analysis. At least *this* case must be fixed.

Best regards, Michael.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1025 bytes --]

diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index 47f195d0b2..ca3d52c36a 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -846,6 +846,9 @@ Single Shell
 shell-command output.
 @end table

+In case the output buffer is not the current buffer, shell command
+output is appended at the end of this buffer.
+
 @node Interactive Shell
 @subsection Interactive Subshell

diff --git a/lisp/simple.el b/lisp/simple.el
index ab277c4e11..2f0626d96e 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3606,6 +3606,9 @@ shell-command
 interactively when the prefix argument is given), insert the
 output in current buffer after point leaving mark after it.  This
 cannot be done asynchronously.
+If OUTPUT-BUFFER is a buffer or buffer name different from the
+current buffer, append the output in this buffer instead of
+inserting it at point.

 The user option `shell-command-dont-erase-buffer', which see, controls
 whether the output buffer is erased and where to put point after

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* bug#40896: 27.0.91; Moving point fails sometimes in shell-command
  2020-05-02 13:12             ` Michael Albinus
@ 2022-01-28 15:34               ` Lars Ingebrigtsen
  0 siblings, 0 replies; 9+ messages in thread
From: Lars Ingebrigtsen @ 2022-01-28 15:34 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 40896, tino.calancha

Michael Albinus <michael.albinus@gmx.de> writes:

> Almost. But it is not documented. Maybe we shall apply the appended
> patch. And if shell-command-dont-erase-buffer is end-last-out with
> output buffer not being the current one, the behavior is simply
> wrong, see my previous analysis. At least *this* case must be fixed.

I've now applied the proposed patch, with some slight alterations.

And the parameters to these shell functions are very, very confusing.
At this point, perhaps it'd be better to write some new functions in
this area that have less weird parameters.  But fixing end-last-out
would also be nice.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-01-28 15:34 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27  8:28 bug#40896: 27.0.91; Moving point fails sometimes in shell-command Michael Albinus
2020-04-27 14:43 ` Eli Zaretskii
2020-04-27 17:50   ` Michael Albinus
2020-04-28 11:32     ` Eli Zaretskii
2020-04-28 14:22       ` Michael Albinus
2020-04-30 13:45         ` Michael Albinus
2020-05-02  9:40           ` Eli Zaretskii
2020-05-02 13:12             ` Michael Albinus
2022-01-28 15:34               ` Lars Ingebrigtsen

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).