all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Shell commands in deleted directories
@ 2011-02-13 21:02 Antoine Levitt
  2011-02-13 21:07 ` Paul Eggert
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Antoine Levitt @ 2011-02-13 21:02 UTC (permalink / raw)
  To: emacs-devel

Hi,

[shell] cd
[shell] mkdir test
[emacs] M-x cd RET ~/test RET
[shell] rmdir test
[emacs] M-! echo hi

Debugger entered--Lisp error: (file-error "Setting current directory"
"no such file or directory" "/home/antoine/test/")

  call-process-region(1 1 "/bin/bash" "/tmp/emacsmVCHW6" #<buffer *Shell
  Command Output*> nil "-c" "echo hi")
  
  shell-command-on-region(1 1 "echo hi" nil nil nil)
  shell-command("echo hi" nil nil)
  shell-command-replace("echo hi" nil nil)
  call-interactively(shell-command-replace nil nil)

Admittedly, this is a bit of an edge case, but it happens to me using
ERC: I usually run ERC from dired or somesuch, on a directory that may
later be removed. Then all the erc buffers have the deleted directory as
current path, and all shell commands fail (and I'm using shell commands
for notification, which means that some hooks fail, and my whole ERC
session basically fails).

The following patch works for me. I'm not sure what the behaviour should
be, but since the "silent fallback to ~" is already used above in the
code in a different case, it should be OK. There's also a bit of code
copied over from above, but I couldn't figure out a way to factorize it
properly. What do you think?

diff --git a/src/callproc.c b/src/callproc.c
index f2543f2..856760b 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -335,8 +335,17 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)  */)
     current_dir = Ffile_name_as_directory (current_dir);
 
     if (NILP (Ffile_accessible_directory_p (current_dir)))
-      report_file_error ("Setting current directory",
-			 Fcons (current_buffer->directory, Qnil));
+      {
+	/* If current_dir is unreachable (typically, does not exist), use
+	   ~/ as default */
+	current_dir = build_string ("~/");
+	current_dir = expand_and_dir_to_file (current_dir, Qnil);
+	current_dir = Ffile_name_as_directory (current_dir);
+	if (NILP (Ffile_accessible_directory_p (current_dir)))
+	  {
+	    report_file_error ("Setting current directory to ~/", Qnil);
+	  }
+      }
 
     if (STRING_MULTIBYTE (infile))
       infile = ENCODE_FILE (infile);




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

end of thread, other threads:[~2011-02-14 18:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-13 21:02 Shell commands in deleted directories Antoine Levitt
2011-02-13 21:07 ` Paul Eggert
2011-02-13 21:21   ` Antoine Levitt
2011-02-13 21:34     ` Ted Zlatanov
2011-02-13 22:05       ` Antoine Levitt
2011-02-14 15:00         ` Ted Zlatanov
2011-02-13 21:13 ` Eli Zaretskii
2011-02-13 21:16   ` Antoine Levitt
2011-02-14 18:30 ` Stefan Monnier

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.