From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: shell-command in Windows 7 Date: Fri, 14 Apr 2017 10:11:36 -0700 Message-ID: References: <40b3fe49-18cb-c7bc-5792-98e0a7c7c8e6@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: blaine.gmane.org 1492189948 13783 195.159.176.226 (14 Apr 2017 17:12:28 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 14 Apr 2017 17:12:28 +0000 (UTC) Cc: 42 147 To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Apr 14 19:12:22 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cz4li-0003Nt-7G for geh-help-gnu-emacs@m.gmane.org; Fri, 14 Apr 2017 19:12:22 +0200 Original-Received: from localhost ([::1]:54018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cz4lk-0007vH-RU for geh-help-gnu-emacs@m.gmane.org; Fri, 14 Apr 2017 13:12:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cz4lL-0007um-9w for help-gnu-emacs@gnu.org; Fri, 14 Apr 2017 13:12:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cz4lK-00019q-66 for help-gnu-emacs@gnu.org; Fri, 14 Apr 2017 13:11:59 -0400 Original-Received: from mail-qk0-x236.google.com ([2607:f8b0:400d:c09::236]:34173) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cz4lK-00019Z-1Y for help-gnu-emacs@gnu.org; Fri, 14 Apr 2017 13:11:58 -0400 Original-Received: by mail-qk0-x236.google.com with SMTP id p68so71511649qke.1 for ; Fri, 14 Apr 2017 10:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=SS8hxgpVtlaE7ovUjBNgDzTBp2Ts7T16nqKzeF8ylic=; b=rjTsQnM5GSQiEqxrMHaGQvFp9aLgGZxAv40TlGIszZlZtn7B7TF8dvE/jx4hEU7Mql JDz2kXXNwgPbBUp4++dKzmbfWWzfi3S5ZDPct4CcdLUlbAb4ESag4X0YKDyzEAHVAKbP m7nNssgmT8XZr3xnaawPNXkxR5yJqfA79UZzngNW6TLmXEDhwD3l8c6VEG/kCf12ZFxP q81atu0+0aLRZFAgpz4ClCYaAMiCJQyFtOugfwTY72HwTnji0kM26CUCj7i1GV1ykXdE jtBI3KpKYG4WlxI/NUijBaKT2XzRqhcESmg6JRMgnQ1l7on2rw2UmAqSjMX0VzCLQiV4 1Qjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=SS8hxgpVtlaE7ovUjBNgDzTBp2Ts7T16nqKzeF8ylic=; b=RGJLFh1G5mU3jPuklc4/hPWPS/jdStexKl0MHdPJuYGY75O8sfvXrzOdLNH1TqbmhJ PjOr2xsYIt8gLP5UWFIfUy6qdZl6ABk3meFCxqcDFxrWOfPDWeN+j7pHJW7+vrdA8xUk lH+Pylig/TMmcPG32ihV7GpJjzerygOPcKAbYfOGU1UgnOpoqxnG0IiVvhp7gpV2MwHj TZlI9RUhmSEmvBDseT71itaU0REd5K1SCdXWKme90mUjUaZN2wQHXvpEFZipFsE4JTv3 eKxzKTSyA4nHLILe+U7XHj731HiNWPbWSGD+BPI5n8Uf/gsZMNiOryJKYbDYqMfjQxOK ldHg== X-Gm-Message-State: AN3rC/4HsXwX+tNE9VKyU8RG/U9ZfVY63sem8jhxMA18CcmiWm9INO5q TF+oeOqfGHiat/zTsfSS3xaZ7M3L0A== X-Received: by 10.55.97.67 with SMTP id v64mr7591335qkb.241.1492189917322; Fri, 14 Apr 2017 10:11:57 -0700 (PDT) Original-Received: by 10.237.32.9 with HTTP; Fri, 14 Apr 2017 10:11:36 -0700 (PDT) In-Reply-To: <40b3fe49-18cb-c7bc-5792-98e0a7c7c8e6@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::236 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112763 Archived-At: 42 147 wrote: > I've been using this code to create functions that open files / folders > within Emacs in Windows 7: > > (defun open-buffer-path () > "Run explorer on the directory of the current buffer." > (interactive) > (shell-command (concat "explorer " (replace-regexp-in-string "/" "\\\\" > (file-name-directory (buffer-file-name)) t t)))) > > (defun firefox () > (interactive) > (shell-command (concat "explorer " (replace-regexp-in-string "/" "\\\\" > "E:\\Program Files\\Mozilla Firefox\\firefox.exe" t t)))) > > This worked fine for a while. Then I erased one of my older OSes on a > different partition and created an NTFS partition for extra Windows 7 > storage. This did not change the drive number of Windows 7 at all. But for > some reason, after that repartitioning, the above code only works if I > alternative between the two different directory string types. Thus if I had > the above before, on system reboot, I have to replace it all with: > > (defun .emacs-open () > "Run explorer on the directory of the current buffer." > (interactive) > (shell-command (concat "explorer " (replace-regexp-in-string "/" "\\\\" > "E:/Users/John/AppData/Roaming/" t t)))) > > And vice-versa, otherwise Emacs is unable to open the file / directory I > want, and just opens to the same default directory when I call each > function. I created a workaround in which I press F12 to alternate between > the two load files (I put these settings in a dedicated .el), but I'm very > curious why this happens, and ideally a workaround like this would not be > necessary. I think using (w32-shell-execute "open" ...) is the right way to do this on Windows. Does the following work for you? (defun w32-open-file (file) (interactive "fOpen file: ") (w32-shell-execute "open" file)) (defun firefox () (interactive) (w32-open-file "e:/Program Files/Mozilla Firefox/firefox.exe")) (defun open-buffer-directory (buffer) (interactive (if current-prefix-arg (read-buffer "Open buffer directory: " nil t) (list (current-buffer)))) (with-current-buffer buffer (let ((file (buffer-file-name))) (if file (w32-open-file (file-name-directory file)) (user-error "Buffer `%s' is not visiting a file" (buffer-name)))))) Hope that helps John