Clean minibuffer during file find in ido mode - emacs

I use C-a,C-k to clean minibuffer when searching for a file in normal emacs. In ido mode, this key is bound to deleting a file.
So, in ido mode, after going deep down the folder hierarchy, how to clean minibuffer and restart my file selection from root folder.
Yes, i can use backspace to go up one step at a time, but that is tedious....

Related

Files Listed in Emacs Find-Files

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.

Refresh remote directory in Emacs Tramp Mode

I've been using Tramp mode on my Emacs to edit files remotely. I'm also using ido mode. When I add a new file in the same directory of a file I opened using Tramp, I couldn't get Tramp to find the new file(with C-x C-f). Is there a way to refresh Tramp?
Your question is about ido-mode used with tramp. To refresh ido auto-complete while in the process of finding a file, you can press C-l, to execute: ido-reread-directory.
As documented here, you can press g in the dired buffer to run revert-buffer and refresh the directory listing.

Emacs: How to view sftp folders

I'm running Ubuntu and playing with Emacs for the first time but unfortunately it doesn't seem to see any sftp folders I currently have mounted. These folder are visible to nautilus and gedit.
Can any experienced emac users point me in the right direction?
I'm not sure how to get Emacs to pick up specifically those servers that have been mounted under Nautilus.
However (and hopefully this meets your needs), you can still view and edit remote files and directories using Tramp if you know the server name:
C-x C-f /sftp:username#server.net:path/to/file.txt RET
or
C-x C-f /sftp:username#server.net:path/to/directory/ RET
Tramp documentation
Although tramp is more efficient, you can "drag and drop" it from $HOME/.gvfs/server.net/ into emacs. $HOME/.gvfs/server.net/ is where it's mounted locally.
Typically I drop the file into scratch where (as you've seen) it's expanded to a filename. Just modify that into an evaluatable function, evaluate it with "C-M-x":
(find-file "/sftp:username#server.net:/path/to/file.txt")

How do I byte-compile everything in my .emacs.d directory?

I have decided to check out Emacs, and I liked it very much. Now, I'm using the Emacs Starter Kit, which sort of provides better defaults and some nice customizations to default install of Emacs.
I have customized it a little, added some stuff like yasnippet, color-themes, unbound, and other stuff. I've set up a github repository where I keep all of the customizations so I can access them from multiple places or in case something goes bad and I lose my .emacs.d directory.
All of this is very nice, but there is a problem: Emacs takes about 1-2 seconds to load. AFAIK I can compile individual .el files with M-x byte-compile-file to .elc, and it works. But there are a lot of .el files, and I wonder if there is a way to compile them all with a simple command or something, to speed up the loading of Emacs. My Emacs is not always open, and I open and close it quite frequently, especially after I've set it up as a default editor for edit command in Total Commander to get used to it faster (yeah, windows xp here).
My Emacs version is 22.3. And yes, the default Emacs installation without any customizations fires up instantly.
I am not sure which version is preferred when loading, the .el or compiled .elc one by the way O.o
So, is there an elisp command or Emacs command line switch to make Emacs byte-compile everything in .emacs.d directory?
C-u 0 M-x byte-recompile-directory
will compile all the .el files in the directory and in all subdirectories below.
The C-u 0 part is to make it not ask about every .el file that does not have a .elc counterpart.
To automatically byte compile everything that needs byte compiling each time I start emacs, I put the following after my changes to load-path at the top of my .emacs file:
(byte-recompile-directory (expand-file-name "~/.emacs.d") 0)
Surprisingly, it doesn't add much to my startup time (unless something needs to be compiled).
To speed up my emacs, I first identified the slow parts using profile-dotemacs.el and then replaced them with autoloads.
You can use the --batch flag to recompile from the command line.
To recompile all, do
emacs --batch --eval '(byte-recompile-directory "~/.emacs.d")'
or to recompile a single file as from a Makefile,
emacs --batch --eval '(byte-compile-file "your-elisp-file.el")'
This is swaying a bit from the question, but to solve the problem of loading slowly you can use the new daemon feature in Emacs 23.
"If you have a lot of support packages,
emacs startup can be a bit slow.
However, emacs 23 brings emacs
--daemon, which enables you to start emacs in the background (for example
when you log in). You can instantly
pop up new emacs windows (frames) with
emacsclient. Of course, you could
already have an emacs 'server' in
older versions, but being able to
start it in the background makes this
a much nicer solution"
From http://emacs-fu.blogspot.com/2009/07/emacs-23-is-very-near.html
The command I use is M-x byte-force-recompile RET, it then asks the directory so, for example, I give it ~/.emacs.d/elpa/. It then recompiles everything in there, usually no need to delete .elc files first or mess with it in other ways.
For my using spacemacs, the command is spacemacs/recompile-elpa. The command byte-recompile-directory does not compile any file.

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...