all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Chris Moore" <christopher.ian.moore@gmail.com>
To: herring@lanl.gov
Cc: rms@gnu.org, emacs-devel@gnu.org
Subject: Re: shell-resync-dirs changes my cursor position
Date: Tue, 11 Sep 2007 12:36:10 +0200	[thread overview]
Message-ID: <a9691ee20709110336l32adb61fh623ae0ec428daf6d@mail.gmail.com> (raw)
In-Reply-To: <22953.128.165.0.81.1189470963.squirrel@webmail.lanl.gov>

On 9/11/07, Davis Herring <herring@lanl.gov> wrote:
> > Is there a clean, simple way of writing it with save-excursion?
> > If that way won't work, then there needs to be a comment explaining
> > why it won't -- why the extra complexity is needed.
>
> I didn't think there was, because point needs to be restored to a
> different location in the buffer (after more output from the process), but
> minimal testing seems to suggest that it works because the original text
> is left in the buffer (just with more inserted before it).  OP, if you
> don't know what we mean, just ask me off-list.

It seems to work just fine for every case except when the cursor
starts at the same place as the process mark (ie. at the beginning of
the command currently being edited, or with no command yet entered).
In that case save-excursion leaves the cursor where it started, rather
than moving it down past the 'dirs' command and its output.

Here's a patch that uses save-excursion and fixes the case where point
starts at the process mark.  I didn't re-indent the code, so it's
easier to see what I changed.  Below it I've pasted a uuencoded
version of the same patch after reindenting for the added
save-excursion.

2007-09-11  Chris Moore  <dooglus@gmail.com>

	* shell.el (shell-resync-dirs): Don't move the cursor relative to
	the command being edited.

*** shell.el	31 Aug 2007 15:25:36 +0200	1.154
--- shell.el	11 Sep 2007 12:27:54 +0200	
***************
*** 808,815 ****
  command again."
    (interactive)
    (let* ((proc (get-buffer-process (current-buffer)))
! 	 (pmark (process-mark proc)))
!     (goto-char pmark)
      ;; If the process echoes commands, don't insert a fake command in
      ;; the buffer or it will appear twice.
      (unless comint-process-echoes
--- 808,817 ----
  command again."
    (interactive)
    (let* ((proc (get-buffer-process (current-buffer)))
! 	 (pmark (process-mark proc))
! 	 (started-at-pmark (= (point) (marker-position pmark))))
!     (save-excursion
!       (goto-char pmark)
      ;; If the process echoes commands, don't insert a fake command in
      ;; the buffer or it will appear twice.
      (unless comint-process-echoes
***************
*** 852,858 ****
  		   (setq shell-dirstack (cdr ds)
  			 shell-last-dir (car shell-dirstack))
  		   (shell-dirstack-message))
! 	  (error (message "Couldn't cd")))))))

  ;; For your typing convenience:
  (defalias 'dirs 'shell-resync-dirs)
--- 854,861 ----
  		   (setq shell-dirstack (cdr ds)
  			 shell-last-dir (car shell-dirstack))
  		   (shell-dirstack-message))
! 	  (error (message "Couldn't cd"))))))
!     (if started-at-pmark (goto-char (marker-position pmark)))))

  ;; For your typing convenience:
  (defalias 'dirs 'shell-resync-dirs)

Here's a uuencoded version of the same patch, but after reindenting
the function:

begin 644 shell-keep-cursor-position.txt.gz
M'XL("`)NYD8``W-H96QL+6ME97`M8W5R<V]R+7!O<VET:6]N+G1X=`#%EDMO
MXS80@,_,KYCZT$A.:-C99ILFW4-1H,">LT`ON3#22"9,DPI)Y?'O.Z1$6X[M
MV,D&:$[F<,1YSY?Q>`QNCDI-4+$O,_BKK>%B.OT=9I?7%Y?77[["V93.;#:9
M7?YVPCE?:\]F<(M-KWUQ??'']?2RUSX9;_Z%,UQ-K\ZO+J\@"@`*LUP*78*H
MA=23$4D`,JD]6E%X^8AY)U'HQY!EC34%9#5Z?M]6%5H>!.@<9$5K+>HDS_/\
MY!=@D#5+81>0]6H\GL*A4XA/U\8;7LR%A:B<Y#<W\+T"/T=(-K"8&W3)8W<.
MI=&G'J1V:#T(J,0"5_%(O7XG/-+Y!<:"]/`DE0+1-$A&_9,L<)*<:;4*IN@5
MRD&*CG>6>YV8GV@RUH"7TCHOB@5_:-&^Y*O;T9T>K:-TTO.*K$]SN`'Z42!8
M+*5KE'A).KU5A[KDSENIZQC[;CN'/HKF5]:I8B&YV">9*F+HJ[5[5-]07C^\
M8"2W6.-STQV"+5T(WY\HT&IOHABCO-\N9+,J2+@"N:NB4;U_F]R^RT;)+H5J
M/.[),P5X=Y>/\N0.Q&\W1$$P.>OU5L'&GO@QEV3_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nested]  mbox.gz  Atom feed  top
2007-09-10 12:07 shell-resync-dirs changes my cursor position Chris Moore
2007-09-10 12:21 ` Chris Moore
2007-09-10 19:17   ` Davis Herring
2007-09-10 23:55   ` Richard Stallman
2007-09-11  0:36     ` Davis Herring
2007-09-11 10:36       ` Chris Moore [this message]
2007-09-12  8:46         ` Richard Stallman
2007-09-13  7:26           ` Glenn Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a9691ee20709110336l32adb61fh623ae0ec428daf6d@mail.gmail.com \
    --to=christopher.ian.moore@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=herring@lanl.gov \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.