DelicateMouseClick

Normally when you click on a character with mouse, the cursor is placed before that character. That’s fine when the cursor is a box, which appears to be on the character.

But when the cursor is a bar, and you click on the right half of the character, you would expect the cursor to be placed on the right of the character. This is more obvious with fatter characters like CJK ones. Anyway, the following mode achieves that behavior (place cursor on the right when clicked on the right).

    (defun adjust-point-after-click (event &optional _)
      "Adjust point.
    Adjust point depending on which portion of the character the
    cursor clicked on, if on the right half, move point after.
    EVENT is the mouse event."
      (let* ((posn (event-end event))
             (x (car (posn-object-x-y posn)))
             (w (car (posn-object-width-height posn))))
        ;; ‘mouse-set-point’ is called twice when you click mouse, first
        ;; in ‘down-mouse-1’, called by ‘mouse-drag-region’ ->
        ;; ‘mouse-drag-track’ to set point, second in ‘mouse-1’, when
        ;; mouse released and Emacs realized that this is a click event.
        ;; We want to adjust point in both cases.
        (when (and (null (posn-object posn))
                   (> x (/ w 2)))
          (forward-char))))
    (define-minor-mode delicate-click-mode
      "Accurate point position on click.
    That is, if you click on the right half of a character, the point
    is set to after it."
      :global t
      :lighter ""
      (if delicate-click-mode
          (advice-add 'mouse-set-point :after #'adjust-point-after-click)
        (advice-remove 'mouse-set-point #'adjust-point-after-click)))

CategoryMouse