20

Some programs like firefox have buttons that when clicked open a file manager for browsing files. How do I make it to open in emacs with dired mode on Debian Linux?

Alex Stragies
  • 403
  • 3
  • 14
godblessfq
  • 1,177
  • 8
  • 21

4 Answers4

18

Dependent on your desktop environment the method to set a default application may differ. That said, many desktop environments respect the associations in ~/.local/share/applications/mimeapps.list, where you can set up an association for the application/x-directory and/or inode/directory types.

My mimeapps.list looks like this now:

[Default Applications]
application/x-directory=emacs-dired.desktop
inode/directory=emacs-dired.desktop

In the same directory I have a file called emacs-dired.desktop with the following contents:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
NoDisplay=true
Exec=emacsclient --eval '(dired "%f")'
Name=Dired
Comment=Emacs Dired

When my long-lived instance of Emacs runs a server (M-x server-start) and I click on, say, the folder icon in the list of Downloads in Icecat a new dired buffer is opened.

This actually works for me now. Thanks for asking the question --- otherwise I would not have set this up.

6

This is how to make emacs as default file manager in ubuntu.

First we have to write a script which will act as our file manager.

#!/usr/bin/env python
import os
import sys


def main():
    if len(sys.argv) > 1:
        dirname =  sys.argv[1]
    else:
        dirname = '~'
    os.system('emacs --eval \'(dired "{}")\'%'.format(dirname))
    # you can use emacsclient if you are running emacs server

if __name__ == "__main__":
    main()

Save this as emacsfm in /usr/bin/. Now in terminal instead of using nautilus or nautilus /foo/bar, we can use emacsfm or emacsfm /foo/bar.

Now we need to set this as default file manager. Install exo-utils using

sudo apt-get install exo-utils

and run it

exo-preferred-applications

It opens a new window. Go to Utilities -> File manager -> Other and enter /usr/bin/emacsfm "%s" in it.

You can goto chrome downloads and if click show in folder it will open emacs dired :-)

Update:

enter image description here Reference: https://help.ubuntu.com/community/DefaultFileManager

Chillar Anand
  • 4,042
  • 1
  • 23
  • 52
  • Anand, it works.. but it opens a new emacs window everytime.. it is good to use emacsclient that will open a new buffer in an already open emacs session.... – Madhavan Sep 16 '15 at 10:01
  • i think, the previous answer addresses this point... – Madhavan Sep 16 '15 at 10:04
4

Although the question is specifically for Linux I went and figured it out for Windows (since this prompted me to find how to do it for myself).

Interestingly enough, you don't have to invoke Dired, simply pass a folder as the file. This saves a lot of hassle on Windows since %1 will pass c:\Users (for example) and break on \U if included in the eval statement, while passing it as a file will properly parse it.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Drive\shell]
@="Dired"

[HKEY_CLASSES_ROOT\Drive\shell\Dired]
@="Open in Dired"

[HKEY_CLASSES_ROOT\Drive\shell\Dired\command]
@="\"%path/to/emacsclientw%\" %1"

[HKEY_CLASSES_ROOT\Directory\shell]
@="XYplorer"

[HKEY_CLASSES_ROOT\Directory\shell\Dired]
@="Open in XYplorer"

[HKEY_CLASSES_ROOT\Directory\shell\Dired\command]
@="\"%path/to/emacsclientw%\" %1"

Reference: Seven Forums - How to change the default File Manager

Jonathan Leech-Pepin
  • 4,307
  • 1
  • 19
  • 32
-4

You can use Ranger. However you can configure xmonad for use emacs a windows default when you start session

mizhac
  • 5