[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: shell-command in Windows 7
From: |
John Mastro |
Subject: |
Re: shell-command in Windows 7 |
Date: |
Fri, 14 Apr 2017 10:11:36 -0700 |
42 147 <aeuster@gmail.com> 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
- shell-command in Windows 7, 42 147, 2017/04/14
- Re: shell-command in Windows 7,
John Mastro <=
- Re: shell-command in Windows 7, John Mastro, 2017/04/14
- Re: shell-command in Windows 7, 42 147, 2017/04/14
- Re: shell-command in Windows 7, 42 147, 2017/04/14
- Re: shell-command in Windows 7, John Mastro, 2017/04/14
- Re: shell-command in Windows 7, 42 147, 2017/04/15
- Re: shell-command in Windows 7, Eli Zaretskii, 2017/04/15
- Re: shell-command in Windows 7, 42 147, 2017/04/15
- Re: shell-command in Windows 7, Eli Zaretskii, 2017/04/15
- Re: shell-command in Windows 7, 42 147, 2017/04/15
- RE: shell-command in Windows 7, Drew Adams, 2017/04/15