emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: shell-resync-dirs changes my cursor position


From: Chris Moore
Subject: Re: shell-resync-dirs changes my cursor position
Date: Tue, 11 Sep 2007 12:36:10 +0200

On 9/11/07, Davis Herring <address@hidden> 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  <address@hidden>

        * 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_/\
address@hidden>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<)*<:;address@hidden
MRD&*CG>6>address@hidden"address@hidden:-&^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'&address@hidden&I^4U,$K?*06=M'%
MEFIXZJ"AM(:42MVT'BIKEN`:8ZH@:]UDJR5BUB&[)S^?A"V[OIYM6/Y74`>&
M5C!D,Q@>O/(TEPHATX8*H8Q9D!E.2>FRT14E$T6!S3KEIO7!M3A4\7XP3_Z-
M,8.L1*HZ)A>I+2TNS2/&\#<RLYZD'W/A3[L$43F4='X"M17W8:A^A498A_1S
M,NBJL#5*11GI]H5K[_LFS9;"%W-^C[74.@@NR*493W+*.TG2'J&W2L45ZO"F
MKOT<2C6X<G":address@hidden<@MDI2D#1V^5:6_P0)W:OQI9N;/L_P#4SCI=%"
M`:EZ=(TH\#R41?.U(#_?I19+T(7(8R2A"1V,8VO>PAFU8CR/R#3(D/5&address@hidden
M546N/_O@>_<$^@<H79PYER8OC5M%_G,MEDA=@)5\CA/$4GCK'(?$OTYS;$;&
address@hidden,^U>F5TO7M%AV10]7I<)3ZS1$\U6%^0@>$;[N/R>U2AASQ0M"%EFJU
M/*AA:RIG-]M%22%2&R:KK%]:#Z]FG[3*J-5'W-TJX7Q0Z=[8_&+XWN8:6=+T
MB!I7JPZMI:',>C&,_C:address@hidden@BC(LC]B+`"=Q#OXAS1?3$CU>FI!4BI-6AT1=
MX/5)Z$BLA)*"address@hidden/.M$7WHHOH01XA'EG\=0;TF_^?+.[N*2W68TD+A_>J
MWQ(.0OD#/7AC7*QGOT0&^\6)1^3X3+8=W:_[8P_>/P_P[T3\8<address@hidden
M$>UF_`<I?R3GCR#]?M:_IOT6[P\1/Q;B/<Q?6?@@]=D6\'<AGWTF[=EAT+-]
MC&?'X)UR<@#PFS/E-Y;QST/^`YC_7-"_B?HC8#_`/=M#^ACC)[$^C-Q/TS[!
M[GV\9^]!_6[8LQ5QDPN[2,_>A'PWQ7LP?PSHCT,]O`OV!W%_%/`3VVB%;<-Q
2/6O[X?BI_S'\!W.1_B`E$```
`
end




reply via email to

[Prev in Thread] Current Thread [Next in Thread]