From 9b9f01d8b26c23dca45b9062734648938ce9901c Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Mon, 7 Apr 2025 09:28:00 +0200 Subject: [PATCH] Pixel-align C-x 8 RET completions --- lisp/international/mule-cmds.el | 7 +++-- lisp/simple.el | 50 +++++++++++++++++---------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index 5bd271b844f..8b296858d81 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el @@ -3168,7 +3168,8 @@ on encoding." "Return Unicode character NAMES with completion affixations." (let ((max (seq-max (cons 0 (mapcar (lambda (n) (if-let ((c (gethash n ucs-names))) - (char-width c) + (/ (string-pixel-width (char-to-string c)) + (frame-char-width)) 0)) names))))) (mapcar (lambda (name) @@ -3177,7 +3178,9 @@ on encoding." (list name (concat str - (make-string (1+ (- max (string-width str))) ?\s)) + (make-string (1+ (- max (/ (string-pixel-width str) + (frame-char-width)))) + ?\s)) ""))) names))) diff --git a/lisp/simple.el b/lisp/simple.el index 10eeba4ba45..fd400d35496 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -10041,30 +10041,32 @@ minibuffer, but don't quit the completions window." ;; In case this is run via the mouse, give temporary modes such as ;; isearch a chance to turn off. (run-hooks 'mouse-leave-buffer-hook) - (with-current-buffer (window-buffer (posn-window (event-start event))) - (let ((buffer completion-reference-buffer) - (base-position completion-base-position) - (insert-function completion-list-insert-choice-function) - (completion-no-auto-exit (if no-exit t completion-no-auto-exit)) - (choice (get-text-property (posn-point (event-start event)) - 'completion--string))) - (unless choice (error "No completion here")) - (unless (buffer-live-p buffer) (error "Destination buffer is dead")) - (unless no-quit - (quit-window nil (posn-window (event-start event)))) - (let ((mstate completions-minibuffer-state)) - (with-current-buffer buffer - (choose-completion-string - choice buffer - (or base-position - ;; If all else fails, just guess. - (list (choose-completion-guess-base-position choice))) - insert-function) - (or (null mstate) - (equal mstate (car completion-history)) - (prog1 (push mstate completion-history) - (run-hooks 'minibuffer-new-completion-input-hook))))) - (setq completions-minibuffer-state nil)))) + (let ((buf (if event (window-buffer (posn-window (event-start event))) + (current-buffer))) + (pos (if event (posn-point (event-start event)) (point)))) + (with-current-buffer buf + (let ((buffer completion-reference-buffer) + (base-position completion-base-position) + (insert-function completion-list-insert-choice-function) + (completion-no-auto-exit (if no-exit t completion-no-auto-exit)) + (choice (get-text-property pos 'completion--string))) + (unless choice (error "No completion here")) + (unless (buffer-live-p buffer) (error "Destination buffer is dead")) + (unless no-quit + (quit-window nil (posn-window (event-start event)))) + (let ((mstate completions-minibuffer-state)) + (with-current-buffer buffer + (choose-completion-string + choice buffer + (or base-position + ;; If all else fails, just guess. + (list (choose-completion-guess-base-position choice))) + insert-function) + (or (null mstate) + (equal mstate (car completion-history)) + (prog1 (push mstate completion-history) + (run-hooks 'minibuffer-new-completion-input-hook))))) + (setq completions-minibuffer-state nil))))) ;; Delete the longest partial match for STRING ;; that can be found before POINT. -- 2.39.5