@@ -94,14 +94,19 @@ Recognize abbreviations like 'C6'."
94
94
(concat (cdr (assoc suit-abbrev suits)) " "
95
95
(cdr (assoc value-abbrev values)))))))
96
96
97
- (defun mr-poker-recall ()
97
+ (defvar mr-poker-last-index nil
98
+ " The last index processed by the mr-poker-recall function." )
99
+
100
+ (defun mr-poker-recall (&optional resume )
98
101
" Recall the shuffled cards displayed in the *Shuffled Cards* buffer.
99
102
Recognize the abbreviation in upper or lower case, and prompt the user to recall
100
103
each card one by one to test if they are in the correct order."
101
104
(interactive )
102
105
(with-current-buffer " *Shuffled Cards*"
103
106
(let ((cards (split-string (buffer-string ) " \n " t ))
104
- (index 0 ))
107
+ (index (if (and resume mr-poker-last-index)
108
+ mr-poker-last-index
109
+ 0 )))
105
110
(if current-prefix-arg ; Check for C-u
106
111
(setq cards (reverse cards))) ; If present, reverse cards list
107
112
(while (< index (length cards))
@@ -110,25 +115,35 @@ each card one by one to test if they are in the correct order."
110
115
(format " Recall card %d (abbreviation): "
111
116
(if current-prefix-arg
112
117
(- (length cards) index)
113
- (1+ index))))))
118
+ (1+ index))))))
114
119
(setq user-input (upcase user-input)) ; Convert to uppercase
115
120
(let ((full-name (mr-poker-abbrev-to-full user-input)))
116
121
(while (not (equal full-name (nth index cards)))
117
122
(message " Incorrect. Try again. " )
118
123
(setq user-input
119
124
(read-string
120
125
(format " Recall card %d (abbreviation): "
121
- (if current-prefix-arg
122
- (- (length cards) index)
123
- (1+ index)))))
126
+ (if current-prefix-arg
127
+ (- (length cards) index)
128
+ (1+ index)))))
124
129
(setq user-input (upcase user-input))
125
130
(setq full-name (mr-poker-abbrev-to-full user-input)))
126
131
(message " Correct! Card %s is %s . "
127
132
(if current-prefix-arg
128
133
(- (length cards) index)
129
134
(1+ index))
130
135
full-name)))
131
- (setq index (1+ index))))))
136
+ (setq index (1+ index))
137
+ (setq mr-poker-last-index index)))))
138
+
139
+ (defun mr-poker-recall-resume ()
140
+ " Resume the mr-poker-recall function from the last index processed."
141
+ (interactive )
142
+ (if mr-poker-last-index
143
+ (progn
144
+ (message " Resuming from index %d . " mr-poker-last-index)
145
+ (mr-poker-recall t ))
146
+ (message " No last index recorded. Please start mr-poker-recall first. " )))
132
147
133
148
134
149
(provide 'mr-poker )
0 commit comments