- (if lock-emacs-from-exiting
- (setq lock-emacs-from-exiting nil)
- (setq lock-emacs-from-exiting t))
- (if lock-emacs-from-exiting
- (message "Emacs is now locked from exiting.")
- (message "Emacs is now unlocked.")))
+ (if emacs-lock-from-exiting
+ (setq emacs-lock-from-exiting nil)
+ (setq emacs-lock-from-exiting t))
+ (if emacs-lock-from-exiting
+ (message "Buffer is now locked")
+ (message "Buffer is now unlocked")))
+
+(defun emacs-lock-check-buffer-lock ()
+ "Check if variable `emacs-lock-from-exiting' is t for a buffer.
+If t is found, signal error and display the locked buffer name."
+ (if emacs-lock-from-exiting
+ (error "Buffer `%s' is locked, can't delete it" (buffer-name))))
+
+; These next defuns make it so if you exit a shell that is locked, the lock
+; is shut off for that shell so you can exit emacs. Same for telnet.
+; Also, if a shell or a telnet buffer was locked and the process killed,
+; turn the lock back on again if the process is restarted.
+
+(defun emacs-lock-shell-sentinel ()
+ (set-process-sentinel
+ (get-buffer-process (buffer-name)) (function emacs-lock-clear-sentinel)))
+
+(defun emacs-lock-clear-sentinel (proc str)
+ (if emacs-lock-from-exiting
+ (progn
+ (setq emacs-lock-from-exiting nil)
+ (setq emacs-lock-buffer-locked t)
+ (message "Buffer is now unlocked"))
+ (setq emacs-lock-buffer-locked nil)))
+
+(defun emacs-lock-was-buffer-locked ()
+ (if emacs-lock-buffer-locked
+ (setq emacs-lock-from-exiting t)))