[Top][All Lists]

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

Shell commands in deleted directories

From: Antoine Levitt
Subject: Shell commands in deleted directories
Date: Sun, 13 Feb 2011 22:02:34 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)


[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);

reply via email to

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