[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/iwindow 13b9c558bf 11/13: Replace cl-labels with named-let
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/iwindow 13b9c558bf 11/13: Replace cl-labels with named-let, use Compat if needed |
Date: |
Sun, 27 Nov 2022 16:01:13 -0500 (EST) |
branch: elpa/iwindow
commit 13b9c558bf213c688ade003be9cc3d6f7fc7d1ae
Author: Akib Azmain Turja <akib@disroot.org>
Commit: Akib Azmain Turja <akib@disroot.org>
Replace cl-labels with named-let, use Compat if needed
---
iwindow.el | 167 ++++++++++++++++++++++++++++++-------------------------------
1 file changed, 81 insertions(+), 86 deletions(-)
diff --git a/iwindow.el b/iwindow.el
index cd8d166f8b..ff690430f6 100644
--- a/iwindow.el
+++ b/iwindow.el
@@ -5,7 +5,7 @@
;; Author: Akib Azmain Turja <akib@disroot.org>
;; Created: 2022-07-31
;; Version: 0.1
-;; Package-Requires: ((emacs "26.1"))
+;; Package-Requires: ((emacs "26.1") (compat "28.1.2.2"))
;; Keywords: frames
;; URL: https://codeberg.org/akib/emacs-iwindow
@@ -45,6 +45,7 @@
;;; Code:
+(require 'compat)
(require 'cl-lib)
(defgroup iwindow nil
@@ -126,28 +127,27 @@ list of form (OPTION...), whose length of no more than
the length of
(let ((current-window (selected-window))
(windows nil)
(decorators nil))
- (cl-labels ((walk
- (tree keys)
- (if (windowp tree)
- (push (cons tree (reverse keys))
- windows)
- (seq-map-indexed
- (lambda (node index)
- (walk node
- (cons (nth index iwindow-selection-keys)
- keys)))
- tree))))
- (walk tree nil))
+ (named-let walk ((tree tree)
+ (keys nil))
+ ;; This doesn't benefit from tail call optimization.
+ (if (windowp tree)
+ (push (cons tree (reverse keys))
+ windows)
+ (seq-map-indexed
+ (lambda (node index)
+ (walk node
+ (cons (nth index iwindow-selection-keys)
+ keys)))
+ tree)))
(run-hook-wrapped 'iwindow-decoration-functions
(lambda (fn) (ignore (push fn decorators))))
- (cl-labels ((call-decorators (fns)
- (with-selected-window current-window
- (if fns
- (funcall (car fns) windows
- (lambda ()
- (call-decorators (cdr fns))))
- (funcall payload)))))
- (call-decorators (nreverse decorators)))))
+ (named-let call-decorators ((fns (nreverse decorators)))
+ ;; This doesn't benefit from tail call optimization.
+ (with-selected-window current-window
+ (if fns
+ (funcall (car fns) windows
+ (lambda () (call-decorators (cdr fns))))
+ (funcall payload))))))
(defun iwindow--ask (tree)
"Given decision tree TREE, ask user for the decision.
@@ -202,25 +202,24 @@ WINDOW and ignore WINDOW when PREDICATE returns nil."
WINDOWS and CALLBACK is described in the docstring of
`iwindow-decoration-functions', which see."
(let ((original-mode-lines nil))
- (cl-labels ((setup-windows (window-list)
- (with-selected-window (caar window-list)
- (unless (assq (current-buffer) original-mode-lines)
- (push (cons (current-buffer) mode-line-format)
- original-mode-lines))
- (let ((mode-line-format
- `(:eval
- (if-let ((keys
- (alist-get (selected-window)
- ',windows)))
- (mapconcat
- (apply-partially #'string ?\s)
- keys "")
- ',(alist-get (current-buffer)
- original-mode-lines)))))
- (if (cdr window-list)
- (setup-windows (cdr window-list))
- (funcall callback))))))
- (setup-windows windows))))
+ (named-let setup-windows ((window-list windows))
+ (with-selected-window (caar window-list)
+ (unless (assq (current-buffer) original-mode-lines)
+ (push (cons (current-buffer) mode-line-format)
+ original-mode-lines))
+ (let ((mode-line-format
+ `(:eval
+ (if-let ((keys
+ (alist-get (selected-window)
+ ',windows)))
+ (mapconcat
+ (apply-partially #'string ?\s)
+ keys "")
+ ',(alist-get (current-buffer)
+ original-mode-lines)))))
+ (if (cdr window-list)
+ (setup-windows (cdr window-list))
+ (funcall callback)))))))
(defun iwindow-highlight-window (windows callback)
"Highlight all candidate windows.
@@ -229,58 +228,54 @@ WINDOWS and CALLBACK is described in the docstring of
`iwindow-decoration-functions', which see."
(let ((buffers nil)
(sym (make-symbol "iwindow-parameter")))
- (cl-labels ((setup-windows
- (window-list)
- (with-selected-window (caar window-list)
- (cl-letf* (((window-parameter nil sym) sym)
- (payload
- (lambda ()
- (if (cdr window-list)
- (setup-windows (cdr window-list))
- (funcall callback)))))
- (if (memq (current-buffer) buffers)
- (funcall payload)
- (let ((face-remapping-alist
- face-remapping-alist))
- (cl-letf (((symbol-function
- 'make-local-variable)
- #'ignore))
- (dolist (pair iwindow-highlight-faces)
- (face-remap-add-relative
- (car pair)
- `(:filtered (:window ,sym ,sym)
- ,(cdr pair)))))
- (push (current-buffer) buffers)
- (funcall payload)))))))
- (setup-windows windows))))
+ (named-let setup-windows ((window-list windows))
+ (with-selected-window (caar window-list)
+ (cl-letf* (((window-parameter nil sym) sym))
+ (if (memq (current-buffer) buffers)
+ (if (cdr window-list)
+ (setup-windows (cdr window-list))
+ (funcall callback))
+ (let ((face-remapping-alist
+ face-remapping-alist))
+ (cl-letf (((symbol-function
+ 'make-local-variable)
+ #'ignore))
+ (dolist (pair iwindow-highlight-faces)
+ (face-remap-add-relative
+ (car pair)
+ `(:filtered (:window ,sym ,sym)
+ ,(cdr pair)))))
+ (push (current-buffer) buffers)
+ (if (cdr window-list)
+ (setup-windows (cdr window-list))
+ (funcall callback)))))))))
(defun iwindow-show-keys-for-minibuffer (windows callback)
"Show the keys to choose minibuffer in minibuffer.
WINDOWS and CALLBACK is described in the docstring of
`iwindow-decoration-functions', which see."
- (cl-labels ((setup-windows (window-list)
- (with-selected-window (caar window-list)
- (let ((ov nil))
- (when (minibufferp)
- (setq ov (make-overlay (point-min)
- (point-min)))
- (overlay-put
- ov 'before-string
- (concat (propertize
- (mapconcat #'string (cdar window-list)
- " ")
- 'face '(iwindow-minibuffer-keys-face
- default))
- " "))
- (overlay-put ov 'window (selected-window)))
- (unwind-protect
- (if (cdr window-list)
- (setup-windows (cdr window-list))
- (funcall callback))
- (when ov
- (delete-overlay ov)))))))
- (setup-windows windows)))
+ (named-let setup-windows ((window-list windows))
+ (with-selected-window (caar window-list)
+ (let ((ov nil))
+ (when (minibufferp)
+ (setq ov (make-overlay (point-min)
+ (point-min)))
+ (overlay-put
+ ov 'before-string
+ (concat (propertize
+ (mapconcat #'string (cdar window-list)
+ " ")
+ 'face '(iwindow-minibuffer-keys-face
+ default))
+ " "))
+ (overlay-put ov 'window (selected-window)))
+ (unwind-protect
+ (if (cdr window-list)
+ (setup-windows (cdr window-list))
+ (funcall callback))
+ (when ov
+ (delete-overlay ov)))))))
;;;###autoload
(defun iwindow-select ()
- [nongnu] branch elpa/iwindow created (now 144c402d5f), ELPA Syncer, 2022/11/27
- [nongnu] elpa/iwindow bfc5e97dfe 03/13: Add iwindow-swap, ELPA Syncer, 2022/11/27
- [nongnu] elpa/iwindow 16c6c97143 09/13: Don't error when PREDICATE is nil, ELPA Syncer, 2022/11/27
- [nongnu] elpa/iwindow 89989ad071 10/13: Minor cleanup, ELPA Syncer, 2022/11/27
- [nongnu] elpa/iwindow fc092c6b64 12/13: Lower Emacs minimum requirement to 24.3, ELPA Syncer, 2022/11/27
- [nongnu] elpa/iwindow cbbcdb32b2 05/13: Suppress runtime warning, ELPA Syncer, 2022/11/27
- [nongnu] elpa/iwindow f7b47e3bd8 04/13: Show keys for minibuffer on minibuffer, ELPA Syncer, 2022/11/27
- [nongnu] elpa/iwindow 13b9c558bf 11/13: Replace cl-labels with named-let, use Compat if needed,
ELPA Syncer <=
- [nongnu] elpa/iwindow 144c402d5f 13/13: Add .dir-locals.el, ELPA Syncer, 2022/11/27
- [nongnu] elpa/iwindow 6c5ea91142 02/13: Allow to use any arbitrary face to highlight, ELPA Syncer, 2022/11/27
- [nongnu] elpa/iwindow 285f40ff09 01/13: Add iwindow-select, ELPA Syncer, 2022/11/27
- [nongnu] elpa/iwindow a32c522f80 06/13: Add iwindow-delete and iwindow-delete-others, ELPA Syncer, 2022/11/27
- [nongnu] elpa/iwindow f5cf9ed724 07/13: Don't show raw key code on unbound key, ELPA Syncer, 2022/11/27
- [nongnu] elpa/iwindow 63426c55a9 08/13: Make window keys more predictable, ELPA Syncer, 2022/11/27