[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/bluetooth 3d0fe7ed9d 09/32: use a struct for the adapte
From: |
Stefan Kangas |
Subject: |
[elpa] externals/bluetooth 3d0fe7ed9d 09/32: use a struct for the adapter property display in the mode line |
Date: |
Mon, 3 Jan 2022 15:11:07 -0500 (EST) |
branch: externals/bluetooth
commit 3d0fe7ed9d1e789bbb0e84562dbb6ac708ba38f0
Author: Raffael Stocker <r.stocker@mnet-mail.de>
Commit: Raffael Stocker <r.stocker@mnet-mail.de>
use a struct for the adapter property display in the mode line
* bluetooth.el (bluetooth-property): new struct
(bluetooth-property-text): new function
---
bluetooth.el | 44 ++++++++++++++++++++++++++++++--------------
1 file changed, 30 insertions(+), 14 deletions(-)
diff --git a/bluetooth.el b/bluetooth.el
index 2c57e48a50..1d3f0bb402 100644
--- a/bluetooth.el
+++ b/bluetooth.el
@@ -87,15 +87,33 @@ This is usually `:system' if bluetoothd runs as a system
service, or
(put 'bluetooth--mode-info 'risky-local-variable t)
-(defvar bluetooth--mode-state '(("Powered" . (nil nil "off"))
- ("Discoverable"
. (nil "discoverable" nil))
- ("Pairable" .
(nil "pairable" nil))
- ("Discovering"
. (nil "scan" nil)))
+(cl-defstruct bluetooth-property
+ "Bluetooth state information for the mode line with texts shown
+in active and inactive state of a property."
+ active-p
+ (active-text nil :read-only t)
+ (inactive-text nil :read-only t))
+
+(defun bluetooth-property-text (property)
+ "Return the text describing the state of PROPERTY."
+ (if (bluetooth-property-active-p property)
+ (bluetooth-property-active-text property)
+ (bluetooth-property-inactive-text property)))
+
+(defvar bluetooth--mode-state `(("Powered" . ,(make-bluetooth-property
+ :inactive-text "off"))
+ ("Discoverable"
. ,(make-bluetooth-property
+
:active-text "discoverable"))
+ ("Pairable" .
,(make-bluetooth-property
+
:active-text "pairable"))
+ ("Discovering"
. ,(make-bluetooth-property
+ :active-text "scan")))
"Mode line adapter state information.
The state information list defines the kind of adapter state
displayed in the mode-line. The first element of each sub-list
-is an adapter property, the second is a list containing the
+is an adapter property, the second is a ‘bluetooth-property’
+structure containing the
- current status of the item (t or nil),
- string displayed if the property is non-nil,
- string displayed if the property is nil.
@@ -556,10 +574,8 @@ This function only uses the first adapter reported by
Bluez."
(defun bluetooth--mode-info ()
"Update the mode info display."
(let ((info (mapconcat #'identity
- (-keep (lambda (x) (if
(cl-second x)
-
(cl-third x)
-
(cl-fourth x)))
-
bluetooth--mode-state)
+ (--keep
(bluetooth-property-text (cl-rest it))
+
bluetooth--mode-state)
",")))
(unless (string-blank-p info)
(concat " [" info "]"))))
@@ -569,11 +585,11 @@ This function only uses the first adapter reported by
Bluez."
Only adapter properties are considered. If an adapter property changes,
update the status display accordingly."
(when (string= interface (alist-get :adapter bluetooth--interfaces))
- (dolist (elt data)
- (let ((prop (car elt))
- (value (caadr elt)))
- (when-let (state (cdr (assoc prop bluetooth--mode-state)))
- (setcar state value))))))
+ (mapc (lambda (elt)
+ (cl-destructuring-bind (prop (value)) elt
+ (when-let (property (cl-rest (assoc prop
bluetooth--mode-state)))
+ (setf (bluetooth-property-active-p property)
value))))
+ data)))
(defun bluetooth--register-signal-handler ()
"Register a signal handler for adapter property changes.
- [elpa] externals/bluetooth updated (4c7d18c99b -> 7ed3db7260), Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 6aebc228b5 02/32: fix a typo in the info display, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 72cb48584f 01/32: widen address field in tab view to accommodate var-pitch fonts, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 3d0fe7ed9d 09/32: use a struct for the adapter property display in the mode line,
Stefan Kangas <=
- [elpa] externals/bluetooth ada89f2faa 10/32: clean up the signal handler function, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth f971b21d66 03/32: use a structure and hash table for device-info, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 8edeb34f61 05/32: add bluetooth--adapter-properties function, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth bd95b1ca0b 15/32: revert to mapc instead of --map when used for side-effects only, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 273306e1e0 25/32: update the list view more intelligently, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 9878aa8051 14/32: add adapter parameters in adapter-properties and devices functions, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth f2d43ebab5 16/32: make bluetooth--choose-uuid somewhat more readable, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 5a49391b00 07/32: clean up device property handling (breaks info view code), Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth 0627cceab3 08/32: clean up the info view code and add an adapter info view, Stefan Kangas, 2022/01/03
- [elpa] externals/bluetooth f75ac5e43d 11/32: clean up the method registration function, Stefan Kangas, 2022/01/03