From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: JD Smith Newsgroups: gmane.emacs.devel Subject: Re: Temporarily select-window, without updating mode-line face and cursor fill? Date: Sat, 1 May 2021 16:32:22 -0400 Message-ID: <6168853E-E5B1-4247-A0D7-4D4191DCED0A@gmail.com> References: <56F746A2-B842-421E-8FBF-EA5E93EA26CE@gmail.com> <83pmya8d49.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.80.0.2.43\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_ACA6B0F2-D021-4920-8BE4-20D5ED784DBD" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28779"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat May 01 22:33:38 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lcwJ0-0007Pi-BM for ged-emacs-devel@m.gmane-mx.org; Sat, 01 May 2021 22:33:38 +0200 Original-Received: from localhost ([::1]:37624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcwIz-0005nv-8v for ged-emacs-devel@m.gmane-mx.org; Sat, 01 May 2021 16:33:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcwHu-0005N7-Jc for emacs-devel@gnu.org; Sat, 01 May 2021 16:32:30 -0400 Original-Received: from mail-qk1-x72a.google.com ([2607:f8b0:4864:20::72a]:35681) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lcwHs-0001Ct-Mn; Sat, 01 May 2021 16:32:30 -0400 Original-Received: by mail-qk1-x72a.google.com with SMTP id x8so1623941qkl.2; Sat, 01 May 2021 13:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=LnZTxLVYGkH+NDqnkUMjIO3yJ40YTMbIA5cTzvfXjHA=; b=EBZ2hpcFGZTS9lLphOrFspLkwFlbjHPiFERWXaWKfwUev2HNdrwr0FnzUFXkK8alAg Pk17Q38jY9rybMvgWVDDq1MJgztRWRhqzdKq2iqn8WKLMVHc4wzAgx2FxFIJN+wg9Pxa jHLz3QuhOC66we9ELndU+bLJhg4DwD5C1YJPS6auRjyLRfOTZi48HDUX7K98FSkl4L7m oHbo7H+Ys8hIKj6NLeOvXV2Vjybp7kEY+XLLXFbF/xQGcQljs1HjqBqYmxPUC/ku4G6k nobsmpT7awOaWdZKB2NbKyqaJ5isQ908yGv3sgABvs1TtsgChs1XHeKPwp1si3+xB6Xi RrSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=LnZTxLVYGkH+NDqnkUMjIO3yJ40YTMbIA5cTzvfXjHA=; b=XBaEE2pPARfHuxUhfy3Vn206SNHPGC/86901zs9y0PLUfgv/A6sU8Xg+jdNgW26v/I J9hlXMdcbZHtJ6Dp/8Fx5jJbAD2QTSBTca2ze1acN209YjJrDwveHLXBQBajvco5yFiL 1ujRrnb0GnnKwL24GcGADE4HVQI3UkDyprWNXxhtzG7OrkzUQAAU8IKFrGZn7L4rDstz 7hKCaJdy8cCfdk6/u0Xi7ZRX3O7dhievHr5ekLYl0UB/x4FokVhJfJf3SSBO71/l+8un kVkz5Di0MqEkyPOJx3T7bJ2qNC8kbS6TsA7HafI2bZvky+VC1wZhnnDRhzy9c2ujG4qv syKw== X-Gm-Message-State: AOAM532Z2IlT9lFlM6k45fznU+syh2il1Oax9eqsHDll9brMbyzVOCb4 N1VFgEaSjGe+hwgFyBhdwcReZtaEyaZi6g== X-Google-Smtp-Source: ABdhPJy8SFHHRoWgWDHrHJITB4YfTA6lrK5pTNfxvQD0MKvFrI+p6GAZ2Il88GeGDXTY/HXEGp16XA== X-Received: by 2002:a37:f512:: with SMTP id l18mr883060qkk.89.1619901144188; Sat, 01 May 2021 13:32:24 -0700 (PDT) Original-Received: from smtpclient.apple (cm-134-228-25-135.buckeyecom.net. [134.228.25.135]) by smtp.gmail.com with ESMTPSA id k1sm4451280qkh.5.2021.05.01.13.32.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 May 2021 13:32:23 -0700 (PDT) In-Reply-To: <83pmya8d49.fsf@gnu.org> X-Mailer: Apple Mail (2.3654.80.0.2.43) Received-SPF: pass client-ip=2607:f8b0:4864:20::72a; envelope-from=jdtsmith@gmail.com; helo=mail-qk1-x72a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:268732 Archived-At: --Apple-Mail=_ACA6B0F2-D021-4920-8BE4-20D5ED784DBD Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On May 1, 2021, at 3:31 PM, Eli Zaretskii wrote: >=20 >> From: JD Smith >> Date: Sat, 1 May 2021 14:46:31 -0400 >>=20 >> I=E2=80=99m working on a small =E2=80=9Cin mode-line=E2=80=9D scroll = bar, and have implemented mouse events for it, which are working well. = When I interact using the mouse with the mode line of a non-selected = window, I need to have that window temporarily selected, so I can = calculate its line offsets and move within it. But (just as for regular = scrollbars), I=E2=80=99d like to retain the originally active window = afterwards. >=20 > Please explain in more detail why do you think you need to select the > window. What are those "line offsets", and why "move within it" > requires to select the window? Sure, thanks. I compute line positions at a number of points = (window-start, window-end, and point-max) inside a mode line :eval form. = To compute line numbers at these positions, for speed in very long = files, I=E2=80=99m actually using: (defun mlscroll-fast-line-number-at-pos (pos) (save-excursion (goto-char pos) (string-to-number (format-mode-line "%l")))) The operative bits of the =E2=80=9Cmove within=E2=80=9D look like: (when (/=3D targ start) (forward-line (- targ start)) (recenter)) During normal automatic mode-line update, the selected window is = automatically bound correctly while the mode line string is computed = (without updating the mode line face, I might add!). But during the = mouse event callback, I must use the starting window of the mouse event = (a press) as the window to target, since the user could click on any of = them.=20 I believe I can re-task all of the =E2=80=9Ccomputing lines=E2=80=9D = code to take a window argument, i.e. to avoid actually selecting the = window itself. But less clear is how to move forward and back a given = number of lines (forward-line) and recenter in an unselected window, = without selecting it temporarily and causing the mode line face = flashing. --Apple-Mail=_ACA6B0F2-D021-4920-8BE4-20D5ED784DBD Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On May 1, 2021, at 3:31 PM, Eli Zaretskii <eliz@gnu.org> = wrote:

From: JD Smith <jdtsmith@gmail.com>
Date: Sat, 1 May = 2021 14:46:31 -0400

I=E2=80=99m working on = a small =E2=80=9Cin mode-line=E2=80=9D scroll bar, and have implemented = mouse events for it, which are working well.  When I interact using = the mouse with the mode line of a non-selected window, I need to have = that window temporarily selected, so I can calculate its line offsets = and move within it.  But (just as for regular scrollbars), I=E2=80=99= d like to retain the originally active window afterwards.

Please explain in more detail why = do you think you need to select the
window.  What are = those "line offsets", and why "move within it"
requires to = select the window?

Sure, thanks.  I compute line positions = at a number of points (window-start, window-end, and point-max) inside a = mode line :eval form.  To compute line numbers at these positions, = for speed in very long files, I=E2=80=99m actually using:

(defun = mlscroll-fast-line-number-at-pos (pos)
  = (save-excursion
    (goto-char = pos)
    (string-to-number = (format-mode-line "%l"))))

The operative bits of the =E2=80=9Cmove = within=E2=80=9D look like:

   (when (/=3D targ = start)
      (forward-line (- targ = start))
      = (recenter))

During normal automatic = mode-line update, the selected window is automatically bound correctly = while the mode line string is computed (without updating the mode line = face, I might add!).  But during the mouse event callback, I must = use the starting window of the mouse event (a press) as the window to = target, since the user could click on any of = them. 

I believe I can re-task all of = the =E2=80=9Ccomputing lines=E2=80=9D code to take a window = argument, i.e. to avoid actually selecting the window itself.  But = less clear is how to move forward and back a = given number of lines (forward-line) and recenter in an = unselected window, without selecting it temporarily and causing the mode = line face flashing.

= --Apple-Mail=_ACA6B0F2-D021-4920-8BE4-20D5ED784DBD--