mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2024-12-13 09:32:47 +00:00
739e3dbe05
* lisp/allout.el (allout-abbreviate-flattened-numbering) (allout-mode-deactivate-hook): * lisp/ansi-color.el (ansi-color-unfontify-region): * lisp/auth-source.el (auth-source-hide-passwords) (auth-source-user-or-password) (auth-source-forget-user-or-password): * lisp/cedet/data-debug.el (data-debug-map): * lisp/cedet/semantic/grammar.el (semantic-grammar-syntax-table) (semantic-grammar-map): * lisp/chistory.el (command-history-map): * lisp/comint.el (comint-dynamic-complete) (comint-dynamic-complete-as-filename) (comint-dynamic-simple-complete): * lisp/dired-x.el (read-filename-at-point) (dired-x-submit-report): * lisp/dos-fns.el (register-name-alist, make-register) (register-value, set-register-value, intdos, mode25, mode4350): * lisp/emacs-lisp/bytecomp.el (byte-compile-disable-print-circle): * lisp/emacs-lisp/chart.el (chart-map): * lisp/emacs-lisp/package.el (package-menu-view-commentary): * lisp/emacs-lock.el (toggle-emacs-lock, emacs-lock-from-exiting): * lisp/erc/erc.el (erc-complete-word): * lisp/eshell/em-cmpl.el (eshell-cmpl-suffix-list): * lisp/eshell/esh-util.el (eshell-for): * lisp/files.el (inhibit-first-line-modes-regexps) (inhibit-first-line-modes-suffixes): * lisp/gnus/gnus-msg.el (gnus-outgoing-message-group) (gnus-debug-files, gnus-debug-exclude-variables): * lisp/gnus/gnus-registry.el (gnus-registry-user-format-function-M): * lisp/gnus/gnus.el (gnus-local-domain, gnus-carpal): * lisp/gnus/nnimap.el (nnimap-split-rule): * lisp/iimage.el (turn-on-iimage-mode): * lisp/image.el (image-extension-data, image-library-alist): * lisp/mail/emacsbug.el (report-emacs-bug-pretest-address): * lisp/mail/mail-utils.el (rmail-dont-reply-to): * lisp/mail/mailalias.el (mail-complete-function) (mail-completion-at-point-function): * lisp/mail/rmail.el (rmail-dont-reply-to-names) (rmail-default-dont-reply-to-names): * lisp/mail/sendmail.el (mail-mailer-swallows-blank-line) (mail-sent-via): * lisp/menu-bar.el (menu-bar-kill-ring-save): * lisp/minibuffer.el (completion-annotate-function) (minibuffer-local-filename-must-match-map): * lisp/msb.el (msb-after-load-hooks): * lisp/obsolete/eieio-compat.el (eieio-defmethod) (eieio-defgeneric): * lisp/obsolete/info-edit.el (Info-edit-map): * lisp/obsolete/starttls.el (starttls-any-program-available): * lisp/progmodes/cfengine.el (cfengine-mode-abbrevs): * lisp/progmodes/cwarn.el (turn-on-cwarn-mode): * lisp/progmodes/make-mode.el (makefile-complete): * lisp/progmodes/meta-mode.el (meta-complete-symbol) (meta-mode-map): * lisp/progmodes/pascal.el (pascal-toggle-completions) (pascal-last-completions, pascal-show-completions): * lisp/progmodes/prolog.el (prolog-char-quote-workaround): * lisp/progmodes/which-func.el (which-func-mode): [FUNCTION] * lisp/simple.el (count-lines-region, minibuffer-completing-symbol): * lisp/speedbar.el (speedbar-syntax-table, speedbar-key-map): * lisp/strokes.el (strokes-report-bug): * lisp/subr.el (condition-case-no-debug): * lisp/term/ns-win.el (ns-alternatives-map) (ns-store-cut-buffer-internal): * lisp/term/w32-win.el (w32-default-color-map): * lisp/term/x-win.el (x-cut-buffer-or-selection-value): * lisp/textmodes/bibtex.el (bibtex-complete) (bibtex-entry-field-alist): * lisp/textmodes/reftex-index.el (reftex-index-map) (reftex-index-phrases-map): * lisp/textmodes/reftex-sel.el (reftex-select-label-map) (reftex-select-bib-map): * lisp/textmodes/reftex-toc.el (reftex-toc-map): * lisp/textmodes/rst.el (rst-block-face, rst-external-face) (rst-definition-face, rst-directive-face, rst-comment-face) (rst-emphasis1-face, rst-emphasis2-face, rst-literal-face) (rst-reference-face): * lisp/vc/vc-hooks.el (vc-toggle-read-only): * lisp/view.el (view-return-to-alist) (view-return-to-alist-update): Remove many functions and variables obsolete since 24.1. * lisp/textmodes/bibtex.el (bibtex-entry-alist): Don't use above removed variable 'bibtex-entry-field-alist'. * lisp/cedet/data-debug.el (data-debug-edebug-expr) (data-debug-eval-expression): * lisp/emacs-lisp/trace.el (trace--read-args): * lisp/files-x.el (read-file-local-variable-value): * lisp/simple.el (read--expression): Don't use above removed variable 'minibuffer-completing-symbol'. * lisp/textmodes/rst.el (rst-font-lock-keywords): Don't use above removed variables. * src/w32fns.c (Fw32_default_color_map): Delete obsolete function. (syms_of_w32fns): Delete defsubr for above defun. * src/keyboard.c (syms_of_keyboard) <Vdeferred_action_list> <Vdeferred_action_function>: Delete DEFVARs. <Qdeferred_action_function>: Delete DEFSYM. (syms_of_keyboard_for_pdumper): Adjust for above change. (command_loop_1): Don't run deferred-action-function hook. * lisp/subr.el (deferred-action-list, deferred-action-function): Delete obsoletion statements. * lisp/emacs-lisp/ert-x.el (ert-simulate-command): Don't run 'deferred-action-list' hook. * doc/lispref/hooks.texi (Standard Hooks): Delete 'deferred-action-function'. * lisp/emacs-lisp/lisp.el (field-complete): * lisp/eshell/em-cmpl.el (eshell-cmpl-initialize): * lisp/gnus/gnus-msg.el (gnus-inews-insert-gcc): * lisp/gnus/nnmail.el (nnmail-fancy-expiry-target): * lisp/mail/mail-utils.el (mail-dont-reply-to): * lisp/mail/sendmail.el (sendmail-send-it): * lisp/mail/smtpmail.el (smtpmail-send-it): * lisp/minibuffer.el (minibuffer-completion-help): * lisp/progmodes/python.el: Don't use above removed items. * lisp/emacs-lisp/eieio-core.el: * lisp/mail/mailalias.el (mail-complete-alist): Doc fixes; don't refer to above removed items. ; * etc/NEWS: List removed items.
250 lines
9.7 KiB
EmacsLisp
250 lines
9.7 KiB
EmacsLisp
;;; emacs-lock.el --- protect buffers against killing or exiting -*- lexical-binding: t -*-
|
|
|
|
;; Copyright (C) 2011-2022 Free Software Foundation, Inc.
|
|
|
|
;; Author: Juanma Barranquero <lekktu@gmail.com>
|
|
;; Inspired by emacs-lock.el by Tom Wurgler <twurgler@goodyear.com>
|
|
;; Maintainer: emacs-devel@gnu.org
|
|
;; Keywords: extensions, processes
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;; This package defines a minor mode Emacs Lock to mark a buffer as
|
|
;; protected against accidental killing, or exiting Emacs, or both.
|
|
;; Buffers associated with inferior modes, like shell or telnet, can
|
|
;; be treated specially, by auto-unlocking them if their inferior
|
|
;; processes are dead.
|
|
|
|
;;; Code:
|
|
|
|
(defgroup emacs-lock nil
|
|
"Emacs-Lock mode."
|
|
:version "24.1"
|
|
:group 'convenience)
|
|
|
|
(defcustom emacs-lock-default-locking-mode 'all
|
|
"Default locking mode of Emacs-Locked buffers.
|
|
|
|
Its value is used as the default for `emacs-lock-mode' (which
|
|
see) the first time that Emacs Lock mode is turned on in a buffer
|
|
without passing an explicit locking mode.
|
|
|
|
Possible values are:
|
|
exit -- Emacs cannot exit while the buffer is locked
|
|
kill -- the buffer cannot be killed, but Emacs can exit as usual
|
|
all -- the buffer is locked against both actions
|
|
nil -- the buffer is not locked"
|
|
:type '(choice
|
|
(const :tag "Do not allow Emacs to exit" exit)
|
|
(const :tag "Do not allow killing the buffer" kill)
|
|
(const :tag "Do not allow killing the buffer or exiting Emacs" all)
|
|
(const :tag "Do not lock the buffer" nil))
|
|
:group 'emacs-lock
|
|
:version "24.1")
|
|
|
|
;; Note: as auto-unlocking can lead to data loss, it would be better
|
|
;; to default to nil; but the value below is for compatibility with
|
|
;; the old emacs-lock.el.
|
|
(defcustom emacs-lock-unlockable-modes '((shell-mode . all)
|
|
(telnet-mode . all))
|
|
"Alist of auto-unlockable modes.
|
|
Each element is a pair (MAJOR-MODE . ACTION), where ACTION is
|
|
one of `kill', `exit' or `all'. Buffers with matching major
|
|
modes are auto-unlocked for the specific action if their
|
|
inferior processes are not alive. If this variable is t, all
|
|
buffers associated to inferior processes are auto-unlockable
|
|
for both actions (NOT RECOMMENDED)."
|
|
:type '(choice
|
|
(const :tag "All buffers with inferior processes" t)
|
|
(repeat :tag "Selected modes"
|
|
(cons :tag "Set auto-unlock for"
|
|
(symbol :tag "Major mode")
|
|
(radio
|
|
(const :tag "Allow exiting" exit)
|
|
(const :tag "Allow killing" kill)
|
|
(const :tag "Allow both" all)))))
|
|
:group 'emacs-lock
|
|
:version "24.1")
|
|
|
|
(defcustom emacs-lock-locked-buffer-functions nil
|
|
"Abnormal hook run when Emacs Lock prevents exiting Emacs, or killing a buffer.
|
|
The functions get one argument, the first locked buffer found."
|
|
:type 'hook
|
|
:group 'emacs-lock
|
|
:version "24.3")
|
|
|
|
(defvar-local emacs-lock-mode nil
|
|
"If non-nil, the current buffer is locked.
|
|
It can be one of the following values:
|
|
exit -- Emacs cannot exit while the buffer is locked
|
|
kill -- the buffer cannot be killed, but Emacs can exit as usual
|
|
all -- the buffer is locked against both actions
|
|
nil -- the buffer is not locked
|
|
|
|
See also `emacs-lock-unlockable-modes', which exempts buffers under
|
|
some major modes from being locked under some circumstances.")
|
|
(put 'emacs-lock-mode 'permanent-local t)
|
|
|
|
(defvar-local emacs-lock--old-mode nil
|
|
"Most recent locking mode set on the buffer.
|
|
Internal use only.")
|
|
(put 'emacs-lock--old-mode 'permanent-local t)
|
|
|
|
(defvar-local emacs-lock--try-unlocking nil
|
|
"Non-nil if current buffer should be checked for auto-unlocking.
|
|
Internal use only.")
|
|
(put 'emacs-lock--try-unlocking 'permanent-local t)
|
|
|
|
(defun emacs-lock-live-process-p (buffer-or-name)
|
|
"Return t if BUFFER-OR-NAME is associated with a live process."
|
|
(and (process-live-p (get-buffer-process buffer-or-name)) t))
|
|
|
|
(defun emacs-lock--can-auto-unlock (action)
|
|
"Return t if the current buffer can auto-unlock for ACTION.
|
|
ACTION must be one of `kill' or `exit'.
|
|
See `emacs-lock-unlockable-modes'."
|
|
(and emacs-lock--try-unlocking
|
|
(not (emacs-lock-live-process-p (current-buffer)))
|
|
(or (eq emacs-lock-unlockable-modes t)
|
|
(let ((unlock (cdr (assq major-mode emacs-lock-unlockable-modes))))
|
|
(or (eq unlock 'all) (eq unlock action))))))
|
|
|
|
(defun emacs-lock--exit-locked-buffer ()
|
|
"Return the first exit-locked buffer found."
|
|
(save-current-buffer
|
|
(catch :found
|
|
(dolist (buffer (buffer-list))
|
|
(set-buffer buffer)
|
|
(unless (or (emacs-lock--can-auto-unlock 'exit)
|
|
(memq emacs-lock-mode '(nil kill)))
|
|
(throw :found buffer)))
|
|
nil)))
|
|
|
|
(defun emacs-lock--kill-emacs-hook ()
|
|
"Signal an error if any buffer is exit-locked.
|
|
Used from `kill-emacs-hook' (which see)."
|
|
(let ((locked (emacs-lock--exit-locked-buffer)))
|
|
(when locked
|
|
(run-hook-with-args 'emacs-lock-locked-buffer-functions locked)
|
|
(error "Emacs cannot exit because buffer %S is locked"
|
|
(buffer-name locked)))))
|
|
|
|
(defun emacs-lock--kill-emacs-query-functions ()
|
|
"Display a message if any buffer is exit-locked.
|
|
Return a value appropriate for `kill-emacs-query-functions' (which see)."
|
|
(let ((locked (emacs-lock--exit-locked-buffer)))
|
|
(if (not locked)
|
|
t
|
|
(run-hook-with-args 'emacs-lock-locked-buffer-functions locked)
|
|
(message "Emacs cannot exit because buffer %S is locked"
|
|
(buffer-name locked))
|
|
nil)))
|
|
|
|
(defun emacs-lock--kill-buffer-query-functions ()
|
|
"Display a message if the current buffer is kill-locked.
|
|
Return a value appropriate for `kill-buffer-query-functions' (which see)."
|
|
(if (or (emacs-lock--can-auto-unlock 'kill)
|
|
(memq emacs-lock-mode '(nil exit)))
|
|
t
|
|
(run-hook-with-args 'emacs-lock-locked-buffer-functions (current-buffer))
|
|
(message "Buffer %S is locked and cannot be killed" (buffer-name))
|
|
nil))
|
|
|
|
(defun emacs-lock--set-mode (mode arg)
|
|
"Setter function for `emacs-lock-mode'."
|
|
(setq emacs-lock-mode
|
|
(cond ((memq arg '(all exit kill))
|
|
;; explicit locking mode arg, use it
|
|
arg)
|
|
((and (eq arg current-prefix-arg) (consp current-prefix-arg))
|
|
;; called with C-u M-x emacs-lock-mode, so ask the user
|
|
(intern (completing-read
|
|
(format-prompt "Locking mode"
|
|
emacs-lock-default-locking-mode)
|
|
'("all" "exit" "kill")
|
|
nil t nil nil
|
|
(symbol-name emacs-lock-default-locking-mode))))
|
|
((eq mode t)
|
|
;; turn on, so use previous setting, or customized default
|
|
(or emacs-lock--old-mode emacs-lock-default-locking-mode))
|
|
(t
|
|
;; anything else (turn off)
|
|
mode))))
|
|
|
|
;;;###autoload
|
|
(define-minor-mode emacs-lock-mode
|
|
"Toggle Emacs Lock mode in the current buffer.
|
|
If called with a plain prefix argument, ask for the locking mode
|
|
to be used.
|
|
|
|
Initially, if the user does not pass an explicit locking mode, it
|
|
defaults to `emacs-lock-default-locking-mode' (which see);
|
|
afterwards, the locking mode most recently set on the buffer is
|
|
used instead.
|
|
|
|
When called from Elisp code, ARG can be any locking mode:
|
|
|
|
exit -- Emacs cannot exit while the buffer is locked
|
|
kill -- the buffer cannot be killed, but Emacs can exit as usual
|
|
all -- the buffer is locked against both actions
|
|
|
|
Other values are interpreted as usual.
|
|
|
|
See also `emacs-lock-unlockable-modes', which exempts buffers under
|
|
some major modes from being locked under some circumstances."
|
|
:init-value nil
|
|
:lighter (""
|
|
(emacs-lock--try-unlocking " locked:" " Locked:")
|
|
(:eval (symbol-name emacs-lock-mode)))
|
|
:group 'emacs-lock
|
|
:variable (emacs-lock-mode .
|
|
(lambda (mode)
|
|
(emacs-lock--set-mode mode arg)))
|
|
(when emacs-lock-mode
|
|
(setq emacs-lock--old-mode emacs-lock-mode)
|
|
(setq emacs-lock--try-unlocking
|
|
(and (if (eq emacs-lock-unlockable-modes t)
|
|
(emacs-lock-live-process-p (current-buffer))
|
|
(assq major-mode emacs-lock-unlockable-modes))
|
|
t))))
|
|
|
|
(unless noninteractive
|
|
(add-hook 'kill-buffer-query-functions 'emacs-lock--kill-buffer-query-functions)
|
|
;; We set a hook in both kill-emacs-hook and kill-emacs-query-functions because
|
|
;; we really want to use k-e-q-f to stop as soon as possible, but don't want to
|
|
;; be caught by surprise if someone calls `kill-emacs' instead.
|
|
(add-hook 'kill-emacs-hook 'emacs-lock--kill-emacs-hook)
|
|
(add-hook 'kill-emacs-query-functions 'emacs-lock--kill-emacs-query-functions))
|
|
|
|
(defun emacs-lock-unload-function ()
|
|
"Unload the Emacs Lock library."
|
|
(catch :continue
|
|
(dolist (buffer (buffer-list))
|
|
(set-buffer buffer)
|
|
(when emacs-lock-mode
|
|
(if (y-or-n-p (format "Buffer %S is locked, unlock it? " (buffer-name)))
|
|
(emacs-lock-mode -1)
|
|
(message "Unloading of feature `emacs-lock' aborted.")
|
|
(throw :continue t))))
|
|
;; continue standard unloading
|
|
nil))
|
|
|
|
(provide 'emacs-lock)
|
|
|
|
;;; emacs-lock.el ends here
|