When I try to close emacs I get the message
"buffer ido.last modified; kill anyway?"
and whatever I answer, emacs stays open. But I can't open this buffer and the ido.last file doesn't exist. How can I get my emacs closed?
If you've used emacs as another user, as root for instance, it's possible that the .ido.last file is owned by root and hence you aren't allowed to remove or save it.
When you get the "buffer .ido.last modified"-question just remove the .ido.last file before you answer yes (if you're using emacs within a shell, just C-z, remove file and then resume with %). Then the .ido.last file will be written to disk with you as the owner.
IDO tries to save a file called ido.last into ~/.emacs.d directory. But, in your case IDO seems to be unable to do so. Maybe your ~/.emacs.d directory is read-only for a particular reason, or your disk is full, etc. So IDO raise an error that prevent your emacs to close.
If you don't use IDO, try to remove this kind of lines from your .emacs :
(require 'ido)
(ido-mode t)
Add this code (eg. to your .emacs.el, init.el, etc.) to
fix the issue with ido preventing emacs from exiting
when the ido.last file is not writable:
(defun ido-kill-emacs-hook ()
(ignore-errors (ido-save-history)))
Like Jérôme Radix said, IDO gives that error when unable to save the ido.last file, and the error prevents emacs from closing.
The default location for IDO to save the file is into ~/.emacs.d directory, but this can be overridden by setting the variable ido-save-directory-list-file. This means you should check the value of this variable (e.g., M-x describe-variable) to see where IDO is trying to save a file, and figure out why it can't save the file.
Possible reasons include:
The directory or file is read-only.
The directory does not exist. IDO will not create the directory for you.
The directory or file is owned by another user.
The disk is full.
Related
Using Emacs with ido mode enabled on Windows, Emacs tries to save a history file .ido.last when exiting. The file is located in C:/.ido.last, but it fails with a permission denied message. This is strange since I actually have access to that folder. However:
Is there a command to change the directory where the .ido.last file gets saved?
Short answer: (setq ido-save-directory-list-file "/some/file/name").
Long answer:
I keep all the little files that remember Emacs's state in a single directory under the user-emacs-directory. I'm not sure what this is on Windows, but I think it's C:\Users\<username>\Application Data\.emacs.d\. On Unix, it's ~/.emacs.d/. The variable user-emacs-directory should be defined by Emacs, no need to set it.
(setq emacs-persistence-directory (concat user-emacs-directory "persistence/"))
(unless (file-exists-p emacs-persistence-directory)
(make-directory emacs-persistence-directory t))
(setq ido-save-directory-list-file (concat emacs-persistence-directory
"ido-last"))
You may want to look at the no-littering package, which sets better default locations for files like this.
I would like to configure emacs so that the Icy mode is active by default. As suggested in "icicles-doc1.el", I added the following code at the end of my .emacs file:
(require 'icicles)
(icicle-mode 1)
When I run emacs, I get a *Warning* buffer:
Warning (initialization): An error occurred while loading `c:/Users/USER/AppData/Roaming/.emacs':
File error: Cannot open load file, icicles
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
When I do the debug option, a *Backtrace* buffer says something like:
Debugger entered--Lisp error: (file-error "Cannot open load file" "icicles")
require(icicles)
eval-buffer(# nil "c:/Users/USER/AppData/Roaming/.emacs" nil t) ;
Reading at buffer position 5062
load-with-code-conversion("c:/Users/USER/AppData/Roaming/.emacs"
"c:/Users/USER/AppData/Roaming/.emacs" t t)
load("~/.emacs" t t)
#[0 "\205\262
With or without those two lines in my .emacs that are causing the problem, icicle-mode seems to work fine when I do a M-x icicle-mode.
(file-error "Cannot open load file" "icicles") means that Emacs didn't know where to find library icicles.el[c]. You need to put the location of the Icicles files in variable load-path.
E.g, if your Icicles files are in directory /my/icicles/ then you need to do this (e.g., in your init file, ~/.emacs):
(add-to-list 'load-path "/my/icicles/")
Do that before you do (require 'icicles). That way, Emacs will know where to load Icicles from.
Given that the (require 'icicles) code is failing, but the M-x icy-mode is working, then it seems that someone has already set up your Emacs installation to include icicles via an autoload command, but didn't update the load-path to include the directory where icicles.el resides.
Replace those two lines with:
(icy-mode 1)
(which is the equivalent of M-x icy-mode when icicles has yet to be enabled)
If you want to use a different version of icicles, then you need to add the proper directory to the load path.
Is there a way to give the 'find-file' function a hint?
I'm working with files in the same directory on a remote server, and I'm getting tired of typing in the machine name, and directory structure all the time. It would sure be great if I could write a function that would bring up the find-file prompt with the machine name and directory already filled in.
(Note: I use Emacs 23.1)
Thanks for your help in advance.
If you're starting the 'find-file command from buffers associated with files on the remote server, the staring point should already include the directory/remote server filled in.
One way to skin this cat is to do
M-x cd /ssh:user#machine:/starting/path
note: I use tramp, and that's how find-file starts. I'd not noticed the /ssh: before today, but I don't use tramp very much any longer.
To answer your question directly, this command calls find-file with the "hint":
(defun my-remote-find-file ()
"call 'find-file with a starting directory"
(interactive)
(let ((default-directory "/ssh:user#machine:/starting/path/"))
(call-interactively 'find-file)))
Obviously customize the starting point.
One last way I can think of solving this is to do M-x dired on the remote server, and do your file finding from that point.
Set up recentf, and when you want to open a file on the server, go through the recentf menu; if the exact file you want is not there, just open something else in the same directory, then type C-x C-f and the directory should be filled in for you.
Use a bookmark to get to the remote directory. Then, as noted by Trey above, once you're in a file or directory that is remote, the default-directory will be set to what you want.
You can bookmark a remote file or directory. With Bookmark+, when you bookmark a Dired buffer you can save also all its file markings, omissions etc. -- IOW, the Dired state. When you later jump to the bookmark that saved state is restored. Use bookmarks to organize code projects etc.
bookmarksbookmark
For session management with emacs, I appended the following lines to my .emacs file
(load "desktop")
(desktop-load-default)
(desktop-read)
I was able to save the session using M-x desktop-save. But after exiting emacs, I am unable to recover the earlier saved session. I did start emacs in the same directory as that during "desktop-save"
Please let me know if I am missing anything or not correct in my efforts
Thanks
-- Harish
Chapter 51 'Saving Emacs Sessions' of my Emacs manual (using a Emacs 23 snapshot) has this
You can save the desktop manually
with the command M-x desktop-save'.
You can also enable automatic saving
of the desktop when you exit Emacs,
and automatic restoration of the last
saved desktop when Emacs starts: use
the Customization buffer (*note Easy
Customization::) to set
desktop-save-mode' to t' for future
sessions, or add this line in your
~/.emacs' file:
(desktop-save-mode 1)
which is different from what you tried.
The following worked for me (emacs 21.3.1):
(load "desktop")
(setq desktop-save-mode 1)
(desktop-load-default)
(desktop-read)
The desktop-save-mode line is only needed if you want to save desktop automatically on exit (i.e. without bothering to type M-x deskstop-save).
The only difference is that I put those lines at the beginning of the .emacs file but I doubt that's a problem.
How exactly can I create a new directory using Emacs? What commands do I use? (If possible, please provide an example)
to create the directory dir/to/create, type:
M-x make-directory RET dir/to/create RET
to create directories dir/parent1/node and dir/parent2/node, type:
M-! mkdir -p dir/parent{1,2}/node RET
It assumes that Emacs's inferior shell is bash/zsh or other compatible shell.
or in a Dired mode
+
It doesn't create nonexistent parent directories.
Example:
C-x d *.py RET ; shows python source files in the CWD in `Dired` mode
+ test RET ; create `test` directory in the CWD
CWD stands for Current Working Directory.
or just create a new file with non-existing parent directories using C-x C-f and type:
M-x make-directory RET RET
Emacs asks to create the parent directories automatically while saving a new file in recent Emacs versions. For older version, see How to make Emacs create intermediate dirs - when saving a file?
Ctrl+X D (C-x d) to open a directory in "dired" mode, then + to create a directory.
You can also run single shell commands using M-!
You're basically sending a string to the command line so you don't get any nice auto-completion but it's useful if you know how to perform an action through the command line but don't know an Emacs equivalent way.
M-! mkdir /path/to/new_dir
I guess I did it the hard way earlier today. I did:
M-x shell-command
then
mkdir -p topdir/subdir
You can use M-x make-directory inside of any buffer, not necessarily a dired buffer. It is a lisp function you can use as well.
I came across this question while searching for how to automatically create directories in Emacs. The best answer I found was in another thread from a few years later. The answer from Victor Deryagin was exactly what I was looking for. Adding that code to your .emacs will make Emacs prompt you to create the directory when you go to save the file.