"Selecting deleted buffer" error in elisp - emacs

In Emacs, I'm trying to create a file on the fly (using with-temp-file), set some file local variables, write the local variables to the file and save it. After some modifications to the newly created file, I delete the file and kill the corresponding buffer. So far it's working.
Now after deleting the file, I do the same process (create file on the fly, open the buffer, etc). But this time when I try to do something on the newly created buffer using with-current-buffer I'm getting this weird error:
Selecting deleted buffer
buffer-live-p on the new buffer returns t.
What could have gone wrong?
I'm using a custom build of Emacs 24.3 on RHEL 6.

Related

emacs as an external editor for other applications (Houdini, Joplin)

I am trying to use emacs as an editor with other applications which allow people to open text in an editor (Sublime in this case), save it, and see it updated in the application. For example, in Houdini, a 3D software, I can type code in an external editor (in this case, Sublime), modify, save... and see it update in the application (Houdini). When I use emacs, it doesn't work. As an example, here I am adding a line of text using Sublime in Houdini:
Once I save and close, the text is updated in Houdini, and I can continue working:
Try as I might, I can't get this to work in emacs. I am sure the file has the same name, and when I save, it confirms the right file path.
What am I missing? I have run into the same problem with an application called Joplin: Sublime works, emacs does not.
A wild guess: Emacs has different behaviour when saving files than Sublime, and Houdini gets confused by that.
When you save a file in Emacs, Emacs creates a backup of the previous contents of the file, suffixing the file name with a tilde. By default it does this by renaming the existing file to the backup name, and then writing the contents to the real filename, thereby creating a new file.
(You can observe this by running ls -i before and after: the backup file will have the inode number that the main file had previously. Note that Emacs doesn't make backups after the first save during the same editor session, so you might need to restart Emacs or kill the buffer with C-x k to see this.)
I suspect that Houdini keeps the file open while Emacs is editing it, and so when you save the file from Emacs, the file that Houdini has open is actually the backup file.
You can configure Emacs to make backups by copying instead of renaming by setting the variable backup-by-copying to t. Add this to your ~/.emacs file (creating it if it doesn't exist):
(setq backup-by-copying t)

How does emacs compile the file and edit it?

There is this feature in emacs. Whenever you compile your code (filename: hello.cpp) run the program and then you edit your code then emcas will store you previous unedited code in another file named hello.cpp~
. hello.cpp~ will always contain first code you compile and whenever you write you edit your code in emacs it will produce file name .#hello.cpp. It automatically remove .#hello.cpp when you save that code but hello.cpp~ will remain same. .#hello.cpp file contain info. such as username#DESKTOP-FN20BRU.13000:1597860074. So anybody can please explain me this working process of emacs?
Emacs does the following when you edit a file filename
#: when you modify the file (in memory), Emacs creates a # file (on disk) and keeps updating it with your changes, until you save the edited version. This draft, on disk, can be recovered in case Emacs or the computer crash before you had time to save your changes.
~: as soon as you save the edited version, Emacs renames first your old version on disk (the one when you opened Emacs) adding a trailing ~ to the filename giving filename~ (it does this only the first time you save within the current session), then it overwrites filename with the modified version, and finally removes the # draft on disk.
Then, when you make further changes, another # file is created, etc.

How to view content of emacs autosave file

How do I directly see the content of an emacs autosave file, without implementing a file recovery operation?
That is, suppose I created a file with 'emacs foo', then emacs crashed, so I'm left with no file named 'foo' (since it never was saved) but with a file '#foo#'. When I type 'more #foo#', I get "Missing filename", as though the more command doesn't even see the #foo# part of the command.
I just want to see the text in #foo# so I can copy it out by hand without risking something going wrong in the file recovery process (eg #foo# getting overwritten by a new autosave operation).
(I'm using Terminal on OSX.)
Bash or another shell use '#' as comment character, try :
more "#foo#"

Is it possible to prevent emacs from creating " .#files " [duplicate]

When I modify a buffer, Emacs automatically creates a temporary symlink in the same directory as the file being edited (e.g. foo.c):
.#foo.c -> user#host.12345:1296583136
where '12345' is Emacs' PID (I don't know what the last number means).
Why does Emacs create these links, and how do I prevent it from doing that?
Note that I have turned off auto save mode (M-x auto-save-mode) and disabled backup files (M-x set-variable -> make-backup-files -> nil). When I save a modified buffer, or undo the changes to it, the symlink disappears.
In particular, I'm trying to prevent Emacs from creating these links because they cause the directory timestamp to be modified, which causes our build system to rebuild an entire module instead of compiling and linking for one changed file :/
Thanks for any input!
Update: In order to prevent Emacs from creating interlocking files permanently, you can change src/filelock.c and build a custom binary:
void
lock_file (fn)
Lisp_Object fn;
{
return;
// Unused code below...
}
Update 2: Arne's answer is correct. It's now possible to disable lock files in the latest Emacs (24.3.1), by adding this to your .emacs file:
(setq create-lockfiles nil)
Update: Emacs 24.3 has been released with full support for this new setting!
In the current trunk of emacs, you can simply customize the variable create-lockfiles:
C-h v create-lockfiles
Documentation:
Non-nil means use lockfiles to avoid editing collisions.
In your init file, you can set
(setq create-lockfiles nil)
Get it via
bzr branch bzr://bzr.savannah.gnu.org/emacs/trunk emacs-trunk
make
src/emacs
(I found out about this, because I decided to get active and just add an option like that myself… :) )
The symbolic link is emacs' file interlocking system: the symbolic link indicates that an instance of emacs is editing this file. If another instance tries to edit the same file, emacs will issue a warning. See http://www.gnu.org/software/emacs/manual/html_node/emacs/Interlocking.html
This has nothing to do with auto-save.
I cannot find how to modify or disable file locking from within emacs.

Why does my *scratch* buffer save data in aquamacs emacs?

In regular emacs my understanding was that if you killed the scratch buffer, when you switched back to it it would be empty, or when you closed and restarted emacs, it would be empty. With Aquamacs, it seems to preserve the buffer contents. Why might this happen?
In Aquamacs changes documentation says:
The scratch buffer is now persistent
across sessions. It is saved to an
internal file, but File / Save As (or
Apple-Shift-S or C-x C-w) still allow
users to save the file elsewhere. (To
switch this off, customize the
`aquamacs-scratch-file' variable to
nil.)
http://braeburn.aquamacs.org/code/master/aquamacs/doc/AquamacsHelp/node42.html