From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.devel Subject: Re: Flymake, compilation-mode lighters very noisy Date: Wed, 21 Nov 2018 16:54:59 +0700 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1542793998 5673 195.159.176.226 (21 Nov 2018 09:53:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 21 Nov 2018 09:53:18 +0000 (UTC) Cc: Emacs developers To: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 21 10:53:13 2018 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 1gPPC5-0001LX-4b for ged-emacs-devel@m.gmane.org; Wed, 21 Nov 2018 10:53:13 +0100 Original-Received: from localhost ([::1]:38069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPPEA-00020Y-1j for ged-emacs-devel@m.gmane.org; Wed, 21 Nov 2018 04:55:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPPE3-00020D-Dd for emacs-devel@gnu.org; Wed, 21 Nov 2018 04:55:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPPE2-0004ci-DQ for emacs-devel@gnu.org; Wed, 21 Nov 2018 04:55:15 -0500 Original-Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]:36319) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gPPE2-0004bW-5t for emacs-devel@gnu.org; Wed, 21 Nov 2018 04:55:14 -0500 Original-Received: by mail-ot1-x332.google.com with SMTP id k98so4419259otk.3 for ; Wed, 21 Nov 2018 01:55:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=+TPeIbOskDFUEnC/HY6Pioz9FlID1RXEdzcVms7WpTo=; b=SoDqT3MHLMIYR0vTRng6uLYJNNZNg+7ZdKUjZ0L7zVeNeF8dFfCVIf0ndzv/H4kpoJ o0TPqFHQK76kb98uDMQN9x4mBnLFD86v6K7E7y7V/QPntBTSC7iceVyInuQccEjZzqq5 jhBmYe0vfF7pcjIK+UhYC4S7mSwIUph8drjc3XOlZNwatdtBHMLdSoKygXDnjsQZFRLq RRwrf9LqnpqqjAQH8yCGdfyfTTzINeBp/5ReOdIo+PVIyJnjtiW/jO1GKLDhn8Yd5vMw Yw/DQ9l62AQC05J1mSpi7anpWBItDphKb1CBAgbfyeWwouF4IY7TSz+2liyI3GdQXhXI SEaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=+TPeIbOskDFUEnC/HY6Pioz9FlID1RXEdzcVms7WpTo=; b=CYT3Jh7l2e97zRSy7hAbaBuzd06pNyyy6tTvu+fj1qsdmEdxOJ6Nhv3QicUyx8Q2i/ vfL+WqFLdbGTDGwFmCT7Tq5HzykP7iaQyB13vEN0QFg5FmsYPPRhWjbOACs96lN6IAwy aK+XHdIk1SVFFftkzV6/NL/huI7FV7MNM2N6uQHslktSw6N05itOspldyWys2cwvfFWZ ZBScLsSJrdrJb5zb/jahJ+wxi2hQuKbxaZS+qQ1xmF/CTHfB9b8eKua2EYLu5JCQb2gG A3xB9KBNGxuVylFLDFpBySW2fBFDx28mNbuHm50+TVHz/ZgN+Emi241SV/kMWpcr3mki fseA== X-Gm-Message-State: AA+aEWbjO3F7tAL71VvTiRqd+N5Lm6ZfrjXXzN3WN/+HgrS5RDDPS9FF e7Odi9wuzRa8QhCiSD/mDq3pw65SOTSzZiql4GI= X-Google-Smtp-Source: AFSGD/Voy8FdQoyXPNLXGNpSPkTm0zLOE/+BAjehf4NVCxjcAh8K5gRUeImKp+xvuCSLNYtzxq5QeYcARz9KbkvsARs= X-Received: by 2002:a9d:6419:: with SMTP id h25mr3624287otl.34.1542794111465; Wed, 21 Nov 2018 01:55:11 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::332 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:231274 Archived-At: On Wed, Nov 21, 2018 at 3:16 AM Jo=C3=A3o T=C3=A1vora wrote: >> Flymake, though, delegates the work to the function >> =E2=80=98flymake--mode-line-format=E2=80=99, which is pretty involved (1= 10 lines of >> code). Not much I can do with that, as a user, except copy-pasting >> that function into my init.el with a minor change. > > To your point, propose a way to break up that function. What variable and= what semantics would you like to see? Would it be enough for a variable to= state the minimum severity you would want to always see, even with zero oc= curance? In your case you would set it somewhere above "error".... If you r= ead closely you'll find it's now at "warning", though indeed hardcoded. Well, as I said before, the function is =E2=80=9Cpretty involved=E2=80=9D. = That is to say, I do not immediately understand all the things it is doing. You are asking me to read and comprehend it. Hm, okay. * I see it first calls a few functions to get the current state and binds their results to local variables. Gonna ignore that for a moment. It also does some data reshaping (7 lines) from the buffer-local variable =E2=80=98flymake--backend-state=E2=80=99 into local v= ariable =E2=80=98diags-by-type=E2=80=99. That could be a helper function. * I see it dynamically builds a mode line construct, which is always a list= . * Its first element is always the minor mode name, propertized to show some statistics on mouse hover, show the mode menu on click, and show help on middle click. This part takes 17 lines. The only dynamic dependencies of this part are (length known), (length running), and (length disabled). * The second element is nil in the normal case, but may turn into a status item when there are no known backends, or some backends are still running, or all backends are disabled. This part consists of a data collection part (12 lines, binds three variables in a pcase-let) and a conditionally applied mode line construct template (10 lines, depends on ind, face, explain variables bound just above). * The last part of the function (56 lines) conditionally generates a list of "[", followed by space-separated counters by type in descending severity level order, followed by "]". A counter for a type is skipped if it has no diagnostics and its severity is lower than :warning. Each counter is a decimal number representation of the number of diagnostics of a particular severity, propertized with the face corresponding to the severity level, a constant mouse-face, and a dynamically-generated keymap. The mode line construct for each counter essentially depends on: (length diags), severity, and type. So I guess what I would like to see is a better separation of logic from presentation. Concretely, what I would do is: 1. Extract many variables, each of which represents a single mode line construct used in the Flymake mode line indicator. Make them reference any necessary data passed as values of predefined symbols. 2. Extract constants such as the Flymake indicator=E2=80=99s keymap as defconsts, and near-constants such as each type=E2=80=99s counter=E2=80=99s= keymap as defuns. 3. Move the decision to display or skip each element into its corresponding data structure, possibly using the (SYMBOL THEN ELSE) mode line construct. 4. The flymake-mode-line-format will be left with all the calculations and a bunch of (format-mode-line) calls using the variables extracted in (1), wrapped in let forms binding the necessary dynamic values to symbols for variables to use. A little code to demonstrate: ;;..5...10....5...20....5...30....5...40....5...50....5...60....5...70.. ;; A user could elide zero counts from here ;; by wrapping each (format =E2=80=A6) into a (when =E2=80=A6) (defvar flymake-overall-indicator-help-echo-format '((:eval (format "%d known backends\n" flymake-known-backend-count)) (:eval (format "%d running backends\n" flymake-running-backend-count)) (:eval (format "%d disabled backends\n" flymake-disabled-backend-count)= ) ("mouse-1: Display minor mode menu\n") ("mouse-2: Show help for minor mode"))) (defvar flymake-overall-indicator-format '(:propertize " Flymake" mouse-face mode-line-highlight help-echo flymake-overall-indicator-help-echo keymap flymake-overall-indicator-keymap)) (defun flymake--mode-line-format () (let* ((known =E2=80=A6) =E2=80=A6more variables=E2=80=A6) `(,(let* ((flymake-known-backend-count (length known)) (flymake-running-backend-count (length running)) (flymake-disabled-backend-count (length disabled)) (flymake-overall-indicator-help-echo (format-mode-line flymake-overall-indicator-help-echo-format= ))) (format-mode-line flymake-overall-indicator)) =E2=80=A6more mode line constructs=E2=80=A6))) This way, for each element, the user gets a well-defined way to customize when and how it appears, without having to copy the whole function. Now as to why a simple severity level variable will not cut it: The color coding is helpful, but people with different accessibility needs will want to replace it with different things. A color-blind user may want to add letters, e.g. 0e 0w. A user with ADD-like symptoms will prefer no color, with or without letters. A visually inclined user may want to replace the string =E2=80=9CFlymake=E2=80=9D with a Unicode check m= ark/info sign/warning sign/cross. A small screen user will want to see only one counter with the most severity, and hide warnings if there are errors.