1
2
3
4
|
;;; ------------------------------------------
;;; Do not edit this file. It was tangled from
;;; an org file.
;;; ------------------------------------------
|
1 Introduction: Emacs Configuration in an Org File
I used spacemacs recently, org-mode is my favourite package of emacs,
I use org-mode to GTD, write slide and documents, so I want to use org-mode to
manager may own configuration of emacs beyond spacemacs.
After searched in google and with my research, I found the way below,
I want to manager my own emacs configuration from now ([2016-11-07 Mon 21:00]).
You could found my org config file in https://github.com/lengyueyang/spacemacs-lengyue
1.1 Custom.el setup
In order to reduce the size of init.el
in .spacemacs
folder, create a custom.el
file
in .spaceamcs
folder, then add the flowing code to the end the init.el
, and copy the
same location code to custom.el
at the same time.
Don’t export this code, so use example
1
2
|
(setq custom-file (expand-file-name "custom.el" dotspacemacs-directory))
(load custom-file 'no-error 'no-message)
|
1.2 Org-mode to customize emacs configuration
Add the follow code to .inti.el
part defun dotspacemacs/user-config ()
Don’t export this code, so use example
1
2
3
4
|
(require 'ob-tangle)
(org-babel-load-file
(expand-file-name "lengyueyang.org"
dotspacemacs-directory))
|
Global keybindings of emacs but for specific customization with keybinding, like some org related keybindings in Org-mode configuration part.
2 Spacemacs better defaults
Include the configuration of spacemacs itself layers and better use of its defaults layers.
2.1 Open my init file
1
2
3
4
5
6
|
(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)
|
2.2 Checkout the spelling of words
1
2
|
;; (define-key global-map (kbd "<f8>") 'flyspell-correct-previous-word-generic)
(spacemacs/set-leader-keys "okf" 'flyspell-correct-previous-word-generic)
|
2.3 Org-agenda and org-download-screenshot
1
2
|
(spacemacs/set-leader-keys "oa" 'org-agenda-list)
(spacemacs/set-leader-keys "os" 'org-download-screenshot)
|
2.4 Bookmark keybindings reconfiguration
1
2
3
4
5
|
(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)
|
2.5 Buffer default coding system
1
2
3
4
5
6
7
8
9
10
|
(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)
|
2.6 Markdown mode
1
2
3
4
5
6
7
8
9
10
|
(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 markdown-command "pandoc -f markdown -t html -s --mathjax --highlight-style pygments")
(spacemacs/set-leader-keys "okm" 'markdown-live-preview-mode)
|
2.7 Spacemacs-layout
1
2
3
4
5
6
7
8
9
10
11
12
13
|
(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)
|
2.8 Deft
1
2
3
|
;; (global-set-key (kbd "<f5>") 'deft)
(setq deft-extensions '("txt" "tex" "org" "mk" "makedown"))
(setq deft-directory "~/MEGA/Lengyue_data/Wiki")
|
2.9 Elfeed
在 Emacs 中用 elfeed 阅读你的 RSS-feeds
1
2
3
4
5
|
(use-package elfeed-org
:ensure t
:config
(elfeed-org)
(setq rmh-elfeed-org-files (list "~/MEGA/Lengyue_data/Wiki/Elfeed.org")))
|
2.10 Mu4e
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
|
(use-package mu4e
:config
(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)
(setq mu4e-view-show-addresses 't)
;; Set up some common mu4e variables
(setq mu4e-maildir "~/MEGA/Lengyue_data/Private_data/Mu4e")
(use-package smtpmail)
(setq
mu4e-sent-folder "/Foxmail/Sent Messages"
mu4e-drafts-folder "/Foxmail/Drafts"
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
)
(defvar my-mu4e-account-alist
'(("Foxmail"
(mu4e-sent-folder "/Foxmail/Sent Messages")
(mu4e-drafts-folder "/Foxmail/Drafts")
(send-mail-function smtpmail-send-it)
(message-send-mail-function smtpmail-send-it)
(smtpmail-auth-credentials (expand-file-name "~/.authinfo"))
(smtpmail-default-smtp-server "smtp.qq.com")
(smtpmail-smtp-server "smtp.qq.com")
(smtpmail-stream-type ssl)
(smtpmail-smtp-service 465))
("Gmail"
(mu4e-sent-folder "/Gmail/[Gmail].Sent Mail")
(mu4e-drafts-folder "/Gmail/[Gmail].Drafts")
(send-mail-function smtpmail-send-it)
(user-mail-address "maoxiaoweihl@gmail.com")
(message-send-mail-function smtpmail-send-it)
(smtpmail-auth-credentials (expand-file-name "~/.authinfo"))
(smtpmail-smtp-server "smtp.gmail.com")
(smtpmail-stream-type starttls)
(smtpmail-smtp-service 587))))
(defun my-mu4e-set-account ()
"Set the account for composing a message."
(let* ((account
(if mu4e-compose-parent-message
(let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
(string-match "/\\(.*?\\)/" maildir)
(match-string 1 maildir))
(completing-read (format "Compose with account: (%s) "
(mapconcat #'(lambda (var) (car var))
my-mu4e-account-alist "/"))
(mapcar #'(lambda (var) (car var)) my-mu4e-account-alist)
nil t nil nil (caar my-mu4e-account-alist))))
(account-vars (cdr (assoc account my-mu4e-account-alist))))
(if account-vars
(mapc #'(lambda (var)
(set (car var) (cadr var)))
account-vars)
(error "No email account found"))))
(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)
;; 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 '("maoxiaowei1988@foxmail.com"
"maoxiaoweihl@gmail.com"))
;; 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 "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/Lengyue_data/Private_data/Mu4e/Attachment")
(setq mu4e-contexts
`(
,(make-mu4e-context
:name "Foxmail_lengyue"
:enter-func (lambda () (mu4e-message "Enter maoxiaowei1988@foxmail.com.com context"))
:leave-func (lambda () (mu4e-message "Leave maoxiaowei1988@foxmail.com.com context"))
:match-func (lambda (msg)
(when msg
(mu4e-message-contact-field-matches msg
:to "maoxiaowei1988@foxmail.com")))
:vars '( ( user-mail-address . "maoxiaowei1988@foxmail.com" )
( user-full-name . "Mao Xiaowei" )
( smtpmail-smtp-server . "smtp.qq.com" )
( mu4e-compose-signature .
(concat
"Xiaowei Mao\n"
"Email: maoxiaoweihl@gmail.com\n"
"Email: maoxiaowei1988@foxmail.com\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 maoxiaoweihl@gmail.com context"))
:leave-func (lambda () (mu4e-message "Leave maoxiaoweihl@gmail.com 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 "maoxiaoweihl@gmail.com")))
:vars '( ( user-mail-address . "maoxiaoweihl@gmail.com" )
( user-full-name . "Mao Xiaowei" )
( smtpmail-smtp-server . "smtp.gmail.com" )
( mu4e-compose-signature .
(concat
"Xiaowei Mao\n"
"Email: maoxiaoweihl@gmail.com\n"
"Email: maoxiaowei1988@foxmail.com\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)
(setq mu4e-org-contacts-file "~/MEGA/Lengyue_data/Wiki/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)
)
|
https://github.com/org-mime/org-mime/blob/master/org-mime.el
http://kitchingroup.cheme.cmu.edu/blog/2016/10/29/Sending-html-emails-from-org-mode-with-org-mime/
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
|
(use-package org-mime
:config
(setq org-mime-library 'mml)
(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)
)
|
2.11 Magit
2.11.1 Magit auto complete
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
(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)))
)
|
3 Basic setup
Some basic customizaton
In emacs, we can use M-x
to execute interactive commands, I
implement some of them to make my emacs more easy to use.
1
2
|
(setq user-full-name "lengyuyang"
user-mail-address "maoxiaoweihl@gmail.com")
|
3.2 Don’t ask me when kill process buffer
1
2
3
|
(setq kill-buffer-query-functions
(remq 'process-kill-buffer-query-function
kill-buffer-query-functions))
|
3.3 Set the chinese font alignment
1
2
3
4
5
6
|
(if window-system
;; (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)
)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
(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))))))
|
3.5 Simple better defaults
1
2
3
4
5
6
7
8
9
10
|
(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))))))
|
3.6 Large file handle
1
2
3
4
5
6
7
8
9
10
11
|
(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)
|
3.7 Keeping files in sync
By default, Emacs will not update the contents of open buffers when a file
changes on disk. This is inconvenient when switching branches in Git - as you’d
risk editing stale buffers.
This problem can be solved by:
1
2
3
4
|
(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
|
3.8 Emacs socks proxy
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
|
;; (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)))
|
3.9 Highlight
1
2
3
4
5
6
7
8
9
10
|
(add-to-load-path "~/.spacemacs.d/package/ov-highlighter")
(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)
|
4 Org-mode configuration
This part is the customization to org-mode.
4.1 Better defaults to org
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
(use-package org
:config
(use-package org-habit)
(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 ")"))
)
(setq org-startup-with-inline-images nil)
(setq org-image-actual-width (quote (600)))
;; (setq org-startup-indented t)
(setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
(use-package ox-ipynb
:load-path "~/.spacemacs.d/package/ox-ipynb")
:hook (
(org-mode . turn-off-auto-fill)
(org-mode . org-mode-my-init)
(org-mode . smartparens-strict-mode)
)
)
|
4.2 Org latex configuration
1
2
3
4
5
6
7
8
|
(use-package org-edit-latex
:hook ((org-mode . org-edit-latex-mode))
:config
(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)
)
|
4.3 Org-mode auto complete
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
|
(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)))
)
|
4.4 Org-agenda font size
Changed the org-agenda font size with the below link methods
https://emacs-china.org/t/agenda-view/1392
1
2
3
4
5
|
(custom-set-faces
'(org-agenda-done ((t (:foreground "#86dc2f" :height 1.0)))))
(custom-set-faces
'(org-scheduled-today ((t (:foreground "#bc6ec5" :height 1.0)))))
|
4.5 Extend org-mode’s easy templates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
(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"))
))
|
4.6 Org columns and properties
1
2
3
4
5
6
7
|
(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"))))
)
)
|
4.7 Org-ispell
1
2
3
4
5
6
7
8
|
(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)
|
4.8 Org-notify
1
2
3
4
5
6
7
8
9
10
11
12
13
|
(use-package org-notify
:config
(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))
)
|
4.9 Org-pomodoro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
;; [[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)))
|
4.10 Org-journal
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
|
(use-package org-journal
:ensure t
:defer t
:custom
(org-journal-dir "~/MEGA/Lengyue_data/GTD/journal")
(org-journal-file-type 'monthly)
(org-journal-file-format "%Y-%m.org")
(org-journal-time-format "TODO ")
(org-journal-enable-agenda-integration t)
(org-journal-date-format "%A, %B %d %Y"))
(defun org-journal-date-format-func (time)
"Custom function to insert journal date header,
and some custom text on a newly created journal file."
(when (= (buffer-size) 0)
(insert
(pcase org-journal-file-type
(`daily "#+TITLE: Daily Journal")
(`weekly "#+TITLE: Weekly Journal")
(`monthly "#+TITLE: Monthly Journal\n#+AUTHOR: lengyue\n#+FILETAGS: Journal \n\n\n")
(`yearly "#+TITLE: Yearly Journal"))))
(concat org-journal-date-prefix (format-time-string "%A, %x" time)))
(setq org-journal-date-format 'org-journal-date-format-func)
(defun org-journal-find-location ()
;; Open today's journal, but specify a non-nil prefix argument in order to
;; inhibit inserting the heading; org-capture will insert the heading.
(org-journal-new-entry t)
;; Position point on the journal's top-level heading so that org-capture
;; will add the new entry as a child entry.
(goto-char (point-min)))
|
4.11 Org-agenda and capture
4.11.1 Org-agenda
The first agenda configuration, which is not complete.
A complete agenda and capture configuration
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
|
(eval-after-load 'org
'(progn
(setq org-agenda-files (quote ("~/MEGA/Lengyue_data/GTD"
"~/MEGA/Lengyue_data/GTD/journal"
"~/MEGA/Lengyue_data/Wiki"
;; "~/MEGA/Baidu-lengyue/Projects"
;; "~/MEGA/Baidu-lengyue/Personal"
)))
;; todo-(next/waitting)-done/cancelled
;; todo-hode-todo/next/cancelled
(setq org-todo-keywords
(quote (
(sequence "TODO(t)" "NEXT(n)" "ONGOING(o)" "|" "DONE(d!/!)")
(sequence "SOMEDAY(s)" "|" "WAITING(w@/!)" "CANCELLED(c@/!)" )
(sequence "REPORT(r)" "BUG(b)" "KNOWNCAUSE(k)" "|" "FIXED(f)")
)))
(setq org-todo-keyword-faces
(quote (
;; ("TODO" :foreground "red" :weight bold)
("NEXT" :foreground "blue" :weight bold)
("DONE" :foreground "forest green" :weight bold)
("CANCELLED" :foreground "forest green" :weight bold)
("WAITING" :foreground "orange" :weight bold)
("SOMEDAY" :foreground "magenta" :weight bold)
)))
(setq org-refile-targets
'(("~/MEGA/Lengyue_data/GTD/GTD.org" :maxlevel . 2)
("~/MEGA/Lengyue_data/GTD/INBOX.org" :maxlevel . 1)
("~/MEGA/Lengyue_data/Wiki/Elfeed.org" :maxlevel . 2)
))
(setq org-log-into-drawer t)
(setq org-agenda-custom-commands
'(
("b" "Blog idea" tags-todo "BLOG")
("s" "Someday" todo "SOMEDAY")
("n" "Next" todo "NEXT")
("o" "Ongoing" todo "ONGOING")
("w" "Waiting" todo "WAITING")
("d" . " 任务安排 ")
("da" " 重要且紧急的任务 " tags-todo "+PRIORITY=\"A\"")
("db" " 重要且不紧急的任务 " tags-todo "+PRIORITY=\"B\"")
("dc" " 不重要且紧急的任务 " tags-todo "+PRIORITY=\"C\"")
("p" . " 项目安排 ")
("W" "Weekly Review" tags-todo "PROJECT")
))
)
)
|
4.11.2 Org-capture
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
|
;; (define-key global-map (kbd "<f9>") 'org-capture)
(spacemacs/set-leader-keys "oc" 'org-capture)
(setq org-capture-templates
'(
("i" "Inbox" entry (file+headline "~/MEGA/Lengyue_data/GTD/INBOX.org" "Inbox")
"* TODO %?\n%i%U"
:empty-lines 1)
("m" "Myself Tasks" entry (file+headline "~/MEGA/Lengyue_data/GTD/GTD.org" "Myself Tasks")
"* TODO %?\n%i%U"
:empty-lines 1)
("o" "Work Related Tasks" entry (file+headline "~/MEGA/Lengyue_data/GTD/GTD.org" "Work Related Tasks")
"* TODO %?\n%i%U"
:empty-lines 1)
("c" "Contacts" entry (file+headline "~/MEGA/Lengyue_data/Wiki/Contacts.org" "Temporary")
"* %?
:PROPERTIES:
:EMAIL:
:PHONE:
:ALIAS:
:NICKNAME:
:IGNORE:
:ICON:
:NOTE:
:ADDRESS:
:BIRTHDAY:
:END:"
:empty-lines 1)
("b" "Blog Ideas" entry (file+headline "~/MEGA/Lengyue_data/GTD/INBOX.org" "Blog Ideas")
"* TODO %?\n%i%U"
:empty-lines 1)
("j" "Journal entry" entry (function org-journal-find-location)
"** %(format-time-string org-journal-time-format)^{}\n%i%?"
:empty-lines 1)
("s" "Someday" entry (file+headline "~/MEGA/Lengyue_data/GTD/INBOX.org" "Someday")
"* SOMEDAY %?\n%i%U"
:empty-lines 1)
("w" "Website bookmark" entry (file+headline "~/MEGA/Lengyue_data/GTD/INBOX.org" "Bookmark")
"* %a :website:\n %? \n%U \n\n%:initial"
:empty-lines 1)
("p" "Projects" entry (file+headline "~/MEGA/Lengyue_data/GTD/INBOX.org" "Projects")
"* TODO %?\n%i%U"
:empty-lines 1)
))
|
4.12 Add bookmark to orgmode
1
2
3
4
|
(add-to-load-path "~/.spacemacs.d/package/org-protocol-capture-html")
(server-start)
(require 'org-protocol)
(require 'org-protocol-capture-html)
|
4.13 Org-babel customizaton
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
|
(setq org-confirm-babel-evaluate nil)
(setq plantuml-default-exec-mode 'jar)
;; (setq plantuml-default-exec-mode 'executable)
(eval-after-load 'org
'(progn
(defun lengyueyang/org-insert-src-block (src-code-type)
"Insert a `SRC-CODE-TYPE' type source code block in org-mode."
(interactive
(let ((src-code-types
'("emacs-lisp" "python" "C" "sh" "java" "js" "clojure" "C++" "css"
"calc" "asymptote" "dot" "gnuplot" "ledger" "lilypond" "mscgen"
"octave" "oz" "plantuml" "R" "sass" "screen" "sql" "awk" "ditaa"
"haskell" "latex" "lisp" "matlab" "ocaml" "org" "perl" "ruby"
"scheme" "sqlite" "ipython")))
(list (ido-completing-read "Source code type: " src-code-types))))
(progn
(newline-and-indent)
(insert (format "#+BEGIN_SRC %s\n" src-code-type))
(newline-and-indent)
(newline-and-indent)
(newline-and-indent)
(insert "#+END_SRC\n")
(previous-line 2)
(org-edit-src-code)))
(add-hook 'org-mode-hook '(lambda ()
;; keybinding for editing source code blocks
;; keybinding for inserting code blocks
(local-set-key (kbd "C-c i s")
'lengyueyang/org-insert-src-block)
))
(org-babel-do-load-languages
'org-babel-load-languages
'((perl . t)
(ruby . t)
(shell . t)
(js . t)
(python . t)
(ipython . t)
(emacs-lisp . t)
(http . t)
(plantuml . t)
(R . t)
(dot . t)
(gnuplot . t)
(latex . t)
(C . t)
(octave . t)
(ditaa . t)))
)
)
(spacemacs/set-leader-keys "oi" 'lengyueyang/org-insert-src-block)
;; Resume clocking task when emacs is restarted
(org-clock-persistence-insinuate)
;; Save the running clock and all clock history when exiting Emacs, load it on startup
(setq org-clock-persist t)
;; Do not prompt to resume an active clock
(setq org-clock-persist-query-resume nil)
|
4.14 Ob-ipython and Jupter notebook
1
2
3
4
5
|
(require 'ob-ipython)
;; (setq org-babel-python-command "/usr/bin/ipython --pylab --pdb --nosep")
(setq python-shell-prompt-detect-failure-warning nil)
;; (add-hook 'org-babel-after-execute-hook 'org-display-inline-images 'append)
|
4.15 Org bullets customization
1
2
3
4
5
6
7
8
9
10
11
12
|
(defun lengyueyang/post-init-org-bullets ()
(setq org-bullets-bullet-list '(
"☰" "☷" "⋗" "⇀"
)))
(add-hook 'org-mode-hook #'lengyueyang/post-init-org-bullets)
;; (require 'org-bullets)
;; ;; make available "org-bullet-face" such that I can control the font size individually
;; (setq org-bullets-face-name (quote org-bullet-face))
;; (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
;; (setq org-bullets-bullet-list '("☰" "☷" "⋗" "⇀" "✙" "♱" "♰" "☥" "✞" "✟" "✝" "†" "✠" "✚" "✜" "✛" "✢" "✣" "✤" "✥"))
|
4.16 Org-latex to pdf
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
|
;;org-mode export to latex
(require 'ox-latex)
(setq org-export-latex-listings t)
;;org-mode source code setup in exporting to latex
(add-to-list 'org-latex-listings
'("" "listings"))
(add-to-list 'org-latex-listings
'("" "color"))
(add-to-list 'org-latex-packages-alist
'("" "xcolor" t))
(add-to-list 'org-latex-packages-alist
'("" "listings" t))
;;(add-to-list 'org-latex-packages-alist
;; '("" "fontspec" t))
(add-to-list 'org-latex-packages-alist
'("" "indentfirst" t))
;;(add-to-list 'org-latex-packages-alist
;; '("" "xunicode" t))
(add-to-list 'org-latex-packages-alist
'("" "geometry"))
(add-to-list 'org-latex-packages-alist
'("" "float"))
(add-to-list 'org-latex-packages-alist
'("" "longtable"))
(add-to-list 'org-latex-packages-alist
'("" "tikz"))
(add-to-list 'org-latex-packages-alist
'("" "fancyhdr"))
(add-to-list 'org-latex-packages-alist
'("" "textcomp"))
(add-to-list 'org-latex-packages-alist
'("" "amsmath"))
(add-to-list 'org-latex-packages-alist
'("" "amsthm"))
(add-to-list 'org-latex-packages-alist
'("" "tabularx" t))
(add-to-list 'org-latex-packages-alist
'("" "booktabs" t))
(add-to-list 'org-latex-packages-alist
'("" "grffile" t))
(add-to-list 'org-latex-packages-alist
'("" "wrapfig" t))
(add-to-list 'org-latex-packages-alist
'("normalem" "ulem" t))
(add-to-list 'org-latex-packages-alist
'("" "amssymb" t))
(add-to-list 'org-latex-packages-alist
'("" "extarrows" t))
(add-to-list 'org-latex-packages-alist
'("" "capt-of" t))
(add-to-list 'org-latex-packages-alist
'("figuresright" "rotating" t))
(add-to-list 'org-latex-packages-alist
'("Lenny" "fncychap" t))
(add-to-list 'org-latex-classes
'("lengyue-org-book"
"\\documentclass{book}
\\usepackage[slantfont, boldfont]{xeCJK}
% chapter set
\\usepackage{titlesec}
\\usepackage{hyperref}
\\hypersetup{colorlinks,linkcolor=black,filecolor=black,urlcolor=blue,citecolor=black}
\\usepackage{fontspec}
\\usepackage{xunicode}
\\titleformat{\\paragraph}{\\normalfont\\normalsize\\bfseries}{\\theparagraph}{1em}{}
[NO-DEFAULT-PACKAGES]
[PACKAGES]
\\setCJKmainfont{WenQuanYi Micro Hei} % 设置缺省中文字体
\\setCJKsansfont{WenQuanYi Micro Hei}
\\setCJKmonofont{WenQuanYi Micro Hei Mono}
\\setmainfont{DejaVu Sans} % 英文衬线字体
\\setsansfont{DejaVu Serif} % 英文无衬线字体
\\setmonofont{DejaVu Sans Mono}
%\\setmainfont{WenQuanYi Micro Hei} % 设置缺省中文字体
%\\setsansfont{WenQuanYi Micro Hei}
%\\setmonofont{WenQuanYi Micro Hei Mono}
%如果没有它,会有一些 tex 特殊字符无法正常使用,比如连字符。
\\defaultfontfeatures{Mapping=tex-text}
% 中文断行
\\XeTeXlinebreaklocale \"zh\"
\\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
% 代码设置
\\lstset{numbers=left,
numberstyle= \\tiny,
keywordstyle= \\color{ blue!70},commentstyle=\\color{red!50!green!50!blue!50},
frame=shadowbox,
breaklines=true,
rulesepcolor= \\color{ red!20!green!20!blue!20}
}
[EXTRA]
"
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
(add-to-list 'org-latex-classes
'("lengyue-org-article"
"\\documentclass{article}
\\usepackage[slantfont, boldfont]{xeCJK}
\\usepackage{titlesec}
\\usepackage{hyperref}
\\hypersetup{colorlinks,linkcolor=black,filecolor=black,urlcolor=blue,citecolor=black}
\\usepackage{fontspec}
\\usepackage{xunicode}
\\titleformat{\\paragraph}{\\normalfont\\normalsize\\bfseries}{\\theparagraph}{1em}{}
[NO-DEFAULT-PACKAGES]
[PACKAGES]
\\parindent 2em
\\setCJKmainfont{WenQuanYi Micro Hei} % 设置缺省中文字体
\\setCJKsansfont{WenQuanYi Micro Hei}
\\setCJKmonofont{WenQuanYi Micro Hei Mono}
\\setmainfont{DejaVu Sans} % 英文衬线字体
\\setsansfont{DejaVu Serif} % 英文无衬线字体
\\setmonofont{DejaVu Sans Mono}
%\\setmainfont{WenQuanYi Micro Hei} % 设置缺省中文字体
%\\setsansfont{WenQuanYi Micro Hei}
%\\setmonofont{WenQuanYi Micro Hei Mono}
%如果没有它,会有一些 tex 特殊字符无法正常使用,比如连字符。
\\defaultfontfeatures{Mapping=tex-text}
% 中文断行
\\XeTeXlinebreaklocale \"zh\"
\\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
% 代码设置
\\lstset{numbers=left,
numberstyle= \\tiny,
keywordstyle= \\color{ blue!70},commentstyle=\\color{red!50!green!50!blue!50},
frame=shadowbox,
breaklines=true,
rulesepcolor= \\color{ red!20!green!20!blue!20}
}
[EXTRA]
"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
(add-to-list 'org-latex-classes
'("lengyue-org-beamer"
"\\documentclass{beamer}
\\usepackage[slantfont, boldfont]{xeCJK}
% beamer set
\\usepackage[none]{hyphenat}
\\usepackage[abs]{overpic}
\\usepackage{fontspec}
\\usepackage{xunicode}
[NO-DEFAULT-PACKAGES]
[PACKAGES]
\\setCJKmainfont{WenQuanYi Micro Hei} % 设置缺省中文字体
\\setCJKsansfont{WenQuanYi Micro Hei}
\\setCJKmonofont{WenQuanYi Micro Hei Mono}
\\setmainfont{DejaVu Sans} % 英文衬线字体
\\setsansfont{DejaVu Serif} % 英文无衬线字体
\\setmonofont{DejaVu Sans Mono}
%\\setmainfont{WenQuanYi Micro Hei} % 设置缺省中文字体
%\\setsansfont{WenQuanYi Micro Hei}
%\\setmonofont{WenQuanYi Micro Hei Mono}
%如果没有它,会有一些 tex 特殊字符无法正常使用,比如连字符。
\\defaultfontfeatures{Mapping=tex-text}
% 中文断行
\\XeTeXlinebreaklocale \"zh\"
\\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt
% 代码设置
\\lstset{numbers=left,
numberstyle= \\tiny,
keywordstyle= \\color{ blue!70},commentstyle=\\color{red!50!green!50!blue!50},
frame=shadowbox,
breaklines=true,
rulesepcolor= \\color{ red!20!green!20!blue!20}
}
[EXTRA]
"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
(setq org-latex-pdf-process
'("xelatex -interaction nonstopmode -output-directory %o %f"
;; "biber %b" "xelatex -interaction nonstopmode -output-directory %o %f"
"bibtex %b"
"xelatex -interaction nonstopmode -output-directory %o %f"
"xelatex -interaction nonstopmode -output-directory %o %f"))
|
4.17 Setup link abbreviations
Link abbreviations
An abbreviated link looks like
1
|
[[linkword:tag][description]]
|
1
2
3
4
|
(setq org-link-abbrev-alist
'(("google" . "http://www.google.com/search?q=")
("google-map" . "http://maps.google.com/maps?q=%s")
))
|
4.18 Org-subtask and org-checklist
1
2
3
4
5
|
(add-to-load-path "~/.spacemacs.d/package/org-subtask-reset")
(require 'org-subtask-reset)
(add-to-load-path "~/.spacemacs.d/package/org-checklist")
(require 'org-checklist)
|
4.19 Org-archive-all-tasks
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
|
(defun lengyueyang//org-archive-tasks (prefix)
(org-map-entries
(lambda ()
(org-archive-subtree)
(setq org-map-continue-from (outline-previous-heading)))
(format "/%s" prefix) 'file))
(defun lengyueyang/org-archive-all-tasks ()
(interactive)
(lengyueyang//org-archive-tasks "DONE")
(lengyueyang//org-archive-tasks "CANCELLED")
(lengyueyang//org-archive-tasks "FIXED")
)
;; org-archive-subtree-hierarchical.el
;; modified from https://lists.gnu.org/archive/html/emacs-orgmode/2014-08/msg00109.html
;; In orgmode
;; * A
;; ** AA
;; *** AAA
;; ** AB
;; *** ABA
;; Archiving AA will remove the subtree from the original file and create
;; it like that in archive target:
;; * AA
;; ** AAA
;; And this give you
;; * A
;; ** AA
;; *** AAA
(defun org-get-local-archive-location ()
"Get the archive location applicable at point."
(let ((re "^[ \t]*#\\+ARCHIVE:[ \t]+\\(\\S-.*\\S-\\)[ \t]*$")
prop)
(save-excursion
(save-restriction
(widen)
(setq prop (org-entry-get nil "ARCHIVE" 'inherit))
(cond
((and prop (string-match "\\S-" prop))
prop)
((or (re-search-backward re nil t)
(re-search-forward re nil t))
(match-string 1))
(t org-archive-location))))))
(defun org-extract-archive-file (&optional location)
"Extract and expand the file name from archive LOCATION.
if LOCATION is not given, the value of `org-archive-location' is used."
(setq location (or location org-archive-location))
(if (string-match "\\(.*\\)::\\(.*\\)" location)
(if (= (match-beginning 1) (match-end 1))
(buffer-file-name (buffer-base-buffer))
(expand-file-name
(format (match-string 1 location)
(file-name-nondirectory
(buffer-file-name (buffer-base-buffer))))))))
(defun org-extract-archive-heading (&optional location)
"Extract the heading from archive LOCATION.
if LOCATION is not given, the value of `org-archive-location' is used."
(setq location (or location org-archive-location))
(if (string-match "\\(.*\\)::\\(.*\\)" location)
(format (match-string 2 location)
(file-name-nondirectory
(buffer-file-name (buffer-base-buffer))))))
(require 'org-archive)
(defun org-archive-subtree-hierarchical--line-content-as-string ()
"Returns the content of the current line as a string"
(save-excursion
(beginning-of-line)
(buffer-substring-no-properties
(line-beginning-position) (line-end-position))))
(defun org-archive-subtree-hierarchical--org-child-list ()
"This function returns all children of a heading as a list. "
(interactive)
(save-excursion
;; this only works with org-version > 8.0, since in previous
;; org-mode versions the function (org-outline-level) returns
;; gargabe when the point is not on a heading.
(if (= (org-outline-level) 0)
(outline-next-visible-heading 1)
(org-goto-first-child))
(let ((child-list (list (org-archive-subtree-hierarchical--line-content-as-string))))
(while (org-goto-sibling)
(setq child-list (cons (org-archive-subtree-hierarchical--line-content-as-string) child-list)))
child-list)))
(defun org-archive-subtree-hierarchical--org-struct-subtree ()
"This function returns the tree structure in which a subtree
belongs as a list."
(interactive)
(let ((archive-tree nil))
(save-excursion
(while (org-up-heading-safe)
(let ((heading
(buffer-substring-no-properties
(line-beginning-position) (line-end-position))))
(if (eq archive-tree nil)
(setq archive-tree (list heading))
(setq archive-tree (cons heading archive-tree))))))
archive-tree))
(defun org-archive-subtree-hierarchical ()
"This function archives a subtree hierarchical"
(interactive)
(let ((org-tree (org-archive-subtree-hierarchical--org-struct-subtree))
(this-buffer (current-buffer))
(file (abbreviate-file-name
(or (buffer-file-name (buffer-base-buffer))
(error "No file associated to buffer")))))
(save-excursion
(setq location (org-get-local-archive-location)
afile (org-extract-archive-file location)
heading (org-extract-archive-heading location)
infile-p (equal file (abbreviate-file-name (or afile ""))))
(unless afile
(error "Invalid `org-archive-location'"))
(if (> (length afile) 0)
(setq newfile-p (not (file-exists-p afile))
visiting (find-buffer-visiting afile)
buffer (or visiting (find-file-noselect afile)))
(setq buffer (current-buffer)))
(unless buffer
(error "Cannot access file \"%s\"" afile))
(org-cut-subtree)
(set-buffer buffer)
(org-mode)
(goto-char (point-min))
(while (not (equal org-tree nil))
(let ((child-list (org-archive-subtree-hierarchical--org-child-list)))
(if (member (car org-tree) child-list)
(progn
(search-forward (car org-tree) nil t)
(setq org-tree (cdr org-tree)))
(progn
(goto-char (point-max))
(newline)
(org-insert-struct org-tree)
(setq org-tree nil)))))
(newline)
(org-yank)
(when (not (eq this-buffer buffer))
(save-buffer))
(message "Subtree archived %s"
(concat "in file: " (abbreviate-file-name afile))))))
(setq org-archive-default-command #'org-archive-subtree-hierarchically)
(defun org-insert-struct (struct)
"TODO"
(interactive)
(when struct
(insert (car struct))
(newline)
(org-insert-struct (cdr struct))))
(defun org-archive-subtree ()
(org-archive-subtree-hierarchical)
)
|
4.20 Org-ref customize
1
2
3
4
5
6
7
8
9
10
11
12
13
|
(setq reftex-default-bibliography '("~/MEGA/Lengyue_data/Papers/references.bib"))
(setq org-ref-default-bibliography '("~/MEGA/Lengyue_data/Papers/references.bib")
org-ref-pdf-directory "~/MEGA/Lengyue_data/Papers/bibtex_pdfs/"
org-ref-bibliography-notes "~/MEGA/Lengyue_data/Papers/notes.org")
(setq org-ref-completion-library 'org-ref-ivy-cite)
(setq bibtex-autokey-year-length 4
bibtex-autokey-name-year-separator "-"
bibtex-autokey-year-title-separator "-"
bibtex-autokey-titleword-separator "-"
bibtex-autokey-titlewords 3
bibtex-autokey-titlewords-stretch 1
bibtex-autokey-titleword-length 5)
|
4.21 Org-project
1
2
3
4
5
6
|
(with-eval-after-load 'org-agenda
(require 'org-projectile)
(mapcar '(lambda (file)
(when (file-exists-p file)
(push file org-agenda-files)))
(org-projectile-todo-files)))
|
4.22 Better equation numbering in LaTeX fragments in org-mode
https://www.youtube.com/embed/pcMuJlUvKCw
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
|
(defun org-renumber-environment (orig-func &rest args)
(let ((results '())
(counter -1)
(numberp))
(setq results (loop for (begin . env) in
(org-element-map (org-element-parse-buffer) 'latex-environment
(lambda (env)
(cons
(org-element-property :begin env)
(org-element-property :value env))))
collect
(cond
((and (string-match "\\\\begin{equation}" env)
(not (string-match "\\\\tag{" env)))
(incf counter)
(cons begin counter))
((string-match "\\\\begin{align}" env)
(prog2
(incf counter)
(cons begin counter)
(with-temp-buffer
(insert env)
(goto-char (point-min))
;; \\ is used for a new line. Each one leads to a number
(incf counter (count-matches "\\\\$"))
;; unless there are nonumbers.
(goto-char (point-min))
(decf counter (count-matches "\\nonumber")))))
(t
(cons begin nil)))))
(when (setq numberp (cdr (assoc (point) results)))
(setf (car args)
(concat
(format "\\setcounter{equation}{%s}\n" numberp)
(car args)))))
(apply orig-func args))
(advice-add 'org-create-formula-image :around #'org-renumber-environment)
;; (advice-remove 'org-create-formula-image #'org-renumber-environment)
|
4.23 Justifying LaTeX preview fragments in org-mode
https://www.youtube.com/embed/nA9YzooqpWY
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
|
;; specify the justification you want
(plist-put org-format-latex-options :justify 'center)
(defun org-justify-fragment-overlay (beg end image imagetype)
"Adjust the justification of a LaTeX fragment.
The justification is set by :justify in
`org-format-latex-options'. Only equations at the beginning of a
line are justified."
(cond
;; Centered justification
((and (eq 'center (plist-get org-format-latex-options :justify))
(= beg (line-beginning-position)))
(let* ((img (create-image image 'imagemagick t))
(width (car (image-size img)))
(offset (floor (- (/ (window-text-width) 2) (/ width 2)))))
(overlay-put (ov-at) 'before-string (make-string offset ? ))))
;; Right justification
((and (eq 'right (plist-get org-format-latex-options :justify))
(= beg (line-beginning-position)))
(let* ((img (create-image image 'imagemagick t))
(width (car (image-display-size (overlay-get (ov-at) 'display))))
(offset (floor (- (window-text-width) width (- (line-end-position) end)))))
(overlay-put (ov-at) 'before-string (make-string offset ? ))))))
(defun org-latex-fragment-tooltip (beg end image imagetype)
"Add the fragment tooltip to the overlay and set click function to toggle it."
(overlay-put (ov-at) 'help-echo
(concat (buffer-substring beg end)
"mouse-1 to toggle."))
(overlay-put (ov-at) 'local-map (let ((map (make-sparse-keymap)))
(define-key map [mouse-1]
`(lambda ()
(interactive)
(org-remove-latex-fragment-image-overlays ,beg ,end)))
map)))
;; advise the function to a
(advice-add 'org--format-latex-make-overlay :after 'org-justify-fragment-overlay)
(advice-add 'org--format-latex-make-overlay :after 'org-latex-fragment-tooltip)
;; (advice-remove 'org--format-latex-make-overlay 'org-justify-fragment-overlay)
;; (advice-remove 'org--format-latex-make-overlay 'org-latex-fragment-tooltip)
|
5 Programming Languages
This part is the customization to programming languages.
5.1 Yasnippet
Yasnippet allows you to type an abbreviation and then expand it into a template. We can look at yasnippet’s documentation on github.
Yasnippet by default checks for snippets in two places: a path relative to yasnippet.el (these are the default snippets that come with the package). If I want to make my own, I can put then in .spacemacs.d/snippets and it should find them there as well.
I downloads some snippets from web like yasnippet-snippet and dot-files, then I defined some snippets of mine.
You can use the tab key to expand a snippet once you’ve typed in the “key”. It’s pretty smart in that if tab fails for yasnippet, it then checks for whatever tab was originally bound to.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
(setq yas-snippet-dirs
'("~/.spacemacs.d/snippets/lengyueyang-snippets"
"~/.spacemacs.d/snippets/dot-files-snippets"
"~/.spacemacs.d/snippets/yasnippet-snippets"
;; "~/.spacemacs.d/snippets/lengyueyang-snippets/"
))
(yas-global-mode 1)
;; (global-set-key (kbd "C-c y i") 'yas-insert-snippet)
;; (global-set-key (kbd "C-c y n") 'yas-new-snippet)
;; (global-set-key (kbd "C-c y t") 'yas-expand-from-trigger-key)
;;(global-set-key (kbd "C-c i e") 'spacemacs/auto-yasnippet-expand)
(spacemacs/declare-prefix "oy" "Yasnippet")
(spacemacs/set-leader-keys "oyi" 'yas-insert-snippet)
(spacemacs/set-leader-keys "oyn" 'yas-new-snippet)
(spacemacs/set-leader-keys "oyt" 'yas-expand-from-trigger-key)
|
5.2 Add support for editorconfig
EditorConfig helps developers define and maintain consistent coding
styles between different editors and IDEs. The EditorConfig project
consists of a file format for defining coding styles and a collection
of text editor plugins that enable editors to read the file format and
adhere to defined styles. EditorConfig files are easily readable and
they work nicely with version control systems.
1
2
3
4
5
|
(use-package editorconfig
:ensure t
:init
(add-hook 'prog-mode-hook (editorconfig-mode 1))
(add-hook 'text-mode-hook (editorconfig-mode 1)))
|
5.3 Ess and R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
;; (defun add-ess-smart-S-assign ()
;; (interactive)
;; (insert " <- "))
;; (global-set-key (kbd "C-;") 'add-ess-smart-S-assign)
(add-hook 'R-mode-hook (lambda () (setq truncate-lines nil)))
(add-hook 'R-mode-hook 'smartparens-mode)
(add-hook 'R-mode-hook 'flycheck-mode)
(add-hook 'R-mode-hook 'flyspell-mode)
(add-hook 'inferior-ess-mode-hook 'company-mode)
(add-hook 'inferior-ess-mode-hook 'smartparens-mode)
(add-hook 'inferior-ess-mode-hook 'flycheck-mode)
(add-hook 'inferior-ess-mode-hook 'flyspell-mode)
|
5.4 Python
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
|
(add-hook 'python-mode-hook (lambda () (setq truncate-lines nil)))
(setq python-fill-column 80)
(add-hook 'inferior-python-mode-hook 'flycheck-mode)
(add-hook 'inferior-python-mode-hook 'flyspell-mode)
(add-hook 'python-mode-hook 'highlight-indentation-mode)
(add-hook 'python-mode-hook 'highlight-indentation-current-column-mode)
;; use poetry
(use-package poetry
:ensure t)
(use-package lsp-ui
:requires lsp-mode flycheck
:config
(setq lsp-ui-doc-enable t
lsp-ui-doc-use-childframe t
lsp-ui-sideline-enable t
lsp-ui-flycheck-enable t
lsp-ui-flycheck-list-position 'right
lsp-ui-flycheck-live-reporting t
lsp-ui-doc-include-signature t
lsp-ui-peek-enable t
lsp-ui-peek-list-width 60
lsp-ui-peek-peek-height 25
)
(add-hook 'lsp-mode-hook 'lsp-ui-mode))
|
5.5 C-C++
1
2
|
(setq lsp-enable-file-watchers t)
(setq lsp-file-watch-threshold 300000)
|
5.6 JS-2 mode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
(use-package nodejs-repl
:init
:defer t)
(use-package nodejs-repl-eval
:load-path "~/.spacemacs.d/package/nodejs-repl-eval"
:commands (nodejs-repl-eval-buffer nodejs-repl-eval-dwim nodejs-repl-eval-function)
:init
(progn
(spacemacs/declare-prefix-for-mode 'js2-mode
"mo" "Nodejs-repl")
(spacemacs/set-leader-keys-for-major-mode 'js2-mode
"oo" 'nodejs-repl
"ob" 'nodejs-repl-eval-buffer
"of" 'nodejs-repl-eval-function
"od" 'nodejs-repl-eval-dwim))
:defer t
)
|
5.7 Elisp enhanced
5.7.1 Emacs Lisp 自动配对问题
1
|
(sp-local-pair '(emacs-lisp-mode lisp-interaction-mode) "'" nil :actions nil)
|
6 External package besides spacemacs
6.1 F3 to open stardict
1
2
3
4
5
6
7
8
|
(use-package chinese-yasdcv
:init
(spacemacs/declare-prefix "od" "dict")
(spacemacs/set-leader-keys "ody" 'yasdcv-translate-at-point)
(spacemacs/set-leader-keys "ods" 'youdao-dictionary-search-from-input)
(spacemacs/set-leader-keys "odi" 'youdao-dictionary-search-at-point+)
)
|
6.2 Use emmet-mode to add Zen Coding support
emmet-mode is a fork of zencoding-mode which add minor mode providing support
for Zen Coding by producing HTML from CSS-like selectors.
GitHub: https://github.com/smihica/emmet-mode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
(req-package emmet-mode
:config
(progn
;; Following mode support emmet-mode
(add-hook 'html-mode-hook 'emmet-mode)
(add-hook 'sgml-mode-hook 'emmet-mode)
(add-hook 'nxml-mode-hook 'emmet-mode)
(add-hook 'css-mode-hook 'emmet-mode)
;; Move cursor between quotes after expand
(add-hook 'emmt-mode-hook
'(lambda()
(setq emmet-move-cursor-between-quotes t)))
;; Make tab can also expand emmt instead of use yasnippet directly
(define-key emmt-mode-keymap (kbd "TAB") 'emmt-expand-yas)
(define-key emmt-mode-keymap (kbd "<tab>") 'emmt-expand-yas)))
|
6.3 Hungry-delete
https://github.com/kaushalmodi/.emacs.d/blob/master/setup-files/setup-hungry-delete.el
hungry-delete borrows hungry deletion from cc-mode
, which will causes deletion
to delete all whitespace in the direction you are deleting.
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
|
(use-package hungry-delete
:config
(progn
(setq hungry-delete-chars-to-skip " \t\r\f\v")
;; Mon Nov 21 08:45:42 EST 2016 - kmodi
;; Override the default definitions of `hungry-delete-skip-ws-forward' and
;; `hungry-delete-skip-ws-backward'; do not delete back-slashes at EOL.
(defun hungry-delete-skip-ws-forward ()
"Skip over any whitespace following point.
This function skips over horizontal and vertical whitespace."
(skip-chars-forward hungry-delete-chars-to-skip)
(while (get-text-property (point) 'read-only)
(backward-char)))
(defun hungry-delete-skip-ws-backward ()
"Skip over any whitespace preceding point.
This function skips over horizontal and vertical whitespace."
(skip-chars-backward hungry-delete-chars-to-skip)
(while (get-text-property (point) 'read-only)
(forward-char)))
(defun modi/turn-off-hungry-delete-mode ()
"Turn off hungry delete mode."
(hungry-delete-mode -1))
;; Enable `hungry-delete-mode' everywhere ..
(global-hungry-delete-mode)
;; Except ..
;; `hungry-delete-mode'-loaded backspace does not work in `wdired-mode',
;; i.e. when editing file names in the *Dired* buffer.
(add-hook 'wdired-mode-hook #'modi/turn-off-hungry-delete-mode)
;; and in python-mode-hook
(add-hook 'python-mode-hook #'modi/turn-off-hungry-delete-mode)
;; and in minibuffer
(add-hook 'minibuffer-setup-hook #'modi/turn-off-hungry-delete-mode)))
|
6.4 Pangu-spacing
pangu-spcing
is an minor-mode to auto add space between Chinese and English characters. Note that these white-space characters are not really added to the contents, it just like to do so.
1
2
3
4
5
6
7
8
9
|
(req-package pangu-spacing
:init
(progn
;; start pangu-spacing globally
(global-pangu-spacing-mode -1)
;; Always insert `real' space in org-mode.
(add-hook 'org-mode-hook
'(lambda ()
(set (make-local-variable 'pangu-spacing-real-insert-separtor) t)))))
|
6.5 Blog setting
6.5.1 Hugo
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
|
(defun lengyueyang/easy-hugo ()
(interactive)
(evil-define-key
(list 'normal 'insert 'visual 'motion)
easy-hugo-mode-map
"n" 'easy-hugo-newpost
"D" 'easy-hugo-article
"p" 'easy-hugo-preview
"P" 'easy-hugo-publish
"o" 'easy-hugo-open
"d" 'easy-hugo-delete
"e" 'easy-hugo-open
"c" 'easy-hugo-open-config
"f" 'easy-hugo-open
"N" 'easy-hugo-no-help
"v" 'easy-hugo-view
"r" 'easy-hugo-refresh
"g" 'easy-hugo-refresh
"s" 'easy-hugo-sort-time
"S" 'easy-hugo-sort-char
"G" 'easy-hugo-github-deploy
"A" 'easy-hugo-amazon-s3-deploy
"C" 'easy-hugo-google-cloud-storage-deploy
"q" 'evil-delete-buffer
(kbd "TAB") 'easy-hugo-open
(kbd "RET") 'easy-hugo-preview)
(define-key global-map (kbd "C-c C-e") 'easy/hugo))
;; (add-hook 'org-mode-hook 'org-hugo-auto-export-mode)
(use-package easy-hugo
;; :after (helm-ag)
:ensure t
:config
(setq easy-hugo-basedir "~/MEGA/Lengyue_data/Blog/"
easy-hugo-postdir "content/zh-cn"
easy-hugo-url "http://127.0.0.1:1313"
easy-hugo-preview-url "http://127.0.0.1:1313"
easy-hugo-sshdomain "me"
easy-hugo-root "~/MEGA/Lengyue_data/Blog/"
easy-hugo-default-text ".md"
easy-hugo-previewtime "20")
(add-hook 'easy-hugo-mode-hook 'lengyueyang/easy-hugo)
(spacemacs/set-leader-keys "ob" 'easy-hugo))
(setq hugo-dir "~/MEGA/Lengyue_data/Blog/")
(defun lengyueyang/hugo-publish (commit-msg)
"git add . & git commit & git push"
(interactive "sInput commit message:")
(async-shell-command (format "cd %s ; hugo ; cd public ; git add . ; git commit -m \"update\" ; git push"
hugo-dir
commit-msg)))
|
6.5.2 Bolg-admin
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
|
;; (add-to-load-path "~/.spacemacs.d/package/blog-admin")
(require 'blog-admin)
(spacemacs/set-leader-keys "ob" 'blog-admin-start)
;; (setq blog-admin-backend-type 'org-page)
;; (setq blog-admin-backend-path "~/MEGA/Emacs-lengyue/Blog-lengyue/source")
;; (setq blog-admin-backend-new-post-in-drafts t)
;; (setq blog-admin-backend-new-post-with-same-name-dir t)
;; (setq blog-admin-backend-org-page-drafts "_drafts")
;; (setq op/repository-directory "~/MEGA/Emacs-lengyue/Blog-lengyue/source")
;; (setq op/site-domain "http://lengyueyang.github.io")
;; (setq op/personal-disqus-shortname "lengyueyang")
;; (setq blog-admin-backend-type 'hexo)
;; (setq blog-admin-backend-path "~/MEGA/Emacs-lengyue/Blog-lengyue/")
;; (setq blog-admin-backend-new-post-in-drafts t)
;; (setq blog-admin-backend-new-post-with-same-name-dir t)
(setq blog-admin-backend-type 'nikola)
(setq blog-admin-backend-path "~/MEGA/Emacs-lengyue/Blog-lengyue")
(setq blog-admin-backend-new-post-in-drafts t)
(setq blog-admin-backend-nikola-executable "/usr/bin/nikola") ;; path to nikola executable
(setq blog-admin-backend-nikola-config-file "conf.py") ;; conf.py is default
|
6.6 Use emms to play music
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
|
;; https://github.com/tumashu/emacs-helper/blob/master/eh-emms.el
(use-package emms
:config
(use-package emms-setup
:ensure nil)
(use-package emms-info-libtag
:ensure nil)
(use-package dired
:ensure nil)
;; (use-package chinese-pyim)
(emms-devel)
(emms-default-players)
(when (fboundp 'emms-cache) (emms-cache 1))
(emms-history-load)
;; EMMS 目录
(setq emms-source-file-default-directory "~/Music/Lengyueyang-music")
(unless (file-directory-p emms-source-file-default-directory)
(make-directory (file-name-as-directory emms-source-file-default-directory)))
(setq emms-directory "~/Music/.emms/")
(setq emms-history-file "~/Music/.emms/history")
(setq emms-cache-file "~/Music/.emms/cache")
(setq emms-stream-bookmarks-file "~/Music/.emms/streams")
(setq emms-score-file "~/Music/.emms/scores")
;; 设定 EMMS 主模式为 Playlist 模式
(setq emms-playlist-default-major-mode 'emms-playlist-mode)
;; 修复播放完后的 BUG
(setq emms-player-next-function 'emms-next)
;; 设定音轨初始化信息
(add-to-list 'emms-track-initialize-functions 'emms-info-initialize-track)
;; 关闭 EMMS 信息异步模式
(setq emms-info-asynchronously nil)
;; 设定 EMMS 启动列表循环播放
(setq emms-repeat-playlist t)
;; 排序方法: 艺术家 -> 专辑 -> 序号
(setq emms-playlist-sort-function
'emms-playlist-sort-by-natural-order)
;; 使用 Gnu find 查找文件
(setq emms-source-file-directory-tree-function
'emms-source-file-directory-tree-find)
;; 在 minibuffer 中显示播放信息(emms-show)
(add-hook 'emms-player-started-hook 'emms-show)
(setq emms-show-format "正在播放: [%s]")
;;设置 Mode-line 的显示方式
(setq emms-mode-line-format "%s")
(setq emms-playing-time-display-format "%s ]")
(setq global-mode-string
'(" " emms-mode-line-string " " emms-playing-time-string " "))
(setq emms-mode-line-mode-line-function
'eh-emms-mode-line-playlist-current)
(defun eh-emms-mode-line-playlist-current ()
"Format the currently playing."
(let ((track (emms-playlist-current-selected-track)))
(if (eq 'file (emms-track-type track))
(if (and (emms-track-get track 'info-artist)
(emms-track-get track 'info-title))
(let ((art (emms-track-get track 'info-artist))
(tit (emms-track-get track 'info-title)))
(format "[ %s -- %s" art tit))
(format "[ %s"
(file-relative-name (emms-track-name track)
emms-source-file-default-directory))))))
;; 显示歌词
(emms-lyrics 1)
(setq emms-lyrics-display-on-modeline t)
;; Function used to format track
(setq emms-track-description-function
#'(lambda (track)
(concat " " (eh-emms-make-track-description track))))
;; 设置 Playlist 的显示方式
(setq emms-last-played-format-alist
'(((emms-last-played-seconds-today) . "%H:%M")
(604800 . "%H:%M")
((emms-last-played-seconds-month) . "%d")
((emms-last-played-seconds-year) . "%m-%d")
(t . "%Y")))
(defun eh-emms-make-track-description (track)
"Return a description of the current track."
(let ((track-type (emms-track-type track))
(play-count (or (emms-track-get track 'play-count) 0))
(last-played (or (emms-track-get track 'last-played) '(0 0 0)))
(name (emms-track-name track))
(pmin (emms-track-get track 'info-playing-time-min))
(psec (emms-track-get track 'info-playing-time-sec))
(ptot (emms-track-get track 'info-playing-time))
(title (emms-track-get track 'info-title))
(artist (emms-track-get track 'info-artist))
(album (emms-track-get track 'info-album)))
(if (eq 'file track-type)
(format "%5s %3s |-> %-s"
(emms-last-played-format-date last-played)
play-count
(cond ((and pmin psec) (format "%s %s -- %s [%02d:%02d]" artist album title pmin psec))
(ptot (format "%s %s -- %s [%02d:%02d]" artist album title (/ ptot 60) (% ptot 60)))
(t (format "%s %s -- %s" artist album title)))))))
;; Function used to get music tags, for example IDv2.3!
(setq emms-info-functions '(eh-emms-info-libtag eh-emms-info-add-pinyin-alias))
(defun eh-emms-info-libtag (track)
(when (and (eq 'file (emms-track-type track))
(string-match
"\\.\\([Mm][Pp]3\\|[oO][gG][gG]\\|[fF][lL][aA][cC]\\|[sS][pP][xX]\\)\\'"
(emms-track-name track)))
(let ((info-list
(split-string (file-relative-name
(emms-track-name track)
emms-source-file-default-directory) "/" t)))
(emms-track-set track 'info-artist (if (> (length info-list) 1) (nth 0 info-list) "未知艺术家"))
(emms-track-set track 'info-album (if (> (length info-list) 2) (nth 1 info-list) "杂项"))
(emms-track-set track 'info-title (car (reverse info-list))))
(with-temp-buffer
(when (string= "0"
(format "%s" (let ((coding-system-for-read 'utf-8))
(call-process emms-info-libtag-program-name
nil '(t nil) nil
(emms-track-name track)))))
(goto-char (point-min))
;; Crush the trailing whitespace
(while (re-search-forward "[[:space:]]+$" nil t)
(replace-match "" nil nil))
(goto-char (point-min))
(while (looking-at "^\\([^=\n]+\\)=\\(.*\\)$")
(let ((name (intern-soft (match-string 1)))
(value (match-string 2)))
(when (> (length value)
0)
(emms-track-set track
name
(if (eq name 'info-playing-time)
(string-to-number value)
value))))
(forward-line 1))))))
(defun eh-emms-info-add-pinyin-alias (track)
"Add pinyin alias to the track"
(when (and (featurep 'chinese-pyim)
(eq 'file (emms-track-type track)))
(emms-track-set track 'info-artist-alias (pyim-hanzi2pinyin (emms-track-get track 'info-artist) t))
(emms-track-set track 'info-album-alias (pyim-hanzi2pinyin (emms-track-get track 'info-album) t))
(emms-track-set track 'info-title-alias (pyim-hanzi2pinyin (emms-track-get track 'info-title) t))))
;; 设置 EMMS 浏览器, 默认显示方式为: 显示所有
(emms-browser-set-filter (assoc "EVERYTHING" emms-browser-filters))
;; filter: 显示所有
(emms-browser-make-filter "EVERYTHING" 'ignore)
;; filter: 只显示文件
(emms-browser-make-filter "ALL-FILES" (emms-browser-filter-only-type 'file))
;; filter: 最近一个星期播放的
(emms-browser-make-filter "LAST-WEEK" (emms-browser-filter-only-recent 7))
;; filter: 最近一个月都没有播放的
(emms-browser-make-filter "LAST-MONTH-NOT-PLAYED" (lambda (track) (not (funcall (emms-browser-filter-only-recent 30) track))))
;; EMMS 浏览器, 删除文件不提醒
(put 'emms-browser-delete-files 'disabled nil)
;; 设置 emms buffer 显示格式
(setq emms-browser-info-artist-format "* %n")
(setq emms-browser-info-album-format " - %n")
(setq emms-browser-info-title-format " ♪. %n")
(setq emms-browser-playlist-info-title-format "%n")
;; 自定义 emms-browser-add-tracks, 禁止在 playlist 文件中添加
;; artist 行 和 album 行,同时使 emacs-browser-playlist-*-*-format
;; 中 "%i"位置符失效
;;
;; 注: emms-browser-playlist-info-artist-format
;; emms-browser-playlist-info-album-format
;; 两个变量设置在这里不起作用
(defun eh-emms-browser-add-tracks ()
"Add all tracks at point.
Return the previous point-max before adding."
(interactive)
(let ((first-new-track (with-current-emms-playlist (point-max)))
(bdata (emms-browser-bdata-at-point)))
(eh-emms-browser-playlist-insert-bdata bdata)
(run-hook-with-args 'emms-browser-tracks-added-hook
first-new-track)
first-new-track))
(defun eh-emms-browser-playlist-insert-bdata (bdata)
"Add all tracks in BDATA to the playlist."
(let ((type (emms-browser-bdata-type bdata)))
;; recurse or add tracks
(dolist (item (emms-browser-bdata-data bdata))
(if (not (eq type 'info-title))
(eh-emms-browser-playlist-insert-bdata item)
(emms-browser-playlist-insert-track bdata)))))
(defun eh-emms-browser-make-name (entry type)
"Override `emms-browser-make-name'. Return a name for ENTRY, used for making a bdata object."
(let ((key (car entry))
(track (cadr entry))
artist title) ;; only the first track
(cond
((eq type 'info-title)
(eh-emms-make-track-description track))
(t key))))
(advice-add 'emms-browser-make-name :override #'eh-emms-browser-make-name)
;; 快捷函数
(defun eh-emms-toggle-playing ()
(interactive)
(if emms-player-playing-p
(emms-pause)
(emms-start)))
(defun eh-emms-search ()
(interactive)
(goto-char (point-min))
(call-interactively 'isearch-forward))
(defun eh-emms ()
(interactive)
(if (or (null emms-playlist-buffer)
(not (buffer-live-p emms-playlist-buffer)))
(let ((playlist (concat
(file-name-as-directory emms-source-file-default-directory)
"default.playlist")))
(if (not (file-readable-p playlist))
(eh-emms-add-directory-tree)
(emms-add-playlist playlist))))
(emms-playlist-mode-go))
(defun eh-emms-add-directory-tree ()
(interactive)
(emms-add-directory-tree
(ido-read-directory-name
"Add directory tree:"
emms-source-file-default-directory)))
(defun eh-emms-add-file ()
(interactive)
(let ((file (ido-read-file-name
"Add directory tree:"
emms-source-file-default-directory)))
(cond
((string-match "\\.\\(m3u\\|pls\\)\\'" file)
(emms-add-playlist file))
(t (emms-add-file file)))))
(defun eh-emms-browser-search-by-names ()
(interactive)
(emms-browser-search '(info-artist info-artist-alias info-title info-title-alias info-album info-album-alias)))
(defun eh-emms-browser-search-by-artist ()
(interactive)
(emms-browser-search '(info-artist info-artist-alias)))
(defun eh-emms-browser-search-by-title ()
(interactive)
(emms-browser-search '(info-title info-title-alias)))
(add-to-list 'emms-info-functions 'emms-info-cueinfo)
(evil-add-hjkl-bindings emms-playlist-mode-map 'emacs)
;; Global keybinding for emms
(global-unset-key (kbd "C-c e"))
(global-set-key (kbd "C-c e e") 'eh-emms)
(global-set-key (kbd "C-c e d") 'eh-emms-add-directory-tree)
(global-set-key (kbd "C-c e f") 'eh-emms-add-file)
(global-set-key (kbd "C-c e SPC") 'eh-emms-toggle-playing)
(global-set-key (kbd "C-c e q") 'emms-stop)
(global-set-key (kbd "C-c e n") 'emms-next)
(global-set-key (kbd "C-c e p") 'emms-previous)
(global-set-key (kbd "C-c e o") 'emms-show)
(global-set-key (kbd "C-c e h") 'emms-shuffle)
(global-set-key (kbd "C-c e H") 'emms-sort)
(global-set-key (kbd "C-c e r") 'emms-toggle-repeat-track)
(global-set-key (kbd "C-c e R") 'emms-toggle-repeat-playlist)
(global-set-key (kbd "C-c e s u") 'emms-score-up-playing)
(global-set-key (kbd "C-c e s d") 'emms-score-down-playing)
(global-set-key (kbd "C-c e s o") 'emms-score-show-playing)
;; browser mode map
(define-key emms-browser-mode-map (kbd "SPC") 'emms-browser-next-non-track)
(define-key emms-browser-mode-map (kbd "<return>") (lambda ()
(interactive)
(eh-emms-browser-add-tracks)
(message "Add current track to playlist")))
(define-key emms-browser-mode-map (kbd "C-SPC") 'emms-browser-next-non-track)
(define-key emms-browser-mode-map (kbd "<tab>") 'emms-browser-toggle-subitems)
(define-key emms-browser-mode-map (kbd "o") 'emms-playlist-mode-go)
(define-key emms-browser-mode-map (kbd "w") 'emms-browser-show-LAST-WEEK)
(define-key emms-browser-mode-map (kbd "a") 'emms-browser-show-EVERYTHING)
(define-key emms-browser-mode-map (kbd "m") 'emms-browser-show-LAST-MONTH-NOT-PLAYED)
(define-key emms-browser-mode-map (kbd "s s") 'eh-emms-browser-search-by-names)
(define-key emms-browser-mode-map (kbd "s a") 'eh-emms-browser-search-by-artist)
(define-key emms-browser-mode-map (kbd "s t") 'eh-emms-browser-search-by-title)
;; playlist-mode-map
(define-key emms-playlist-mode-map (kbd "o") 'emms-browser-show-LAST-WEEK)
(define-key emms-playlist-mode-map (kbd "SPC") 'emms-pause)
(define-key emms-playlist-mode-map (kbd "/") 'eh-emms-search)
(define-key emms-playlist-mode-map (kbd "+") 'emms-volume-raise)
(define-key emms-playlist-mode-map (kbd "-") 'emms-volume-lower)
(define-key emms-playlist-mode-map (kbd "C-<right>") (lambda () (interactive) (emms-seek +10)))
(define-key emms-playlist-mode-map (kbd "C-<left>") (lambda () (interactive) (emms-seek -10)))
(define-key emms-playlist-mode-map (kbd "C-<right>") (lambda () (interactive) (emms-seek +60)))
(define-key emms-playlist-mode-map (kbd "C-<left>") (lambda () (interactive) (emms-seek -60)))
(define-key emms-playlist-mode-map (kbd "S u") 'emms-score-up-file-on-line)
(define-key emms-playlist-mode-map (kbd "S d") 'emms-score-down-file-on-line)
(define-key emms-playlist-mode-map (kbd "S o") 'emms-score-show-file-on-line)
(define-key emms-playlist-mode-map (kbd "S l") 'emms-score-less-tolerant)
(define-key emms-playlist-mode-map (kbd "S m") 'emms-score-more-tolerant)
(define-key emms-playlist-mode-map (kbd "S t") 'emms-score-set-tolerance)
(define-key emms-playlist-mode-map (kbd "S s") 'emms-score-show-playing))
;; https://www.gnu.org/software/emms/manual/#Introduction
;; (require 'emms-setup)
;; (emms-all)
;; (emms-default-players)
;; (setq emms-directory "~/Music/.emms")
;; (setq emms-cache-file "~/Music/.emms/cache")
;; (setq emms-score-file "~/Music/.emms/scores")
;; (setq emms-history-file "~/Music/.emms/history")
;; (setq emms-source-file-default-directory "~/Music/")
;; (emms-history-load)
(spacemacs/declare-prefix "oe" "Emms-Music")
(spacemacs/set-leader-keys "oee" 'emms)
(spacemacs/set-leader-keys "oea" 'emms-add-directory-tree)
(spacemacs/set-leader-keys "oef" 'emms-play-file)
(spacemacs/set-leader-keys "oes" 'emms-stop)
(spacemacs/set-leader-keys "oen" 'emms-next)
(spacemacs/set-leader-keys "oep" 'emms-previous)
|
6.7 Use fuo to play web music
1
2
|
(use-package fuo
:load-path "~/.spacemacs.d/package/fuo")
|
6.8 Embrace/evil-embrace
https://github.com/cute-jumper/embrace.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
(global-set-key (kbd "C-,") #'embrace-commander)
(spacemacs/set-leader-keys "or" 'embrace-commander)
(add-hook 'org-mode-hook 'embrace-org-mode-hook)
(evil-embrace-enable-evil-surround-integration)
;; (add-hook 'org-mode-hook
;; (lambda ()
;; (add-to-list 'embrace-semantic-units-alist '(?e . er/mark-email))))
(defun embrace-org-mode-hook ()
(dolist (lst '((?b "{{{color(blue," . ")}}}")
(?r "{{{color(red," . ")}}}")
(?g "{{{color(green," . ")}}}")
(?/ "/" . "/")))
(embrace-add-pair (car lst) (cadr lst) (cddr lst))))
(add-hook 'org-mode-hook 'embrace-org-mode-hook)
;; (embrace-add-pair key left right)
;; (add-hook 'org-mode-hook
;; (lambda ()
;; (embrace-add-pair ?b "{{{color(blue," . ")}}}")
;; (embrace-add-pair ?r "{{{color(red," . ")}}}")
;; (embrace-add-pair ?g "{{{color(greem," . ")}}}")
;; ))
|
7 Other customization
This part is some customization not belong to the anterior part.
7.1 Column indicator
1
2
3
4
5
|
(require 'fill-column-indicator)
(setq fci-rule-column 80)
(add-hook 'prog-mode-hook 'fci-mode)
(add-hook 'git-commit-mode-hook 'fci-mode)
|
7.2 Disable auto paste from clipboard
1
2
|
(add-hook 'spacemacs-buffer-mode-hook (lambda ()
(set (make-local-variable 'mouse-1-click-follows-link) nil)))
|
7.3 Truncate lines automatically
1
2
3
4
5
|
(add-hook 'magit-mode-hook (lambda () (setq truncate-lines nil)))
(add-hook 'org-mode-hook (lambda () (setq truncate-lines nil)))
(add-hook 'text-mode-hook (lambda () (setq truncate-lines nil)))
(add-hook 'R-mode-hook (lambda () (setq truncate-lines nil)))
(add-hook 'python-mode-hook (lambda () (setq truncate-lines nil)))
|
7.4 Hotspots
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
(defun lengyueyang/hotspots ()
"helm interface to my hotspots, which includes my locations,
org-files and bookmarks"
(interactive)
(helm :buffer "*helm: utities*"
:sources `(,(lengyueyang//hotspots-sources))))
(defun lengyueyang//hotspots-sources ()
"Construct the helm sources for my hotspots"
`((name . "lengyueyang's center")
(candidates . (
("Agenda List" . (lambda () (org-agenda "" "a")))
("Agenda Menu" . (lambda () (org-agenda)))
("Blog" . (lambda() (easy-hugo)))
("Elfeed" . (lambda () (elfeed)))
;; ("Agenda Next TODO" . (lambda () (org-agenda "" "t")))
("Open Github" . (lambda() (browse-url "https://github.com/lengyueyang")))
("Open Blog" . (lambda() (browse-url "http://lengyueyang.github.io")))))
(candidate-number-limit)
(action . (("Open" . (lambda (x) (funcall x)))))))
(define-key global-map (kbd "<f1>") 'lengyueyang/hotspots)
(spacemacs/set-leader-keys "oh" 'lengyueyang/hotspots)
|
7.5 Count chinese word
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
|
(defvar wc-regexp-chinese-char-and-punc
(rx (category chinese)))
(defvar wc-regexp-chinese-punc
"[。,!?;:「」『』()、【】《》〈〉※—]")
(defvar wc-regexp-english-word
"[a-zA-Z0-9-]+")
(defun lengyueyang/word-count-for-chinese ()
"「較精確地」統計中 / 日 / 英文字數。
- 文章中的註解不算在字數內。
- 平假名與片假名亦包含在「中日文字數」內,每個平 / 片假名都算單獨一個字(但片假
名不含連音「ー」)。
- 英文只計算「單字數」,不含標點。
- 韓文不包含在內。
※計算標準太多種了,例如英文標點是否算入、以及可能有不太常用的標點符號沒算入等
。且中日文標點的計算標準要看 Emacs 如何定義特殊標點符號如ヴァランタン・アルカン
中間的點也被 Emacs 算為一個字而不是標點符號。"
(interactive)
(let* ((v-buffer-string
(progn
(if (eq major-mode 'org-mode) ; 去掉 org 文件的 OPTIONS(以 #+ 開頭)
(setq v-buffer-string (replace-regexp-in-string "^#\\+.+" ""
(buffer-substring-no-properties (point-min) (point-max))))
(setq v-buffer-string (buffer-substring-no-properties (point-min) (point-max))))
(replace-regexp-in-string (format "^ *%s *.+" comment-start) "" v-buffer-string)))
; 把註解行刪掉(不把註解算進字數)。
(chinese-char-and-punc 0)
(chinese-punc 0)
(english-word 0)
(chinese-char 0))
(with-temp-buffer
(insert v-buffer-string)
(goto-char (point-min))
;; 中文(含標點、片假名)
(while (re-search-forward wc-regexp-chinese-char-and-punc nil :no-error)
(setq chinese-char-and-punc (1+ chinese-char-and-punc)))
;; 中文標點符號
(goto-char (point-min))
(while (re-search-forward wc-regexp-chinese-punc nil :no-error)
(setq chinese-punc (1+ chinese-punc)))
;; 英文字數(不含標點)
(goto-char (point-min))
(while (re-search-forward wc-regexp-english-word nil :no-error)
(setq english-word (1+ english-word))))
(setq chinese-char (- chinese-char-and-punc chinese-punc))
(message
(format " 中日文字數(不含標點):%s
中日文字數(包含標點):%s
英文字數(不含標點):%s
=======================
中英文合計(不含標點):%s"
chinese-char chinese-char-and-punc english-word
(+ chinese-char english-word)))))
|
7.6 Display Calendar numbers in calendar-mode
Define a function to display week numbers in calender-mode
. The snippet
is from EmacsWiki.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
(defun calendar-show-week (arg)
"Displaying week number in calendar-mode."
(interactive "P")
(copy-face font-lock-constant-face 'calendar-iso-week-face)
(set-face-attribute
'calendar-iso-week-face nil :height 0.7)
(setq calendar-intermonth-text
(and arg
'(propertize
(format
"%2d"
(car (calendar-iso-from-absolute
(calendar-absolute-from-gregorian
(list month day year)))))
'font-lock-face 'calendar-iso-week-face))))
|
Evaluate the calendar-show-week
function.
Set Monday as the first day of the week, and set my location.
1
2
3
4
|
(setq calendar-week-start-day 1
calendar-latitude 39.92
calendar-longitude 116.46
calendar-location-name "Beijing, China")
|
8 Reference
Following link is refrence for my emac config.
[1]
https://github.com/r0man/.emacs.d/blob/master/init.el.org
[2]
https://github.com/bodil/emacs.d
[3]
https://github.com/mgalgs/.emacs.d
[4]
https://raw.githubusercontent.com/sbisaacson/literate-emacs/master/README.org
[5]
https://github.com/jhenahan/emacs.d/blob/master/emacs-init.org
[6]
https://ryuslash.org/dotfiles/emacs/init.html
[7]
http://www.wisdomandwonder.com/wordpress/wp-content/uploads/2014/03/C3F.org%5F.txt
[8]
https://github.com/howardabrams/dot-files
[9]
https://github.com/coldnew/coldnew-spacemacs