]> git.eshelyaron.com Git - emacs.git/commitdiff
Pixel-align C-x 8 RET completions
authorEshel Yaron <me@eshelyaron.com>
Mon, 7 Apr 2025 07:28:00 +0000 (09:28 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 7 Apr 2025 07:28:00 +0000 (09:28 +0200)
lisp/international/mule-cmds.el
lisp/simple.el

index 5bd271b844fc0c8417b3c70813af77d3704af8be..8b296858d81ef7feed1f6fb09f5772d59d1471be 100644 (file)
@@ -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)))
 
index 10eeba4ba45ae6c00a4d27c797c727e90681b685..fd400d3549601775f3dc8f857c949bd88301e60a 100644 (file)
@@ -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.