[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/posframe 330cae2 15/40: Improve 'posframe-delete-frame'

From: Feng Shu
Subject: [elpa] externals/posframe 330cae2 15/40: Improve 'posframe-delete-frame'
Date: Wed, 5 Feb 2020 04:27:18 -0500 (EST)

branch: externals/posframe
commit 330cae28b23af3bcf64d2e643cb44a6203e1082a
Author: Štěpán Němec <address@hidden>
Commit: Štěpán Němec <address@hidden>

    Improve 'posframe-delete-frame'
    We don't need to walk the frame list, because every posframe + buffer
    pair is unique; there is at most one posframe for a single buffer, and
    at most one buffer for a single posframe.
    We also don't need to check the frame parameters, as the
    posframe--frame buffer-local variable records the pertinent frame.
 posframe.el | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/posframe.el b/posframe.el
index d41a7f4..ea0892f 100644
--- a/posframe.el
+++ b/posframe.el
@@ -130,6 +130,7 @@
 ;;; Code:
 ;; * posframe's code                         :CODE:
 (require 'cl-lib)
+(eval-when-compile (require 'subr-x))   ; `when-let'
 (defgroup posframe nil
   "Pop a posframe (just a frame) at point"
@@ -677,20 +678,15 @@ WIDTH and MIN-WIDTH."
   (posframe--kill-buffer buffer-or-name))
 (defun posframe-delete-frame (buffer-or-name)
-  "Kill child-frame of posframe.
-This posframe's buffer is BUFFER-OR-NAME."
-  (dolist (frame (frame-list))
-    (let ((buffer-info (frame-parameter frame 'posframe-buffer))
-          (buffer (get-buffer buffer-or-name)))
-      (when (or (equal buffer-or-name (car buffer-info))
-                (equal buffer-or-name (cdr buffer-info)))
-        (when buffer
-          (with-current-buffer buffer
-            (dolist (timer '(posframe--refresh-timer
-                             posframe--timeout-timer))
-              (when (timerp timer)
-                (cancel-timer timer)))))
-        (delete-frame frame)))))
+  "Delete posframe pertaining to BUFFER-OR-NAME."
+  (when-let ((buffer (get-buffer buffer-or-name)))
+    (with-current-buffer buffer
+      (dolist (timer '(posframe--refresh-timer
+                       posframe--timeout-timer))
+        (when (timerp timer)
+          (cancel-timer timer)))
+      (when (frame-live-p posframe--frame)
+        (delete-frame posframe--frame)))))
 (defun posframe--kill-buffer (buffer-or-name)
   "Kill posframe's buffer: BUFFER-OR-NAME."

reply via email to

[Prev in Thread] Current Thread [Next in Thread]