Emacs Tip: A Key to open the Current Folder in Windows

2008 June 10
by Arun Bhai

If the over-descriptive title was not enough, this is another one of my tips to use my favorite editor – Emacs. Some of you really liked my earlier post on Emacs tips on Windows, so here is one more tip to improve your productivity.

Most of the time while editing a document, we need to quickly browse the folder of that file. Add the following lines to your .emacs files and so that by just pressing function key F12 you can immediately view its corresponding folder:

[source:css] ;; explorer ;; ———- ;;; Windows explorer to open current file – Arun Ravindran(defun explorer () “Launch the windows explorer in the current directory and selects current file” (interactive) (w32-shell-execute “open” “explorer” (concat “/e,/select,” (convert-standard-filename buffer-file-name))))(global-set-key [f12] ‘explorer) ; F12 – Open Explorer for the current file path[/source]

A nice extra is that the opened explorer will have the current file automatically selected. Press F12 once in a while, it quickly becomes addictive ;)

Distantly Related posts:

  1. Emacs tip: Prevent too many buffers in Dired
  2. 5 Indispensable Tips for Emacs on Windows
  3. Is Python Intellisense Possible in Emacs?
  4. Office Diff: An Open Source Diff for Office 2007 or 2003 documents
  5. Work Faster in Windows With Launchy and a few Python Scripts
5 Responses leave one →
  1. July 18, 2008

    You can find some more of this kind in Emacs+EmacsW32.

  2. July 23, 2008

    This is extremely useful for me. Unfortunately I can’t get it working. The error message is: “convert-standard-filename: Wrong type argument: stringp, nil” (in the Messages buffer).

    By the way I rather would like explorer to open the current directory (belonging to the current buffer) than the current file.

    If I evaluate the following in the Scratch buffer: (setq fname-temp (convert-standard-filename “f:/numericalexamplecom/.emacs”)) then the value of fname-temp becomes “f:/numericalexamplecom/.emacs” so convert-standard-filename does not convert forward slashes into backward slashes either.

  3. July 23, 2008

    @numericalexample.com:

    I am not able to reproduce this problem. Can you have a look at your w32-shell-dos-semantics ? Maybe it will solve your issue.

  4. July 25, 2008

    This function returned ‘nil’. So I added the following to my emacs file: (defun w32-shell-dos-semantics() t) Now it does exactly what I want when I execute the explorer command from an emacs buffer containing a file.

    The error I got before seems to occur only when I execute the explorer command from a Dired buffer or from a cygwin shell.

    Another way of quickly browsing a folder when editing an emacs buffer is just pressing “ctrl-x ctrl-f return”. But this does not help us when we want to open a file that can not be opened in emacs such as a pdf.

  5. November 24, 2009

    Awesome emacs tips. Thanks!

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS

Additional comments powered by BackType