* suggestion: reverting/notifying of files that no longer exist @ 2004-07-09 15:47 Karl Chen 2004-07-12 16:18 ` Juri Linkov 0 siblings, 1 reply; 9+ messages in thread From: Karl Chen @ 2004-07-09 15:47 UTC (permalink / raw) I think Emacs (maybe as part of auto-revert-mode) should notify you when you edit files that no longer exist. Sometimes I rename or move a file in shell, but still have the old file open and accidentally edit buffer for the old file. It would be very useful if Emacs tells you when a file that used to exist vanishes: (1) when you edit its buffer (2) if (global-)auto-revert-mode or some customizable variable is enabled, as soon as the file vanishes -- Karl 2004-07-09 08:41 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: suggestion: reverting/notifying of files that no longer exist 2004-07-09 15:47 suggestion: reverting/notifying of files that no longer exist Karl Chen @ 2004-07-12 16:18 ` Juri Linkov 2004-07-12 16:28 ` default file name to buffer name (was: reverting/notifying of files that no longer exist) Juri Linkov ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: Juri Linkov @ 2004-07-12 16:18 UTC (permalink / raw) Cc: emacs-devel Karl Chen <quarl@hkn.eecs.berkeley.edu> writes: > I think Emacs (maybe as part of auto-revert-mode) should notify > you when you edit files that no longer exist. Sometimes I rename > or move a file in shell, but still have the old file open and > accidentally edit buffer for the old file. > > It would be very useful if Emacs tells you when a file that used > to exist vanishes: > (1) when you edit its buffer > (2) if (global-)auto-revert-mode or some customizable variable > is enabled, as soon as the file vanishes This is the kind of situation Emacs should warn the user about. It's no fun having an unintentionally forked version which needs to be merged later with the original version when the fact of forking is discovered by the user. One place where the warning could be added is `basic-save-buffer'. It could ask if the user tries to save the buffer which was at least once saved to the file and was renamed or moved afterwards. The complete condition to check this situation is: (and (not (verify-visited-file-modtime (current-buffer))) (not (file-exists-p buffer-file-name)) (> buffer-saved-size 0)) It works in all cases with the exception of the case when a 0-sized file is moved or renamed. However, this case is not noteworthy. Index: lisp/files.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/files.el,v retrieving revision 1.707 diff -c -r1.707 files.el *** lisp/files.el 26 Jun 2004 14:41:13 -0000 1.707 --- lisp/files.el 12 Jul 2004 14:05:51 -0000 *************** *** 3082,3090 **** (set-visited-file-name filename))) (or (verify-visited-file-modtime (current-buffer)) ! (not (file-exists-p buffer-file-name)) (yes-or-no-p ! (format "%s has changed since visited or saved. Save anyway? " ! (file-name-nondirectory buffer-file-name))) (error "Save not confirmed")) (save-restriction (widen) --- 3082,3093 ---- (set-visited-file-name filename))) (or (verify-visited-file-modtime (current-buffer)) ! (not (or (file-exists-p buffer-file-name) ! (> buffer-saved-size 0))) (yes-or-no-p ! (format "%s was %s since visited or saved. Save anyway? " ! (file-name-nondirectory buffer-file-name) ! (if (file-exists-p buffer-file-name) ! "changed" "renamed or deleted"))) (error "Save not confirmed")) (save-restriction (widen) -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* default file name to buffer name (was: reverting/notifying of files that no longer exist) 2004-07-12 16:18 ` Juri Linkov @ 2004-07-12 16:28 ` Juri Linkov 2004-07-14 0:17 ` Richard Stallman 2004-07-12 19:00 ` suggestion: reverting/notifying of files that no longer exist Karl Chen 2004-07-14 0:16 ` suggestion: reverting/notifying of files that no longer exist Richard Stallman 2 siblings, 1 reply; 9+ messages in thread From: Juri Linkov @ 2004-07-12 16:28 UTC (permalink / raw) BTW, I'd like to suggest other improvements in `basic-save-buffer': 1. Add a default value to the minibuffer asking for the file name of the buffer not visiting any file. It makes sense to use the buffer name as the default value of the file name. 2. Currently, if the user specifies the directory name in the minibuffer asking for the file name, then the user is asked later about overwriting the existing directory with a new file. Since overwriting a directory with a file is too dangerous (or not possible at all on some systems), it is better to treat directory names specially and to ask the user about saving the file with the name composed from the specified directory name and the current buffer name. Index: lisp/files.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/files.el,v retrieving revision 1.707 diff -c -r1.707 files.el *** lisp/files.el 26 Jun 2004 14:41:13 -0000 1.707 --- lisp/files.el 12 Jul 2004 15:17:43 -0000 *************** *** 3074,3084 **** (or buffer-file-name (let ((filename (expand-file-name ! (read-file-name "File to save in: ") nil))) ! (and (file-exists-p filename) ! (or (y-or-n-p (format "File `%s' exists; overwrite? " ! filename)) ! (error "Canceled"))) (set-visited-file-name filename))) (or (verify-visited-file-modtime (current-buffer)) --- 3074,3092 ---- (or buffer-file-name (let ((filename (expand-file-name ! (read-file-name ! (format "File to save in (default %s): " (buffer-name)) ! nil (expand-file-name (buffer-name)))))) ! (if (file-exists-p filename) ! (if (file-directory-p filename) ! (let ((new-name (concat (file-name-as-directory filename) ! (buffer-name)))) ! (if (y-or-n-p (format "Save as %s? " new-name)) ! (setq filename new-name) ! (error "Canceled"))) ! (or (y-or-n-p (format "File %s exists; overwrite? " ! filename)) ! (error "Canceled")))) (set-visited-file-name filename))) (or (verify-visited-file-modtime (current-buffer)) -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: default file name to buffer name (was: reverting/notifying of files that no longer exist) 2004-07-12 16:28 ` default file name to buffer name (was: reverting/notifying of files that no longer exist) Juri Linkov @ 2004-07-14 0:17 ` Richard Stallman 0 siblings, 0 replies; 9+ messages in thread From: Richard Stallman @ 2004-07-14 0:17 UTC (permalink / raw) Cc: emacs-devel These changes seem useful. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: suggestion: reverting/notifying of files that no longer exist 2004-07-12 16:18 ` Juri Linkov 2004-07-12 16:28 ` default file name to buffer name (was: reverting/notifying of files that no longer exist) Juri Linkov @ 2004-07-12 19:00 ` Karl Chen 2004-07-14 14:17 ` Juri Linkov 2004-07-14 0:16 ` suggestion: reverting/notifying of files that no longer exist Richard Stallman 2 siblings, 1 reply; 9+ messages in thread From: Karl Chen @ 2004-07-12 19:00 UTC (permalink / raw) Cc: emacs-devel >>>>> "Juri" == Juri Linkov <juri@jurta.org> writes: Juri> One place where the warning could be added is Juri> `basic-save-buffer'. That would be good; I think it'd be even better however if it notified you the second you start editing. Because otherwise if you work on it for 20 minutes before saving, you've already "forked." -- Karl 2004-07-12 11:59 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: suggestion: reverting/notifying of files that no longer exist 2004-07-12 19:00 ` suggestion: reverting/notifying of files that no longer exist Karl Chen @ 2004-07-14 14:17 ` Juri Linkov 2004-07-14 17:30 ` Karl Chen 0 siblings, 1 reply; 9+ messages in thread From: Juri Linkov @ 2004-07-14 14:17 UTC (permalink / raw) Cc: emacs-devel Karl Chen <quarl@hkn.eecs.berkeley.edu> writes: >> One place where the warning could be added is `basic-save-buffer'. > > That would be good; I think it'd be even better however if it > notified you the second you start editing. Because otherwise if > you work on it for 20 minutes before saving, you've already > "forked." Notifying at the moment you start editing would be good too. Perhaps instead of creating a new function, that could be done in the existing function `ask-user-about-supersession-threat' which is already used for a similar purpose, and which could be called from `prepare_to_modify_buffer' when a previously saved file was deleted or renamed. Index: src/insdel.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/insdel.c,v retrieving revision 1.178 diff -u -r1.178 insdel.c --- src/insdel.c 22 May 2004 22:15:37 -0000 1.178 +++ src/insdel.c 14 Jul 2004 14:05:07 -0000 @@ -1931,7 +1931,14 @@ /* Make binding buffer-file-name to nil effective. */ && !NILP (current_buffer->filename) && SAVE_MODIFF >= MODIFF) - lock_file (current_buffer->file_truename); + { + lock_file (current_buffer->file_truename); + if (NILP (Fverify_visited_file_modtime (Fcurrent_buffer ())) + && current_buffer->save_length > 0 + && NILP (Ffile_exists_p (current_buffer->filename))) + call1 (intern ("ask-user-about-supersession-threat"), + current_buffer->filename); + } #else /* At least warn if this file has changed on disk since it was visited. */ if (!NILP (current_buffer->filename) Index: lisp/userlock.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/userlock.el,v retrieving revision 1.14 diff -u -r1.14 userlock.el --- lisp/userlock.el 1 Sep 2003 15:45:17 -0000 1.14 +++ lisp/userlock.el 14 Jul 2004 14:05:34 -0000 @@ -112,8 +112,10 @@ (save-window-excursion (let (answer) (while (null answer) - (message "%s changed on disk; really edit the buffer? (y, n, r or C-h) " - (file-name-nondirectory fn)) + (message "%s %s on disk; really edit the buffer? (y, n, r or C-h) " + (file-name-nondirectory fn) + (if (file-exists-p buffer-file-name) + "changed" "renamed or deleted")) (let ((tem (downcase (let ((cursor-in-echo-area t)) (read-char-exclusive))))) (setq answer @@ -137,8 +139,11 @@ (signal 'file-supersession (list "File reverted" fn))) ((eq answer 'yield) - (signal 'file-supersession - (list "File changed on disk" fn)))))) + (if (file-exists-p buffer-file-name) + (signal 'file-supersession + (list "File changed on disk" fn)) + (signal 'file-supersession + (list "File renamed or deleted on disk" fn))))))) (message "File on disk now will become a backup file if you save these changes.") (setq buffer-backed-up nil)))) -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: suggestion: reverting/notifying of files that no longer exist 2004-07-14 14:17 ` Juri Linkov @ 2004-07-14 17:30 ` Karl Chen 2004-07-15 18:42 ` i18n (was: reverting/notifying of files that no longer exist) Juri Linkov 0 siblings, 1 reply; 9+ messages in thread From: Karl Chen @ 2004-07-14 17:30 UTC (permalink / raw) Cc: emacs-devel Looks good (haven't tested it). Thanks for working on this! >>>>> "Juri" == Juri Linkov <juri@jurta.org> writes: Juri> + (message "%s %s on disk; really edit the buffer? (y, Juri> n, r or C-h) " Juri> + (file-name-nondirectory fn) Juri> + (if (file-exists-p buffer-file-name) Juri> + "changed" "renamed or deleted")) BTW, I don't know if Emacs coding standards say much regarding internationalization, but in general it's better to write out (message "%s changed on disk...") and (message "%s renamed or deleted on disk...") for translation. (http://www.gnu.org/software/gettext/manual/html_node/gettext_15.html) -- Karl 2004-07-14 10:24 ^ permalink raw reply [flat|nested] 9+ messages in thread
* i18n (was: reverting/notifying of files that no longer exist) 2004-07-14 17:30 ` Karl Chen @ 2004-07-15 18:42 ` Juri Linkov 0 siblings, 0 replies; 9+ messages in thread From: Juri Linkov @ 2004-07-15 18:42 UTC (permalink / raw) Cc: emacs-devel Karl Chen <quarl@hkn.eecs.berkeley.edu> writes: > BTW, I don't know if Emacs coding standards say much regarding > internationalization, but in general it's better to write out > (message "%s changed on disk...") > and > (message "%s renamed or deleted on disk...") > for translation. > (http://www.gnu.org/software/gettext/manual/html_node/gettext_15.html) According to those guidelines the right way to translate messages is to call the `gettext' function on messages before placeholders in them get expanded with arguments, i.e. to write: (message (gettext "File %s renamed") filename) However, this might not be the best solution for Emacs, since it has several powerful mechanisms like regexps to avoid the need to add `gettext' functions to every `message' call. So after the call to (message "File %s renamed" filename) the function `message' receives a string like "File /some/path/somefile renamed" and could use a variable with translation mappings to performs regexp replacements before messages get displayed in the echo area, e.g.: (defvar message-translations '(("some_language_name" "^File \\(.?+\\) renamed$" "Elif \1 demaner") (... ... ...))) Anyway, I believe this feature is for Emacs 22, and etc/TODO already has an entry for that. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: suggestion: reverting/notifying of files that no longer exist 2004-07-12 16:18 ` Juri Linkov 2004-07-12 16:28 ` default file name to buffer name (was: reverting/notifying of files that no longer exist) Juri Linkov 2004-07-12 19:00 ` suggestion: reverting/notifying of files that no longer exist Karl Chen @ 2004-07-14 0:16 ` Richard Stallman 2 siblings, 0 replies; 9+ messages in thread From: Richard Stallman @ 2004-07-14 0:16 UTC (permalink / raw) Cc: quarl, emacs-devel Thanks for thining of this. Please install your change. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2004-07-15 18:42 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2004-07-09 15:47 suggestion: reverting/notifying of files that no longer exist Karl Chen 2004-07-12 16:18 ` Juri Linkov 2004-07-12 16:28 ` default file name to buffer name (was: reverting/notifying of files that no longer exist) Juri Linkov 2004-07-14 0:17 ` Richard Stallman 2004-07-12 19:00 ` suggestion: reverting/notifying of files that no longer exist Karl Chen 2004-07-14 14:17 ` Juri Linkov 2004-07-14 17:30 ` Karl Chen 2004-07-15 18:42 ` i18n (was: reverting/notifying of files that no longer exist) Juri Linkov 2004-07-14 0:16 ` suggestion: reverting/notifying of files that no longer exist Richard Stallman
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).