all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* shell-resync-dirs changes my cursor position
@ 2007-09-10 12:07 Chris Moore
  2007-09-10 12:21 ` Chris Moore
  0 siblings, 1 reply; 8+ messages in thread
From: Chris Moore @ 2007-09-10 12:07 UTC (permalink / raw)
  To: emacs-devel

I'm editing a long shell command in a *shell* buffer.  Part way
through I try completing a filename and notice that the
default-directory isn't synced with the shell's working directory, so
I run M-x dirs RET to sync it.  That resets my cursor position to the
start of the line I was editing, rather than leaving it where I was
before.  I was trying to complete a filename, so I'd like now to just
be able to hit TAB and do so, rather than trying to find the place I
was at before.

Here's a patch and changelog (and uuencoded patch in case the patch
gets messed up by my mail client again):

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

	* shell.el (shell-resync-dirs): Restore the cursor position to its
	previous location after syncing.

*** shell.el	31 Aug 2007 15:25:36 +0200	1.154
--- shell.el	10 Sep 2007 14:01:17 +0200	
***************
*** 808,813 ****
--- 808,814 ----
  command again."
    (interactive)
    (let* ((proc (get-buffer-process (current-buffer)))
+ 	 (starting-point (set-marker (make-marker) (point)))
  	 (pmark (process-mark proc)))
      (goto-char pmark)
      ;; If the process echoes commands, don't insert a fake command in
***************
*** 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)
--- 853,861 ----
  		   (setq shell-dirstack (cdr ds)
  			 shell-last-dir (car shell-dirstack))
  		   (shell-dirstack-message))
! 	  (error (message "Couldn't cd")))))
!     (goto-char starting-point)
!     (set-marker starting-point nil)))

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

begin 644 shell-resync-dirs-patch.txt.gz
M'XL(")DRY48``W-H96QL+7)E<WEN8RUD:7)S+7!A=&-H+G1X=`#-4D%NVS`0
M/%NOV/IB2C$-T;8203D%!0KTW!>PU$HF(I$*207P[[L4K;0.>NRA/&F'L\N9
MT19%`?Z"PW#`87,2\#+W<"S+)Q!5<ZR:TR,\E%1OQ$%4YXQS_ILM2OB!TXU]
M;DK1B*<;.RON3ZRA+NM]+4ZP`'%2`LY`WSP#4'8<I6E!]E*;PY80`*9-0"=5
MT.^8)V3`4`!CD[,*6(^!_YR[#AV/`'H/3,W.H5GQ/,^S!]@`\T&ZH$W/)TM#
MJ:;64;I7=,!&^8JW(@>V$&(?Q+XIXL!NXQ<6Q"(1%DF]#9:KBW2PD%?\^1F^
M=Q`N"*LV5!>+?G7J]]!:LPN@C4<70$)'.CYRT.;O,5;'?5W5*492N(D*R,Q;
M^C.\U8ZL*I*L6@>M7VP0*]T.TH=(H5N2>]^1'*=Y=Q=\)/&R1R)\H4B`H7,V
MQI9@V'ZU\]!&)ZK=YNG0J&R)X!LQKW9V$*X3Q4_VS#L:C49A0PS68B<'+3WL
MXG.P2T\[]%>C%@5Y6I;JM*\?Q;HL_Z=MXGU:B/NM^R#\L7R?]M+HX1^G]PM;
':>&SXP,`````
`
end

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

* Re: shell-resync-dirs changes my cursor position
  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
  0 siblings, 2 replies; 8+ messages in thread
From: Chris Moore @ 2007-09-10 12:21 UTC (permalink / raw)
  To: emacs-devel

On 9/10/07, Chris Moore <christopher.ian.moore@gmail.com> wrote:

> Here's a patch and changelog (and uuencoded patch in case the patch
> gets messed up by my mail client again):

That patch didn't work if the cursor was at the beginning of the
command being edited.

This one does.  There's probably a better way of doing this.

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

       * shell.el (shell-resync-dirs): Restore the cursor position to its
       previous location after syncing.

*** shell.el	31 Aug 2007 15:25:36 +0200	1.154
--- shell.el	10 Sep 2007 14:19:02 +0200	
***************
*** 808,813 ****
--- 808,816 ----
  command again."
    (interactive)
    (let* ((proc (get-buffer-process (current-buffer)))
+ 	 (starting-point (if (eq (marker-position (process-mark
(get-buffer-process (current-buffer)))) (point))
+ 			     'start
+ 			   (set-marker (make-marker) (point))))
  	 (pmark (process-mark proc)))
      (goto-char pmark)
      ;; If the process echoes commands, don't insert a fake command in
***************
*** 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)
--- 855,864 ----
  		   (setq shell-dirstack (cdr ds)
  			 shell-last-dir (car shell-dirstack))
  		   (shell-dirstack-message))
! 	  (error (message "Couldn't cd")))))
!     (unless (eq starting-point 'start)
!       (goto-char starting-point)
!       (set-marker starting-point nil))))

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

begin 644 shell-resync-dirs-patch2.txt.gz
M'XL("$LVY48``W-H96QL+7)E<WEN8RUD:7)S+7!A=&-H,BYT>'0`S5+!CILP
M$#W#5TQSB6'C")*04O945:K4<[_`-0.QEMBL;5;*WW>,P^ZRZJ&''LH)/S^_
M>3/S\CP'=\%AV..0'$OX.O5P*(K/4%;-H6J.9W@HZ)R4^[(ZI9SS-W99P$\<
M[^Q34WYIBL.=G>;K+YRA+NI=71YA!H)2!,Y`_SP%D.9Z%;H%T0NE]QM"`)C2
M'JV07KU@%I$!?0Z,C=9(8#UZ_FOJ.K0\`.@<,#E9BWK!LRQ+'R`!YKRP7NF>
MCX9$2;D#AL_`KL(^A>?&*:^,!G87XN'B+RMD]"JHQEI)$HS"=J[X"C!'2K%8
M*/J$]\/;VRQT2$['6'GE(QPB81Y";[SA\B(LS.0%?WR$'QWX"\+B%>7%H%MF
MZW;0&KWUH+1#ZT%`1T9>)Z_TGQ=7'79U5<?%D<.EF^>8!=XJ2ZU*LBQ;"ZV;
MVR!6O!V$\X%"MV1W_2)V'/56%_Q*YD6/1/A$(Z%-66O"W"(,FV]F&MK0B6PW
M6?Q(*IU'\)V8-S-9\+>1%D[MZ1?4"K7$AABLQ4X,2CC8AG*TI[FT17?3<G:0
MQ7A6U:X^GY9X_I]M$V\.Q*2'.9J4Z`]!CS%<B*OLK)GO*.^B^D%-J^%?S_HW
(AKO0>8,$````
`
end

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

* Re: shell-resync-dirs changes my cursor position
  2007-09-10 12:21 ` Chris Moore
@ 2007-09-10 19:17   ` Davis Herring
  2007-09-10 23:55   ` Richard Stallman
  1 sibling, 0 replies; 8+ messages in thread
From: Davis Herring @ 2007-09-10 19:17 UTC (permalink / raw)
  To: Chris Moore; +Cc: emacs-devel

> This one does.  There's probably a better way of doing this.

Could you simplify it by storing the difference between point and the
process-mark, and then call `forward-char' at the end of the function?

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.

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

* Re: shell-resync-dirs changes my cursor position
  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
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Stallman @ 2007-09-10 23:55 UTC (permalink / raw)
  To: Chris Moore; +Cc: emacs-devel

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.

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

* Re: shell-resync-dirs changes my cursor position
  2007-09-10 23:55   ` Richard Stallman
@ 2007-09-11  0:36     ` Davis Herring
  2007-09-11 10:36       ` Chris Moore
  0 siblings, 1 reply; 8+ messages in thread
From: Davis Herring @ 2007-09-11  0:36 UTC (permalink / raw)
  To: rms; +Cc: Chris Moore, emacs-devel

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

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.

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

* Re: shell-resync-dirs changes my cursor position
  2007-09-11  0:36     ` Davis Herring
@ 2007-09-11 10:36       ` Chris Moore
  2007-09-12  8:46         ` Richard Stallman
  0 siblings, 1 reply; 8+ messages in thread
From: Chris Moore @ 2007-09-11 10:36 UTC (permalink / raw)
  To: herring; +Cc: rms, emacs-devel

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-\N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X?BI_S'\!W.1_B`E$```
`
end

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

* Re: shell-resync-dirs changes my cursor position
  2007-09-11 10:36       ` Chris Moore
@ 2007-09-12  8:46         ` Richard Stallman
  2007-09-13  7:26           ` Glenn Morris
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Stallman @ 2007-09-12  8:46 UTC (permalink / raw)
  To: Chris Moore; +Cc: emacs-devel

Thanks for fixing this.  Would someone please install the patch?
Since it is a bug in Emacs 22, the fix should go there.

Chris, please remind people after a few days if it isn't installed.

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

* Re: shell-resync-dirs changes my cursor position
  2007-09-12  8:46         ` Richard Stallman
@ 2007-09-13  7:26           ` Glenn Morris
  0 siblings, 0 replies; 8+ messages in thread
From: Glenn Morris @ 2007-09-13  7:26 UTC (permalink / raw)
  To: rms; +Cc: Chris Moore, emacs-devel

Richard Stallman wrote:

> Thanks for fixing this.  Would someone please install the patch?
> Since it is a bug in Emacs 22, the fix should go there.

ack

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

end of thread, other threads:[~2007-09-13  7:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2007-09-12  8:46         ` Richard Stallman
2007-09-13  7:26           ` Glenn Morris

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.