From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eshel Yaron Newsgroups: gmane.emacs.help Subject: Re: Package critique: modeline for air quality information Date: Fri, 01 Sep 2023 13:57:47 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28727"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: help-gnu-emacs@gnu.org To: John Haman Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 01 13:58:47 2023 Return-path: Envelope-to: geh-help-gnu-emacs@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 1qc2nX-0007F8-1f for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 01 Sep 2023 13:58:47 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qc2mr-00027n-BI; Fri, 01 Sep 2023 07:58:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qc2mp-00027M-Oc for help-gnu-emacs@gnu.org; Fri, 01 Sep 2023 07:58:03 -0400 Original-Received: from mail.eshelyaron.com ([107.175.124.16] helo=eshelyaron.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qc2mh-0000vg-Ul for help-gnu-emacs@gnu.org; Fri, 01 Sep 2023 07:58:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1693569474; bh=e2bL6bDunD9BVHg9IR6blIel7H4B8sGjPhFfoVf2jio=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=eAlxwxrhzBU5XEUAlFxTRrqNrGUTBL/gCnowCUqFq2djz50polk3HxgtJ4TGzNiZd rXGTow/amuJ+qhOLrl0cCpgkm2TRD3sTUS4XFy3n3r7d/adF/xQcIcF2uQh5D+kLEc HNr957Q1j6hsh4e/z7yjf99YAziZ0YgNUXFxn19W5l/3X4WodvVfjF0ai3oFWyDOSl kfYhBHmO304qVK0EOxCkVLQbwrutSi8dBpTo2rhngyRPPeBT7LVzGpfHQIUUEUubsf nfckX/O9trng6ZqyUIKaHVbHdO0JId7kJq5AHjv/UYKL1X68HDPnWctN8oHP+1JuG9 AKHhra6aA80+w== In-Reply-To: (John Haman's message of "Fri, 01 Sep 2023 06:49:49 -0400") Received-SPF: pass client-ip=107.175.124.16; envelope-from=me@eshelyaron.com; helo=eshelyaron.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.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, FORGED_SPF_HELO=1, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:145050 Archived-At: --=-=-= Content-Type: text/plain John Haman writes: > > I had some 404 issue with the new version of > `air-quality--make-api-call', so I reverted back to the old one that > just uses a simple string concatenation. Is that OK? Sure, > Or is there some specific advantage to using `url-parse-make-urlobj' ? Not that I know of, I just find it a bit cleaner. > > https://github.com/jthaman/air-quality > > You might check to see if I implemented the variable checking in a correct way in the definition of `air-quality-mode'. > Looks good, a possible improvement in that area would be to prompt the user for these settings when they try to activate the mode, instead of silently failing. Also note that for the `defcustom`s, if you set the `:type` to `number` then the default value `nil` isn't of the right type. You can see this mismatch indicated in the Custom buffer, for example. Here are two patches to make these suggestions concrete, feel free to apply them as they are, ignore them completely, or anything in between: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Refine-defcustom-types.patch >From 0b6f014db9d275d6ea6f3b1e04d3389018fd1705 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Fri, 1 Sep 2023 13:40:34 +0200 Subject: [PATCH 1/2] Refine 'defcustom' types --- air-quality.el | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/air-quality.el b/air-quality.el index 8f55100..7895b8c 100644 --- a/air-quality.el +++ b/air-quality.el @@ -45,16 +45,18 @@ (defcustom air-quality-open-weather-api-key nil (string :tag "Your API key"))) (defcustom air-quality-refresh-interval 60 - "An integer. Number of minutes between refreshes of air quality information." - :type 'number) + "Number of minutes between refreshes of air quality information." + :type 'integer) (defcustom air-quality-latitude nil - "A float. Your latitude." - :type 'number) + "Your latitude." + :type '(choice (const :tag "Unset" nil) + (integer :tag "Your latitude"))) (defcustom air-quality-longitude nil - "A float. Your longitude." - :type 'number) + "Your longitude." + :type '(choice (const :tag "Unset" nil) + (integer :tag "Your longitude"))) ;;;; Private Variables -- 2.42.0 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-Prompt-for-missing-settings.patch Content-Description: attachment >From bc4c729ab26e34515cbc9d90ca182af4a8939a00 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Fri, 1 Sep 2023 13:42:22 +0200 Subject: [PATCH 2/2] Prompt for missing settings --- air-quality.el | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/air-quality.el b/air-quality.el index 7895b8c..c6d2250 100644 --- a/air-quality.el +++ b/air-quality.el @@ -144,14 +144,27 @@ (define-minor-mode air-quality-mode :group 'air-quality :global t (if air-quality-mode - (progn - ;; Check that air-quality-open-weather-api-key, - ;; air-quality-latitude and air-quality-longitude are set - (when (and air-quality-open-weather-api-key air-quality-latitude air-quality-longitude) - (add-to-list 'mode-line-misc-info 'air-quality-indicator t ) - (setq air-quality--timer - (run-with-timer 0 (* 60 air-quality-refresh-interval) - #'air-quality--get-update)))) + (let ((need-save nil)) + (unless air-quality-open-weather-api-key + (setq air-quality-open-weather-api-key + (read-string "Set your Open Weather API key: ") + need-save t) + (customize-mark-to-save 'air-quality-open-weather-api-key)) + (unless air-quality-latitude + (setq air-quality-latitude + (read-number "Set your latitude: ") + need-save t) + (customize-mark-to-save 'air-quality-latitude)) + (unless air-quality-longitude + (setq air-quality-longitude + (read-number "Set your longitude: ") + need-save t) + (customize-mark-to-save 'air-quality-longitude)) + (when need-save (custom-save-all)) + (add-to-list 'mode-line-misc-info 'air-quality-indicator t ) + (setq air-quality--timer + (run-with-timer 0 (* 60 air-quality-refresh-interval) + #'air-quality--get-update))) (setq mode-line-misc-info (delq 'air-quality-indicator mode-line-misc-info)) (cancel-timer air-quality--timer)) (force-mode-line-update)) -- 2.42.0 --=-=-= Content-Type: text/plain Best, Eshel > -John > > -- > Dr. John Haman > Maryland, USA --=-=-=--