-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathigist.el
6191 lines (5552 loc) · 248 KB
/
igist.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; igist.el --- List, create, update and delete GitHub gists -*- lexical-binding: t; -*-
;; Copyright (C) 2022, 2023 Karim Aziiev <karim.aziiev@gmail.com>
;; Author: Karim Aziiev <karim.aziiev@gmail.com>
;; URL: https://github.com/KarimAziev/igist
;; Version: 1.6.4
;; Keywords: tools
;; Package-Requires: ((emacs "27.1") (ghub "3.6.0") (transient "0.4.1"))
;; SPDX-License-Identifier: GPL-3.0-or-later
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Edit, create and view your GitHub gists.
;; Usage
;; `igist-dispatch' - Invoke transient menu with the list of available
;; commands.
;; Tabulated display:
;; M-x `igist-list-gists' - Display your gists as table.
;; M-x `igist-list-other-user-gists' - Display public gists of any user.
;; M-x `igist-explore-public-gists' - List public gists sorted.
;; Completions display:
;; M-x `igist-edit-list' Read Gist to edit from the minibuffer.
;;; Create commands:
;; M-x `igist-create-new-gist'
;; Create the editable gist buffer with the content of the current buffer.
;; M-x `igist-new-gist-from-buffer'
;; Setup new gist buffer whole buffer contents.
;; M-x `igist-list-add-file'
;; Add new file name to gist at point.
;; M-x `igist-fork-gist'
;; Fork gist at point in `igist-list-mode' or currently opened.
;; M-x `igist-post-files' Post multiple files to Gist. If
;; there are marked files in the Dired buffer, use them; otherwise, read
;; the directory in the minibuffer with completions and then read multiple
;; files.
;; Delete commands:
;; M-x `igist-delete-current-gist'
;; Delete current gist with all files.
;; M-x `igist-delete-current-filename'
;; Delete current file from gist.
;; M-x `igist-delete-other-gist-or-file' (gist)
;; Delete GIST with id.
;; M-x `igist-kill-all-gists-buffers'
;; Delete all gists buffers.
;;; Edit commands:
;; M-x `igist-list-view-current'
;; Fetch tabulated gist entry at point.
;; M-x `igist-list-edit-gist-at-point-async' (&optional _entry)
;; Open tabulated GIST-ITEM at point in edit buffer.
;; M-x `igist-browse-gist'
;; Browse gist at point or currently open.
;; M-x `igist-save-current-gist-and-exit'
;; Save current gist.
;; M-x `igist-save-current-gist'
;; Save current gist.
;; M-x `igist-read-filename' (&rest _args)
;; Update filename for current gist without saving.
;; M-x `igist-read-description' (&rest _args)
;; Update description for current gist without saving.
;; M-x `igist-add-file-to-gist'
;; Add new file to existing gist.
;; M-x `igist-toggle-public' (&rest _)
;; Toggle value of variable `igist-current-public'.
;; M-x `igist-list-edit-description' (&rest _)
;; Edit description for current gist at point in tabulated list mode.
;; Comments commands:
;; M-x `igist-post-comment'
;; Post current comment.
;; M-x `igist-delete-comment-at-point' (&rest _)
;; Add or edit comment for gist at point or edit buffer.
;; M-x `igist-add-or-edit-comment' (&rest _)
;; Add or edit comment for gist at point or edit buffer.
;; M-x `igist-add-comment' (&rest _)
;; Add new comment for gist.
;; M-x `igist-load-comments' (&rest _)
;; Load comments for gist at point or edit buffer.
;; User commands:
;; M-x `igist-change-user' (&rest _)
;; Change user for retrieving gist.
;;; Customization
;; - `igist-current-user-name': This variable should be set to a string
;; that contains your GitHub username.
;; - `igist-auth-marker': This variable can either be a string that
;; contains the OAuth token or a symbol indicating where to retrieve
;; the OAuth token.
;; - `igist-message-function': A custom function for displaying messages.
;; Should accept the same arguments as the `message' function.
;; - `igist-per-page-limit': The number of results displayed per page
;; should be a value ranging between 30 to 100. The default value is 30.
;; - `igist-ask-for-description': Determines when to prompt for a
;; description before posting new gists. The default setting prompts
;; for a description before saving a new gist.
;; - `igist-enable-copy-gist-url-p': Specifies whether and when to add
;; the URL of a new or updated gist to the kill ring. The default
;; setting is after the creation of new gists.
;; - `igist-list-format': Specifies the format of the user's Tabulated
;; Gists buffers.
;; - `igist-explore-format': Specifies the format of the Explore Public
;; Gists tabulated buffers.
;;; Keymaps
;; `igist-comments-list-mode-map'
;; A keymap used for displaying comments.
;; `igist-list-mode-map'
;; Keymap used in tabulated gists views.
;; `igist-comments-edit-mode-map'
;; Keymap for posting and editing comments.
;; `igist-edit-mode-map'
;; Keymap used in edit gist buffers.
;;; Code:
(eval-when-compile
(require 'subr-x))
(require 'transient)
(require 'parse-time)
(require 'ghub)
(defvar url-http-end-of-headers)
(declare-function text-property-search-backward "text-property-search")
(defvar-local igist-list-hidden-ids nil)
(defvar-local igist-list-response nil)
(defvar-local igist-table-list-format nil)
(defvar-local igist-render-timer nil)
(defvar-local igist-sync-timer nil)
(defvar-local igist-languages-filters nil)
(defvar-local igist-files-filter nil)
(defvar-local igist-description-filter nil)
(defvar-local igist-filters nil)
(defvar-local igist-rendered-hash nil)
(defvar-local igist-default-collapsed nil)
(defvar igist-tabulated-list--original-order nil)
(defcustom igist-tabulated-list-gui-sort-indicator-asc ?▼
"Indicator for columns sorted in ascending order, for GUI frames.
See `igist-tabulated-list-tty-sort-indicator-asc' for the indicator used on
`text-mode' frames."
:group 'igist
:type 'character)
(defcustom igist-tabulated-list-gui-sort-indicator-desc ?▲
"Indicator for columns sorted in descending order, for GUI frames.
See `igist-tabulated-list-tty-sort-indicator-desc' for the indicator used on
`text-mode' frames."
:group 'igist
:type 'character)
(defcustom igist-tabulated-list-tty-sort-indicator-asc ?v
"Indicator for columns sorted in ascending order, for `text-mode' frames.
See `igist-tabulated-list-gui-sort-indicator-asc' for the indicator used on GUI
frames."
:group 'igist
:type 'character)
(defcustom igist-tabulated-list-tty-sort-indicator-desc ?^
"Indicator for columns sorted in descending order, for `text-mode' frames.
See `igist-tabulated-list-gui-sort-indicator-desc' for the indicator used on GUI
frames."
:group 'igist
:type 'character)
(defcustom igist-tabulated-list-padding 2
"Number of characters preceding each IGist List mode entry."
:group 'igist
:type 'integer)
(defcustom igist-debug nil
"Whether to allow debug logging.
Debug messages are logged to the *IGIST-DEBUG* buffer.
If t, all messages will be logged.
If a number, all messages will be logged, as well shown via `message'.
If a list, it is a list of the types of messages to be logged."
:group 'igist
:type '(radio
(const :tag "none" nil)
(const :tag "all" t)
(checklist :tag "custom"
(integer :tag "Allow echo message buffer")
(const :tag "Loaded list callback" list-callback)
(const :tag "Update rerender" list-update)
(const :tag "Print list" list-print)
(symbol :tag "Other"))))
(defcustom igist-use-header-line t
"Whether the Igist List buffer should use a header line.
If nil, an overlay will be used."
:type 'boolean
:group 'igist)
(defcustom igist-immediate-resize-strategy 20
"Strategy for resizing tabulated entries.
This variable is used in the `igist-tabulated-list-widen-current-column' to
prevent performance issues. According to it's value, some entries may be updated
to this new width immediately, while others - after a slight delay.
- If the value is an integer (e.g. 20), then that many entries near the current
entry will be adjusted immediately. The remaining entries are re-rendered with
the updated new width after a debounced delay of 0.5 seconds.
- If the value is t, all entries in the list will have their column width
changed immediately.
- If the value is `visible', only the on-screen entries in the list will have
their column width changed immediately. Off-screen entries will be updated after
a debounced delay of 1 second.
- If the value is nil or have any other value, only the entry pointed by the
cursor will be altered immediately. The remaining entries are re-rendered with
the updated new width after a debounced delay of 0.5 seconds.
The debouncing mechanism prevents multiple rapid call executions in quick
succession, thereby improving the overall performance while providing immediate
visual feedback for the resizing operation."
:type '(radio
(const :tag "Resize only current entry" nil)
(integer :tag "Maxiumum number of entries" 20)
(const :tag "All visible entries within the window" visible)
(const :tag "All entries" t))
:group 'igist)
(defvar-local igist-tabulated-list-entries nil
"Entries displayed in the current IGist Buffer.")
(put 'igist-tabulated-list-entries 'permanent-local t)
(defvar-local igist-tabulated-list-sort-key nil
"Sort key for the current Igist List mode buffer.
If nil, no additional sorting is performed.
Otherwise, this should be a cons cell (NAME . FLIP).
NAME is a string matching one of the column names in
`igist-list-format' (the corresponding SORT entry in
`igist-list-format' then specifies how to sort). FLIP, if
non-nil, means to invert the resulting sort.")
(put 'igist-tabulated-list-sort-key 'permanent-local t)
(defsubst igist-alist-get-symb (key alist)
"Find the first element of ALIST whose car is eq KEY and return its cdr."
(cdr (assq key alist)))
(defsubst igist-alist-get (key alist)
"Find the first element of ALIST whose car equals KEY and return its cdr."
(cdr (assoc key alist)))
(defsubst igist-tabulated-list-get-id (&optional pos)
"Return the entry ID of the IGist entry at POS.
POS, if omitted or nil, defaults to point."
(get-text-property (or pos (point)) 'igist-tabulated-list-id))
(defun igist-debug (tag &rest args)
"Log debug messages based on the variable `igist-debug'.
Argument TAG is a symbol or string used to identify the debug message.
Remaining arguments ARGS are format string followed by objects to format,
similar to `format' function arguments."
(when (and igist-debug
(or (eq igist-debug t)
(numberp igist-debug)
(and (listp igist-debug)
(memq tag igist-debug))))
(with-current-buffer (get-buffer-create "*IGIST-DEBUG*")
(goto-char (point-max))
(insert (format "%s" tag) " -> " (apply #'format args) "\n")
(when (numberp igist-debug)
(apply #'message args)))))
(defun igist-find-entry-bounds (id)
"Find and return the boundaries of a specific entry in a tabulated list.
Argument ID is a value that is used to find the entry bounds in the igist
tabulated list."
(require 'text-property-search)
(pcase-let ((`(,beg . ,end)
(cond ((equal (igist-tabulated-list-get-id) id)
(igist-property-boundaries 'igist-tabulated-list-id))
((text-property-search-forward
'igist-tabulated-list-id
id
t)
(forward-char -1)
(igist-property-boundaries 'igist-tabulated-list-id))
((text-property-search-backward 'igist-tabulated-list-id
id
t)
(igist-property-boundaries 'igist-tabulated-list-id)))))
(when beg
(cons beg end))))
(defun igist-update-entry (data)
"Update a specific row in the tabulated list with new DATA.
Argument DATA is a list that contains the DATA to be updated in the row."
(pcase-let* ((col (current-column))
(`(,beg . ,end)
(save-excursion
(igist-find-entry-bounds (cdr (assq 'id data))))))
(when (and beg end)
(goto-char beg)
(let ((inhibit-read-only t))
(delete-region beg (1+ end))
(igist-render-entry data)
(goto-char beg)
(move-to-column col)))))
(defun igist-remove-entry (id)
"Remove a specific entry identified by its ID from the igist tabulated list.
Argument ID is a value that identifies the entry to be removed from the list."
(pcase-let* ((col (current-column))
(`(,beg . ,end)
(save-excursion
(igist-find-entry-bounds id))))
(when (and beg end)
(goto-char beg)
(let ((inhibit-read-only t))
(delete-region beg (1+ end))
(goto-char beg)
(move-to-column col)))))
(defun igist-collapse-row-children ()
"Collapse the children of a row in a tabulated list."
(when-let* ((id (igist-tabulated-list-get-id)))
(setq igist-list-hidden-ids (push id igist-list-hidden-ids))
(igist-update-entry (gethash id igist-rendered-hash))))
(defun igist-expand-row-children ()
"Expand the row children in a tabulated list.
Argument VALUE is an optional parameter that represents the entries of
subcolumns if provided, otherwise it get the entries from the
`igist-list-response'."
(when-let* ((id (igist-tabulated-list-get-id)))
(setq igist-list-hidden-ids (delete id igist-list-hidden-ids))
(igist-update-entry (gethash id igist-rendered-hash))))
(defun igist-entry-expanded-p (id)
"Check if ID is a member of `igist-list-hidden-ids''.
Argument ID is the identifier that will be checked for membership in the list
`igist-list-hidden-ids'."
(not (member id igist-list-hidden-ids)))
(defun igist-toggle-children-row (&optional _subentries)
"Toggle visibility of row's children in igist mode.
Argument SUBENTRIES is an optional argument that specifies the subentries to be
expanded when toggling the children row."
(when-let* ((id (igist-tabulated-list-get-id)))
(if (igist-entry-expanded-p id)
(igist-collapse-row-children)
(igist-expand-row-children))))
(defun igist-toggle-all-children ()
"Toggle the visibility of all children in the igist tabulated list."
(interactive)
(setq igist-default-collapsed (not igist-list-hidden-ids))
(setq igist-list-hidden-ids (if igist-list-hidden-ids
nil
(mapcar (apply-partially
#'igist-alist-get-symb 'id)
igist-tabulated-list-entries)))
(igist-tabulated-list-print t))
(defun igist-toggle-row-children-at-point ()
"Toggle visibility of current row's children at point."
(interactive)
(igist-toggle-children-row))
(defun igist--format-plural (count singular-str)
"Format COUNT with SINGULAR-STR, adding \"s\" for plural.
Argument COUNT is an integer representing the quantity to consider for
pluralization.
Argument SINGULAR-STR is a string representing the singular form of the word to
be potentially pluralized."
(concat (format "%d " count)
(concat singular-str
(if (= count 1) "" "s"))))
(defun igist-format-time-diff (time)
"Format a human-readable string representing TIME difference.
Argument TIME is a time value representing the number of seconds since the epoch
\\=(January 1, 1970, 00:00:00 GMT)."
(let ((diff-secs
(- (float-time (encode-time (append (list 0)
(cdr (decode-time
(current-time))))))
(float-time
(encode-time (append (list 0)
(cdr (decode-time time))))))))
(if (zerop (round diff-secs))
"Now"
(let* ((past (> diff-secs 0))
(diff-secs-int (if past diff-secs (- diff-secs)))
(suffix (if past "ago" "from now"))
(minutes-secs 60)
(hours-secs (* 60 minutes-secs))
(day-secs (* 24 hours-secs))
(month-secs (* 30 day-secs))
(year-secs (* 365 day-secs))
(res
(cond ((< diff-secs-int minutes-secs)
(igist--format-plural (truncate diff-secs-int) "second"))
((< diff-secs-int hours-secs)
(igist--format-plural (truncate (/ diff-secs-int
minutes-secs))
"minute"))
((< diff-secs-int day-secs)
(igist--format-plural (truncate
(/ diff-secs-int hours-secs))
"hour"))
((< diff-secs-int month-secs)
(igist--format-plural (truncate (/ diff-secs-int day-secs))
"day"))
((< diff-secs-int year-secs)
(igist--format-plural (truncate
(/ diff-secs-int month-secs))
"month"))
(t
(let* ((months (truncate (/ diff-secs-int month-secs)))
(years (/ months 12))
(remaining-months (% months 12)))
(string-join
(delq nil
(list
(when (> years 0)
(igist--format-plural years "year"))
(when (> remaining-months 0)
(igist--format-plural remaining-months "month"))))
" "))))))
(concat res " " suffix)))))
(defun igist-render-time (value)
"Format a given VALUE as a date and time.
Argument VALUE is the input value that will be used to calculate the rendered
time."
(if value
(igist-format-time-diff
(parse-iso8601-time-string value))
""))
(defun igist-render-comments (comments)
"Default renderer for COMMENTS column."
(cons
(format "%s" comments)
(list
'action
#'igist-load-comments)))
(defun igist-render-user (owner)
"Default renderer for OWNER column."
(let ((user (igist-alist-get-symb
'login owner)))
(list (or (igist-alist-get-symb
'login owner)
"")
'button-data user
'action #'igist-explore-load-other-user-gists)))
(defun igist-render-public (public)
"Default renderer for PUBLIC column."
(if public "Public" "Secret"))
(defun igist-render-url (url)
"Render URL as a browseable button.
Render the URL for browsing."
(list url 'action #'browse-url 'button-data url))
(defun igist-render-api-url (url)
"Render API URL and download it.
Render the API URL for the given URL."
(list url 'action (lambda (it)
(kill-new it)
(igist-message "Copied %s" it))
'button-data url))
(defun igist-render-language (language)
"Default renderer for LANGUAGE column."
(list
(or language "None")
'action #'igist-toggle-language-filter
'button-data (or language "None")))
(defvar igist-default-formats
'((id "ID" 9 nil "%s" :pad-right 4)
(description "Description" 50 igist-sort-pred-string "%s")
(created_at "Created" 15 igist-sort-pred-date igist-render-time)
(updated_at "Updated" 15 igist-sort-pred-date igist-render-time)
(owner "User" 10 t igist-render-user)
(comments "Comments" 9 igist-sort-pred-integer igist-render-comments
:center-align t)
(public "Public" 8 igist-sort-pred-boolean igist-render-public)
(files "Files" 10 igist-sort-pred-list "%s"
:children ((filename "File" 90 nil "%s")
(language "Language" 8
nil igist-render-language :right-align t))
:align-to-column 1)
(comments_url "Comment URL" 8 igist-sort-pred-string "%s")
(html_url "URL" 20 igist-sort-pred-string igist-render-url)
(forks_url "Forks" 20 igist-sort-pred-string igist-render-api-url)
(truncated "Trunc." 4 t "%s" :center-align t)
(git_push_url "Push URL" 20 igist-sort-pred-string igist-render-api-url)
(git_pull_url "Pull URL" 20 igist-sort-pred-string igist-render-api-url)))
(defvar igist-sort-pred-alist
'((id . igist-sort-pred-string)
(url . igist-sort-pred-string)
(forks_url . igist-sort-pred-string)
(commits_url . igist-sort-pred-string)
(node_id . igist-sort-pred-string)
(git_pull_url . igist-sort-pred-string)
(git_push_url . igist-sort-pred-string)
(html_url . igist-sort-pred-string)
(public . igist-sort-pred-boolean)
(created_at . igist-sort-pred-date)
(updated_at . igist-sort-pred-date)
(description . igist-sort-pred-string)
(comments . igist-sort-pred-integer)
(comments_url . igist-sort-pred-string)
(owner . igist-sort-pred-owner-login)
(files . igist-sort-pred-list)))
(defvar igist-explore-buffer-name "*igist-explore*"
"Buffer name for tabulated gists display of multiple owners.")
(defcustom igist-explore-gists-init-collapsed t
"Whether the gists should be collapsed by default in explore buffers."
:type 'boolean
:group 'igist)
(defcustom igist-user-gists-init-collapsed nil
"Whether the gists should be collapsed by default in user buffers."
:type 'boolean
:group 'igist)
(defun igist-make-column-custom-type (field-name &optional width)
"Create a custom column type for the igist interface.
Argument FIELD-NAME is the name of the field for which a custom column type is
being created.
Argument WIDTH is an optional argument that specifies the WIDTH of the column;
if not provided, the length of the field name is used as the WIDTH."
(let ((title (capitalize (car
(split-string
(symbol-name field-name) "[^a-z]" t))))
(default-sorter (cdr (assq field-name igist-sort-pred-alist)))
(default-formatter (or
(car (nthcdr 4 (assq field-name
igist-default-formats)))
"%s"))
(props `(set
:inline t
(list
:inline t
(radio :value :center-align
(const
:tag "Right"
:right-align)
(const
:tag "Center"
:center-align))
(const :format "" t))
(list
:format "%v"
:inline t
(const
:format ""
:pad-right)
(integer :tag ":pad-right" 1)))))
(when (eq field-name 'files)
(setq props (append props '((list
:format "%v"
:inline t
(const
:format ""
:align-to-column)
(integer :tag ":align-to-column" 1))
(list
:format "%v"
:inline t
(const
:format ""
:children)
(alist
:tag "Subrow"
:key-type (choice
(const :tag "Filename" filename)
(const :tag "Language" language)
(const :tag "Raw_url" raw_url)
(const :tag "Size" size))
:value-type
(list
(string :tag "Column Name")
(integer :tag "Column Width" 10)
(choice
(boolean :tag "Sortable")
(function :tag "Sort function"))
(choice :value "%s"
(string
:tag "Format")
(function :tag "Formatter"))
(set
:inline t
(list
:inline t
(radio :value :center-align
(const
:tag "Right"
:right-align)
(const
:tag "Left"
:center-align))
(const :format "" t))
(list
:format "%v"
:inline t
(const
:format ""
:pad-right)
(integer :tag ":pad-right" 1))))))))))
`(list
:tag ,(symbol-name field-name)
(const ,field-name)
(string
:tag "Column Name"
:completions
(lambda
(string pred action)
(let ((completion-ignore-case t))
(complete-with-action action (list ,title) string pred)))
:value ,title)
(integer :tag "Column Width" ,(or width
(length title)))
(choice
:tag "Sortable"
:value ,default-sorter
(boolean :tag "Sortable" t)
(function :tag "Sort function" ,default-sorter))
,(if (stringp default-formatter)
`(radio :value ,default-formatter
(string :tag "Format" "%s")
(function :tag "Formatter"))
`(radio :value ,default-formatter
(string :tag "Format" "%s")
(function :tag "Formatter" ,default-formatter)))
,props)))
(defcustom igist-explore-format '((id "ID" 10 nil "%s" :pad-right 4)
(description "Description" 50
igist-sort-pred-string "%s")
(updated_at "Updated" 15 igist-sort-pred-date
igist-render-time)
(owner "User" 10 t igist-render-user
:center-align t
:pad-right 4)
(comments "Comments" 9 igist-sort-pred-integer
igist-render-comments
:center-align t)
(files "Files" 10 igist-sort-pred-list "%s"
:children
((filename "File" 90 nil "%s")
(language "Language" 8 nil
igist-render-language
:right-align t))
:align-to-column 1))
"The format of the Explore Public Gists tabulated buffers.
Each element in the alist represents a column and has the following structure:
\(FIELD COLUMN-NAME WIDTH SORTABLE FORMAT-FUNCTION/FORMAT-STRING PROPS)
- FIELD: Specifies the field name or key for the column.
- COLUMN-NAME: Specifies the name or label for the column.
- WIDTH: Specifies the width of the column.
- SORTABLE: Indicates whether the column is sortable. Can be t, nil or
a function.
- FORMAT-FUNCTION/FORMAT-STRING: Specifies the function or format string
used to format the data. A function will be called with the value of
the corresponding field name.
- PROPS is a plist of additional column properties.
Currently supported properties are:
- :center-align or :right-align:
If non-nil, align the column should be center or right-aligned.
- :pad-right: Number of additional padding spaces to theright of the column,
- :children - Specification expandable row values in the same format,
but without PROPS:
\(FIELD COLUMN-NAME WIDTH SORTABLE FORMAT-FUNCTION/FORMAT-STRING)
- :align-to-column - index of parent column to align children.
User can interactively add or remove columns, edit them adjusts the
width of the columns with transient inferface:
- `igist-table-menu'
and save the result with command `igist-save-column-settings'."
:type `(repeat
(choice
:tag "Column"
:value ,(car (last igist-default-formats))
,@(mapcar (lambda (it)
(igist-make-column-custom-type it))
'(id description comments owner
user
files
node_id git_pull_url
url forks_url commits_url
git_push_url
html_url public created_at
updated_at
comments_url truncated))))
:group 'igist)
(defcustom igist-list-format '((id "ID" 9 nil "%s" :pad-right 4)
(description "Description" 50
igist-sort-pred-string "%s")
(public "Public" 8 igist-sort-pred-boolean
igist-render-public)
(updated_at "Updated" 15 igist-sort-pred-date
igist-render-time)
(comments "Comments" 9 igist-sort-pred-integer
igist-render-comments
:center-align t)
(files "Files" 10 igist-sort-pred-list "%s"
:children
((filename "File" 90 nil "%s")
(language "Language" 8 nil
igist-render-language
:right-align t))
:align-to-column 1))
"The format of the Gists to display in users buffers.
Each element in the alist represents a column and has the following structure:
\(FIELD COLUMN-NAME WIDTH SORTABLE FORMAT-FUNCTION/FORMAT-STRING PROPS)
- FIELD: Specifies the field name or key for the column.
- COLUMN-NAME: Specifies the name or label for the column.
- WIDTH: Specifies the width of the column.
- SORTABLE: Indicates whether the column is sortable. Can be t, nil or
a function.
- FORMAT-FUNCTION/FORMAT-STRING: Specifies the function or format string
used to format the data. A function will be called with the value of
the corresponding field name.
- PROPS is a plist of additional column properties.
Currently supported properties are:
- :center-align or :right-align:
If non-nil, align the column should be center or right-aligned.
- :pad-right: Number of additional padding spaces to theright of the column,
- :children - Specification expandable row values in the same format,
but without PROPS:
\(FIELD COLUMN-NAME WIDTH SORTABLE FORMAT-FUNCTION/FORMAT-STRING)
- :align-to-column - index of parent column to align children.
User can interactively add or remove columns, edit them adjusts the
width of the columns with transient inferface:
- `igist-table-menu'
and save the result with command `igist-save-column-settings'."
:type `(repeat
(choice
:tag "Column"
:value ,(car (last igist-default-formats))
,@(mapcar (lambda (it)
(igist-make-column-custom-type it))
'(id description comments owner
user
files
node_id git_pull_url
url forks_url commits_url
git_push_url
html_url public created_at
updated_at
comments_url truncated))))
:group 'igist)
(defcustom igist-enable-copy-gist-url-p 'after-new
"Whether and when to add new or updated gist's URL to kill ring."
:group 'igist
:type '(radio
(const :tag "After creating new and saving existing gists" t)
(const :tag "After saving existing gists" after-update)
(const :tag "After creating new gist" after-new)
(const :tag "Never" nil)))
(defcustom igist-mode-for-comments 'markdown-mode
"Major mode when editing and viewing comments.
Program `pandoc' should be installed for `org-mode'."
:type '(radio
(const :tag "Org mode" org-mode)
(const :tag "Markdown" markdown-mode)
(function :tag "Other"))
:group 'igist)
(defcustom igist-ask-for-description 'before-save
"When to prompt for description before posting new gists."
:type '(radio
(const :tag "Never" nil)
(const :tag "Immediately" immediately)
(const :tag "Auto" auto)
(const :tag "Before posting" before-save))
:group 'igist)
(defun igist-check-per-page-range (n)
"Validate per page N."
(and (numberp n)
(>= n 1)
(<= n 100)))
(defcustom igist-per-page-limit 30
"The number of results per page. It should be the value between 30 to 100."
:type '(restricted-sexp
:tag "Per page"
:value 30
:match-alternatives (igist-check-per-page-range))
:group 'igist)
(defcustom igist-message-function 'minibuffer-message
"Function to show messages.
Should accept the same arguments as `message'."
:type '(choice
(const :tag "None" nil)
(function :tag "Function"))
:group 'igist)
(defvar igist-before-save-hook '()
"A list of hooks run before posting gist.")
(defcustom igist-current-user-name ""
"The GitHub username for the current user.
This is the username used by the `igist' for interactions
with the GitHub service. Setting this variable allows the
package to make requests on behalf of the user for actions such
as listing or creating gists."
:group 'igist
:type 'string)
(defcustom igist-auth-marker 'igist
"GitHub OAuth token or suffix added to the USERNAME^MARKER in auth sources.
This variable can either hold an explicit OAuth token as a string,
in which case igist will use this token for authentication, or a
symbol that is used as a suffix for the `login' field in `auth-sources'.
For example, if you set this to the symbol `igist' (the default setting),
you would add an entry like this to your auth-sources:
\"machine api.github.com login GITHUB_USERNAME^igist password GITHUB_TOKEN\".
Igist will then use the GITHUB_TOKEN from this entry when authenticating
with the GitHub API."
:group 'igist
:type '(radio
(string :tag "OAuth Token")
(symbol :tag "Suffix" igist)))
(defcustom igist-clone-default-directory 'igist-clone-get-default-directory
"Default directory to use when `igist-clone-gist' reads destination.
If nil or symbol `default-directory' then use the value of `default-directory'.
If a directory, then use that. If a function, then call that
with the gist id as only argument and use the returned value."
:group 'igist
:type '(radio (const :tag "value of default-directory" default-directory)
(directory :tag "constant directory")
(function :tag "function's value")))
(defvar igist-github-token-scopes '(gist)
"The required GitHub API scopes.
You need the gist OAuth scope and a token.
You have to manually create or update the token at
https://github.com/settings/tokens. This variable
only serves as documentation.")
(defvar-local igist-current-gist-error nil
"Current gist error in the edit buffer.")
(put 'igist-current-gist-error 'permanent-local t)
(defvar-local igist-current-gist-loading nil
"Current gist status in the edit buffer.")
(put 'igist-current-gist-loading 'permanent-local t)
(defvar-local igist-current-gist nil
"Current gist in the edit buffer.")
(put 'igist-current-gist 'permanent-local t)
(defvar-local igist-current-description nil
"Current gist description in the edit buffer.")
(put 'igist-current-description 'permanent-local t)
(defvar-local igist-current-public nil
"Whether the current gist in the edit buffer is public or private.")
(put 'igist-current-public 'permanent-local t)
(defvar-local igist-current-filename nil
"Current gist filename.")
(put 'igist-current-filename 'permanent-local t)
(defvar-local igist-comment-gist-id nil
"Current gist's id in the comment buffer.")
(put 'igist-comment-gist-id 'permanent-local t)
(defvar-local igist-comment-id nil
"Current comment id.")