forked from hayamiz/twittering-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
twittering-mode.el
13230 lines (12388 loc) · 477 KB
/
twittering-mode.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
;;; twittering-mode.el --- Major mode for Twitter
;; Copyright (C) 2009-2015 Tadashi MATSUO
;; 2007, 2009-2011 Yuto Hayamizu.
;; 2008 Tsuyoshi CHO
;; 2014, 2015 Xavier Maillard
;; Author: Tadashi MATSUO <[email protected]>
;; Y. Hayamizu <[email protected]>
;; Tsuyoshi CHO <[email protected]>
;; Alberto Garcia <[email protected]>
;; Xavier Maillard <[email protected]>
;; Created: Sep 4, 2007
;; Version: HEAD
;; Identity: $Id$
;; Keywords: twitter web
;; URL: http://twmode.sf.net/
;; This file 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 2, or (at your option)
;; any later version.
;; This file 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 GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; twittering-mode.el is a major mode for Twitter.
;; You can check friends timeline, and update your status on Emacs.
;;; Feature Request:
;; URL : http://twitter.com/d00dle/statuses/577876082
;; * Status Input from Popup buffer and C-cC-c to POST.
;; URL : http://code.nanigac.com/source/view/419
;; * update status for region
;;; Code:
(eval-when-compile (require 'cl)
(require 'easymenu))
(require 'xml)
(eval-and-compile
;; On byte-compilation, Emacs21 requires loading the libraries
;; distributed with twittering-mode.el for macros defined in them.
(when (> 22 emacs-major-version)
(setq load-path
(append (mapcar (lambda (dir)
(expand-file-name
dir
(if load-file-name
(or (file-name-directory load-file-name)
".")
".")))
'("url-emacs21" "emacs21"))
load-path))))
(when (> 22 emacs-major-version)
(and (require 'un-define nil t)
;; the explicitly require 'unicode to update a workaround with
;; navi2ch. see a comment of `twittering-ucs-to-char' for more
;; details.
(require 'unicode nil t))
(defadvice url-scheme-register-proxy (around twittering-fix-process-env (scheme) activate)
(let ((process-environment
(apply 'append
(let ((env-var (concat scheme "_proxy")))
(mapcar
(lambda (str)
(if (string-match
(concat "^\\("
(regexp-opt (list (upcase env-var)
(downcase env-var)))
"\\)=$")
str)
nil
(list str)))
process-environment)))))
ad-do-it)))
(require 'url)
(defgroup twittering-mode nil
"Settings for twittering-mode."
:link '(url-link "https://github.com/hayamiz/twittering-mode")
:prefix "twittering-"
:group 'hypermedia)
(defconst twittering-mode-version "HEAD")
(defconst twittering-mode-identity "$Id$")
(defvar twittering-api-host "api.twitter.com")
(defvar twittering-api-search-host "search.twitter.com")
(defvar twittering-web-host "twitter.com")
(defvar twittering-oauth-request-token-url-without-scheme
"://api.twitter.com/oauth/request_token")
(defvar twittering-oauth-authorization-url-base-without-scheme
"://api.twitter.com/oauth/authorize?oauth_token=")
(defvar twittering-oauth-access-token-url-without-scheme
"://api.twitter.com/oauth/access_token")
(defun twittering-mode-version ()
"Display a message for twittering-mode version."
(interactive)
(let ((version-string
(format "twittering-mode-v%s" twittering-mode-version)))
(if (interactive-p)
(message "%s" version-string)
version-string)))
(defcustom twittering-auth-method 'oauth
"*Authentication method to use with `twittering-mode'.
Choose between symbols `oauth' (default), `basic' or `xauth'.
OAuth Authentication requires `twittering-oauth-consumer-key' and
`twittering-oauth-consumer-secret'.
Additionally, it requires an external command `curl' or another
command included in `tls-program', which may be `openssl' or
`gnutls-cli', for SSL."
:group 'twittering-mode
:type '(choice :tag "Twitter authentication method"
(const :tag "Basic authentication" :value basic)
(const :tag "OAuth authentication" :value oauth)
(const :tag "xAuth authentication" :value xauth)))
(defvar twittering-account-authorization nil
"State of account authorization for `twittering-username' and
`twittering-password'. The value is one of the following symbols:
nil -- The account have not been authorized yet.
queried -- The authorization has been queried, but not finished yet.
authorized -- The account has been authorized.")
(defcustom twittering-oauth-use-ssl t
"*If non-nil, use SSL authentication for OAuth.
Twitter requires SSL on authorization via OAuth."
:group 'twittering-mode
:type 'boolean)
(defcustom twittering-oauth-invoke-browser nil
"*If non-nil, invoke a browser on authorization of access key automatically."
:type 'boolean
:group 'twittering-mode)
(defvar twittering-oauth-consumer-key nil)
(defvar twittering-oauth-consumer-secret nil)
(defvar twittering-oauth-access-token-alist nil)
(defconst twittering-max-number-of-tweets-on-retrieval 200
"The maximum number of `twittering-number-of-tweets-on-retrieval'.")
(defcustom twittering-number-of-tweets-on-retrieval 20
"*Number of tweets which will be retrieved in one request.
The upper limit is `twittering-max-number-of-tweets-on-retrieval'."
:type 'integer
:group 'twittering-mode)
(defcustom twittering-tinyurl-service 'tinyurl
"*Shorten URI service to use.
This must be one of key symbols of `twittering-tinyurl-services-map'.
To use bit.ly or j.mp services, you have to configure
`twittering-bitly-login' and `twittering-bitly-api-key'."
:type '(radio (symbol :tag "bit.ly"
:value bit.ly)
(symbol :tag "goo.gl"
:value goo.gl)
(symbol :tag "is.gd"
:value is.gd)
(symbol :tag "j.mp"
:value j.mp)
(symbol :tag "migre.me"
:value migre.me)
(symbol :tag "tinyurl"
:value tinyurl)
(symbol :tag "toly"
:value toly))
:group 'twittering-mode)
(defcustom twittering-tinyurl-services-map
'((bit.ly twittering-make-http-request-for-bitly
(lambda (service reply)
(if (string-match "\n\\'" reply)
(substring reply 0 (match-beginning 0))
reply)))
(goo.gl
(lambda (service longurl)
(twittering-make-http-request-from-uri
"POST" '(("Content-Type" . "application/json"))
"https://www.googleapis.com/urlshortener/v1/url"
(concat "{\"longUrl\": \"" longurl "\"}")))
(lambda (service reply)
(when (string-match "\"id\"[[:space:]]*:[[:space:]]*\"\\([^\"]*\\)\""
reply)
(match-string 1 reply))))
(is.gd . "http://is.gd/create.php?format=simple&url=")
(j.mp twittering-make-http-request-for-bitly
(lambda (service reply)
(if (string-match "\n\\'" reply)
(substring reply 0 (match-beginning 0))
reply)))
(migre.me . "http://migre.me/api.txt?url=")
(tinyurl . "http://tinyurl.com/api-create.php?url=")
(toly
(lambda (service longurl)
(twittering-make-http-request-from-uri
"POST" nil
"http://to.ly/api.php"
(concat "longurl=" (twittering-percent-encode longurl))))))
"Alist of URL shortening services.
The key is a symbol specifying the service.
The value is a string or a list consisting of two elements at most.
If the value is a string, `(concat THE-FIRST-ELEMENT longurl)' is used as the
URL invoking the service.
If the value is a list, it is interpreted as follows.
The first element specifies how to make a HTTP request for shortening a URL.
If the first element is a string, `(concat THE-FIRST-ELEMENT longurl)' is
used as the URL invoking the service.
If the first element is a function, it is called as `(funcall THE-FIRST-ELEMENT
service-symbol longurl)' to obtain a HTTP request alist for invoking the
service, which must be generated by `twittering-make-http-request'.
The second element specifies how to post-process a HTTP reply by the HTTP
request.
If the second element is nil, the reply is directly used as a shortened URL.
If the second element is a function, it is called as `(funcall
THE-SECOND-ELEMENT service-symbol HTTP-reply-string)' and its result is used
as a shortened URL."
:type 'alist
:group 'twittering-mode)
(defcustom twittering-bitly-login nil
"*The login name for URL shortening service bit.ly and j.mp."
:type '(choice (const nil)
string)
:group 'twittering-mode)
(defcustom twittering-bitly-api-key nil
"*API key for `bit.ly' and `j.mp' URL shortening services."
:type '(choice (const nil)
string)
:group 'twittering-mode)
(defvar twittering-mode-map (make-sparse-keymap))
(defvar twittering-mode-menu-on-uri-map (make-sparse-keymap "Twittering Mode"))
(defvar twittering-mode-on-uri-map (make-sparse-keymap))
(defvar twittering-tweet-history nil)
(defvar twittering-user-history nil)
(defvar twittering-timeline-history nil)
(defvar twittering-hashtag-history nil)
(defvar twittering-search-history nil)
(defvar twittering-current-hashtag nil
"A hash tag string currently set. You can set it by calling
`twittering-set-current-hashtag'.")
(defvar twittering-timer nil
"Timer object for timeline refreshing will be stored here.
DO NOT SET VALUE MANUALLY.")
(defcustom twittering-timer-interval 90
"Number of seconds to wait before an auto-reload occurs.
Number of API calls per hour is limited so this value should be 60 or more."
:type 'integer
:group 'twittering-mode)
(defvar twittering-timer-for-redisplaying nil
"Timer object for timeline redisplay statuses will be stored here.
DO NOT SET VALUE MANUALLY.")
(defvar twittering-timer-interval-for-redisplaying 5.0
"The interval of auto redisplaying statuses.
Each time Emacs remains idle for the interval, twittering-mode updates parts
requiring to be redrawn.")
(defcustom twittering-username nil
"*A username of your Twitter account."
:type '(choice (const nil)
string)
:group 'twittering-mode)
(defcustom twittering-password nil
"*A password of your Twitter account. Leave it blank is the
recommended way because writing a password in .emacs file is so
dangerous."
:type '(choice (const nil)
string)
:group 'twittering-mode)
(defcustom twittering-initial-timeline-spec-string ":home"
"*An initial timeline spec string or a list of timeline spec strings.
This specifies one or more initial timeline spec strings, which are
automatically visited when invoking `twittering-mode' or `twit'.
If it is a string, it specifies a timeline spec string.
If it is a list of strings, it specifies multiple timeline spec strings."
:type '(choice (const nil)
string
(repeat string))
:group 'twittering-mode)
(defvar twittering-timeline-spec nil
"The timeline spec for the current buffer.")
(defvar twittering-timeline-spec-string ""
"The timeline spec string for the current buffer.")
(defcustom twittering-timeline-spec-alias nil
"*Alist for aliases of timeline spec.
Each element is (NAME . SPEC-STRING), where NAME is a string and
SPEC-STRING is a string or a function that returns a timeline spec string.
The alias can be referred as \"$NAME\" or \"$NAME(ARG)\" in timeline spec
string. If SPEC-STRING is a string, ARG is simply ignored.
If SPEC-STRING is a function, it is called with a string argument.
For the style \"$NAME\", the function is called with nil.
For the style \"$NAME(ARG)\", the function is called with a string ARG.
For example, if you specify
`((\"FRIENDS\" . \"my-account/friends-list\")
(\"related-to\" .
,(lambda (username)
(if username
(format \":search/to:%s OR from:%s OR @%s/\"
username username username)
\":home\")))),
then you can use \"$FRIENDS\" and \"$related-to(USER)\" as
\"my-account/friends-list\" and \":search/to:USER OR from:USER OR @USER/\",
respectively."
:type 'alist
:group 'twittering-mode)
(defvar twittering-current-timeline-spec-string nil
"The current timeline spec string. This variable should not be referred
directly. Use `twittering-current-timeline-spec-string' or
`twittering-current-timeline-spec'.")
(defvar twittering-list-index-retrieved nil)
(defvar twittering-process-info-alist nil
"Alist of active process and timeline spec retrieved by the process.")
(defvar twittering-server-info-alist nil
"Alist of server information.")
(defvar twittering-api-limit-info-alist '()
"Alist of an API identifier and an alist representing rate limit for the API.")
(defvar twittering-timeline-spec-to-api-table '()
"Alist of a timeline spec and an API identifier for retrieving the timeline.")
(defcustom twittering-mode-init-hook nil
"*Hook run after initializing global variables for `twittering-mode'."
:type 'hook
:group 'twittering-mode)
(defcustom twittering-mode-hook nil
"*Hook run every time a buffer is initialized as a `twittering-mode' buffer."
:type 'hook
:group 'twittering-mode)
(defvar twittering-cookie-alist nil
"Alist for stroing cookies for each account.
This variable stores an alist.
A key of the alist is a string that is a screen name of an account.
A value of the alist is a cookie alist which corresponds to a list of
a pair of a cookie name and value.")
(defvar twittering-new-tweets-count 0
"Number of new tweets when `twittering-new-tweets-hook' is run.")
(defvar twittering-new-tweets-spec nil
"Timeline spec, which new tweets belong to, when
`twittering-new-tweets-hook' is run.")
(defvar twittering-new-tweets-statuses nil
"New tweet status messages, when
`twittering-new-tweets-hook' is run.")
(defcustom twittering-new-tweets-hook nil
"*Hook run when new tweets are received.
You can read `twittering-new-tweets-count' or `twittering-new-tweets-spec'
to get the number of new tweets received when this hook is run."
:type 'hook
:group 'twittering-mode)
(defvar twittering-rendered-new-tweets-spec nil
"A timeline spec of newly rendered tweets.
This variable is bound when invoking hooks registered with
`twittering-new-tweets-rendered-hook'.")
(defvar twittering-rendered-new-tweets-spec-string nil
"A timeline spec string of newly rendered tweets.
This variable is bound when invoking hooks registered with
`twittering-new-tweets-rendered-hook'.")
(defvar twittering-rendered-new-tweets nil
"A list of newly rendered tweets.
Hooks registered with `twittering-new-tweets-rendered-hook' can use this
variable as a list of rendered tweets. Each tweet is represented as an alist.
You can refer to a property of a tweet alist as
(cdr (assq PROPERTY-SYMBOL TWEET-ALIST)).
Valid symbols are following; id, text, user-name, user-screen-name, user-id,
source, source-uri.
In the list, tweets are placed in order of time. The car of the list is the
latest one, and the last is the oldest one.")
(defcustom twittering-new-tweets-rendered-hook nil
"*Hook run when new tweets are rendered.
When the registered functions are called, the current buffer is the buffer
that the new tweets are just rendered on.
The functions can refer to the timeline spec and timeline spec string as
`twittering-rendered-new-tweets-spec' and
`twittering-rendered-new-tweets-spec-string', repectively.
Hooks can also use the local variable `twittering-rendered-new-tweets' as a
list of rendered tweets.
For the detail of the representation of tweets, see the variable
`twittering-rendered-new-tweets'."
:type 'hook
:group 'twittering-mode)
(defvar twittering-active-mode nil
"Non-nil if new statuses should be retrieved periodically.
Do not modify this variable directly. Use `twittering-activate-buffer',
`twittering-deactivate-buffer', `twittering-toggle-activate-buffer' or
`twittering-set-active-flag-for-buffer'.")
(defvar twittering-jojo-mode nil)
(defcustom twittering-reverse-mode nil
"*Non-nil means tweets are aligned in reverse order of `http://twitter.com/'."
:type 'boolean
:group 'twittering-mode)
(defcustom twittering-display-remaining nil
"*If non-nil, display remaining of rate limit on the mode-line."
:type 'boolean
:group 'twittering-mode)
(defcustom twittering-display-connection-method t
"*If non-nil, display the current connection method on the mode-line."
:type 'boolean
:group 'twittering-mode)
(defcustom twittering-status-format "%RT{%FACE[bold]{RT}}%i %s, %@:\n%FOLD[ ]{%T // from %f%L%r%R%QT{\n+----\n%FOLD[|]{%i %s, %@:\n%FOLD[ ]{%T // from %f%L%r%R}}\n+----}}\n "
"Format string for rendering statuses.
Ex. \"%i %s, %@:\\n%FILL{ %T // from %f%L%r%R}\n \"
Items:
%s - screen_name
%S - name
%i - profile_image
%d - description
%l - location
%L - \" [location]\"
%r - \" sent to user\" (use on direct_messages{,_sent})
%r - \" in reply to user\" (use on other standard timeline)
%R - \" (retweeted by user)\"
%RT{...} - strings rendered only when the tweet is a retweet.
The braced strings are rendered with the information of the
retweet itself instead of that of the retweeted original tweet.
For example, %s for a retweet means who posted the original
tweet, but %RT{%s} means who retweeted it.
%QT{...} - strings rendered only when the tweet quotes a tweet.
The braced strings are rendered with the information of the
quoted tweet. For example, %QT{%s} means the author of the
quoted tweet.
%u - url
%j - user.id
%p - protected?
%c - created_at (raw UTC string)
%C{time-format-str} - created_at (formatted with time-format-str)
%@{time-format-str} - X seconds ago (formatted with time-format-str)
%T - raw text
%t - text filled as one paragraph
%' - truncated
%FACE[face-name]{...} - strings decorated with the specified face.
%FIELD[format-str]{field-name}
- a value of the given field of a tweet formatted with format-str.
The format-str is optional. As a field-name, you can use
\"retweet_count\", \"favorite_count\" and so on.
%FIELD-IF-NONZERO[format-str]{field-name}
- similar to %FIELD[...]{...} except that this makes an empty string
if the field value is zero.
%FILL[prefix]{...} - strings filled as a paragraph. The prefix is optional.
You can use any other specifiers in braces.
%FOLD[prefix]{...} - strings folded within the frame width.
The prefix is optional. This keeps newlines and does not
squeeze a series of white spaces.
You can use any other specifiers in braces.
%f - source
%# - id"
:type 'string
:group 'twittering-mode)
(defcustom twittering-retweet-format '(nil _ " RT: %t (via @%s)")
"*A format string or a skeleton for retweet.
If the value is a string, it means a format string for generating an initial
string of a retweet. The format string is converted with the below replacement
table. And then, the cursor is placed on the next of the initial string.
It is equivalent to the skeleton '(nil STRING _).
Note that this string is inserted before the edit skeleton specified by
`twittering-edit-skeleton' is performed.
If the value is a list, it is treated as a skeleton used with
`skeleton-insert'. The strings included in the list are converted with the
following replacement table. And then, the list with converted strings is
inserted by `skeleton-insert'.
Note that this skeleton is performed before the edit skeleton specified by
`twittering-edit-skeleton' is performed.
Replacement table:
%s - The screen-name of the cited tweet.
%t - The text of the cited tweet.
%u - The URL of the cited tweet.
%# - The ID of the cited tweet.
%% - % itself."
:type 'sexp
:group 'twittering-mode)
(defcustom twittering-fill-column nil
"*The `fill-column' used for \"%FILL{...}\" in `twittering-status-format'.
If nil, the fill-column is automatically calculated."
:type '(choice (const nil)
integer)
:group 'twittering-mode)
(defcustom twittering-show-replied-tweets t
"*The number of replied tweets which will be showed in one tweet.
If the value is not a number and is non-nil, show all replied tweets
which is already fetched.
If the value is nil, doesn't show replied tweets."
:type '(choice (const :tag "Do not show replied tweets"
:value nil)
(const :tag "Show all replied tweets"
:value t)
(integer :tag "Number of replied tweet"))
:group 'twittering-mode)
(defcustom twittering-default-show-replied-tweets nil
"*The number of default replied tweets which will be shown in one tweet.
This value will be used only when showing new tweets.
See `twittering-show-replied-tweets' for more details."
:type '(choice (const nil)
integer)
:group 'twittering-mode)
(defcustom twittering-disable-overlay-on-too-long-string nil
"*If non-nil, disable overlay on too long string on edit buffer.
If nil, `twittering-edit-mode' puts an overlay `twittering-warning-overlay' on
characters exceeding the maximum length.
On some environments, some input methods seem to interfere the update of the
overlay. In such case, you may avoid the problems by setting this variable to
non-nil."
:type 'boolean
:group 'twittering-mode)
(defcustom twittering-use-show-minibuffer-length t
"*Show current length of minibuffer if this variable is non-nil.
We suggest that you should set to nil to disable the showing function
when it conflict with your input method (such as AquaSKK, etc.)"
:type 'boolean
:group 'twittering-mode)
(defvar twittering-notify-successful-http-get t)
(defcustom twittering-use-ssl t
"*Use SSL connection if this variable is non-nil.
SSL connections use an external command as a backend."
:type 'boolean
:group 'twittering-mode)
(defcustom twittering-allow-insecure-server-cert nil
"*If non-nil, `twittering-mode' allows insecure server certificates."
:type 'boolean
:group 'twittering-mode)
(defvar twittering-curl-program nil
"Cache a result of `twittering-find-curl-program'.
DO NOT SET VALUE MANUALLY.")
(defvar twittering-curl-program-https-capability nil
"Cache a result of `twittering-start-http-session-curl-https-p'.
DO NOT SET VALUE MANUALLY.")
(defvar twittering-curl-program-http2-capability nil
"Cache a result of `twittering-start-http-session-curl-http2-p'.
DO NOT SET VALUE MANUALLY.")
(defvar twittering-wget-program nil
"Cache a result of `twittering-find-wget-program'.
DO NOT SET VALUE MANUALLY.")
(defcustom twittering-tls-program nil
"*List of strings containing commands to start TLS stream to a host.
Each entry in the list is tried until a connection is successful.
%h is replaced with server hostname, %p with port to connect to.
Also see `tls-program'.
If nil, this is initialized with a list of valied entries extracted from
`tls-program'."
:type '(repeat string)
:group 'twittering-mode)
(defcustom twittering-connection-type-order
'(curl wget urllib-http native urllib-https)
"*A list of connection methods in the preferred order."
:type 'list
:group 'twittering-mode)
(defun twittering-connection-build-customize-option ()
"Generate a valid `defcustom' entry to build `twittering-connection-type-table' variable."
(list 'repeat
(list
'cons :tag "Connection"
'(symbol :tag "Name" :value "")
'(repeat
:tag "Connection method definition"
(choice
(cons :tag "Check test method"
(const :format "" check)
(choice :value t (const :tag "Do not check" t)
(function :tag "Check function")))
(cons :tag "Display name"
(const :format "" display-name)
string)
(cons :tag "HTTPS connection method"
(const :format "" https)
(choice :value nil (const :tag "None" nil)
(const :tag "True" t)
(function :tag "HTTPS test function")))
(cons :tag "Send HTTP request function"
(const :format "" send-http-request)
function)
(cons :tag "Pre process buffer"
(const :format "" pre-process-buffer)
function))))))
(defcustom twittering-connection-type-table
'((native
(check . t)
(send-http-request . twittering-send-http-request-native)
(pre-process-buffer . twittering-pre-process-buffer-native))
(curl
(check . twittering-start-http-session-curl-p)
(https . twittering-start-http-session-curl-https-p)
(send-http-request . twittering-send-http-request-curl)
(pre-process-buffer . twittering-pre-process-buffer-curl))
(wget
(check . twittering-start-http-session-wget-p)
(https . ignore)
(send-http-request . twittering-send-http-request-wget)
(pre-process-buffer . twittering-pre-process-buffer-wget))
(urllib-http
(display-name . "urllib")
(check . twittering-start-http-session-urllib-p)
(https . nil)
(send-http-request . twittering-send-http-request-urllib)
(pre-process-buffer . twittering-pre-process-buffer-urllib))
(urllib-https
(display-name . "urllib")
(check . twittering-start-http-session-urllib-p)
(https . twittering-start-http-session-urllib-https-p)
(send-http-request . twittering-send-http-request-urllib)
(pre-process-buffer . twittering-pre-process-buffer-urllib)))
"A list of alist of connection methods."
:group 'twittering-mode
:type (twittering-connection-build-customize-option))
(defvar twittering-format-status-function-source ""
"The status format string that has generated the current
`twittering-format-status-function'.")
(defvar twittering-format-status-function nil
"The formating function generated from `twittering-format-status-function-source'.")
(defvar twittering-format-status-function-without-compile nil
"The formating function generated from `twittering-format-status-function-source',
which is a lambda expression without being compiled.")
(defvar twittering-timeline-data-table (make-hash-table :test 'equal))
(defcustom twittering-username-face 'twittering-username-face
"*Face used to display USERNAME."
:type 'face
:group 'twittering-mode)
(defcustom twittering-uri-face 'twittering-uri-face
"*Face used to display URIs."
:type 'face
:group 'twittering-mode)
(defcustom twittering-use-native-retweet nil
"*If non-nil, post retweet using native retweets."
:type 'boolean
:group 'twittering-mode)
(defcustom twittering-update-status-function
'twittering-update-status-from-pop-up-buffer
"*The function which is used to post a tweet.
It takes the following 5 arguments, INIT-STR, REPLY-TO-ID, USERNAME,
TWEET-TYPE and CURRENT-SPEC.
The first argument INIT-STR is nil or an initial text to be edited.
REPLY-TO-ID and USERNAME are an ID and a user-screen-name of a tweet to
which you are going to reply. If the tweet is not a reply, they are nil.
TWEET-TYPE is a symbol specifying a type of a tweet being edited. It must
be one of 'direct-message, 'normal, 'organic-retweet and 'reply.
CURRENT-SPEC means on which timeline the function is called.
Twittering-mode provides two functions for updating status:
* `twittering-update-status-from-minibuffer': edit tweets in minibuffer
* `twittering-update-status-from-pop-up-buffer': edit tweets in pop-up buffer"
:type '(choice (const :tag "built-in: from minibuffer"
twittering-update-status-from-minibuffer)
(const :tag "built-in: from a popup buffer"
twittering-update-status-from-pop-up-buffer)
(function :tag "Your own function"))
:group 'twittering-mode)
(defcustom twittering-request-confirmation-on-posting nil
"*If non-nil, confirmation will be requested on posting a tweet edited in
pop-up buffer."
:type 'boolean
:group 'twittering-mode)
(defcustom twittering-use-master-password nil
"*If non-nil, store private information encrypted with a master password."
:type 'boolean
:group 'twittering-mode)
(defcustom twittering-private-info-file (expand-file-name "~/.twittering-mode.gpg")
"*File for storing encrypted private information.
Only used when `twittering-use-master-password' is non-nil."
:group 'twittering-mode
:type 'file)
(defvar twittering-private-info-file-loaded nil
"Whether the private info file has been loaded or not.")
(defvar twittering-variables-stored-with-encryption
'(twittering-oauth-access-token-alist))
(defvar twittering-api-prefix "1/")
(defvar twittering-search-api-method "search")
(defvar twittering-web-path-prefix "")
(defconst twittering-service-method-table
'((twitter (status-url . twittering-get-status-url-twitter)
(search-url . twittering-get-search-url-twitter))
(twitter-api-v1.1
(status-url . twittering-get-status-url-twitter)
(search-url . twittering-get-search-url-twitter))
(statusnet (status-url . twittering-get-status-url-statusnet)
(search-url . twittering-get-search-url-statusnet)))
"A list of alist of service methods.")
(defcustom twittering-service-method 'twitter-api-v1.1
"*Service method for `twittering-mode'.
The symbol `twitter' means Twitter Service.
The symbol `statusnet' means StatusNet Service.
Default to `twitter-api-v1.1' which is an alias for `twitter'.
See also `twittering-service-method-table'."
:type (if (> (length (mapcar #'car twittering-service-method-table)) 0)
`(choice ,@(mapcar (lambda (entry) `(const ,(car entry)))
twittering-service-method-table))
'symbol)
:group 'twittering-mode)
(defcustom twittering-timeline-header-face 'twittering-timeline-header-face
"*Face for the header on `twittering-mode'.
The face is used for rendering `twittering-timeline-header'."
:type 'face
:group 'twittering-mode)
(defcustom twittering-timeline-footer-face 'twittering-timeline-footer-face
"*Face for the footer on `twittering-mode'.
The face is used for rendering `twittering-timeline-footer'."
:type 'face
:group 'twittering-mode)
(defcustom twittering-timeline-header "-- Press Enter here to update --\n"
"*Timeline header string on `twittering-mode'.
The string is rendered on the beginning of a `twittering-mode' buffer.
Its face is specified by `twittering-timeline-header-face'."
:type 'string
:group 'twittering-mode)
(defcustom twittering-timeline-footer "-- Press Enter here to update --"
"*Timeline footer string on `twittering-mode'.
The string is rendered on the end of a `twittering-mode' buffer.
Its face is specified by `twittering-timeline-footer-face'."
:type 'string
:group 'twittering-mode)
(defcustom twittering-pop-to-buffer-function
'twittering-pop-to-buffer-in-bottom-largest-window
"*Function being invoked by `twittering-pop-to-buffer'.
It will receive an argument, the buffer being selected.
For example, the following functions can be used; `pop-to-buffer',
`twittering-pop-to-buffer-simple',
`twittering-pop-to-buffer-in-current-window',
`twittering-pop-to-buffer-in-largest-window', and
`twittering-pop-to-buffer-in-bottom-largest-window'."
:type 'function
:group 'twittering-mode)
;; FIXME: change to something better than alist
(defcustom twittering-relative-retrieval-interval-alist
'(("\\`:direct.*\\'" 4)
(":home" ":mentions" 1)
(t 1))
"*An alist of relative intervals of retrieving timelines.
Each element looks like (TIMELINE-SPEC-REGEXP RELATIVE-INTERVAL).
TIMELINE-SPEC-REGEXP must be t or a regexp string specifying primary
timeline specs.
If TIMELINE-SPEC-REGEXP is t, it matches all timelines.
RELATIVE-INTERVAL must be zero or a positive integer specifying relative
interval of retrieving timelines that match TIMELINE-SPEC-REGEXP.
An interval for a timeline is determined as follows;
1. Find the first element where TIMELINE-SPEC-REGEXP matches the
timeline or TIMELINE-SPEC-REGEXP is t.
If no elements are found, the interval is `twittering-timer-interval'.
2. Check the RELATIVE-INTERVAL of the element.
If RELATIVE-INTERVAL is a positive integer, the interval is
RELATIVE-INTERVAL times as long as `twittering-timer-interval'.
If RELATIVE-INTERVAL is zero, the interval is infinity.
The timeline is not retrieved automatically."
:type 'alist
:group 'twittering-mode)
(defvar twittering-relative-retrieval-count-alist '()
"An alist for counting retrieval of primary timelines.")
(defvar twittering-filter-alist '()
"*An alist of hidden tweet patterns for each primary timeline.
Each element looks like:
(TIMELINE-SPECIFIER (SYM1 . REGEXP1) (SYM2 . REGEXP2) ...).
TIMELINE-SPECIFIER must be a string or a list of strings.
Each string is a regexp for specifying primary timelines.
Note that you cannot specify composite timelines such as \":merge\",
\":exclude-if\" or \":exclude-re\".
Following regexps (REGEXP1, REGEXP2, ...) specify which tweet should
be hidden in a certain timeline.
In a timeline that matches TIMELINE-SPECIFIER, a tweet is hidden if
its elements specified by SYM1, SYM2, ... match corresponding REGEXP1, REGEXP2,
... respectively.
If a timeline matches multiple specifiers, all regexps of matched elements
are effective.
For example, if you specify
'(((\":home\" \":mentions\") (text . \"http://\"))
(\"^[^:]\" (text . \"sample\") (user-screen-name . \"\\`FOO\\'\"))
(\"twitter/.*\" (text . \"^aa\"))),
the following tweets are hidden.
- tweets including \"http://\" in the home timeline and the mentions timeline,
- tweets that are posted by the user FOO and include \"sample\"
in user timelines and list timelines,
- tweets including \"aa\" at a beginning of a line in list timelines of
twitter, such as \"twitter/media\" or \"twitter/support\".")
;;;;
;;;; Macro and small utility function
;;;;
(defun assocref (item alist)
(cdr (assoc item alist)))
(defmacro list-push (value listvar)
`(setq ,listvar (cons ,value ,listvar)))
(defmacro case-string (str &rest clauses)
`(cond
,@(mapcar
(lambda (clause)
(let ((keylist (car clause))
(body (cdr clause)))
`(,(if (listp keylist)
`(or ,@(mapcar (lambda (key) `(string-equal ,str ,key))
keylist))
't)
,@body)))
clauses)))
(defmacro twittering-wait-while (timeout interval condition &optional form &rest timeout-forms)
"Wait while CONDITION returns non-nil until TIMEOUT seconds passes.
The form CONDITION is repeatedly evaluated for every INTERVAL seconds
until CONDITION returns nil or TIMEOUT seconds passes unless TIMEOUT is nil.
If TIMEOUT is nil, there is no time limit.
If CONDITION returns nil, evaluate the form FORM and return its value.
If TIMEOUT seconds passes, evaluate the forms TIMEOUT-FORMS and return
the value of the last form in TIMEOUT-FORMS."
`(lexical-let (,@(when timeout `((timeout ,timeout)))
(interval ,interval)
(current 0.0))
(while (and ,@(when timeout '((< current timeout)))
,condition)
(sleep-for interval)
(setq current (+ current interval)))
,(when (or form timeout-forms)
(if (null timeout)
form
`(if (< current timeout)
,form
,@timeout-forms)))))
(defun twittering-extract-matched-substring-all (regexp str)
(let ((pos 0)
(result nil))
(while (string-match regexp str pos)
(setq result (cons (match-string 1 str) result))
(setq pos (match-end 0)))
(reverse result)))
(defun twittering-process-alive-p (proc)
"Return non-nil if PROC is alive."
(not (memq (process-status proc) '(nil closed exit failed signal))))
(defun twittering-start-process-with-sentinel (name buffer program args sentinel)
"Start a program in a subprocess with a sentinel.
This function is the same as `start-process' except that SENTINEL must
be invoked when the process is successfully started."
(let* (;; By binding `process-connection-type' to nil,
;; ensure that the new process communicates with Emacs
;; via a pipe instead of a pty.
(process-connection-type nil)
(proc (apply 'start-process name buffer program args)))
(when (and proc (functionp sentinel))
(if (twittering-process-alive-p proc)
(set-process-sentinel proc sentinel)
;; Ensure that the sentinel is invoked if a subprocess is
;; successfully started.
(funcall sentinel proc "finished")))
proc))
(defun twittering-parse-time-string (str &optional round-up)
"Parse the time-string STR into (SEC MIN HOUR DAY MON YEAR DOW DST TZ).
This function is the same as `parse-time-string' except to complement the
lacked parameters with the current time.
If ROUND-UP is nil, complement the lacked parameters with the oldest ones.
If ROUND-UP is non-nil, complement the lacked parameters with the latest ones.
For example, (twittering-parse-time-string \"2012-04-20\")
returns (0 0 0 20 4 2012 nil nil 32400).
And (twittering-parse-time-string \"2012-04-20\" t)
returns (59 59 23 20 4 2012 nil nil 32400).
The values are identical to those of `decode-time', but any values that are
unknown are returned as nil."
(let* ((parsed (parse-time-string str))
(current (decode-time (current-time)))
(replacement-alist
`((SEC . ,(if round-up
59
0))
(MIN . ,(if round-up
59
0))
(HOUR . ,(if round-up
23
0))
(DAY . nil)
(MON . nil)
(YEAR . nil)
(DOW . nil)
(DST . nil)
(TZ . nil)))
(sym-list (mapcar 'car replacement-alist))
(result nil))
(while (and parsed current sym-list)