SiteMap Search ElispArea HowTo Glossary RecentChanges News Problems Suggestions
Georgia, National Day

MsWindowsDiredContextMenu

Last edit

Added:

> I couldn't find the mentioned w32context.exe at github.com/bkz/w32context.
> I use !ShellContextMenu.exe from the Eclipse plugin [https://code.google.com/a/eclipselabs.org/p/navigatorext/ Navigator Extensions]: Its download [https://code.google.com/a/eclipselabs.org/p/navigatorext/downloads/detail?name=nax_1.1.2.201201311435.zip&can=2&q= nax_1.1.2.201201311435.zip] contains a nested Jar (Zip) file plugins/com.googlecode.eclipse.navigatorext_1.1.2.201201311435.jar with !ShellContextMenu.exe in it.
> However, !ShellContextMenu.exe does not understand the forward slashes returned by function buffer-file-name. So i put [http://cygwin.com/ cygwin]'s cygpath around it. Using a Stack Overflow answer [http://stackoverflow.com/questions/4697322/elisp-call-command-on-current-file#answer-4697863 how to call an external command], i ended up with this function:
> (defun external-command-context-menu()
> "runs external command ShellContextMenu on the current file"
> (interactive)
> (shell-command
> (format "bash -c \"ShellContextMenu %s '$(cygpath -w -- %s)'\""
> '0 (shell-quote-argument (buffer-file-name)))))
> ----


You can get emacs to display Explorer’s context menu in dired, exactly as you would be able to do when using RMB in Explorer.

This is an example of how it can look:

WThirtyTwoDiredContextMenuPicture

To get this working, add the following functions to your .emacs:

  (defun w32-context-menu (filename)
    (start-process-shell-command "context" "*context*" "context" filename))
  (defun w32-context-menu-dired-get-filename (event)
    (interactive "e")
    ;; moves point to clicked row
    (mouse-set-point event)
    (w32-context-menu (concat "\"" (dired-get-filename) "\"")))

Add a new key binding for dired. This is from my-dired-init which is hooked to dired-load-hook:

  ;; Bind RMB                 
  (define-key dired-mode-map [mouse-3]
  'w32-context-menu-dired-get-filename)

At last, an external program (licensed under the GPL), context.exe is needed to get this working. The program must be placed somewhere in the system path. You can dowload it together with the equally nice propsfor.exe (same thing but opens the property dialog instead) from here:

http://www.maddogsw.com/cmdutils/

I don’t need the propsfor tool as I can as well use the Properties dub menu on the context menu., but a similar hack could be done for those who want direct access to that dialog.

When not in dired, I use this:

  (defun w32-context-menu-current-buffer ()
    (interactive)
    (w32-context-menu (concat "\"" buffer-file-name "\"")))
  (global-set-key "\C-cc" 'w32-context-menu-current-buffer)

Very handy.


I couldn’t get the solution above to work on 64-bit Vista or Windows 7 so I decided to code up a small utility of my own.

The resulting project can be found on Github http://github.com/bkz/w32context


I couldn’t find the mentioned w32context.exe at github.com/bkz/w32context. I use ShellContextMenu.exe from the Eclipse plugin Navigator Extensions: Its download nax_1.1.2.201201311435.zip contains a nested Jar (Zip) file plugins/com.googlecode.eclipse.navigatorext_1.1.2.201201311435.jar with ShellContextMenu.exe in it.

However, ShellContextMenu.exe does not understand the forward slashes returned by function buffer-file-name. So i put cygwin’s cygpath around it. Using a Stack Overflow answer how to call an external command, i ended up with this function:

    (defun external-command-context-menu()
      "runs external command ShellContextMenu on the current file"
      (interactive)
      (shell-command
        (format "bash -c \"ShellContextMenu %s '$(cygpath -w -- %s)'\""
          '0 (shell-quote-argument (buffer-file-name)))))

CategoryWThirtyTwo