I'm using GNU Emacs 24.3 under Windows. At work I have to conform to specific file-naming standards, some of which include spaces in the file name.
How do I create a file with a space in the file name in Emacs? I can easily open them for editing, but can't find any info on how to create one. (i.e., create the file C:\temp\foo bar.txt)?
Update
In response to the question in the comments under the accepted answer: I'm using ido-mode, and this is the cause of the specific issue I was experiencing at the time.
I don't have the Windows version to test, but with the Linux version, there is no particular issue. I can open a file with spaces in it and save it with these two commands:
C-x C-f ~/tmp/this is a test.txt
C-x C-s
Note that C-x C-f does not require an existing file. When you do C-x C-s, it automatically creates it.
I hope for you that this is the same behaviour with the Windows version...
In Emacs you create a file the same way you open it for editing: C-x C-f c:/temp/foo bar.txt (no need for backslashes in Emacs).
And in Emacs 24.3 you can just type spaces like any other file-name chars. (In old Emacs versions you needed to quote SPC chars by preceding them with C-q: C-q SPC inserts a space char.)
(Actually, that just creates a new buffer for the new file (the buffer "visits" the file). The file itself is created when you save the buffer: C-x C-s.)
Related
I'm running GNU Emacs 24.3.1 on Windows 7. As mentioned in this manual page, I can type
C-x d ~/ RET
to determine the location of my home directory. In my case, Emacs returns:
e:/EmacsDocs
which, according to Windows Explorer, indeed contains a file .emacs. When I open .emacs with Emacs, the file appears to be empty.
Now, I want to set Emacs so that it is in overwrite mode by default. According to this page, that can be done by adding the following to .emacs:
(setq-default overwrite-mode t)
But when I make this change to .emacs and close and reopen Emacs, Emacs does not overwrite when I select text and start typing. (Rather, it still operates in insertion mode, with new characters inserted before the cursor.)
I also tried, for example, adding this command to .emacs, which according to this page will disable cursor blinking:
(blink-cursor-mode 0)
but again, there is no change when I restart Emacs.
How can I tell if Emacs is actually reading the .emacs in the home directory (upon restarting Emacs)?
You are confusing what Emacs calls overwrite-mode with the requested behavior "overwrite when I select text and start typing".
In Emacs, the latter behavior is called delete-selection-mode, and overwrite-mode means that when you type text (without selecting anything), any existing text that follows the cursor is overwritten by what you type.
Most Emacs users do not turn on overwrite-mode by default, and they just hit the insert key (typically to the left of the home key) to toggle `overwrite-mode on/off when they need/want to.
One way to turn on delete-selection-mode by default is to put one of the following in your init file (.emacs):
(setq delete-selection-mode t)
or
(delete-selection-mode)
Another way is to customize the option delete-selection-mode using M-x customize-option RET delete-selection-mode RET and save the customized value.
Instead of editing the file outside of Emacs, just type
C-x C-f ~/.emacs
and add your configurations there. Save with
C-x C-s
and restart. This should work, since ~ in Emacs defaults to the home directory.
If I C-c on some other program (lets say a terminal, or a web browser) and then C-v into Emacs, autopair sometimes creates extra parentheses or brackets that I don't want. How do I restrict this from happening when I am copy pasting external text to Emacs? My relavent lines in my init.el file are:
(require 'autopair)
(autopair-global-mode 1)
(setq autopair-autowrap t)
If I understand correctly, you're pasting into an Emacs running inside a terminal emulator. In that case, the paste really sends the pasted chars as if they were key-presses, so weird things can happen (e.g. when pasting into a Dired buffer).
For what it's worth, Emacs-25 supports "bracketed paste", which is a special functionality of "recent" xterms in which those terminals send pasted text surrounded with special escape sequences, so Emacs can know that it's a paste.
In other words, this problem should be fixed in Emacs-25.
I opened a file in Emacs using Ctrl+x and Ctrl+f. The file replaces the buffer in which an old file was residing. Now I want to go back to the old file without giving the actual path to open it. Is there any command for this?
File opening does not replace buffers. It opens new buffers, so the old buffer is already there. Try the command M-x list-buffers (C-x C-b) to see the open buffers.
Also see this: http://www.gnu.org/software/emacs/manual/html_node/emacs/Select-Buffer.html
And this: http://www.emacswiki.org/emacs/SwitchingBuffers
I use session.el and minibuf-isearch.el. If you use them, you can search the history of file you opened with C-x C-f by C-x C-f C-r what-file-you-want RET RET even if you closed and restart Emacs. It's incredibly useful.
Is there any way to quickly clear the pre-filled text in the Find File: buffer (C-x C-f)? I find it's often annoying to M-Backspace each element out of the way, and CMD-a (on a mac) selects all the text in the buffer, including the Find File: text, which throws a Text is read-only error when hitting delete.
You can ignore the text if you do not want to edit it. If you start typing / (for full path) or ~ (for home), the default path gets gray and is ignored.
I'd suggest C-a C-k (go to the beginning of the line and kill it - same as in OSX actually) or C-S-backspace (kill-whole-line).
If you use ido, you won't need to use M-Backspace anymore (Backspace alone will do the same) and typing "~/" will directly take you to the home directory independently of the current path.
All you need is:
(require 'ido)
(ido-mode 'both) ;; for buffers and files
Usually you don't need to clear the text.
You can type the file name right after the pre-filled text:
C:/work/mydir/C:/temp/anotherdir
It works on Windows and on Unix as well.
When using ido-mode in emacs, it tends to get in my way when I'm trying to create a new file inside a directory, using: C-x C-f ( start typing a new filename, which doesn't yet exist ) RET
Ordinarily this should create a new file, but when I have ido mode, I have to type the new filename really quickly, otherwise ido-mode decides to move me into a directory that has a file with a matching name, causing me to open that file, instead of creating a new file.
Does anybody know how to force ido-mode to avoid looking in directories other than the one you're currently in?
You can disable the merging (the "looking in other directories" in ido vulgo) with
(setq ido-auto-merge-work-directories-length -1)
but you can also undo the merge with C-z in ido.
Doing this really helps. Basically use ido-mode up until you get to the correct directory, then hit C-f again to get out of ido-mode as you type the new filename.
C-x C-f navigate to directory C-f enter new filename RET.
Use C-j to tell ido to input what you have typed rather than the first completion. This is also mentioned on emacswiki.