From 853c5214e4863330016cc983b6c5f30a5bcd3750 Mon Sep 17 00:00:00 2001
From: JSDurand <mmemmew@gmail.com>
Date: Tue, 25 May 2021 16:00:02 +0800
Subject: Refine the mechanism of joining WIFI ports.

* wifi-bluetooth-conf.el (durand-wifi-ssid-machine-alist): The port EX
  has the same password as that of 4F.

(durand-wifi-scanned-ssids):
(durand-wifi-list-sentinel): Record the scanned ports in a variable
for the purpose of completion.

(durand-wifi-join-history): Record the history

(durand-wifi-join-port): Use `completing-read' to read the port.
---
 wifi-bluetooth-conf.el | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/wifi-bluetooth-conf.el b/wifi-bluetooth-conf.el
index 52bff4d..588024d 100644
--- a/wifi-bluetooth-conf.el
+++ b/wifi-bluetooth-conf.el
@@ -151,16 +151,28 @@ If ARG is non-nil, then list the currently connected port."
 (defvar durand-wifi-ssid-machine-alist
   (list
    (cons "20-1" "wifi-2")
-   (cons "1-20-4F" "wifi-4"))
+   (cons "1-20-4F" "wifi-4")
+   (cons "1-20-4F_2EX" "wifi-4"))
   "A list of associations between the SSID of WIFI and the
   machine name that we can use to search for the password in my
   secret file.")
 
+;;;###autoload
+(defvar durand-wifi-scanned-ssids nil
+  "The variable that holds the list of SSIDs of WIFI ports found
+  during the scan.")
+
+;;;###autoload
+(defvar durand-wifi-join-history nil
+  "The variable that holds the history of WIFI ports joined.")
+
 ;;;###autoload
 (defun durand-wifi-join-port (port &optional pwd)
   "Join PORT.
 If PWD is non-nil, use that as the password."
-  (interactive (let ((po (read-string "Port to join: "))
+  (interactive (let ((po (completing-read
+                           "Port to join: " durand-wifi-scanned-ssids
+                           nil nil nil 'durand-wifi-join-history))
                      (pwd (read-string "Password: ")))
                  (cond ((and pwd (not (string= pwd "")))
                         (list po pwd))
@@ -200,6 +212,7 @@ This only does something when STATUS is the string \"finished\\n\"."
                 process)))
   (let (first-var)
     (cond ((string-equal status "finished\n")
+           (setq durand-wifi-scanned-ssids nil)
            (with-current-buffer durand-wifi-bluetooth-buffer
              (goto-char (point-min))
              (cond ((re-search-forward "AirPort: Off" nil t)
@@ -207,20 +220,20 @@ This only does something when STATUS is the string \"finished\\n\"."
                    ((re-search-forward "\\s-+SSID" (line-end-position) t)
                     (setq first-var t)
                     (forward-line 1)
-                    (let ((start 0) list-of-ssids)
+                    (let ((start 0))
                       (while (re-search-forward "\\S-" (line-end-position) t)
                         (forward-char -1)
                         (setq start (point))
                         (re-search-forward "\\s-" (line-end-position) t)
                         (forward-char -1)
-                        (setq list-of-ssids
+                        (setq durand-wifi-scanned-ssids
                               (cons (buffer-substring-no-properties
                                      start (point))
-                                    list-of-ssids))
+                                    durand-wifi-scanned-ssids))
                         (forward-line 1))
                       (erase-buffer)
                       (goto-char (point-min))
-                      (insert (string-join list-of-ssids (string 10)))
+                      (insert (string-join durand-wifi-scanned-ssids (string 10)))
                       (goto-char (point-min))))
                    ((re-search-forward "\\s-+SSID: " nil t)
                     (message (buffer-substring-no-properties
-- 
cgit v1.2.3-18-g5258