From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?B?6Lev5a6i?= Newsgroups: gmane.emacs.devel Subject: Re: `window-hscroll' does not report correct value when `text-scale-mode' is on Date: Tue, 23 May 2017 11:37:07 +0800 Message-ID: References: <83y3tu42vr.fsf@gnu.org> <83d1b54ag9.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1495510680 28496 195.159.176.226 (23 May 2017 03:38:00 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 23 May 2017 03:38:00 +0000 (UTC) Cc: Emacs developers To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue May 23 05:37:56 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dD0dw-0007Ig-F9 for ged-emacs-devel@m.gmane.org; Tue, 23 May 2017 05:37:56 +0200 Original-Received: from localhost ([::1]:45975 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dD0e0-0000dJ-8Y for ged-emacs-devel@m.gmane.org; Mon, 22 May 2017 23:38:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32874) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dD0ds-0000dD-Ma for emacs-devel@gnu.org; Mon, 22 May 2017 23:37:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dD0dr-00018d-Du for emacs-devel@gnu.org; Mon, 22 May 2017 23:37:52 -0400 Original-Received: from mail-qt0-x22e.google.com ([2607:f8b0:400d:c0d::22e]:33965) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dD0dp-00012v-Ia; Mon, 22 May 2017 23:37:49 -0400 Original-Received: by mail-qt0-x22e.google.com with SMTP id c13so117723857qtc.1; Mon, 22 May 2017 20:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=OnUBjhOmYAEq8X5QIeqX2+V9Mj4ZiRjTvjEbiM3kyhw=; b=FGwCJaZBWLpH6q+DSswPgCAzbxrYbhIMtFFHB/UBBvAvMtTqQwX8R8D8hDRo5e0XKs Chmwasex8JfMrb/pxLoujeEM3gdvBk4Jy1g+66noIXVtM52QCZSPFrNMECz/+XUF8SWA yA5ZKwaUPTwOp4KpTPGpCew7Im0Aax1W0e98Of07gWmGVlNtpMG+/7coB0gCOkzUT+mI ZSMgGYSMzpJOXlLnWoqtQD9rMkruxjesYYPAM1DnPKuDGeYU5g0b7s61ZTfHAfKJ4NSS 1yL2bb3dNJo5R/Pfw2toAsA2zg+La7icYWO8qlsJgyVi2/TnCCH/zZ7e/oFm7hjfbbRn UwPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=OnUBjhOmYAEq8X5QIeqX2+V9Mj4ZiRjTvjEbiM3kyhw=; b=cJVAq+sljgH7nEWW+JDKgA+XuavzsbSLdnQ6RZLOk3lGrtIGUvhl6RFVMr6lqQbi7x 71VCpxs8kSgrqNEnvzRwZjT94hjTL7wXsxb2bSsrlwhv5lRrDCQe263bJYjV+AOTvTMk 5BgGN90KClGWYy+sLUZIQ9ILt4N6QN2p2q8yxy1SktarrHybdUm4iRU87z+hQ34XOZG2 zp/wRGSUg/YRD6R7ELZUceTH2Kq7wbMqeg1ImB1rhxq5b4Lpw8S/Lj17tX5sk2zmFxVL pe/X8KiGqyw9T/SrLIirCwriOaWayir25GM84MjxWnKyDLkJ2EZznJ84xbV0Juet3lXw siAQ== X-Gm-Message-State: AODbwcB7w9vTavGqXrS7PWVbtuSb0uoWfmAnx0ZJ6vbN94qq6ifRZIOT hTYNXY3jqsRHXTksU3vN4zfsYscoEMzH X-Received: by 10.200.56.216 with SMTP id g24mr23823099qtc.267.1495510668226; Mon, 22 May 2017 20:37:48 -0700 (PDT) Original-Received: by 10.140.83.5 with HTTP; Mon, 22 May 2017 20:37:07 -0700 (PDT) In-Reply-To: <83d1b54ag9.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::22e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:215116 Archived-At: >I don't think I understand what needs fixing. Is this question >different from the second one, i.e. if you can compute a suitable >value requested in your second question, is there something else that >needs fixing in ruler-mode? If so, what else needs fixing? There are three problems result from the same reason: First, when you use text-scale-mode (S-leftmouse) to decrease font size, you will first see the ruler becomes smaller than the `window-width'. Second, when you move the cursor rightwards, you will see the "indicator" of the cursor not at the correct x-coordinate as our cursor. Third, when you edit a long line with line-wrap mode off, the `window-hscroll' value it used is not scaled so the ruler will start showing incorrect positions. It get more worse as the line grows longer. > (* (/ (window-hscroll) (frame-char-width)) (default-font-width)) Cool! After some experiment I think it should be (/ (* (window-hscroll) (frame-char-width)) (default-font-width)) This can give the the *exact* value of scaled window-hscroll. I tried to round it up to the closest integer but it seems not required (I am not 100% sure). Here is my patch to ruler-mode, please review my changes. I don't think my function names are good. Thanks! -------------- diff --git a/lisp/ruler-mode.el b/lisp/ruler-mode.el index 4f09a1887f5..36d399c7c91 100644 --- a/lisp/ruler-mode.el +++ b/lisp/ruler-mode.el @@ -360,6 +360,21 @@ ruler-mode-dragged-symbol 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'. The return value is rounded up to the closest +integer." + (/ (* width (frame-char-width)) (default-font-width))) + +(defun ruler-mode-window-hscroll () + "Text scaled `window-hscroll'." + (ruler-mode-text-scaled-width (window-hscroll))) + +(defun ruler-mode-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 +387,9 @@ ruler-mode-mouse-grab-any-column (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-window-hscroll))) (and - (>= col 0) (< col (window-width)) + (>= col 0) (< col (ruler-mode-window-width)) (cond ;; Handle the fill column. @@ -457,8 +472,8 @@ ruler-mode-mouse-drag-any-column (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-window-hscroll))) + (when (and (>= col 0) (< col (ruler-mode-window-width))) (set ruler-mode-dragged-symbol newc))))) (defun ruler-mode-mouse-add-tab-stop (start-event) @@ -473,8 +488,8 @@ ruler-mode-mouse-add-tab-stop (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-window-hscroll))) + (and (>= col 0) (< col (ruler-mode-window-width)) (not (member ts tab-stop-list)) (progn (message "Tab stop set to %d" ts) @@ -494,8 +509,8 @@ ruler-mode-mouse-del-tab-stop (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-window-hscroll))) + (and (>= col 0) (< col (ruler-mode-window-width)) (member ts tab-stop-list) (progn (message "Tab stop at %d deleted" ts) @@ -648,11 +663,11 @@ ruler-mode-space (defun ruler-mode-ruler () "Compute and return a header line ruler." - (let* ((w (window-width)) + (let* ((w (ruler-mode-window-width)) (m (window-margins)) (f (window-fringes)) (i 0) - (j (window-hscroll)) + (j (ruler-mode-window-hscroll)) ;; Setup the scrollbar, fringes, and margins areas. (lf (ruler-mode-space 'left-fringe Best regards, Luke Lee