* shell-resync-dirs
@ 2004-12-03 1:22 Andrew Kurn
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Kurn @ 2004-12-03 1:22 UTC (permalink / raw)
To: bug-gnu-emacs@gnu.org
Subject: shell-resync-dirs
--text follows this line--
This bug report will be sent to the Free Software Foundation,
not to your local site managers!
Please write in English, because the Emacs maintainers do not have
translators to read other languages for them.
Your bug report will be posted to the bug-gnu-emacs@gnu.org mailing list,
and to the gnu.emacs.bug news group.
In GNU Emacs 21.2.1 (i386-redhat-linux-gnu, X toolkit, Xaw3d scroll bars)
of 2002-04-08 on porky.devel.redhat.com
configured using `configure i386-redhat-linux --prefix=/usr
--exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc
--datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib
--libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com
--mandir=/usr/share/man --infodir=/usr/share/info --with-gcc --with-pop
--with-sound'
Important settings:
value of $LC_ALL: nil
value of $LC_COLLATE: C
value of $LC_CTYPE: nil
value of $LC_MESSAGES: nil
value of $LC_MONETARY: nil
value of $LC_NUMERIC: nil
value of $LC_TIME: nil
value of $LANG: en_US
locale-coding-system: iso-latin-1
default-enable-multibyte-characters: t
Please describe exactly what actions triggered the bug
and the precise symptoms of the bug:
Trigger: To a shell process: M-x dirs
Symptoms: Message "Can't cd" and the action fails.
Reason: All shell commands (on my box) are echoed on the line following the
command
line, so it attempts to cd to "dirs".
Below is a patch which looks at the line to see if it starts out
with "dirs" or "pwd" or "echo". If it does, it eats the line.
'Course, if that happens to be the name of your directory it flops.
But, I don't know how to tell whether the shell is going to echo.
Maybe you do, but this is an improvement over the existing situation.
HTH,
AK
----------
--- shell.el Tue Jul 30 13:15:12 2002
+++ shell2.el Thu Dec 2 16:57:43 2004
@@ -737,6 +737,11 @@
(expand-file-name dir))))
(cd dir))
+(defun shell-echo-eater-word (d)
+ "Return the first word (i.e. non-white-space)"
+ (string-match "\\s *\\(\\S +\\)\\s *" d) ; pick off first word
+ (substring d (match-beginning 1) (match-end 1)))
+
(defun shell-resync-dirs ()
"Resync the buffer's idea of the current directory stack.
This command queries the shell with the command bound to
@@ -749,40 +754,49 @@
command again."
(interactive)
(let* ((proc (get-buffer-process (current-buffer)))
- (pmark (process-mark proc)))
+ (pmark (process-mark proc))
+ (dl nil))
(goto-char pmark)
(insert shell-dirstack-query) (insert "\n")
- (sit-for 0) ; force redisplay
+ (sit-for 0) ; force redisplay
(comint-send-string proc shell-dirstack-query)
(comint-send-string proc "\n")
(set-marker pmark (point))
- (let ((pt (point))) ; wait for 1 line
+ (let ((pt (point))
+ (skip t))
;; This extra newline prevents the user's pending input from spoofing
us.
- (insert "\n") (backward-char 1)
- (while (not (looking-at ".+\n"))
- (accept-process-output proc)
- (goto-char pt)))
- (goto-char pmark) (delete-char 1) ; remove the extra newline
- ;; That's the dirlist. grab it & parse it.
- (let* ((dl (buffer-substring (match-beginning 0) (1- (match-end 0))))
- (dl-len (length dl))
- (ds '()) ; new dir stack
- (i 0))
- (while (< i dl-len)
- ;; regexp = optional whitespace, (non-whitespace), optional
whitespace
- (string-match "\\s *\\(\\S +\\)\\s *" dl i) ; pick off next dir
- (setq ds (cons (concat comint-file-name-prefix
- (substring dl (match-beginning 1)
- (match-end 1)))
- ds))
- (setq i (match-end 0)))
- (let ((ds (nreverse ds)))
- (condition-case nil
- (progn (shell-cd (car ds))
- (setq shell-dirstack (cdr ds)
- shell-last-dir (car shell-dirstack))
- (shell-dirstack-message))
- (error (message "Couldn't cd")))))))
+ (insert "\n")
+ (while skip
+ (goto-char pt)
+ (while (not (looking-at ".+\n"))
+ (accept-process-output proc)
+ (goto-char pt))
+ (setq pt (match-end 0))
+ (setq dl (buffer-substring (match-beginning 0) (1- (match-end 0))))
+ ;; This skips a line if it is just "dirs"
+ (setq skip (equal (shell-echo-eater-word dl)
+ (shell-echo-eater-word shell-dirstack-query))))
+ (goto-char pmark) (delete-char 1) ; remove the extra newline
+ ;; That's the dirlist. grab it & parse it.
+ (let* (
+ (dl-len (length dl))
+ (ds '()) ; new dir stack
+ (i 0))
+ (while (< i dl-len)
+ ;; regexp = optional whitespace, (non-whitespace), optional
whitespace
+ (string-match "\\s *\\(\\S +\\)\\s *" dl i) ; pick off next dir
+ (setq ds (cons (concat comint-file-name-prefix
+ (substring dl (match-beginning 1)
+ (match-end 1)))
+ ds))
+ (setq i (match-end 0)))
+ (let ((ds (nreverse ds)))
+ (condition-case nil
+ (progn (shell-cd (car ds))
+ (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)
------------
Andrew Kurn, PhD
Software Group Lead
Empower Technologies Corporation
#120 - 13551 Verdun Pl.
Richmond, BC, Canada V6V 1W5
604-278-3100 x 232
604-278-3102 (fax)
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.804 / Virus Database: 546 - Release Date: 11/30/2004
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-12-03 16:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.3208.1102037598.27204.bug-gnu-emacs@gnu.org>
2004-12-03 16:55 ` shell-resync-dirs Stefan Monnier
2004-12-03 1:22 shell-resync-dirs Andrew Kurn
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.