-
Notifications
You must be signed in to change notification settings - Fork 1
/
lengyueyang.el
2327 lines (2006 loc) · 87.5 KB
/
lengyueyang.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
;;; ------------------------------------------
;;; Do not edit this file. It was tangled from
;;; an org file.
;;; ------------------------------------------
(require 'req-package)
(defun open-my-init-file()
(interactive)
(find-file "~/.spacemacs.d/lengyueyang.org"))
(global-set-key (kbd "<f2>") 'open-my-init-file)
(spacemacs/set-leader-keys "oo" 'open-my-init-file)
(require 'chinese-yasdcv)
(define-key global-map (kbd "<f3>") 'youdao-dictionary-search-at-point+)
(spacemacs/declare-prefix "ok" "Keybindings")
(spacemacs/set-leader-keys "oky" 'yasdcv-translate-at-point)
(spacemacs/set-leader-keys "oks" 'youdao-dictionary-search-from-input)
(spacemacs/set-leader-keys "oki" 'youdao-dictionary-search-at-point+)
(define-key global-map (kbd "<f8>") 'flyspell-correct-previous-word-generic)
(spacemacs/set-leader-keys "okf" 'flyspell-correct-previous-word-generic)
(spacemacs/set-leader-keys "oa" 'org-agenda-list)
(global-set-key (kbd "C-c b") 'org-iswitchb)
(spacemacs/set-leader-keys "okb" 'org-iswitchb)
(spacemacs/declare-prefix "om" "Bookmark")
(spacemacs/set-leader-keys "oms" 'bookmark-set)
(spacemacs/set-leader-keys "omr" 'bookmark-rename)
(spacemacs/set-leader-keys "omd" 'bookmark-delete)
(spacemacs/set-leader-keys "omj" 'counsel-bookmark)
(global-set-key (kbd "<f7>") 'org-download-screenshot)
(setq system-time-locale "en_US")
(set-language-environment "UTF-8")
(setq-default default-buffer-file-coding-system 'utf-8)
;; (setq coding-system-for-write 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(setq locale-coding-system 'utf-8)
(prefer-coding-system 'gb18030)
(prefer-coding-system 'utf-8)
(use-package semantic
:config
(setq-mode-local emacs-lisp-mode
semanticdb-find-default-throttle
(default-value 'semanticdb-find-default-throttle)))
(when (configuration-layer/layer-usedp 'markdown)
(setq auto-mode-alist (cons '("\\.text$" . gfm-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.md$" . gfm-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.mdown$" . gfm-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.mdt$" . gfm-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.markdown$" . gfm-mode) auto-mode-alist)))
(setq lengyueyang-configuration-path "~/.spacemacs.d/")
(defun lengyueyang/load-my-layout ()
(interactive)
(persp-load-state-from-file (concat lengyueyang-configuration-path "lengyueyang")))
(defun lengyueyang/save-my-layout ()
(interactive)
(persp-save-state-to-file (concat lengyueyang-configuration-path "lengyueyang")))
(spacemacs/declare-prefix "ol" "Layout-lengyueyang")
(spacemacs/set-leader-keys "oll" 'lengyueyang/load-my-layout)
(spacemacs/set-leader-keys "ols" 'lengyueyang/save-my-layout)
;;(defun lengyueyang-misc/post-init-persp-mode ()
;; (setq persp-kill-foreign-buffer-action 'kill)
;; (setq persp-lighter nil)
;; (when (fboundp 'spacemacs|define-custom-layout)
;; (spacemacs|define-custom-layout "@Cocos2D-X"
;; :binding "c"
;; :body
;; (find-file "~/cocos2d-x/cocos/ui/UIWidget.cpp")
;; (split-window-right)
;; (find-file "~/cocos2d-x/cocos/cocos2d.cpp"))))
(global-set-key (kbd "<f5>") 'deft)
(setq deft-extensions '("txt" "tex" "org" "mk" "makedown"))
(setq deft-directory "~/MEGA/Emacs-lengyue/Wiki-lengyue")
(use-package elfeed-org
:ensure t
:config
(elfeed-org)
(setq rmh-elfeed-org-files (list "~/MEGA/Emacs-lengyue/Wiki-lengyue/Elfeed.org")))
;; (add-to-load-path "~/.spacemacs.d/package/mu4e")
;; (require 'mu4e)
;; (setq mu4e-account-alist
;; '(("Gmail"
;; ;; Under each account, set the account-specific variables you want.
;; (mu4e-sent-messages-behavior delete)
;; (mu4e-sent-folder "/Gmail/[Gmail].Sent Mail")
;; (mu4e-drafts-folder "/Gmail/[Gmail].Drafts")
;; (user-mail-address "[email protected]")
;; (user-full-name "Mao Xiaowei")
;; (smtpmail-stream-type ssl)
;; (smtpmail-smtp-service 465)
;; )
;; ("Foxmail"
;; (mu4e-sent-messages-behavior sent)
;; (mu4e-sent-folder "/Foxmail/Sent Messages")
;; (mu4e-drafts-folder "/Foxmail/Drafts")
;; (user-mail-address "[email protected]")
;; (user-full-name "Mao Xiaowei")
;; (smtpmail-stream-type ssl)
;; (smtpmail-smtp-service 465)
;; )
;; ;; ("Lengyue-163"
;; ;; (mu4e-sent-messages-behavior sent)
;; ;; (mu4e-sent-folder "/Lengyue-163/Sent Items")
;; ;; (mu4e-drafts-folder "/Lengyue-163/Drafts")
;; ;; (user-mail-address "[email protected]")
;; ;; (user-full-name "Mao Xiaowei"))
;; )
;; )
;; ;;(mu4e/mail-account-reset)
;; ;;; Set up some common mu4e variables
;; (setq mu4e-maildir "~/MEGA/Emacs-lengyue/Data Collection/Mu4e"
;; mu4e-trash-folder "/Gmail/Trash"
;; mu4e-refile-folder "/Gmail/Archive"
;; ;; mu4e-get-mail-command "mbsync -a"
;; mu4e-update-interval nil
;; mu4e-compose-signature-auto-include nil
;; mu4e-view-show-images t
;; mu4e-view-show-addresses t)
;; ;;; Mail directory shortcuts
;; (setq mu4e-maildir-shortcuts
;; '(
;; ("/Foxmail/INBOX" . ?f)
;; ("/Foxmail/Drafts" . ?d)
;; ("/Foxmail/Sent Messages" . ?s)
;; ("/Gmail/INBOX" . ?g)
;; ;; ("/Gmail/[Gmail].All Mail" . ?a)
;; ("/Gmail/[Gmail].Drafts" . ?r)
;; ("/Gmail/[Gmail].Sent Mail" . ?e)
;; ;;("/Gmail/[Gmail].Trash" . ?t)
;; ;; ("/Lengyue-163/INBOX" . ?i)
;; ))
;; ;;; Bookmarks
;; (setq mu4e-bookmarks
;; `(("flag:unread AND NOT flag:trashed" "Unread messages" ?u)
;; ("date:today..now" "Today's messages" ?t)
;; ("date:7d..now" "Last 7 days" ?w)
;; ("mime:image/*" "Messages with images" ?p)
;; (,(mapconcat 'identity
;; (mapcar
;; (lambda (maildir)
;; (concat "maildir:" (car maildir)))
;; mu4e-maildir-shortcuts) " OR ")
;; "All inboxes" ?i)))
;; (mu4e-alert-set-default-style 'libnotify)
;; (alert-add-rule :category "mu4e-alert" :style 'fringe :predicate (lambda (_) (string-match-p "^mu4e-" (symbol-name major-mode))) :continue t)
;; (mu4e-alert-enable-notifications)
;; ;; (setq mu4e-alert-email-notification-types '(count))
;; (setq mu4e-alert-email-notification-types '(subjects))
;; ;; (setq mu4e-enable-notifications t)
;; ;; (with-eval-after-load 'mu4e-alert
;; ;; Enable Desktop notifications
;; ;; (mu4e-alert-set-default-style 'notifications)) ; For linux
;; ;; (mu4e-alert-set-default-style 'libnotify)) ; Alternative for linux
;; ;; (mu4e-alert-set-default-style 'notifier)) ; For Mac OSX (through the
;; ; terminal notifier app)
;; ;; (mu4e-alert-set-default-style 'growl)) ; Alternative for Mac OSX
;; ;; (setq mu4e-enable-mode-line t)
;; (setq mu4e-get-mail-command "offlineimap")
;; ;; Fetch mail in 60 sec interval
;; (setq mu4e-update-interval 1200)
;; (require 'mu4e-contrib)
;; (setq mu4e-html2text-command 'mu4e-shr2text)
;; ;; try to emulate some of the eww key-bindings
;; (add-hook 'mu4e-view-mode-hook
;; (lambda ()
;; (local-set-key (kbd "<tab>") 'shr-next-link)
;; (local-set-key (kbd "<backtab>") 'shr-previous-link)))
;; ;; something about ourselves
;; (require 'smtpmail)
;; (setq user-mail-address "[email protected]"
;; user-full-name "Xiaowei, Mao"
;; smtpmail-stream-type 'starttls
;; starttls-use-gnutls t
;; mu4e-compose-signature
;; (concat
;; "Xiaowei Mao\n"
;; "Email: [email protected]\n"
;; "Email: [email protected]\n"
;; "Blog: http://lengyueyang.github.io\n"
;; "\n")
;; mu4e-compose-signature-auto-include t
;; )
;; (setq send-mail-function 'smtpmail-send-it
;; message-send-mail-function 'smtpmail-send-it
;; smtpmail-auth-credentials (expand-file-name "~/.authinfo")
;; smtpmail-stream-type 'ssl
;; smtpmail-smtp-server "smtp.qq.com"
;; smtpmail-smtp-service 465
;; smtpmail-smtp-user "[email protected]")
;; ;; (mu4e/mail-account-reset)
;; (setq message-kill-buffer-on-exit t)
;; ;; save attachment to my desktop (this can also be a function)
;; (setq mu4e-attachment-dir "/home/lengyue/Documents/Mu4e/Attachment")
;; (add-to-load-path "~/.spacemacs.d/package/mu4e")
(require 'mu4e)
;; I want my format=flowed thank you very much
;; mu4e sets up visual-line-mode and also fill (M-q) to do the right thing
;; each paragraph is a single long line; at sending, emacs will add the
;; special line continuation characters.
(setq mu4e-compose-format-flowed t)
;; every new email composition gets its own frame! (window)
(setq mu4e-compose-in-new-frame t)
;; give me ISO(ish) format date-time stamps in the header list
(setq mu4e-headers-date-format "%Y-%m-%d %H:%M")
;; show full addresses in view message (instead of just names)
;; toggle per name with M-RET
(setq mu4e-view-show-addresses 't)
;;; Set up some common mu4e variables
(setq mu4e-maildir "~/MEGA/Emacs-lengyue/Data-collection/Mu4e"
mu4e-trash-folder "/Gmail/Trash"
mu4e-refile-folder "/Gmail/Archive"
mu4e-sent-folder "/Foxmail/Sent Messages"
mu4e-drafts-folder "/Foxmail/Drafts")
(require 'smtpmail)
(setq
send-mail-function 'smtpmail-send-it
message-send-mail-function 'smtpmail-send-it
smtpmail-auth-credentials (expand-file-name "~/.authinfo")
smtpmail-smtp-server "smtp.qq.com"
smtpmail-smtp-service 465
smtpmail-stream-type 'ssl
)
;; don't keep message buffers around
(setq message-kill-buffer-on-exit t)
;;; Mail directory shortcuts
(setq mu4e-maildir-shortcuts
'(
("/Foxmail/INBOX" . ?f)
("/Foxmail/Drafts" . ?d)
("/Foxmail/Sent Messages" . ?s)
("/Gmail/INBOX" . ?g)
;; ("/Gmail/[Gmail].All Mail" . ?a)
("/Gmail/[Gmail].Drafts" . ?r)
("/Gmail/[Gmail].Sent Mail" . ?e)
;;("/Gmail/[Gmail].Trash" . ?t)
;; ("/Lengyue-163/INBOX" . ?i)
))
;; the list of all of my e-mail addresses
(setq mu4e-user-mail-address-list '("[email protected]"
;; the headers to show in the headers list -- a pair of a field
;; and its width, with `nil' meaning 'unlimited'
;; (better only use that for the last field.
;; These are the defaults:
(setq mu4e-headers-fields
'( (:date . 25) ;; alternatively, use :human-date
(:flags . 6)
(:from . 22)
(:subject . nil))) ;; alternatively, use :thread-subject
(setq mu4e-get-mail-command "proxychains offlineimap")
;; Fetch mail in 60 sec interval
(setq mu4e-update-interval 1200)
;; (mu4e/mail-account-reset)
(setq message-kill-buffer-on-exit t)
;; save attachment to my desktop (this can also be a function)
(setq mu4e-attachment-dir "~/MEGA/Emacs-lengyue/Data-collection/Mu4e/Attachment")
(setq mu4e-contexts
`(
,(make-mu4e-context
:name "Foxmail_lengyue"
:enter-func (lambda () (mu4e-message "Enter [email protected] context"))
:leave-func (lambda () (mu4e-message "Leave [email protected] context"))
:match-func (lambda (msg)
(when msg
(mu4e-message-contact-field-matches msg
:to "[email protected]")))
:vars '( ( user-mail-address . "[email protected]" )
( user-full-name . "Mao Xiaowei" )
( smtpmail-smtp-server . "smtp.qq.com" )
( mu4e-compose-signature .
(concat
"Xiaowei Mao\n"
"Email: [email protected]\n"
"Email: [email protected]\n"
"Blog: http://lengyueyang.github.io\n"
"Github: https://github.com/lengyueyang\n"))))
,(make-mu4e-context
:name "Gmail_lengyue"
:enter-func (lambda () (mu4e-message "Enter [email protected] context"))
:leave-func (lambda () (mu4e-message "Leave [email protected] context"))
;; we match based on the contact-fields of the message (that we are replying to)
;; https://www.djcbsoftware.nl/code/mu/mu4e/What-are-contexts.html#What-are-contexts
:match-func (lambda (msg)
(when msg
(mu4e-message-contact-field-matches msg
:to "[email protected]")))
:vars '( ( user-mail-address . "[email protected]" )
( user-full-name . "Mao Xiaowei" )
( smtpmail-smtp-server . "smtp.gmail.com" )
( mu4e-compose-signature .
(concat
"Xiaowei Mao\n"
"Email: [email protected]\n"
"Email: [email protected]\n"
"Blog: http://lengyueyang.github.io\n"
"Github: https://github.com/lengyueyang\n"))))
)
)
;;; Bookmarks
(setq mu4e-bookmarks
`(("flag:unread AND NOT flag:trashed" "Unread messages" ?u)
("date:today..now" "Today's messages" ?t)
("date:7d..now" "Last 7 days" ?w)
("mime:image/*" "Messages with images" ?p)
(,(mapconcat 'identity
(mapcar
(lambda (maildir)
(concat "maildir:" (car maildir)))
mu4e-maildir-shortcuts) " OR ")
"All inboxes" ?i)))
(mu4e-alert-set-default-style 'libnotify)
(alert-add-rule :category "mu4e-alert" :style 'fringe :predicate (lambda (_) (string-match-p "^mu4e-" (symbol-name major-mode))) :continue t)
(mu4e-alert-enable-notifications)
;; (setq mu4e-alert-email-notification-types '(count))
(setq mu4e-alert-email-notification-types '(subjects))
(setq mu4e-enable-mode-line t)
;; start with the first (default) context;
(setq mu4e-context-policy 'pick-first)
;; compose with the current context if no context matches;
(setq mu4e-compose-context-policy nil)
;; don't save messages to Sent Messages, Gmail/IMAP takes care of this
(setq mu4e-sent-messages-behavior 'delete)
(add-hook 'message-mode-hook 'turn-on-flyspell 'append)
(add-hook 'mu4e-view-mode-hook
(lambda()
(mu4e-view-toggle-hide-cited)
;; try to emulate some of the eww key-bindings
(local-set-key (kbd "<tab>") 'shr-next-link)
(local-set-key (kbd "<backtab>") 'shr-previous-link)))
(setq mu4e-org-contacts-file "~/MEGA/Emacs-lengyue/Wiki-lengyue/Contacts.org")
(add-to-list 'mu4e-headers-actions
'("org-contact-add" . mu4e-action-add-org-contact) t)
(add-to-list 'mu4e-view-actions
'("org-contact-add" . mu4e-action-add-org-contact) t)
(require 'ivy)
(add-to-load-path "~/.spacemacs.d/package/org-mime")
(require 'org-mime)
;; for gnus – this is set by default
(setq org-mime-library 'mml)
;; OR for Wanderlust (WL)
;; (setq org-mime-library 'semi)
;; OR for VM – not yet supported
;; (setq org-mime-library 'vm)
(add-hook 'message-mode-hook
(lambda ()
(local-set-key (kbd "C-c M-o") 'org-mime-htmlize)))
(add-hook 'org-mode-hook
(lambda ()
(local-set-key (kbd "C-c M-o") 'org-mime-org-buffer-htmlize)))
(add-hook 'org-mime-html-hook
(lambda ()
(org-mime-change-element-style
"pre" (format "color: %s; background-color: %s; padding: 0.5em;"
"#E6E1DC" "#232323"))))
;; the following can be used to nicely offset block quotes in email bodies
(add-hook 'org-mime-html-hook
(lambda ()
(org-mime-change-element-style
"blockquote" "border-left: 2px solid gray; padding-left: 4px;")))
(add-hook 'org-mime-html-hook
(lambda ()
(while (re-search-forward "@\\([^@]*\\)@" nil t)
(replace-match "<span style=\"color:red\">\\1</span>"))))
(setq org-mime-export-options '(:section-numbers nil
:with-author nil
:with-toc nil))
;; here we set aliases for groups.
(setq email-groups
'(("ms" . "email1, email2")
("phd" . "email3, email4")))
(setq mu4e-compose-complete-only-personal nil)
(defun org-contacts-open-from-email (email)
"Open org-contact with matching EMAIL. If no match, create new
entry with prompts for first and last name."
(let ((contact (catch 'contact
(loop for contact in (org-contacts-db)
do
(when (string= email (cdr (assoc "EMAIL" (elt contact 2))))
(throw 'contact contact))))))
(unless contact
(set-buffer (find-file-noselect (ido-completing-read
"Select org-contact file: "
org-contacts-files)))
(goto-char (point-max))
(insert (format "\n* %s %s\n"
(read-input "First name: ")
(read-input "Last name: ")))
(org-entry-put (point) "EMAIL" email)
(save-buffer))
(when contact
(find-file (cdr (assoc "FILE" (elt contact 2))))
(goto-char (elt contact 1))
(show-subtree))))
(defun org-contacts-tag-selection (selection)
"Prompts you for a tag, and tags each entry in org-contacts
that has a matching email in `helm-marked-candidates'. Ignore
emails that are not in an org-contact file. I am not sure what
the best thing to do there is. Probably prompt for a file, and
add an entry to the end of it."
(save-excursion
(let ((tag (read-input "Tag: ")))
(loop for email in (helm-marked-candidates)
do
(let ((contact (catch 'contact
(loop for contact in (org-contacts-db)
do
(when (string=
email
(cdr (assoc
"EMAIL"
(elt contact 2))))
(throw 'contact contact))))))
;; add new contact and tag it
(unless contact
(set-buffer (find-file-noselect (ido-completing-read
"Select org-contact file: "
org-contacts-files)))
(goto-char (point-max))
(insert (format "\n* %s %s\n"
(read-input "First name: ")
(read-input "Last name: ")))
(org-entry-put (point) "EMAIL" email)
(org-set-tags-to (list tag))
(save-buffer))
;; update tags on existing entry
(when contact
(find-file-noselect (cdr (assoc "FILE" (elt contact 2))))
(set-buffer (marker-buffer (elt contact 1)))
(goto-char (elt contact 1))
(org-set-tags-to (append (org-get-tags) (list tag)))))))))
(defun j-insert-emails ()
"Helm interface to email addresses"
(interactive)
(helm :sources `(((name . "Email address candidates")
(candidates . ,(append
;; my aliases
email-groups
;; org-contacts
(loop for contact in (org-contacts-db)
collect
(cons (format
"%s %s %s <%s> org-contact"
(cdr (assoc "FIRSTNAME" (elt contact 2)))
(cdr (assoc "LASTNAME" (elt contact 2)))
(cdr (assoc "TAGS" (elt contact 2)))
(cdr (assoc "EMAIL" (elt contact 2))))
(cdr (assoc "EMAIL" (elt contact 2)))))
;; mu contacts
(loop for contact in mu4e~contacts-for-completion
collect (cons contact contact))))
;; only action is to insert string at point.
(action . (("insert" . (lambda (x)
(insert
(mapconcat
'identity
(helm-marked-candidates)
","))))
("open" . org-contacts-open-from-email)
("tag" . org-contacts-tag-selection)))))))
;; Finally, let us bind this to something probably convenient. I use c-c ] for
;; citations. Lets try that in compose mode.
(define-key mu4e-compose-mode-map "\C-c]" 'j-insert-emails)
;; (require 'org-mu4e)
;; ;; (require 'org-mime)
;; ;; Use org-mode(mine) to html
;; (defun mu4e-toggle-org-mode ()
;; (interactive)
;; (cond
;; ((eq major-mode 'mu4e-view-mode) (mu4e-org-mode))
;; ((eq major-mode 'mu4e-org-mode) (mu4e-view-mode))
;; ((eq major-mode 'mu4e-compose-mode) (org-mu4e-compose-org-mode))
;; ((eq major-mode 'org-mu4e-compose-org-mode) (mu4e-compose-mode))))
;; (with-eval-after-load 'mu4e-view
;; (spacemacs/set-leader-keys-for-major-mode 'mu4e-view-mode
;; "to" 'mu4e-toggle-org-mode))
;; (with-eval-after-load 'mu4e-utils
;; (spacemacs/set-leader-keys-for-major-mode 'mu4e-org-mode
;; "to" 'mu4e-toggle-org-mode))
;; (with-eval-after-load 'mu4e-compose
;; (spacemacs/set-leader-keys-for-major-mode 'mu4e-compose-mode "to" 'mu4e-toggle-org-mode))
;; (with-eval-after-load 'org-mu4e
;; (setq org-mu4e-convert-to-html t)
;; (spacemacs/set-leader-keys-for-major-mode 'org-mu4e-compose-org-mode "to" 'mu4e-toggle-org-mode)
;; (defun org~mu4e-mime-convert-to-html ()
;; "Convert the current body to html."
;; (unless (fboundp 'org-export-string-as)
;; (mu4e-error "require function 'org-export-string-as not found."))
;; (let* ((begin
;; (save-excursion
;; (goto-char (point-min))
;; (search-forward mail-header-separator)))
;; (end (point-max))
;; (raw-body (buffer-substring begin end))
;; (tmp-file (make-temp-name (expand-file-name "mail"
;; temporary-file-directory)))
;; (org-export-skip-text-before-1st-heading nil)
;; (org-export-htmlize-output-type 'inline-css)
;; (org-export-preserve-breaks t)
;; (org-export-with-LaTeX-fragments
;; (if (executable-find "dvipng") 'dvipng
;; (mu4e-message "Cannot find dvipng, ignore inline LaTeX") nil))
;; (html-and-images
;; (org~mu4e-mime-replace-images
;; (org-export-string-as raw-body 'html nil)
;; tmp-file))
;; (html-images (cdr html-and-images))
;; (html (car html-and-images)))
;; (delete-region begin end)
;; (save-excursion
;; (goto-char begin)
;; (newline)
;; (insert (org~mu4e-mime-multipart
;; raw-body html (mapconcat 'identity html-images "\n")))))))
(defun my/dabbrev-friend-buffer (other-buffer)
(cond ( ;; ignore very large files
(> (buffer-size other-buffer) (* 1024 1024))
nil)
( ;; doing a magit commit - use the magit status buffer
(and (boundp git-commit-mode) git-commit-mode)
(with-current-buffer other-buffer
(eq major-mode 'magit-status-mode)))
( ;; in projectile project - use projectile buffers
(and (buffer-file-name other-buffer)
(not (file-remote-p (buffer-file-name other-buffer)))
(projectile-project-p))
(string= (projectile-project-name)
(with-current-buffer other-buffer
(projectile-project-name))))
(t ;; fallback - same mod
(dabbrev--same-major-mode-p other-buffer))))
(add-hook 'text-mode-hook 'company-mode)
(add-hook 'text-mode-hook
(lambda ()
(set (make-local-variable 'company-backends) '(company-files company-en-words company-dabbrev)))
)
(setq user-full-name "lengyuyang"
user-mail-address "[email protected]")
(setq kill-buffer-query-functions
(remq 'process-kill-buffer-query-function
kill-buffer-query-functions))
;; (spacemacs//set-monospaced-font "Inconsolata" "Source Han Sans CN" 16 20)
;; (spacemacs//set-monospaced-font "Fira Mono" "Source Han Sans CN" 16 20)
(spacemacs//set-monospaced-font "Fira Mono" "Wenquanyi Micro Hei" 16 20)
;; (spacemacs//set-monospaced-font "DejaVu Sans Mono" "Source Han Sans CN" 16 20)
(dolist (command '(yank yank-pop))
(eval
`(defadvice ,command (after indent-region activate)
(and (not current-prefix-arg)
(member major-mode
'(emacs-lisp-mode
lisp-mode
clojure-mode
scheme-mode
haskell-mode
ruby-mode
rspec-mode
python-mode
c-mode
c++-mode
objc-mode
latex-mode
js-mode
plain-tex-mode))
(let ((mark-even-if-inactive transient-mark-mode))
(indent-region (region-beginning) (region-end) nil))))))
(global-prettify-symbols-mode 1)
;; (setq-default fill-column 80)
(defadvice find-file (before make-directory-maybe
(filename &optional wildcards) activate)
"Create parent directory if not exists while visiting file."
(unless (file-exists-p filename)
(let ((dir (file-name-directory filename)))
(when dir
(unless (file-exists-p dir)
(make-directory dir t))))))
(setq large-file-warning-threshold 300000000)
(defun spacemacs/check-large-file ()
(when (> (buffer-size) 50000000)
(progn (fundamental-mode)
(hl-line-mode -1)))
(if (and (executable-find "wc")
(> (string-to-number (shell-command-to-string (format "wc -l %s" (buffer-file-name))))
5000))
(linum-mode -1)))
(add-hook 'find-file-hook 'spacemacs/check-large-file)
(defun indent-whole-buffer ()
"Indent whole buffer."
(interactive)
(save-excursion
(indent-region (point-min) (point-max))))
(defun quick-folding-source ()
"Use emacs buildin easy to folding code."
(interactive)
(set-selective-display
(if selective-display nil 1)))
(defun insert-U200B-char ()
"Insert <U200B> char, this character is nice use in org-mode."
(interactive)
(insert "\ufeff"))
(defun insert-empty-line ()
"Insert an empty line after current line and position cursor on newline."
(interactive)
(move-end-of-line nil)
(open-line 1)
(next-line 1))
(defun file-reopen-as-root ()
(interactive)
(when buffer-file-name
(find-alternate-file
(concat "/sudo:root@localhost:"
buffer-file-name))))
(defun delete-current-buffer-file ()
"Removes file connected to current buffer and kills buffer."
(interactive)
(let ((filename (buffer-file-name))
(buffer (current-buffer))
(name (buffer-name)))
(if (not (and filename (file-exists-p filename)))
(ido-kill-buffer)
(when (yes-or-no-p "Are you sure you want to remove this file? ")
(delete-file filename)
(kill-buffer buffer)
(message "File '%s' successfully removed" filename)))))
(defun rename-current-buffer-file ()
"Renames current buffer and file it is visiting."
(interactive)
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
(if (get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name)
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(message "File '%s' successfully renamed to '%s'"
name (file-name-nondirectory new-name)))))))
(defun set-file-executable()
"Add executable permissions on current file."
(interactive)
(when (buffer-file-name)
(set-file-modes buffer-file-name
(logior (file-modes buffer-file-name) #o100))
(message (concat "Made " buffer-file-name " executable"))))
(defun clone-file-and-open (filename)
"Clone the current buffer writing it into FILENAME and open it"
(interactive "FClone to file: ")
(save-restriction
(widen)
(write-region (point-min) (point-max) filename nil nil nil 'confirm))
(find-file filename))
(global-auto-revert-mode 1)
(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-verbose nil)
(setq revert-without-query '(".*")) ;; disable revert query
(defun eval-buffer-until-error ()
"Evaluate emacs buffer until error occured."
(interactive)
(goto-char (point-min))
(while t (eval (read (current-buffer)))))
;; (setq url-gateway-method 'socks)
;; (setq socks-server '("Default server" "127.0.0.1" 1080 5))
(defcustom my-proxy "127.0.0.1:8118"
"Set network proxy."
:type 'string)
;; Configure network proxy
(defun show-proxy ()
"Show http/https proxy."
(interactive)
(if url-proxy-services
(message "Current proxy is \"%s\"" my-proxy)
(message "No proxy")))
(defun set-proxy ()
"Set http/https proxy."
(interactive)
(setq url-proxy-services `(("http" . ,my-proxy)
("https" . ,my-proxy)))
(show-proxy))
(defun unset-proxy ()
"Unset http/https proxy."
(interactive)
(setq url-proxy-services nil)
(show-proxy))
(defun toggle-proxy ()
"Toggle http/https proxy."
(interactive)
(if url-proxy-services
(unset-proxy)
(set-proxy)))
(add-to-load-path "~/.spacemacs.d/package/ov-highlighter")
(require 'ov-highlighter)
;; (use-package ov-highlighter
;; :config
;; (progn
;; (setq ov-highlight-disable-save t)
;; ;; Gruvbox scheme
;; (ov-make-highlight "red" '(:background "#9d0006"))
;; (ov-make-highlight "green" '(:background "#79740e"))
;; (ov-make-highlight "yellow" '(:background "#b57614"))
;; (ov-make-highlight "blue" '(:background "#076678"))
;; (ov-make-highlight "purple" '(:background "#8f3f71"))
;; (ov-make-highlight "aqua" '(:background "#427b58"))
;; (ov-make-highlight "orange" '(:background "#af3a03"))
;; (ov-make-highlight "red-fg" '(:foreground "red"))
;; (ov-make-highlight "green-fg" '(:foreground "green"))
;; (ov-make-highlight "blue-fg" '(:foreground "blue"))
;; (defhydra yxl-ov-highlighter (:hint nil :color blue)
;; ("r" ov-highlight-red)
;; ("g" ov-highlight-green)
;; ("y" ov-highlight-yellow)
;; ("b" ov-highlight-blue)
;; ("p" ov-highlight-purple)
;; ("a" ov-highlight-aqua)
;; ("o" ov-highlight-orange)
;; ("c" ov-highlight-color)
;; ("f" ov-highlight-foreground)
;; ("[" ov-highlight-decrease-font-size :color red)
;; ("]" ov-highlight-increase-font-size :color red)
;; ("F" ov-highlight-font)
;; ("B" ov-highlight-bold)
;; ("I" ov-highlight-italic)
;; ("U" ov-highlight-underline)
;; ("S" ov-highlight-strikethrough)
;; ("X" ov-highlight-box)
;; ("k" ov-highlight-clear)
;; ("K" ov-highlight-clear-all)
;; ("q" nil "quit"))))
(ov-make-highlight "green-fg" '(:foreground "green"))
(ov-make-highlight "blue-fg" '(:foreground "blue"))
(spacemacs/declare-prefix "ov" "ov-highlighter")
(spacemacs/set-leader-keys "ovo" 'ov-highlighter/body)
(spacemacs/set-leader-keys "ovr" 'ov-highlight-red-fg)
(spacemacs/set-leader-keys "ovb" 'ov-highlight-blue-fg)
(spacemacs/set-leader-keys "ovg" 'ov-highlight-green-fg)
(spacemacs/set-leader-keys "ovc" 'ov-highlight-clear)
;; (add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
(require 'org-habit)
(setq org-startup-indented t)
(defun org-mode-my-init ()
(define-key org-mode-map (kbd "×") (kbd "*"))
;;(define-key org-mode-map (kbd "-") (kbd "-"))
(define-key org-mode-map (kbd "(") (kbd "("))
(define-key org-mode-map (kbd ")") (kbd ")"))
)
(add-hook 'org-mode-hook 'org-mode-my-init)
(add-hook 'org-mode-hook 'smartparens-strict-mode)
(setq org-startup-with-inline-images nil)
(setq org-image-actual-width (quote (600)))
(setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
(add-to-load-path "~/.spacemacs.d/package/ox-ipynb")
(require 'ox-ipynb)
;; (add-to-load-path "~/.spacemacs.d/package/org-edit-latex")
(require 'org-edit-latex)
(add-hook 'org-mode-hook 'org-edit-latex-mode)
(spacemacs/declare-prefix "ou" "Org-latex")
(spacemacs/set-leader-keys "ouu" 'org-toggle-latex-fragment)
(spacemacs/set-leader-keys "oui" 'org-edit-special)
(spacemacs/set-leader-keys "ouo" 'org-preview-latex-fragment)
(use-package company-math
:ensure t)
(use-package company-auctex
:ensure t
:config (progn
(defun company-auctex-labels (command &optional arg &rest ignored)
"company-auctex-labels backend"
(interactive (list 'interactive))
(case command
(interactive (company-begin-backend 'company-auctex-labels))
(prefix (company-auctex-prefix "\\\\.*ref{\\([^}]*\\)\\="))
(candidates (company-auctex-label-candidates arg))))
(add-to-list 'company-backends
'(company-auctex-macros
company-auctex-environments
company-math-symbols-unicode
company-math-symbols-latex))
(add-to-list 'company-backends #'company-auctex-labels)
(add-to-list 'company-backends #'company-auctex-bibs)))
(load "~/.spacemacs.d/package/emacscompanywords/company-words-discn")
(add-hook 'org-mode-hook 'company-mode)
(add-hook 'org-mode-hook
(lambda ()
(set (make-local-variable 'company-backends) '(company-math-symbols-unicode company-math-symbols-latex company-files company-en-words company-dabbrev)))
)
(custom-set-faces
'(org-agenda-done ((t (:foreground "#86dc2f" :height 1.0)))))
(custom-set-faces
'(org-scheduled-today ((t (:foreground "#bc6ec5" :height 1.0)))))
(eval-after-load 'org
'(progn
(add-to-list 'org-structure-template-alist
'("el" "#+BEGIN_SRC emacs-lisp\n\n?\n\n #+END_SRC"))
(add-to-list 'org-structure-template-alist
'("sh" "#+BEGIN_SRC sh\n\n?\n\n #+END_SRC"))
(add-to-list 'org-structure-template-alist
'("pl" "#+BEGIN_SRC :file \n\n?\n\n #+END_SRC"))
(add-to-list 'org-structure-template-alist
'("ipa" "#+BEGIN_SRC ipython :session :exports both :results output \n\n?\n\n #+END_SRC"))
(add-to-list 'org-structure-template-alist
'("ipb" "#+BEGIN_SRC ipython :session :exports both :file \n\n?\n\n#+END_SRC"))
;; (add-to-list 'org-structure-template-alist
;; '("p" "#+BEGIN_SRC plantuml :file uml.png \n\n?\n\n#+END_SRC"))
;; (add-to-list 'org-structure-template-alist
;; '("p" "#+BEGIN_SRC plantuml :file uml.png \n\n?\n\n#+END_SRC"))
))
(eval-after-load 'org
'(progn
(setq org-columns-default-format "%50ITEM(Task) %CATEGORY %SCHEDULED %5Effort %5CLOCKSUM %PRIORITY")
(setq org-global-properties (quote (("Effort_ALL" . "0:15 0:30 0:45 1:00 2:00 3:00 4:00 5:00 6:00 0:00")
("STYLE_ALL" . "habit"))))
)
)
(defun lengyueyang/org-ispell ()
"Configure `ispell-skip-region-alist' for `org-mode'."
(make-local-variable 'ispell-skip-region-alist)
(add-to-list 'ispell-skip-region-alist '(org-property-drawer-re))
(add-to-list 'ispell-skip-region-alist '("~" "~"))
(add-to-list 'ispell-skip-region-alist '("=" "="))
(add-to-list 'ispell-skip-region-alist '("^#\\+BEGIN_SRC" . "^#\\+END_SRC")))
(add-hook 'org-mode-hook #'lengyueyang/org-ispell)
(require 'org-notify)
(org-notify-start)
(org-notify-add 'appt
'(:time "-1s" :period "20s" :duration 10
:actions (-message -ding))
'(:time "15m" :period "2m" :duration 100
:actions -notify)
'(:time "2h" :period "10m" :actions -message)
'(:time "3d" :period "12h" :actions -message)
'(:time "7d" :period "24h" :actions -message)
'(:time "30d" :actions -email))
;; [[https://www.reddit.com/r/emacs/comments/5ayjjl/pomodoro_in_emacs/][Pomodoro in Emacs : emacs]]
(use-package org-pomodoro
:ensure t
:commands (org-pomodoro)
:config
(setq alert-user-configuration (quote ((((:category . "org-pomodoro")) libnotify nil))))
(setq org-pomodoro-length 50)
(setq org-pomodoro-short-break-length 10)
(setq org-pomodoro-long-break-length 30)
)
;; (add-hook 'org-pomodoro-break-finished-hook
;; (lambda ()
;; (interactive)
;; (org-pomodoro '(16)))
(eval-after-load 'org
'(progn
(setq org-agenda-files (quote ("~/MEGA/Emacs-lengyue/GTD-lengyue"
"~/MEGA/Emacs-lengyue/Wiki-lengyue"
"~/MEGA/Kangfuzi")))
(setq org-todo-keywords
(quote ((sequence "TODO(t)" "STARTED(s)" "|" "CANCELLED(c@/!)" "DONE(d!/!)")
(sequence "SOMEDAY(S)" "|" "WAITING(w@/!)" "MEETING(m)" "PHONE(p)")
(sequence "REPORT(r)" "BUG(b)" "KNOWNCAUSE(k)" "|" "FIXED(f)")
)))
(setq org-todo-keyword-faces
(quote (
("STARTED" :foreground "magenta" :weight bold)
;; ("NEXT" :foreground "blue" :weight bold)
;; ("DONE" :foreground "forest green" :weight bold)
("WAITING" :foreground "red" :weight bold)