From b0177da7fe51b267de6ffa84a38bd0ec3f6c0fa9 Mon Sep 17 00:00:00 2001 From: Luke Yen-Xun Lee Date: Sat, 27 May 2017 16:25:02 +0300 Subject: [PATCH] Fix ruler-mode text-scaling issues * lisp/ruler-mode.el (ruler-mode-text-scaled-width): New function for computing scaled text width. (ruler-mode-text-scaled-window-hscroll) (ruler-mode-text-scaled-window-width): Compute text scaled `window-width' value. (ruler-mode-mouse-grab-any-column, ruler-mode-mouse-add-tab-stop) (ruler-mode-ruler): Change `window-hscroll' into `ruler-mode-text-scaled-window-hscroll', and change `window-width' into `ruler-mode-text-scaled-window-width'. --- lisp/ruler-mode.el | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lisp/ruler-mode.el b/lisp/ruler-mode.el index 4f09a1887f5..7b0588dfead 100644 --- a/lisp/ruler-mode.el +++ b/lisp/ruler-mode.el @@ -360,6 +360,20 @@ START-EVENT is the mouse click event." That is `fill-column', `comment-column', `goal-column', or nil when nothing is dragged.") +(defun ruler-mode-text-scaled-width (width) + "Compute scaled text width according to current font scaling. +Convert a width of char units into a text-scaled char width units, +Ex. `window-hscroll'." + (/ (* width (frame-char-width)) (default-font-width))) + +(defun ruler-mode-text-scaled-window-hscroll () + "Text scaled `window-hscroll'." + (ruler-mode-text-scaled-width (window-hscroll))) + +(defun ruler-mode-text-scaled-window-width () + "Text scaled `window-width'." + (ruler-mode-text-scaled-width (window-width))) + (defun ruler-mode-mouse-grab-any-column (start-event) "Drag a column symbol on the ruler. Start dragging on mouse down event START-EVENT, and update the column @@ -372,9 +386,9 @@ dragging. See also the variable `ruler-mode-dragged-symbol'." (save-selected-window (select-window (posn-window start)) (setq col (ruler-mode-window-col (car (posn-col-row start))) - newc (+ col (window-hscroll))) + newc (+ col (ruler-mode-text-scaled-window-hscroll))) (and - (>= col 0) (< col (window-width)) + (>= col 0) (< col (ruler-mode-text-scaled-window-width)) (cond ;; Handle the fill column. @@ -457,8 +471,8 @@ Called on each mouse motion event START-EVENT." (save-selected-window (select-window (posn-window start)) (setq col (ruler-mode-window-col (car (posn-col-row end))) - newc (+ col (window-hscroll))) - (when (and (>= col 0) (< col (window-width))) + newc (+ col (ruler-mode-text-scaled-window-hscroll))) + (when (and (>= col 0) (< col (ruler-mode-text-scaled-window-width))) (set ruler-mode-dragged-symbol newc))))) (defun ruler-mode-mouse-add-tab-stop (start-event) @@ -473,8 +487,8 @@ START-EVENT is the mouse click event." (save-selected-window (select-window (posn-window start)) (setq col (ruler-mode-window-col (car (posn-col-row start))) - ts (+ col (window-hscroll))) - (and (>= col 0) (< col (window-width)) + ts (+ col (ruler-mode-text-scaled-window-hscroll))) + (and (>= col 0) (< col (ruler-mode-text-scaled-window-width)) (not (member ts tab-stop-list)) (progn (message "Tab stop set to %d" ts) @@ -494,8 +508,8 @@ START-EVENT is the mouse click event." (save-selected-window (select-window (posn-window start)) (setq col (ruler-mode-window-col (car (posn-col-row start))) - ts (+ col (window-hscroll))) - (and (>= col 0) (< col (window-width)) + ts (+ col (ruler-mode-text-scaled-window-hscroll))) + (and (>= col 0) (< col (ruler-mode-text-scaled-window-width)) (member ts tab-stop-list) (progn (message "Tab stop at %d deleted" ts) @@ -648,11 +662,11 @@ Optional argument PROPS specifies other text properties to apply." (defun ruler-mode-ruler () "Compute and return a header line ruler." - (let* ((w (window-width)) + (let* ((w (ruler-mode-text-scaled-window-width)) (m (window-margins)) (f (window-fringes)) (i 0) - (j (window-hscroll)) + (j (ruler-mode-text-scaled-window-hscroll)) ;; Setup the scrollbar, fringes, and margins areas. (lf (ruler-mode-space 'left-fringe -- 2.39.2