diff options
| author | John Wiegley <johnw@newartisans.com> | 2005-06-27 23:52:50 +0000 |
|---|---|---|
| committer | John Wiegley <johnw@newartisans.com> | 2005-06-27 23:52:50 +0000 |
| commit | 43f581fada047e1bf531e723e45c88879d021ff2 (patch) | |
| tree | 60cb8233a3f8bf33f288ca0380b33003eadabc4c | |
| parent | b47066bbd7173752066930bf2a4199738be80ace (diff) | |
(chess-ics-sought-add): Added this routine to factor out a lot of
duplicated code.
| -rw-r--r-- | chess-ics.el | 230 |
1 files changed, 91 insertions, 139 deletions
diff --git a/chess-ics.el b/chess-ics.el index 56959d5..1b244dc 100644 --- a/chess-ics.el +++ b/chess-ics.el @@ -567,7 +567,8 @@ See `chess-ics-game'.") ;; calculate this each time? (when nil (chess-pos-set-status position :stalemate)) - (match-string 29)))) + (match-string 29))) + error) (unwind-protect (if move (if (progn (setq error 'comparing-index) @@ -753,9 +754,12 @@ descending order.") (let ((map (current-local-map))) (define-key map "\r" 'chess-ics-sought-accept) (define-key map [mouse-2] 'chess-ics-sought-accept) + (define-key map [return] 'chess-ics-sought-accept) (define-key map [??] 'describe-mode) (define-key map [?s] 'chess-ics-sought-toggle-sort-state) - (define-key map [? ] 'chess-ics-sought-toggle-sort-direction)) + (define-key map [? ] 'chess-ics-sought-toggle-sort-direction) + (define-key map [?n] 'next-line) + (define-key map [?p] 'previous-line)) (setq sort-fold-case t mode-line-format chess-ics-sought-mode-line-format header-line-format @@ -766,51 +770,56 @@ descending order.") (7 . " Time") " " "Variant%-"))) +(defun chess-ics-sought-add (id name rating rated time inc variant + ics-buffer cmd) + (setq id (concat id (make-string (- 4 (length id)) ? ))) + (setq name (concat name (make-string (- 20 (length name)) ? ))) + (setq variant (concat variant (make-string (- 25 (length variant)) ? ))) + (with-current-buffer + (or (get-buffer chess-ics-sought-buffer-name) + (with-current-buffer (get-buffer-create + chess-ics-sought-buffer-name) + (chess-ics-sought-mode) + (setq chess-ics-sought-parent-buffer ics-buffer) + (and chess-ics-popup-sought (display-buffer (current-buffer))) + (current-buffer))) + (let ((here (point))) + (when (re-search-forward (concat "^" (regexp-quote id) " ") nil t) + (goto-char (line-beginning-position)) + (delete-region (point) (1+ (line-end-position)))) + (goto-char (point-min)) + (let ((beg (point))) + (insert (format "%s %s %4d %4s %3d/%3d %s" + id name rating rated time inc variant)) + (add-text-properties + beg (point) + (list 'rear-nonsticky t + 'mouse-face 'highlight + 'ics-command cmd)) + (insert "\n")) + (chess-ics-sought-sort) + (goto-char here)))) + (defun chess-ics-seeking (string) (while (string-match (concat "[\n\r]+\\(\\S-+\\) (\\([0-9+ -]+\\)) seeking \\([a-z]\\S-+ \\)?\\([0-9]+\\) \\([0-9]+\\) \\(\\(un\\)?rated\\) \\([^(]*\\)(\"\\([^\"]+\\)\" to respond)\\s-*[\n\r]+" chess-ics-prompt-regexp) string) - (let* ((name (match-string 1 string)) - (rating (string-to-int (match-string 2 string))) - (time (string-to-int (match-string 4 string))) - (inc (string-to-int (match-string 5 string))) - (rated (if (string= (match-string 6 string) "rated") "yes" "no")) - (variant (concat (if (match-string 3 string) - (concat (match-string 3 string) " ") "") - (match-string 8 string))) - (cmd (match-string 9 string)) - (id (substring cmd 5)) - (ics-buffer (current-buffer)) - (pre (substring string 0 (match-beginning 0))) + (let* ((pre (substring string 0 (match-beginning 0))) (post (substring string (match-end 0)))) - (setq id (concat id (make-string (- 3 (length id)) ? ))) - (setq name (concat name (make-string (- 20 (length name)) ? ))) - (setq variant (concat variant (make-string (- 25 (length variant)) ? ))) - (with-current-buffer - (or (get-buffer chess-ics-sought-buffer-name) - (with-current-buffer (get-buffer-create - chess-ics-sought-buffer-name) - (chess-ics-sought-mode) - (setq chess-ics-sought-parent-buffer ics-buffer) - (and chess-ics-popup-sought (display-buffer (current-buffer))) - (current-buffer))) - (let ((here (point))) - (when (re-search-forward (concat "^" (regexp-quote id) " ") nil t) - (goto-char (line-beginning-position)) - (delete-region (point) (1+ (line-end-position)))) - (goto-char (point-min)) - (let ((beg (point))) - (insert (format "%s %s %4d %4s %3d/%3d %s" - id name rating rated time inc variant)) - (add-text-properties - beg (point) - (list 'rear-nonsticky t - 'mouse-face 'highlight - 'ics-command cmd)) - (insert "\n")) - (chess-ics-sought-sort) - (goto-char here))) + (chess-ics-sought-add (substring (match-string 9 string) 5) + (match-string 1 string) + (string-to-int (match-string 2 string)) + (if (string= (match-string 6 string) "rated") + "yes" "no") + (string-to-int (match-string 4 string)) + (string-to-int (match-string 5 string)) + (concat + (if (match-string 3 string) + (concat (match-string 3 string) " ") "") + (match-string 8 string)) + (current-buffer) + (match-string 9 string)) (setq string (concat pre post)))) string) @@ -940,55 +949,26 @@ This function should be put on `comint-preoutput-filter-functions'." (chess-game-set-data game color sec)) "") ((and (= dg 50) - (string-match "^\\([0-9]+\\) \\(\\S-+\\) {\\([^}]*\\)} \\([0-9]+\\) \\([0-2]\\) \\([0-9]+\\) \\(\\S-+\\) \\([0-9]+\\) \\([0-9]+\\) \\([01]\\) \\(-?[01]\\) \\([0-9]+\\) \\([0-9]+\\) \\([01]\\) \\([01]\\) {\\([^}]*\\)}" args)) - (let* ((name (concat (match-string 2 args) - (if (not (string= (match-string 3 args) "")) - (format "(%s)" (match-string 3 args)) - ""))) - (rating (string-to-int (match-string 4 args))) - (time (string-to-int (match-string 8 args))) - (inc (string-to-int (match-string 9 args))) - (rated (if (string= (match-string 10 args) "1") "yes" "no")) - (variant (concat (match-string 7 args) - (if (not (string= (match-string 6 args) "0")) - (concat " " (match-string 6 args)) - "") - (if (string= (match-string 14 args) "0") - " m" - "") - (if (string= (match-string 15 args) "1") - " f" - ""))) - (cmd (concat "play " (match-string 1 args))) - (id (substring cmd 5)) - (ics-buffer (current-buffer))) - (setq id (concat id (make-string (- 4 (length id)) ? ))) - (setq name (concat name (make-string (- 20 (length name)) ? ))) - (setq variant (concat variant (make-string (- 25 (length variant)) ? ))) - (with-current-buffer - (or (get-buffer chess-ics-sought-buffer-name) - (with-current-buffer (get-buffer-create - chess-ics-sought-buffer-name) - (chess-ics-sought-mode) - (setq chess-ics-sought-parent-buffer ics-buffer) - (and chess-ics-popup-sought (display-buffer (current-buffer))) - (current-buffer))) - (let ((here (point))) - (when (re-search-forward (concat "^" (regexp-quote id) " ") nil t) - (goto-char (line-beginning-position)) - (delete-region (point) (1+ (line-end-position)))) - (goto-char (point-min)) - (let ((beg (point))) - (insert (format "%s %s %4d %4s %3d/%3d %s" - id name rating rated time inc variant)) - (add-text-properties - beg (point) - (list 'rear-nonsticky t - 'mouse-face 'highlight - 'ics-command cmd)) - (insert "\n")) - (chess-ics-sought-sort) - (goto-char here)))) + (string-match "^\\([0-9]+\\) \\(\\S-+\\) {\\([^}]*\\)} \\([0-9]+\\) \\([0-2]\\) \\([0-9]+\\) \\(\\S-+\\) \\([0-9]+\\) \\([0-9]+\\) \\([01]\\) \\(-?[01]\\) \\([0-9]+\\) \\([0-9]+\\) \\([01]\\) \\([01]\\) {\\([^}]*\\)}" args)) + (chess-ics-sought-add + (match-string 1 args) + (concat (match-string 2 args) + (if (not (string= (match-string 3 args) "")) + (format "(%s)" (match-string 3 args)) + "")) + (string-to-int (match-string 4 args)) + (if (string= (match-string 10 args) "1") "yes" "no") + (string-to-int (match-string 8 args)) + (string-to-int (match-string 9 args)) + (concat (match-string 7 args) + (if (not (string= (match-string 6 args) "0")) + (concat " " (match-string 6 args)) "") + (if (string= (match-string 14 args) "0") + " m" "") + (if (string= (match-string 15 args) "1") + " f" "")) + (current-buffer) + (concat "play " (match-string 1 args))) "") ((= dg 51) (let ((id (car (split-string args " "))) @@ -1080,55 +1060,27 @@ This function should be put on `comint-preoutput-filter-functions'." (chess-game-set-data game color sec)) (setq string (concat pre post))) ((and (= dg 50) - (string-match "\\([0-9]+\\) \\(\\S-+\\) {\\([^}]*\\)} \\([0-9]+\\) \\([0-2]\\) \\([0-9]+\\) \\(\\S-+\\) \\([0-9]+\\) \\([0-9]+\\) \\([01]\\) \\(-?[01]\\) \\([0-9]+\\) \\([0-9]+\\) \\([01]\\) \\([01]\\) {\\([^}]*\\)}" args)) - (let* ((name (concat (match-string 2 args) - (if (not (string= (match-string 3 args) "")) - (format "(%s)" (match-string 3 args)) - ""))) - (rating (string-to-int (match-string 4 args))) - (time (string-to-int (match-string 8 args))) - (inc (string-to-int (match-string 9 args))) - (rated (if (string= (match-string 10 args) "1") "yes" "no")) - (variant (concat (match-string 7 args) - (if (not (string= (match-string 6 args) "0")) - (concat " " (match-string 6 args)) - "") - (if (string= (match-string 14 args) "0") - " m" - "") - (if (string= (match-string 15 args) "1") - " f" - ""))) - (cmd (concat "play " (match-string 1 args))) - (id (substring cmd 5)) - (ics-buffer (current-buffer))) - (setq id (concat id (make-string (- 4 (length id)) ? ))) - (setq name (concat name (make-string (- 20 (length name)) ? ))) - (setq variant (concat variant (make-string (- 25 (length variant)) ? ))) - (with-current-buffer - (or (get-buffer chess-ics-sought-buffer-name) - (with-current-buffer (get-buffer-create - chess-ics-sought-buffer-name) - (chess-ics-sought-mode) - (setq chess-ics-sought-parent-buffer ics-buffer) - (and chess-ics-popup-sought (display-buffer (current-buffer))) - (current-buffer))) - (let ((here (point))) - (when (re-search-forward (concat "^" (regexp-quote id) " ") nil t) - (goto-char (line-beginning-position)) - (delete-region (point) (1+ (line-end-position)))) - (goto-char (point-min)) - (let ((beg (point))) - (insert (format "%s %s %4d %4s %3d/%3d %s" - id name rating rated time inc variant)) - (add-text-properties - beg (point) - (list 'rear-nonsticky t - 'mouse-face 'highlight - 'ics-command cmd)) - (insert "\n")) - (chess-ics-sought-sort) - (goto-char here)))) + (string-match "\\([0-9]+\\) \\(\\S-+\\) {\\([^}]*\\)} \\([0-9]+\\) \\([0-2]\\) \\([0-9]+\\) \\(\\S-+\\) \\([0-9]+\\) \\([0-9]+\\) \\([01]\\) \\(-?[01]\\) \\([0-9]+\\) \\([0-9]+\\) \\([01]\\) \\([01]\\) {\\([^}]*\\)}" args)) + (chess-ics-sought-add + (match-string 1 args) + (concat (match-string 2 args) + (if (not (string= (match-string 3 args) "")) + (format "(%s)" (match-string 3 args)) + "")) + (string-to-int (match-string 4 args)) + (if (string= (match-string 10 args) "1") + "yes" "no") + (string-to-int (match-string 8 args)) + (string-to-int (match-string 9 args)) + (concat (match-string 7 args) + (if (not (string= (match-string 6 args) "0")) + (concat " " (match-string 6 args)) "") + (if (string= (match-string 14 args) "0") + " m" "") + (if (string= (match-string 15 args) "1") + " f" "")) + (current-buffer) + (concat "play " (match-string 1 args))) (setq string (concat pre post))) ((= dg 51) (let ((id (car (split-string args " "))) |
