6
6
; ; Keywords: extensions, tools
7
7
; ; URL: https://github.com/kaiwk/leetcode.el
8
8
; ; Package-Requires: ((emacs "26") (dash "2.16.0") (graphql "0.1.1") (spinner "1.7.3") (aio "1.0") (log4e "0.3.3"))
9
- ; ; Version: 0.1.21
9
+ ; ; Version: 0.1.22
10
10
11
11
; ; This program is free software; you can redistribute it and/or modify
12
12
; ; it under the terms of the GNU General Public License as published by
@@ -103,7 +103,7 @@ The object with following attributes:
103
103
The object with following attributes:
104
104
:num Number
105
105
:tag String
106
- :problems Vector
106
+ :problems List
107
107
108
108
The elements of :problems has attributes:
109
109
:status String
@@ -300,19 +300,20 @@ USER-AND-PROBLEMS is an alist comes from
300
300
:easy .ac_easy
301
301
:medium .ac_medium
302
302
:hard .ac_hard))
303
- (leetcode--debug " problem status pairs : %s" .stat_status_pairs )
303
+ (leetcode--debug " set user : %s, solved %s in %s problems " .user_name .num_solved .num_total )
304
304
; ; problem list
305
305
(setq leetcode--all-problems
306
306
(list
307
307
:num .num_total
308
308
:tag " all"
309
309
:problems
310
310
(let* ((len .num_total)
311
- (problems ( make-vector len nil ) ))
311
+ (problems nil ))
312
312
(dotimes (i len)
313
313
(let-alist (aref .stat_status_pairs i)
314
- (aset problems (1- .stat.frontend_question_id)
315
- (list
314
+ (leetcode--debug " frontend_question_id: %s, question_id: %s, title: %s"
315
+ .stat.frontend_question_id .stat.question_id .stat.question__title)
316
+ (push (list
316
317
:status .status
317
318
:id .stat.frontend_question_id
318
319
:backend-id .stat.question_id
@@ -323,15 +324,15 @@ USER-AND-PROBLEMS is an alist comes from
323
324
(/ (float .stat.total_acs)
324
325
.stat.total_submitted)))
325
326
:difficulty .difficulty.level
326
- :paid-only (eq .paid_only t )))))
327
+ :paid-only (eq .paid_only t ))
328
+ problems)))
327
329
problems)))))
328
330
329
331
(defun leetcode--set-tags (all-tags )
330
332
" Set `leetcode--all-tags' and `leetcode--all-problems' with ALL-TAGS."
331
- (leetcode--debug " all tags: %s" all-tags)
332
333
(let-alist all-tags
333
334
; ; set problems tags
334
- (dovec (problem (plist-get leetcode--all-problems :problems ))
335
+ (dolist (problem (plist-get leetcode--all-problems :problems ))
335
336
(dolist (topic (to-list .topics))
336
337
(let-alist topic
337
338
(when (member (plist-get problem :backend-id ) (to-list .questions))
@@ -341,7 +342,7 @@ USER-AND-PROBLEMS is an alist comes from
341
342
; ; set leetcode--all-tags
342
343
(dolist (topic (to-list .topics))
343
344
(let-alist topic
344
- (unless (member topic leetcode--all-tags)
345
+ (unless (member .slug leetcode--all-tags)
345
346
(push .slug leetcode--all-tags))))))
346
347
347
348
(defun leetcode--slugify-title (title )
@@ -458,7 +459,7 @@ Return a list of rows, each row is a vector:
458
459
(medium-tag " medium" )
459
460
(hard-tag " hard" )
460
461
rows)
461
- (dovec (p problems)
462
+ (dolist (p problems)
462
463
(setq rows
463
464
(cons
464
465
(vector
@@ -473,8 +474,8 @@ Return a list of rows, each row is a vector:
473
474
(number-to-string (plist-get p :id ))
474
475
; ; title
475
476
(concat
476
- (plist-get p :title )
477
- " "
477
+ (plist-get p :title )
478
+ " "
478
479
(if (eq (plist-get p :paid-only ) t )
479
480
(prog1 leetcode--paid
480
481
(put-text-property
@@ -486,7 +487,7 @@ Return a list of rows, each row is a vector:
486
487
; ; difficulty
487
488
(leetcode--stringify-difficulty (plist-get p :difficulty ))
488
489
; ; tags
489
- (string-join (plist-get p :tags ) " , " ))
490
+ (if leetcode--display-tags ( string-join (plist-get p :tags ) " , " ) " " ))
490
491
rows)))
491
492
(reverse rows)))
492
493
@@ -500,7 +501,6 @@ Return a list of rows, each row is a vector:
500
501
501
502
(defun leetcode--filter (rows )
502
503
" Filter ROWS by `leetcode--filter-regex' , `leetcode--filter-tag' and `leetcode--filter-difficulty' ."
503
- (leetcode--debug " filter rows: %s" rows)
504
504
(seq-filter
505
505
(lambda (row )
506
506
(and
@@ -553,6 +553,12 @@ Return a list of rows, each row is a vector:
553
553
(completing-read " Difficulty: " leetcode--all-difficulties))
554
554
(leetcode-refresh))
555
555
556
+ (defun leetcode-toggle-tag-display ()
557
+ " Toggle `leetcode--display-tags` and refresh"
558
+ (interactive )
559
+ (setq leetcode--display-tags (not leetcode--display-tags))
560
+ (leetcode-refresh))
561
+
556
562
(aio-defun leetcode--fetch-all-tags ()
557
563
(let* ((url-request-method " GET" )
558
564
(url-request-extra-headers
@@ -587,7 +593,8 @@ Return a list of rows, each row is a vector:
587
593
(defun leetcode-refresh ()
588
594
" Make `tabulated-list-entries' ."
589
595
(interactive )
590
- (let* ((header-names '(" " " #" " Problem" " Acceptance" " Difficulty" " Tags" ))
596
+ (let* ((header-names (append '(" " " #" " Problem" " Acceptance" " Difficulty" )
597
+ (if leetcode--display-tags '(" Tags" ))))
591
598
(rows (leetcode--filter (leetcode--problems-rows)))
592
599
(headers (leetcode--make-tabulated-headers header-names rows)))
593
600
(with-current-buffer (get-buffer-create leetcode--buffer-name)
@@ -611,6 +618,7 @@ Return a list of rows, each row is a vector:
611
618
(leetcode--set-user-and-problems users-and-problems)
612
619
(leetcode--set-tags all-tags))
613
620
(leetcode--warn " LeetCode parse user and problems failed" ))
621
+ (setq leetcode--display-tags leetcode-prefer-tag-display)
614
622
(leetcode-reset-filter)
615
623
(leetcode-refresh))
616
624
@@ -1033,6 +1041,13 @@ Call `leetcode-solve-problem' on the current problem id."
1033
1041
(get-buffer (leetcode--get-code-buffer-name title))))
1034
1042
leetcode--problem-titles))
1035
1043
1044
+ (defcustom leetcode-prefer-tag-display t
1045
+ " Whether to display tags by default in the *leetcode* buffer."
1046
+ :type :boolean )
1047
+
1048
+ (defvar leetcode--display-tags leetcode-prefer-tag-display
1049
+ " (Internal) Whether tags are displayed the *leetcode* buffer." )
1050
+
1036
1051
(defvar leetcode-prefer-language " python3"
1037
1052
" LeetCode programming language.
1038
1053
c, cpp, csharp, golang, java, javascript, kotlin, php, python,
@@ -1104,11 +1119,9 @@ python3, ruby, rust, scala, swift, mysql, mssql, oraclesql.")
1104
1119
1105
1120
(defun leetcode--get-problem-by-id (id )
1106
1121
" Get problem from `leetcode--all-problems' by ID."
1107
- (let ((num (plist-get leetcode--all-problems :num ))
1108
- (problems (plist-get leetcode--all-problems :problems )))
1109
- (when (or (< id 1 ) (> id num))
1110
- (user-error " Not found: No such problem with given id `%d' " id))
1111
- (aref problems (1- id))))
1122
+ (seq-find (lambda (p )
1123
+ (equal id (plist-get p :id )))
1124
+ (plist-get leetcode--all-problems :problems )))
1112
1125
1113
1126
(defun leetcode--get-problem-id (slug-title )
1114
1127
" Get problem id by SLUG-TITLE."
@@ -1189,6 +1202,7 @@ major mode by `leetcode-prefer-language'and `auto-mode-alist'."
1189
1202
(define-key map " s" #'leetcode-set-filter-regex )
1190
1203
(define-key map " l" #'leetcode-set-prefer-language )
1191
1204
(define-key map " t" #'leetcode-set-filter-tag )
1205
+ (define-key map " T" #'leetcode-toggle-tag-display )
1192
1206
(define-key map " d" #'leetcode-set-filter-difficulty )
1193
1207
(define-key map " g" #'leetcode-refresh )
1194
1208
(define-key map " G" #'leetcode-refresh-fetch )
0 commit comments