algon-ns · 2022-08-04 08:30
One is '**find-file-not-found-hooks**', which I think have spoiled my 'C-x C-f' find-file way to get a header on new files.
Just now I just get an empty file, and I can't figure out why the 'auto-insert' functionality does not work.
Any advice to have it work again?
jsonr_r · 2022-08-04 08:44
In Emacs 28, the doc string says:
This variable is an alias for ‘find-file-not-found-functions’.
This variable is obsolete since 22.1;
use ‘find-file-not-found-functions’ instead.
This variable may be risky if used as a file-local variable.
Probably introduced at or before Emacs version 18.
So probably for this specific case, you can use find-file-not-found-functions instead. But I am not sure why the auto-insert functionality is not working, as that is separate from that hook. Maybe your code for enabling is is also obsolete, as at some time in the distant past minor modes were changed to toggle instead of turning on when a then common method of enabling them in init files was used.
algon-ns · 2022-08-04 09:09
(info: I'm running emacs 29.0.50 (build yesterday), and the problem started just after the maintainers had at (minor) problem with find-file)
I'm not sure, my way to getting a template for new files is very old, and not well understood (by me), I did not use file-not-found-hook directly (AFAIK), the ordinary C-x C-f just vent to creation with templates if it did find not the file.
mickeyp · 2022-08-04 10:26
You mention "get a header" which I assume is about C programming?
Have you tried `M-x ffap` or `M-x ff-find-other-file` when your point is on a `#include` header definition? The latter in particular has a large body of customizations that you can tweak, exactly for this use case.
arthurno1 · 2022-08-04 10:51
> Some functions and variables obsolete since Emacs 21 or 22 have been removed
I just pulled, rebuild and restarted my Emacs (29.0.50). C-h v says:
find-file-not-found-hooks is a variable defined in ‘files.el’.
Its value is (w32-find-file-not-found-set-buffer-file-coding-system)
This variable is obsolete since 22.1; use ‘find-file-not-found-functions’
instead.
List of functions to be called for ‘find-file’ on nonexistent file.
These functions are called as soon as the error is detected.
Variable ‘buffer-file-name’ is already set up.
The functions are called in the order given until one of them returns non-nil.
This variable is an alias for ‘find-file-not-found-functions’.
This variable may be risky if used as a file-local variable.
Probably introduced at or before Emacs version 18.
In Emacs, usually, nothing is removed (unfortunately). They just "obsolete" stuff and let it emit a warning when you byte compile, but everything is (usually) still there and working. You should probably check your setup. Likely there is an error in your setup elsewhere, before the part where you enable auto-insert mode. Check also if you did enable auto-insert for the particular file type. Is it about C/C++, since as /u/mickeyp suggests, you are talking about headers? Can it be that you have switched the file extension? Using 'hh' instead of 'h' for C++ or something similar?
For example this is my setup to recognize which are C or C++ files:
(add-to-list 'auto-mode-alist '("\\.\\(c\\|h\\|inc\\|src\\)\\'" . c-mode))
(add-to-list 'auto-mode-alist '("\\.\\(|hh\\|cc\\|c++\\|cpp\\|tpp\\|hpp\\|hxx\\|cxx\\|inl\\|cu\\)'" . c++-mode))
By the way, I can confirm that auto-insert works just fine here, and I haven't changed my setup for quite some long time. It is most likely something with your setup.
algon-ns · 2022-08-04 11:16
It's in general mostly for python-, org- and to lisp-files
7890yuiop · 2022-08-04 12:27
> In Emacs, usually, nothing is removed (unfortunately). They just "obsolete" stuff and let it emit a warning when you byte compile, but everything is (usually) still there and working.
Many obsoleted things get removed. It's just on a long time-scale of, typically, several releases (meaning many years), giving users plenty of time to make noise about it if they have an objection. Remember that many users won't get to use a given release of Emacs until several years after it's been released, so these things need to happen slowly.
ieure · 2022-08-04 15:54
This is somewhat unsatisfying for me, but I think this should work:
(defun auto-insert-new-file ()
(when (and buffer-file-name (not (file-exists-p buffer-file-name))
(= (bobp) (eobp)))
(auto-insert)))
(add-hook 'find-file-hook #'auto-insert-new-file)
When you open a new file, the buffer is associated with a file, but it doesn't exist until you save it, so you can test for that situation (and the buffer being empty) in the normal `FIND-FILE-HOOK`.
It seems awful fiddly, maybe someone here has a suggestion for a cleaner approach.