19

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?

  • 9
    What's your operating system? – Drew Jul 12 '15 at 21:33
  • 1
    I am using debian jessie. – godblessfq Jul 13 '15 at 22:46
17

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

  • 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

-3

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

  • 7
    Please expand on your answer to make it self-contained. – Dan Jul 14 '15 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.