Files Listed in Emacs Find-Files - emacs

I was using Emacs on another terminal today and I noticed that when I hit C-x C-f to open a file that Emacs showed "Loading Tramp..." and then listed the files. I could either type my desired directory/file or I could use the left/right arrow key and Return to shift through directories and open a file. I was totally awesome. I am familiar with Tramp mode and started fiddling with it but I could not figure out how to get it to work, or if the two are even related, on my machine.
How do I get a file tree that I can use arrow keys with in Emacs?
This is how it appears on the other terminal:
Find file: .../dir1/dir1/{css/ | try.org | misc.txt | .emacs}

That likely was ido-mode, which is bundled with Emacs. Put this in the init file:
(ido-mode)
While it's on, it will rebind some common commands to its own versions that use this visual interface.
Tramp mode is not related. It just gets loaded if ido-use-virtual-buffers is t and you visited some remote files recently.

Related

My .emacs.el file is not loading, how can I get it to load? [duplicate]

I tried looking for the .emacs file for my Windows installation for Emacs, but I could not find it. Does it have the same filename under Windows as in Unix?
Do I have to create it myself? If so, under what specific directory does it go?
Copy and pasted from the Emacs FAQ, http://www.gnu.org/software/emacs/windows/:
Where do I put my init file?
On Windows, the .emacs file may be called _emacs for backward compatibility with DOS and FAT filesystems where filenames could not start with a dot. Some users prefer to continue using such a name, because Windows Explorer cannot create a file with a name starting with a dot, even though the filesystem and most other programs can handle it. In Emacs 22 and later, the init file may also be called .emacs.d/init.el. Many of the other files that are created by Lisp packages are now stored in the .emacs.d directory too, so this keeps all your Emacs related files in one place.
All the files mentioned above should go in your HOME directory. The HOME directory is determined by following the steps below:
If the environment variable HOME is set, use the directory it indicates.
If the registry entry HKCU\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates.
If the registry entry HKLM\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates. Not recommended, as it results in users sharing the same HOME directory.
If C:\.emacs exists, then use C:/. This is for backward compatibility, as previous versions defaulted to C:/ if HOME was not set.
Use the user's AppData directory, usually a directory called Application Data under the user's profile directory, the location of which varies according to Windows version and whether the computer is part of a domain.
Within Emacs, ~ at the beginning of a file name is expanded to your HOME directory, so you can always find your .emacs file with C-x C-f ~/.emacs.
There's further information at HOME and Startup Directories on MS-Windows.
It should be stored in the variable user-init-file. Use C-H v user-init-file RET to check. You can also open it directly by using M-x eval-expression RET (find-file user-init-file) RET
Open the file like this in Emacs for Windows:
C-x C-f ~/.emacs
More information in the Emacs Wiki
On my Vista box it's in C:\Users\<USER>\AppData\Roaming\
Note that it may NOT be enough to just type Ctrl-x Ctrl-f ~/.emacs and create the file.
It may be that your Emacs application uses a different place to store your init file, and if so, then creating the file ~/.emacs simply creates a useless file which your Emacs application ignores.
Also, you may want to do more than just access the .emacs init file, but you may want to know where it is, i.e., its pathname.
To get at this there are two methods:
Easy way: type Ctrl + H V user-init-file Return
Slightly trickier way:
You can find out where your system is storing its own .emacs file by:
Click options and scroll down to "Set Default Font..."
Change the font setting and click okay
On the options menu, go down to "Save Options"
When the options are saved, the system saves its .emacs file,
and you can read the file path in the minibuffer at the bottom of the Emacs screen
In Windows 7 put your init.el file in C:\Users\user-name\AppData\Roaming\.emacs.d\, where user-name is your user/login folder.
Take care so your init.el file won't be named init.el.txt. This is something Windows does if you create your file with some editor like Notepad.
On versions of Emacs on Windows above 22, it seems to have moved to
~/.emacs.d/init.el
, ~ being the value of your environment variable HOME (see Control Panel → System → Advanced → Environment variables).
The file itself might not exist. In that case just create it.
You must create an emacs initialization file. One is not automatically created.
I had a similar issue and this answer tracks down what I did.
My issue was my ~/.emacs.el file was not loading. Strange because this has always worked for me.
This question/answer helped me but I had to put my init file in the %USERPROFILE%\AppData\Roaming\.emacs.d\init.el because this is apparently the default behavior on Windows.
To troubleshoot this, I ran the following in the emacs *scratch* buffer.
user-emacs-directory
"~/.emacs.d/"
When I saw user-emacs-directory was ~/.emacs.d, I simply moved my .emacs.el file to %USERPROFILE%\.emacs.d\init.el. But this still didn't work.
I continued with expand-file-name as shown below:
(expand-file-name user-emacs-directory)
"c:/Users/pats/AppData/Roaming/.emacs.d/"
Got to love how Windows works. (not) So I moved my emacs.el file to the %USERPROFILE%\AppData\Roaming\.emacs.d\init.el and this worked. The file was now being read. But I got other errors because my initialization file loaded other (personal emacs) files (in ~/myenv/emacs/*.el.
Warning (initialization): An error occurred while loading ‘c:/Users/pats/AppData/Roaming/.emacs.d/init.el’:
Hum... Seems like all my files ~/myenv/emacs/*.el would need to be moved in order for this to work but I didn't want to do that. Then I realized that because the HOME environment variable was not set, emacs was performing its default behavior.
SOLUTION
Once I set my windows HOME environment variable to %USERPROFILE% everything began to work like it has for the past 25 years. :-)
To set the HOME environment variable, I typed WindowsKey+"edit environment variables for your account" to open the Environment Variables dialog box, and entered HOME=%USERPROFILE%.
Now my emacs initialization file .emacs.el is is back to its rightful place $HOME/.emacs.el and not in %USERPROFILE%\AppData\Roaming\.emacs.d\init.el
To be fair, if Windows had just one place to put files for user installed packages the solution of making HOME=%USERPROFILE\AppData\Roaming might be acceptable, but because some applications use %USERPROFILE%, some use %USERPROFILE\AppData\Roaming and others use %USERPROFILE\AppData\Local it just makes it difficult to know where to find your configuration files.
I prefer having everything in my %USERPROFILE% or $HOME directory.
Another similar question was here:
Emacs init.el file doesn't load
As kanja answered, the path to this file is stored in the user-init-file variable (or if no init file exists, the variable contains the default value for where to create it).
So regardless of which of the possible init file names you are using, and which directory it is in, you should be able to visit your init file with:
M-: (find-file user-init-file) RET
Or display its full path in the echo area with:
M-: (expand-file-name user-init-file) RET
On Emacs 23 and Windows 7 it only works if you set:
HKCU\SOFTWARE\GNU\Emacs\HOME
After Emacs 27.1, emacs has started respecting the $XDG_CONFIG_HOME. The init file or the init directory can now be found in $XDG_CONFIG_HOME/emacs/init.el.
In Windows $XDG_CONFIG_HOME could translate to %LOCALAPPDATA%.
In any case you can use the following emacs variables to find out the location of the your initialization file by M-x eval-expression
user-init-file
or the emacs configuration directory
user-emacs-directory
I've found that Emacs 22 will occasionally open either "C:\Documents and Settings\username\Application Data\.emacs", or just "C:\Documents and Settings\username\.emacs" on my XP machine. I haven't found an explanation for why it occasionally changes it's mind.
~ will always point to whatever the current instance of emacs thinks is HOME, but kanja's tip (C-h v user-init-file) will always tell you what ~/.emacs actually maps to.
On Windows 8.1, if Emacs is started from Windows Explorer, a shortcut or from cmd console it uses C:\Users\<USER>\AppData\Roaming.emacs init file. When I start Emacs from PowerShell, Emacs looks for its init file in C:\Users\<USER> folder. The fix to this issue was to set the HOME user environment variable (Control Panel\System and Security\System->Advanced system settings->Advanced->Environment variables) to C:\Users\<USER>. After this change, no matter how I start Emacs, it uses the same init file (see the accepted answer of this question)
On Windows XP it's:
C:\Documents and Settings\yourusernamehere\Application Data\
There is a list of directories based on your Windows version and extra information:
http://www.gnu.org/software/emacs/manual/html_node/emacs/Windows-HOME.html
For WIndows7& Emacs26.3:
if HOME environment is set, then the .emacs file should be in that folder.
otherwise, it should be in c:\.
In both cases, if .emacs is not there, _emacs should be used.
This is because we cannot create .emacs file according to the windows file naming rules.(but we can download or copy it from somewhere else).

emacs not picking up my init.el file on windows

I have my emacs.d folder located at:
C:\Users\<loggedin_user>\AppData\Roaming\.emacs.d
In this folder, I have my init.el file but it is not being picked up by emacs.
Is there another step I am missing, do I need to set an environment variable or something?
When I enter C-x d ~/ RET I end up at
C:\Users\<loggedin_user>\AppData\Roaming\
If I move the init.el file there, it is still not picked up. I have a deliberate error in the file that is not causing emacs to crash when it is opened.
Most likely you have an old ~/.emacs file somewhere else which Emacs ends up using in preference to the other one.
You probably want to check the value of user-init-file which will tell you which file Emacs ended up using as "the ~/.emacs file".
I suggest you report this as a bug, requesting that when several files are found as possible init file, Emacs should not just pick the first and ignore the others but should at least emit a warning about the fact that it ignored the others.
This is tricky on Windows 10 but I solved since I was suffering from same issue.
I created an Environment Variable called HOME with the path C:/user/<username> in the box "User variables for " create a new one
Just open with double click any file that is by default opened with Emacs and it will take few seconds to load then take changed on the init.el
create an init.el with just one line of code like:set-background-color "honeydew"
to test this, first before doing something more complex.
Hope That It Helps!
On Windows, Emacs is started with some Properties defined, found when you right-click the executable on your windows system. There you can define the
execution-directory, e.g. "C:\Users\loggedin_user\" (in parantheses)
where emacs executes
and looks for the .xemacs (.emacs) directory, where it find its init.el. (I had to create an .emacs File in my Windows Home Directory, which is defined in the Windows HOME Environment)
And where you can define the startup instructions (like (setenv "HOME" "c:/Users/Username/") ) etc.
If you configure that, the next time, emacs starts from the directory, you defined, with the initialisation-file
Windows 10 and Emacs 27.1 could not find .emacs.d: one more possibility, in my case %HOME% was set like HOME=%HOMEDRIVE%%HOMEPATH%. This redirection seems not to work and emacs was using literally C:\Users\<loggedin_user>\%HOMEDRIVE%%HOMEPATH% for searching .emacs.d. I did not dare to edit %HOME% but created link:
C:\Users\username> cd %HOME%
You perhaps need to remove some files in C:\Users\<loggedin_user>\%HOMEDRIVE%%HOMEPATH% which emacs already created.
Create link:
C:\Users\<loggedin_user>\%HOMEDRIVE%%HOMEPATH%> mklink /d .emacs.d ..\.emacs.d

emacs shortcuts are not working

I've been trying to get tramp to work for Emacs and was having some problems so I upgraded my Aquamacs to the latest version. Ever since then I've had massive problems with shortcuts. C-x C-f no longer works as find-file and instead does next-buffer. If I try to remap it back to find-file in my .emacs file it still doesn't work. Though I have managed to map C-x C-o to find-file temporarily. Several other shortcuts are also broken inexplicably (with no sign of anything in my .emacs file). I've tried deleting my .emacs file completely, but it doesn't refresh back to the original shortcuts though I do know that it is reading that file because when I do make some changes ( such as C-x C-o mapped to find-file) it does reflect this. However, even when I delete the .emacs file it still keeps the color-face I chose in it.
It's also giving me problems with tramp still in that I get the following error even though I can ssh to the exact same remote host just fine when using a shell window inside of Aquamacs:
"ssh: Could not resolve hostname ssh: nodename nor servname provided, or not known. Process tramp/ssh ssh exited abnormally with code 255"
I've tried reverting to older versions of Aquamacs, deleting the application and reinstalling, but nothing seems to work. Any advice would be greatly appreciated.
Mac OS X 10.6.8, Aquamacs 2.4 Emacs 23.50.1.

Emacs Tramp unable to open directory at times

Normally I am able to use tramp just fine to edit files and browse through the remote file system through SSH. Though at seemingly random times I would lose the ability to browse remote folders in emacs.
I get the error message:
Wrong type argument: number-or-marker-p, //DIRED-OPTIONS//
I've tried doing a clean reinstall of emacs without any customizations and the error still happens.
Also sometimes the error happens after browsing 1 or 2 directories while other times I'm able to do five or six directories before the error will appear.
Edit:
I'm using Emacs 23.3 running on OS X 10.6.8
Edit 2:
While I'm still going through the tramp debug log A couple of other pieces of information.
After the error I'm still able to use tramp of open and save files, just not view directory listings.
It seems to happen only when I save to a directory that is version controlled using git.
In the debug log the directory contents are listed out but it is not being outputted to the user
The directory listing inside the debug log show ^M (I usually notice this in the emacs info bar when editing files that have been versioned in git) even when I try to access a non-version controlled directory
The message is useless by itself. You should try to obtain more traces on the tramp behavior in order to find where is the issue. See the Traces and Profiles Section of the TRAMP User Manual.
Sorry to not help more but with another release on another platform…
Update:
Put the following in your emacs file
(require 'tramp)
(setq tramp-verbose 10)
(setq tramp-debug-buffer t)
Then, use tramp. Now, You should have a *debug tramp/method hostname* buffer.
I found out that this happens when I enable:
(setq-default dired-omit-mode t)
But for now I don't know how to make it work with this mode

Changing the default folder in Emacs

I am fairly new to Emacs and I have been trying to figure out how to change the default folder for C-x C-f on start-up. For instance when I first load Emacs and hit C-x C-f its default folder is C:\emacs\emacs-21.3\bin, but I would rather it be the desktop. I believe there is some way to customize the .emacs file to do this, but I am still unsure what that is.
Update: There are three solutions to the problem that I found to work, however I believe solution 3 is Windows only.
Solution 1: Add (cd "C:/Users/Name/Desktop") to the .emacs file
Solution 2: Add (setq default-directory "C:/Documents and Settings/USER_NAME/Desktop/") to the .emacs file
Solution 3: Right click the Emacs short cut, hit properties and change the start in field to the desired directory.
You didn't say so, but it sounds like you're starting Emacs from a Windows shortcut.
The directory that you see with c-x c-f is the cwd, in Emacs terms, the default-directory (a variable).
When you start Emacs using an MS Windows shortcut, the default-directory is initially the folder (directory) specified in the "Start In" field of the shortcut properties. Right click the shortcut, select Properties, and type the path to your desktop in the Start In field.
If you're using Emacs from the command line, default-directory starts as the directory where you started Emacs (the cwd).
This approach is better than editing your .emacs file, since it will allow you to have more than one shortcuts with more than one starting directory, and it lets you have the normal command line behavior of Emacs if you need it.
CWD = current working directory = PWD = present working directory. It makes a lot more sense at the command line than in a GUI.
I think the line you need to add to your .emacs is is
(setq default-directory "C:/Documents and Settings/USER NAME/Desktop/" )
Emacs will start in your desktop that way, unless you have a file open. It will usually start in the same directory as the file in your current buffer otherwise.
You can type the 'cd' emacs command. ( M-x cd ) to change the default folder as a one off.
I've put
(cd "c:/cvsroot/")
in my .emacs and it did the job
The default folder is actually the same as the current working folder for the buffer, i.e. it can be different for every file you work with. Say that the file you are working with is located in C:\dir_a, then the working directory for that buffer will by default be C:\dir_a. You can change this with M-x cd and type in whatever directory you would like to be the default instead (and by default I mean the one that will show up when you do C-x C-f).
If you start emacs without opening a file, you will end up with the *scratch* buffer open. If you started emacs from a Windows shortcut, the working directory will be the same as that specified in the shortcut properties. If you started it from the command line, it will be the directory from where you started it. You can still change this default directory with M-x cd, also from the *scratch* buffer.
Finally, you can do as Vadim suggests and put
(cd "c:/dir_a/")
in your .emacs file, to make that directory the default no matter how you start emacs.
As you're on Windows you can do it with a shortcut.
Create a shortcut to C:\emacs\emacs-21.3\bin\runemacs.exe. Edit the properties of the shortcut and change the value of Start In: to be whatever you want your default directory to be.
I am using emacs 22.2.1 under Windows XP and have been helped by the answers above to get the response in the minibuffer I want to the command C-x C-f. Initially I was getting
"Find file: C:\Program Files\emacs\bin/" like Anton.
I have HOME set to "C:\Documents and settings\USER NAME\My Documents".
The response to C-x C-f I want in the minibuffer is "Find file: ~/".
By adding (setq default-directory "C:/Documents and Settings/USER NAME/My Documents") to my .emacs file I was able to get the response "Find file: C:\Documents and settings\USER NAME\My Documents/" which is functionally the same as "Find file: ~/".
However, I noticed one further point. "Customize Emacs" under "Options" allowed me to inhibit the startup screen. Now when I open emacs I go immediately to the scratch buffer. When I type C-x C-f in the scratch buffer I get the exact response I want.
I have added to my shortcut (in Gnome, Linux) a pramater which is a blank dummy file name, and I specify the directory. Since my emacs defaults to "home" I simply say:
/Desktop/blank_file
and that opens a file called "blank_file"
That also moves the current working directory for that emacs session to the desktop.
If I happen to put stuff in "blank_file" then save it, of course, I've got that stuff saved. Which might be an annoyance or it might be a good thing, depending!
To change default directory to DESKTOP in Dired and shell put this in your ~/.emacs:
;;This works for Windows XP.
(setq default-directory (concat "C:\Documents and Settings\MY_ACCOUNT\DESKTOP\"))
For windows users, the best way that I found is to create the shortcut for runemacs.exe and placing the shortcut in the root directory of my notes folder.
This way, when you use this shortcut to open emacs, it will by default open in the root directory without having to specifically set the Start In property (you can leave the Start In property blank).
Reference: According to Microsoft, if you leave the 'Start In' box empty, the script will run in the current working directory
TIP:
Additionally, if you have organized your notes into multiple root folders (Personal, Work etc...), you can copy multiple such shortcuts in each folder to open various instances of emacs with their own default directories.
In Windows 8, it works to create a shortcut in the Desktop and change the property 'Start In:' for the shortcut.
Now, I ran the program emacs-23.3\bin\addpm.exe as recommended, and the Windows-8 screen (that horrendous invention from Microsoft) it appeared an icon-link to Emacs. But there you have to change again the property 'Start In'. (It is different from the one in the desktop).
Just right-click, choose in the bottom bar 'Open the file location' (or similar, I did it in my language), and you are taken to the folder with a new shortcut, in which you can (must) also change the property 'Start In:'.
A little involved, but in fact very easy.
Since the most annoying thing is having windows Emacs dump you into system32 when you are just using the shortcut, but want every other case to work, just use a bit of elisp...
(when (string< "C:\WINDOWS\system32" default-directory) (setq default-directory "~/"))
So it will only default to your home directory when you end up in system. The only drawback is if you really want to start emacs in system32...