From 553ad9c9e8550416d38c50aa5ec188d0b4f4d5cf Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Fri, 16 Jul 2021 18:13:28 +0200 Subject: [PATCH] Add lock-file-mode * doc/emacs/files.texi (Interlocking): * doc/lispref/files.texi (File Locks): * etc/NEWS: Add lock-file-mode. * lisp/files.el (lock-file-name-transforms) (remote-file-name-inhibit-locks): Move down. (lock-file-mode): New minor mode. --- doc/emacs/files.texi | 4 ++++ doc/lispref/files.texi | 5 +++++ etc/NEWS | 25 ++++++++++++++--------- lisp/files.el | 46 ++++++++++++++++++++++++------------------ 4 files changed, 51 insertions(+), 29 deletions(-) diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 54ffcd3cafc..7edf4d2bbbf 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -849,6 +849,10 @@ diff-buffer-with-file} command. @xref{Comparing Files}. You can prevent the creation of remote lock files by setting the variable @code{remote-file-name-inhibit-locks} to @code{t}. +@cindex lock-file-mode + The minor mode @code{lock-file-mode}, called interactively, toggles +the local value of @code{create-lockfiles} in the current buffer. + @node File Shadowing @subsection Shadowing Files @cindex shadow files diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index 1f4049f715c..c7e5537c10c 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi @@ -826,6 +826,11 @@ You can prevent the creation of remote lock files by setting the variable @code{remote-file-name-inhibit-locks} to @code{t}. @end defopt +@deffn Command lock-file-mode +This command, called interactively, toggles the local value of +@code{create-lockfiles} in the current buffer. +@end deffn + @node Information about Files @section Information about Files @cindex file, information about diff --git a/etc/NEWS b/etc/NEWS index e18b3d04aa4..4bfb5b4d165 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2191,6 +2191,22 @@ Shift while typing 'C-a', i.e. 'C-S-a', will now highlight the text. If the 'EMACS_TEST_VERBOSE' environment variable is set, failure summaries will include the failing condition. +** File Locks + ++++ +*** New user option 'lock-file-name-transforms'. +This option allows controlling where lock files are written. It uses +the same syntax as 'auto-save-file-name-transforms'. + ++++ +*** New user option 'remote-file-name-inhibit-locks'. +When non-nil, this option suppresses lock files for remote files. + ++++ +*** New minor mode 'lock-file-mode'. +This command, called interactively, toggles the local value of +'create-lockfiles' in the current buffer. + ** Miscellaneous --- @@ -2209,15 +2225,6 @@ will now restore the original order. This is like 'insert-buffer-substring', but works in the opposite direction. -+++ -*** New user option 'lock-file-name-transforms'. -This option allows controlling where lock files are written. It uses -the same syntax as 'auto-save-file-name-transforms'. - -+++ -*** New user option 'remote-file-name-inhibit-locks'. -When non-nil, this option suppresses lock files for remote files. - +++ *** New user option 'kill-transform-function'. This can be used to transform (and suppress) strings from entering the diff --git a/lisp/files.el b/lisp/files.el index 862982b71df..8ccf9a9c75a 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -412,26 +412,6 @@ ignored." :initialize 'custom-initialize-delay :version "21.1") -(defcustom lock-file-name-transforms nil - "Transforms to apply to buffer file name before making a lock file name. -This has the same syntax as -`auto-save-file-name-transforms' (which see), but instead of -applying to auto-save file names, it's applied to lock file names. - -By default, a lock file is put into the same directory as the -file it's locking, and it has the same name, but with \".#\" prepended." - :group 'files - :type '(repeat (list (regexp :tag "Regexp") - (string :tag "Replacement") - (boolean :tag "Uniquify"))) - :version "28.1") - -(defcustom remote-file-name-inhibit-locks nil - "Whether to use file locks for remote files." - :group 'files - :version "28.1" - :type 'boolean) - (defvar auto-save--timer nil "Timer for `auto-save-visited-mode'.") (defcustom auto-save-visited-interval 5 @@ -485,6 +465,32 @@ If `silently', don't ask the user before saving." :type '(choice (const t) (const nil) (const silently)) :group 'abbrev) +(defcustom lock-file-name-transforms nil + "Transforms to apply to buffer file name before making a lock file name. +This has the same syntax as +`auto-save-file-name-transforms' (which see), but instead of +applying to auto-save file names, it's applied to lock file names. + +By default, a lock file is put into the same directory as the +file it's locking, and it has the same name, but with \".#\" prepended." + :group 'files + :type '(repeat (list (regexp :tag "Regexp") + (string :tag "Replacement") + (boolean :tag "Uniquify"))) + :initialize 'custom-initialize-delay + :version "28.1") + +(defcustom remote-file-name-inhibit-locks nil + "Whether to use file locks for remote files." + :group 'files + :version "28.1" + :type 'boolean) + +(define-minor-mode lock-file-mode + "Toggle file locking in the current buffer (Lock File mode)." + :version "28.1" + (setq-local create-lockfiles (and lock-file-mode t))) + (defcustom find-file-run-dired t "Non-nil means allow `find-file' to visit directories. To visit the directory, `find-file' runs `find-directory-functions'." -- 2.39.2