Skip to content

Commit c2da8ba

Browse files
committed
1 parent c7cb315 commit c2da8ba

File tree

1 file changed

+58
-16
lines changed

1 file changed

+58
-16
lines changed

ace-window.el

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
(require 'avy)
6666
(require 'ring)
6767
(require 'subr-x)
68+
(require 'posframe)
6869

6970
;;* Customization
7071
(defgroup ace-window nil
@@ -407,6 +408,32 @@ LEAF is (PT . WND)."
407408
(overlay-put ol 'window wnd)
408409
(push ol avy--overlays-lead)))))
409410

411+
(defvar aw--posframes-lead nil
412+
"List of posframe buffer names currently shown on screen")
413+
414+
(defun aw--lead-posframe (path leaf)
415+
"Create a posframe using PATH at LEAF.
416+
LEAF is (PT . WND)."
417+
(let* ((wnd (cdr leaf))
418+
(s (aw--overlay-str wnd (point-min) path))
419+
(posframe-name (format "*avy-window %s*" s)))
420+
;; Add a posframe to every window and it won't interfere with buffer contents.
421+
(push posframe-name aw--posframes-lead)
422+
(with-selected-window wnd
423+
(posframe-show posframe-name
424+
:string s
425+
;; Show the hint in the center of each window.
426+
:poshandler 'posframe-poshandler-window-center
427+
:foreground-color (face-attribute 'aw-leading-char-face :foreground nil t)
428+
:override-parameters aw-posframe-parameters
429+
;; :font "18"
430+
:font (face-font 'aw-leading-char-face)
431+
))))
432+
433+
(defun aw--remove-leading-posframes nil
434+
(mapc #'posframe-hide aw--posframes-lead)
435+
(setq aw--posframes-lead nil))
436+
410437
(defun aw--make-backgrounds (wnd-list)
411438
"Create a dim background overlay for each window on WND-LIST."
412439
(when aw-background
@@ -516,9 +543,15 @@ The new frame is set to the same size as the previous frame, offset by
516543
(let ((avy-dispatch-alist))
517544
(avy-handler-default char)))))))
518545

519-
(defcustom aw-display-mode-overlay t
520-
"When nil, don't display overlays. Rely on the mode line instead."
521-
:type 'boolean)
546+
(defcustom aw-display-style 'overlay
547+
"Display ace-window navigation markers either as an overlay or posframe. When nil, rely on the mode line instead."
548+
:type '(choice (const :tag "Overlay" overlay)
549+
(const :tag "Child Frame" posframe)
550+
(const :tag "None" nil)))
551+
552+
(defcustom aw-posframe-parameters nil
553+
"The frame parameters used when aw-display-style is 'posframe"
554+
:type 'string)
522555

523556
(defvar ace-window-display-mode)
524557

@@ -564,19 +597,23 @@ Amend MODE-LINE to the mode line for the duration of the selection."
564597
;; turn off helm transient map
565598
(remove-hook 'post-command-hook 'helm--maybe-update-keymap)
566599
(unwind-protect
567-
(let* ((avy-handler-function aw-dispatch-function)
568-
(avy-translate-char-function aw-translate-char-function)
569-
(transient-mark-mode nil)
570-
(res (avy-read (avy-tree candidate-list aw-keys)
571-
(if (and ace-window-display-mode
572-
(null aw-display-mode-overlay))
573-
(lambda (_path _leaf))
574-
#'aw--lead-overlay)
575-
#'avy--remove-leading-chars)))
576-
(if (eq res 'exit)
577-
(setq aw-action nil)
578-
(or (cdr res)
579-
start-window)))
600+
(let* ((avy-handler-function aw-dispatch-function)
601+
(avy-translate-char-function aw-translate-char-function)
602+
(transient-mark-mode nil)
603+
(res (avy-read (avy-tree candidate-list aw-keys)
604+
(if (and ace-window-display-mode
605+
aw-display-style)
606+
(lambda (_path _leaf))
607+
(pcase aw-display-style
608+
('overlay #'aw--lead-overlay)
609+
('posframe #'aw--lead-posframe)))
610+
(pcase aw-display-style
611+
('overlay #'avy--remove-leading-chars)
612+
('posframe #'aw--remove-leading-posframes)))))
613+
(if (eq res 'exit)
614+
(setq aw-action nil)
615+
(or (cdr res)
616+
start-window)))
580617
(aw--done))))))
581618
(if aw-action
582619
(funcall aw-action window)
@@ -954,3 +991,8 @@ window list."
954991
(provide 'ace-window)
955992

956993
;;; ace-window.el ends here
994+
995+
996+
997+
;; from https://github.com/loafofpiecrust/ace-window/tree/posframe
998+
;; https://github.com/abo-abo/ace-window/pull/204

0 commit comments

Comments
 (0)