(recenter)
(pulse-momentary-highlight-one-line))))
- (defun esy/buttons (&optional buffer)
+ (defun esy/button-completion-candidate (index button)
+ "Return a completion candidate for BUTTON prefixed by INDEX."
+ (cons (concat (propertize (format "%d " index)
+ 'invisible t)
+ (truncate-string-to-width
+ (esy/inline (button-label button))
+ 64 nil ?\s t))
+ (button-start button)))
+
+ (defun esy/buttons (&optional buffer pom)
"Return an alist of buttons in BUFFER.
- Buttons following point appear first in the resulting list."
- (let ((buf (or buffer (current-buffer))))
- (with-current-buffer buf
- (let ((button (next-button (point-min))))
- (let ((index 1)
- (buttons-before nil)
- (buttons-after nil))
- (while (and button (< (button-start button) (point)))
- (setq buttons-before
- (cons `(,(concat (propertize (format "%d " index)
- 'invisible t)
- (truncate-string-to-width
- (esy/inline (button-label button))
- 64 nil ?\s t))
- .
- ,(button-start button))
- buttons-before))
- (setq index (1+ index))
- (setq button (next-button (button-end button))))
- (while button
- (setq buttons-after
- (cons `(,(concat (propertize (format "%d " index)
- 'invisible t)
- (truncate-string-to-width
- (esy/inline (button-label button))
- 64 nil ?\s t))
- .
- ,(button-start button))
- buttons-after))
- (setq index (1+ index))
- (setq button (next-button (button-end button))))
- (append (reverse buttons-after) (reverse buttons-before)))))))
+ Buttons following POM appear first in the resulting list."
+ (with-current-buffer (or buffer (current-buffer))
+ (let ((pos (or pom (point)))
+ (button (next-button (point-min)))
+ (index 1)
+ (buttons-before nil)
+ (buttons-after nil))
+ (while (and button (< (button-start button) pos))
+ (setq buttons-before
+ (cons (esy/button-completion-candidate index button)
+ buttons-before))
+ (setq index (1+ index))
+ (setq button (next-button (button-end button))))
+ (while button
+ (setq buttons-after
+ (cons (esy/button-completion-candidate index button)
+ buttons-after))
+ (setq index (1+ index))
+ (setq button (next-button (button-end button))))
+ (append (reverse buttons-after) (reverse buttons-before)))))
(defun esy/inline (str)
"Inline STR."
(string-replace "\n" " " str)))
(defun esy/completing-read-with-preview (prompt collection window buffer)
- "PROMPT, COLLECTION, WINDOW, BUFFER."
+ "Prompt for an element of COLLECTION with preview of the selection.
+ PROMPT passed on to `completing-read'. WINDOW is the window in
+ which to show preview for locations in BUFFER."
(advice-add #'next-completion :after #'esy/preview-completion)
(unwind-protect
(let ((esy/preview-window window)