(add-hook 'after-init-hook #'esy/setup-display)
#+end_src
-* Org-mode settings :org:
+* Org-mode settings
:PROPERTIES:
:CUSTOM_ID: org
:END:
org-refile-use-outline-path t))
#+end_src
-** Interactively fill missing CUSTOM_ID properties
+** Interactively fill missing CUSTOM_ID properties :cmd:
:PROPERTIES:
:CUSTOM_ID: orgs-custom-ids
:END:
'(("P" (list project-current))))
#+end_src
-* Email settings :mail:
+* Email settings
:PROPERTIES:
:CUSTOM_ID: email
:END:
(global-set-key [remap ns-print-buffer] #'move-dup-duplicate-up)
(global-set-key (kbd "M-p") #'move-dup-move-lines-up)
(global-set-key (kbd "M-n") #'move-dup-move-lines-down)
- (global-set-key (kbd "M-o") #'esy/consult-push-button)
+ (global-set-key (kbd "M-o") #'esy/push-button)
(global-set-key (kbd "C-,") #'backward-delete-char)
(global-set-key (kbd "C-.") #'embark-act)
(global-set-key (kbd "C-;") #'avy-goto-char-timer)
(add-to-list 'zoneinfo-style-world-list '("Europe/Amsterdam" "Amsterdam")))
#+end_src
-** Push a button in the current buffer with completions
+** Push a button in the current buffer with completions :cmd:
:PROPERTIES:
- :CUSTOM_ID: consult-push-button
+ :CUSTOM_ID: completing-push-button
:CreatedAt: <2022-05-14 Sat>
:CapturedAt:
:CapturedAs: Emacs configuration fragment
:END:
#+begin_src emacs-lisp
- (defun esy/preview-button (action candidate)
- "If ACTION is `preview', preview CANDIDATE."
- (when (eq action 'preview)
- (let ((pos (cdr candidate)))
+ (defvar esy/preview-table nil)
+ (defvar esy/preview-window nil)
+ (defvar esy/preview-buffer nil)
+
+ (defun esy/preview-completion (&rest _)
+ "Preview the current completion."
+ (let* ((completion (with-minibuffer-completions-window
+ (substring-no-properties
+ (get-text-property (point)
+ 'completion--string))))
+ (pos (cdr (assoc completion esy/preview-table))))
+ (message "%S" completion-extra-properties)
+ (with-selected-window esy/preview-window
(unless (= (goto-char pos) (point))
(widen)
(goto-char pos))
(buttons nil))
(while button
(setq buttons
- (cons `(,(concat (truncate-string-to-width
+ (cons `(,(concat (propertize (format "%d " index)
+ 'invisible t)
+ (truncate-string-to-width
(esy/inline (button-label button))
- 64 nil ?\s t)
- " "
- (propertize (format "[%d]" index) 'invisible t))
+ 64 nil ?\s t))
.
,(button-start button))
buttons))
(when str
(string-replace "\n" " " str)))
- (defun esy/consult-push-button ()
- "Choose a button in the current buffer with `consult--read' and push it."
+ (defun esy/completing-read-with-preview (prompt collection window buffer)
+ "PROMPT, COLLECTION, WINDOW, BUFFER."
+ (advice-add #'next-completion :after #'esy/preview-completion)
+ (unwind-protect
+ (let ((esy/preview-window window)
+ (esy/preview-buffer buffer)
+ (esy/preview-table collection))
+ (completing-read prompt collection nil t))
+ (advice-remove #'next-completion #'esy/preview-completion)))
+
+ (defun esy/annotate-button (key)
+ "Annotate completion candidate KEY with its button properties."
+ (with-current-buffer esy/preview-buffer
+ (let* ((button (button-at
+ (cdr
+ (assoc key esy/preview-table))))
+ (type (button-type button))
+ (action (button-get button 'action)))
+ (esy/inline
+ (if type
+ (format "%32S #'%S"
+ type
+ action)
+ (when action (format "#'%S" action)))))))
+
+ (defun esy/push-button ()
+ "Push a button in the current buffer with comlpetions and preview."
(interactive)
- (require 'consult)
(save-excursion
- (if-let ((buf (current-buffer))
- (table (esy/buttons)))
- (push-button (cdr (consult--read
- table
- :state #'esy/preview-button
- :prompt "Button: "
- :require-match t
- :category 'button
- :lookup #'consult--lookup-cons
- :annotate
- (lambda (key)
- (with-current-buffer buf
- (let* ((button (button-at
- (cdr
- (assoc key table))))
- (type (button-type button))
- (action (button-get button 'action)))
- (esy/inline
- (if type
- (format "%32S #'%S"
- type
- action)
- (when action (format "#'%S" action)))))))
- :sort nil)))
- (user-error "No buttons found in current buffer"))))
+ (let* ((buf (current-buffer))
+ (win (selected-window))
+ (table (esy/buttons))
+ (completions-sort nil)
+ (completion-annotate-function #'esy/annotate-button))
+ (if table
+ (push-button
+ (cdr (assoc
+ (esy/completing-read-with-preview "Button: "
+ table
+ win
+ buf)
+ table)))
+ (user-error "No buttons found in current buffer")))))
#+end_src