Skip to content

Commit a856a7d

Browse files
committed
feat: add mr-poker-recall-resume, universal argument(C-u) for reverse order. close #4 and #5
1 parent bd8a845 commit a856a7d

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

mr-poker.el

+22-7
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,19 @@ Recognize abbreviations like 'C6'."
9494
(concat (cdr (assoc suit-abbrev suits)) " "
9595
(cdr (assoc value-abbrev values)))))))
9696

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)
98101
"Recall the shuffled cards displayed in the *Shuffled Cards* buffer.
99102
Recognize the abbreviation in upper or lower case, and prompt the user to recall
100103
each card one by one to test if they are in the correct order."
101104
(interactive)
102105
(with-current-buffer "*Shuffled Cards*"
103106
(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)))
105110
(if current-prefix-arg ; Check for C-u
106111
(setq cards (reverse cards))) ; If present, reverse cards list
107112
(while (< index (length cards))
@@ -110,25 +115,35 @@ each card one by one to test if they are in the correct order."
110115
(format "Recall card %d (abbreviation): "
111116
(if current-prefix-arg
112117
(- (length cards) index)
113-
(1+ index))))))
118+
(1+ index))))))
114119
(setq user-input (upcase user-input)) ; Convert to uppercase
115120
(let ((full-name (mr-poker-abbrev-to-full user-input)))
116121
(while (not (equal full-name (nth index cards)))
117122
(message "Incorrect. Try again.")
118123
(setq user-input
119124
(read-string
120125
(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)))))
124129
(setq user-input (upcase user-input))
125130
(setq full-name (mr-poker-abbrev-to-full user-input)))
126131
(message "Correct! Card %s is %s."
127132
(if current-prefix-arg
128133
(- (length cards) index)
129134
(1+ index))
130135
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.")))
132147

133148

134149
(provide 'mr-poker)

0 commit comments

Comments
 (0)