aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Colascione2018-06-11 16:54:23 -0700
committerDaniel Colascione2018-06-11 16:54:23 -0700
commit0626d5aba518a6d22ffacd7a1e3f4c70d7248e5f (patch)
tree8ed6504f2530faa7ed7cd768181cb5fabfc00700
parent4ff438a45a5d3e380622ceaf4b9aa93cf89be4c8 (diff)
downloademacs-0626d5aba518a6d22ffacd7a1e3f4c70d7248e5f.tar.gz
emacs-0626d5aba518a6d22ffacd7a1e3f4c70d7248e5f.zip
Add after-delete-frame-functions
Instead of working around the behavior delete-frame-functions, just add an after-delete-frame-functions hook. * doc/lispref/frames.texi (Deleting Frames): Document `after-delete-frame-functions'. * etc/NEWS: Mention `after-delete-frame-functions'. * lisp/frame.el (blink-cursor--should-blink): (blink-cursor--rescan-frames, blink-frame-mode): Get rid of the ugly ignored-frame parameter and switch from `delete-frame-functions' to `after-delete-frame-functions'. * src/frame.c (syms_of_frame): New variable `after-delete-frame-functions'. (delete_frame): Use it.
-rw-r--r--doc/lispref/frames.texi5
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/frame.el27
-rw-r--r--src/frame.c18
4 files changed, 38 insertions, 18 deletions
diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi
index 3a97ec01384..5e8b5b46d5d 100644
--- a/doc/lispref/frames.texi
+++ b/doc/lispref/frames.texi
@@ -2530,6 +2530,7 @@ it.
2530 2530
2531@deffn Command delete-frame &optional frame force 2531@deffn Command delete-frame &optional frame force
2532@vindex delete-frame-functions 2532@vindex delete-frame-functions
2533@vindex after-delete-frame-functions
2533This function deletes the frame @var{frame}. The argument @var{frame} 2534This function deletes the frame @var{frame}. The argument @var{frame}
2534must specify a live frame (see below) and defaults to the selected 2535must specify a live frame (see below) and defaults to the selected
2535frame. 2536frame.
@@ -2541,7 +2542,9 @@ performed recursively; so this step makes sure that no other frames with
2541@var{frame} as their ancestor will exist. Then, unless @var{frame} 2542@var{frame} as their ancestor will exist. Then, unless @var{frame}
2542specifies a tooltip, this function runs the hook 2543specifies a tooltip, this function runs the hook
2543@code{delete-frame-functions} (each function getting one argument, 2544@code{delete-frame-functions} (each function getting one argument,
2544@var{frame}) before actually killing the frame. 2545@var{frame}) before actually killing the frame. After actually killing
2546the frame and removing the frame from the frame list, @code{delete-frame}
2547runs @code{after-delete-frame-functions}.
2545 2548
2546Note that a frame cannot be deleted as long as its minibuffer serves as 2549Note that a frame cannot be deleted as long as its minibuffer serves as
2547surrogate minibuffer for another frame (@pxref{Minibuffers and Frames}). 2550surrogate minibuffer for another frame (@pxref{Minibuffers and Frames}).
diff --git a/etc/NEWS b/etc/NEWS
index 7b14b9f8960..402dcb13c7f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -583,6 +583,12 @@ manual for more details.
583* Lisp Changes in Emacs 27.1 583* Lisp Changes in Emacs 27.1
584 584
585+++ 585+++
586** New hook `after-delete-frame-functions'. Works like
587 `delete-frame-functions', but runs after the frame to be deleted
588 has been made dead and removed from the frame list, simplifying
589 some kinds of code.
590
591+++
586** New focus state inspection interface: `focus-in-hook' and 592** New focus state inspection interface: `focus-in-hook' and
587 `focus-out-hook' are marked obsolete. Instead, attach to 593 `focus-out-hook' are marked obsolete. Instead, attach to
588 `after-focus-change-function' using `add-function' and inspect the 594 `after-focus-change-function' using `add-function' and inspect the
diff --git a/lisp/frame.el b/lisp/frame.el
index a0e7b35a138..38f785901e7 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -2416,40 +2416,33 @@ frame receives focus."
2416 (cancel-timer blink-cursor-idle-timer) 2416 (cancel-timer blink-cursor-idle-timer)
2417 (setq blink-cursor-idle-timer nil))) 2417 (setq blink-cursor-idle-timer nil)))
2418 2418
2419(defun blink-cursor--should-blink (&optional ignored-frame) 2419(defun blink-cursor--should-blink ()
2420 "Determine whether we should be blinking. 2420 "Determine whether we should be blinking.
2421Returns whether we have any focused non-TTY frame. IGNORED-FRAME 2421Returns whether we have any focused non-TTY frame."
2422is a frame to ignore during the scan, used when we want to ignore
2423a frame about to be deleted."
2424 (and blink-cursor-mode 2422 (and blink-cursor-mode
2425 (let ((frame-list (frame-list)) 2423 (let ((frame-list (frame-list))
2426 (any-graphical-focused nil)) 2424 (any-graphical-focused nil))
2427 (while frame-list 2425 (while frame-list
2428 (let ((frame (pop frame-list))) 2426 (let ((frame (pop frame-list)))
2429 (when (and (not (eq frame ignored-frame)) 2427 (when (and (display-graphic-p frame) (frame-focus-state frame))
2430 (display-graphic-p frame)
2431 (frame-focus-state frame))
2432 (setf any-graphical-focused t) 2428 (setf any-graphical-focused t)
2433 (setf frame-list nil)))) 2429 (setf frame-list nil))))
2434 any-graphical-focused))) 2430 any-graphical-focused)))
2435 2431
2436(defun blink-cursor-check (&optional ignored-frame) 2432(defun blink-cursor-check ()
2437 "Check if cursor blinking shall be restarted. 2433 "Check if cursor blinking shall be restarted.
2438This is done when a frame gets focus. Blink timers may be 2434This is done when a frame gets focus. Blink timers may be
2439stopped by `blink-cursor-suspend'. Internally calls 2435stopped by `blink-cursor-suspend'. Internally calls
2440`blink-cursor--should-blink' and returns its result." 2436`blink-cursor--should-blink' and returns its result."
2441 (let ((should-blink (blink-cursor--should-blink ignored-frame))) 2437 (let ((should-blink (blink-cursor--should-blink)))
2442 (when (and should-blink (not blink-cursor-idle-timer)) 2438 (when (and should-blink (not blink-cursor-idle-timer))
2443 (remove-hook 'post-command-hook 'blink-cursor-check) 2439 (remove-hook 'post-command-hook 'blink-cursor-check)
2444 (blink-cursor--start-idle-timer)) 2440 (blink-cursor--start-idle-timer))
2445 should-blink)) 2441 should-blink))
2446 2442
2447(defun blink-cursor--rescan-frames (&optional ignored-frame) 2443(defun blink-cursor--rescan-frames (&optional _ign)
2448 "Called when the set of focused frames changes or when we 2444 "Called when the set of focused frames changes or when we delete a frame."
2449delete a frame. Re-check whether we want to enable blinking. 2445 (unless (blink-cursor-check)
2450IGNORED-FRAME is there so we ignore a frame about to be deleted
2451when we're called under via `delete-frame-functions'."
2452 (unless (blink-cursor-check ignored-frame)
2453 (blink-cursor-suspend))) 2446 (blink-cursor-suspend)))
2454 2447
2455(define-minor-mode blink-cursor-mode 2448(define-minor-mode blink-cursor-mode
@@ -2474,11 +2467,11 @@ terminals, cursor blinking is controlled by the terminal."
2474 :group 'cursor 2467 :group 'cursor
2475 :global t 2468 :global t
2476 (blink-cursor-suspend) 2469 (blink-cursor-suspend)
2477 (remove-hook 'delete-frame-functions #'blink-cursor--rescan-frames) 2470 (remove-hook 'after-delete-frame-functions #'blink-cursor--rescan-frames)
2478 (remove-function after-focus-change-function #'blink-cursor--rescan-frames) 2471 (remove-function after-focus-change-function #'blink-cursor--rescan-frames)
2479 (when blink-cursor-mode 2472 (when blink-cursor-mode
2480 (add-function :after after-focus-change-function #'blink-cursor--rescan-frames) 2473 (add-function :after after-focus-change-function #'blink-cursor--rescan-frames)
2481 (add-hook 'delete-frame-functions #'blink-cursor--rescan-frames) 2474 (add-hook 'after-delete-frame-functions #'blink-cursor--rescan-frames)
2482 (blink-cursor--start-idle-timer))) 2475 (blink-cursor--start-idle-timer)))
2483 2476
2484 2477
diff --git a/src/frame.c b/src/frame.c
index bf0269292d6..d477c1acc3f 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -2161,6 +2161,16 @@ delete_frame (Lisp_Object frame, Lisp_Object force)
2161 if (!is_tooltip_frame) 2161 if (!is_tooltip_frame)
2162 update_mode_lines = 15; 2162 update_mode_lines = 15;
2163 2163
2164 /* Now run the post-deletion hooks. */
2165 if (NILP (Vrun_hooks) || is_tooltip_frame)
2166 ;
2167 else if (EQ (force, Qnoelisp))
2168 pending_funcalls
2169 = Fcons (list3 (Qrun_hook_with_args, Qafter_delete_frame_functions, frame),
2170 pending_funcalls);
2171 else
2172 safe_call2 (Qrun_hook_with_args, Qafter_delete_frame_functions, frame);
2173
2164 return Qnil; 2174 return Qnil;
2165} 2175}
2166 2176
@@ -5897,6 +5907,14 @@ recursively). */);
5897 Vdelete_frame_functions = Qnil; 5907 Vdelete_frame_functions = Qnil;
5898 DEFSYM (Qdelete_frame_functions, "delete-frame-functions"); 5908 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5899 5909
5910 DEFVAR_LISP ("after-delete-frame-functions",
5911 Vafter_delete_frame_functions,
5912 doc: /* Functions run after deleting a frame.
5913The functions are run with one arg, the frame that was deleted and
5914which is now dead. */);
5915 Vafter_delete_frame_functions = Qnil;
5916 DEFSYM (Qafter_delete_frame_functions, "after-delete-frame-functions");
5917
5900 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode, 5918 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5901 doc: /* Non-nil if Menu-Bar mode is enabled. 5919 doc: /* Non-nil if Menu-Bar mode is enabled.
5902See the command `menu-bar-mode' for a description of this minor mode. 5920See the command `menu-bar-mode' for a description of this minor mode.