Skip to content

Commit 1c93e7d

Browse files
author
梁俊杰
committed
add
1 parent 56b5771 commit 1c93e7d

10 files changed

+7399
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## autogenerated files
22
.starter-kit-*.part.*.org
3+
bookmarks
4+
recentf
5+
smex-items
36

47
## misc
58
loaddefs.el*
@@ -25,7 +28,6 @@ url/*
2528

2629
## exported and encrypted files
2730
*gpg
28-
*el
2931
*elc
3032
*html
3133
*tex

starter-kit-bindings.el

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
(global-set-key (kbd "C-M-h") 'backward-kill-word)
3+
4+
(global-set-key (kbd "C-x \\") 'align-regexp)
5+
6+
(global-set-key (kbd "M-/") 'hippie-expand)
7+
8+
(global-set-key [f1] 'menu-bar-mode)
9+
10+
(define-key global-map (kbd "C-+") 'text-scale-increase)
11+
(define-key global-map (kbd "C--") 'text-scale-decrease)
12+
13+
(global-set-key (kbd "C-s") 'isearch-forward-regexp)
14+
(global-set-key (kbd "\C-r") 'isearch-backward-regexp)
15+
(global-set-key (kbd "C-M-s") 'isearch-forward)
16+
(global-set-key (kbd "C-M-r") 'isearch-backward)
17+
18+
(global-set-key (kbd "C-x M-f") 'ido-find-file-other-window)
19+
(global-set-key (kbd "C-x C-p") 'find-file-at-point)
20+
(global-set-key (kbd "C-c y") 'bury-buffer)
21+
(global-set-key (kbd "C-c r") 'revert-buffer)
22+
(global-set-key (kbd "M-`") 'file-cache-minibuffer-complete)
23+
(global-set-key (kbd "C-x C-b") 'ibuffer)
24+
(global-set-key (kbd "C-x f") 'recentf-ido-find-file)
25+
26+
(windmove-default-keybindings) ;; Shift+direction
27+
(global-set-key (kbd "C-x O") (lambda () (interactive) (other-window -1))) ;; back one
28+
(global-set-key (kbd "C-x C-o") (lambda () (interactive) (other-window 2))) ;; forward two
29+
30+
(global-set-key (kbd "C-x ^") 'join-line)
31+
32+
(global-set-key (kbd "C-x C-m") 'execute-extended-command)
33+
34+
(global-set-key (kbd "C-h a") 'apropos)
35+
36+
(define-key isearch-mode-map (kbd "C-o")
37+
(lambda () (interactive)
38+
(let ((case-fold-search isearch-case-fold-search))
39+
(occur (if isearch-regexp
40+
isearch-string
41+
(regexp-quote isearch-string))))))
42+
43+
(define-key global-map "\C-ca" 'org-agenda)
44+
45+
(define-key global-map "\C-cl" 'org-store-link)
46+
47+
(define-key global-map "\C-x\C-r" 'rgrep)

starter-kit-defuns.el

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
(defun starter-kit-local-column-number-mode ()
3+
(make-local-variable 'column-number-mode)
4+
(column-number-mode t))
5+
6+
(defun starter-kit-local-comment-auto-fill ()
7+
(set (make-local-variable 'comment-auto-fill-only-comments) t)
8+
(auto-fill-mode t))
9+
10+
(defun starter-kit-turn-on-save-place-mode ()
11+
(setq save-place t))
12+
13+
(defun starter-kit-turn-on-whitespace ()
14+
(whitespace-mode t))
15+
16+
(add-hook 'starter-kit-coding-hook 'starter-kit-local-column-number-mode)
17+
18+
(add-hook 'starter-kit-coding-hook 'starter-kit-local-comment-auto-fill)
19+
20+
(when (window-system)
21+
(add-hook 'starter-kit-coding-hook 'starter-kit-pretty-lambdas))
22+
23+
(defun run-starter-kit-coding-hook ()
24+
"Enable things that are convenient across all coding buffers."
25+
(run-hooks 'starter-kit-coding-hook))
26+
27+
(defun recentf-ido-find-file ()
28+
"Find a recent file using Ido."
29+
(interactive)
30+
(let* ((file-assoc-list
31+
(mapcar (lambda (x)
32+
(cons (file-name-nondirectory x)
33+
x))
34+
recentf-list))
35+
(filename-list
36+
(remove-duplicates (mapcar #'car file-assoc-list)
37+
:test #'string=))
38+
(filename (ido-completing-read "Choose recent file: "
39+
filename-list
40+
nil
41+
t)))
42+
(when filename
43+
(find-file (cdr (assoc filename
44+
file-assoc-list))))))

starter-kit-misc.el

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
(starter-kit-install-if-needed 'magit)
3+
4+
(when window-system
5+
(setq frame-title-format '(buffer-file-name "%f" ("%b")))
6+
(blink-cursor-mode -1)
7+
(when (require 'mwheel nil 'no-error) (mouse-wheel-mode t)))
8+
9+
(set-terminal-coding-system 'utf-8)
10+
(set-keyboard-coding-system 'utf-8)
11+
(prefer-coding-system 'utf-8)
12+
13+
(setq visible-bell t
14+
echo-keystrokes 0.1
15+
font-lock-maximum-decoration t
16+
inhibit-startup-message t
17+
transient-mark-mode t
18+
color-theme-is-global t
19+
delete-by-moving-to-trash t
20+
shift-select-mode nil
21+
truncate-partial-width-windows nil
22+
uniquify-buffer-name-style 'forward
23+
whitespace-style '(trailing lines space-before-tab
24+
indentation space-after-tab)
25+
whitespace-line-column 100
26+
ediff-window-setup-function 'ediff-setup-windows-plain
27+
oddmuse-directory (concat starter-kit-dir "oddmuse")
28+
xterm-mouse-mode t
29+
save-place-file (concat starter-kit-dir "places"))
30+
31+
(auto-compression-mode t)
32+
33+
(show-paren-mode 1)
34+
35+
(when (> emacs-major-version 21)
36+
(ido-mode t)
37+
(setq ido-enable-prefix nil
38+
ido-enable-flex-matching t
39+
ido-create-new-buffer 'always
40+
ido-use-filename-at-point t
41+
ido-max-prospects 10))
42+
43+
(set-default 'indent-tabs-mode nil)
44+
(set-default 'indicate-empty-lines t)
45+
(set-default 'imenu-auto-rescan t)
46+
47+
(add-hook 'text-mode-hook 'turn-on-auto-fill)
48+
(eval-after-load "ispell"
49+
'(when (executable-find ispell-program-name)
50+
(add-hook 'text-mode-hook 'turn-on-flyspell)))
51+
52+
(defvar starter-kit-coding-hook nil
53+
"Hook that gets run on activation of any programming mode.")
54+
55+
(defalias 'yes-or-no-p 'y-or-n-p)
56+
;; Seed the random-number generator
57+
(random t)
58+
59+
(defun starter-kit-pretty-lambdas ()
60+
(font-lock-add-keywords
61+
nil `(("(\\(lambda\\>\\)"
62+
(0 (progn (compose-region (match-beginning 1) (match-end 1)
63+
,(make-char 'greek-iso8859-7 107))
64+
nil))))))
65+
66+
(when (boundp 'hippie-expand-try-functions-list)
67+
(delete 'try-expand-line hippie-expand-try-functions-list)
68+
(delete 'try-expand-list hippie-expand-try-functions-list))
69+
70+
(setq backup-directory-alist `(("." . ,(expand-file-name
71+
(concat starter-kit-dir "backups")))))
72+
73+
(setq diff-switches "-u")
74+
75+
(eval-after-load 'diff-mode
76+
'(progn
77+
(set-face-foreground 'diff-added "green4")
78+
(set-face-foreground 'diff-removed "red3")))
79+
80+
(eval-after-load 'magit
81+
'(progn
82+
(set-face-foreground 'magit-diff-add "green3")
83+
(set-face-foreground 'magit-diff-del "red3")))

starter-kit-registers.el

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
(dolist
3+
(r `((?i (file . ,(concat starter-kit-dir "init.el")))
4+
(?I (file . ,(let* ((user user-login-name)
5+
(org (expand-file-name (concat user ".org") starter-kit-dir))
6+
(el (expand-file-name (concat user ".el") starter-kit-dir))
7+
(dir (expand-file-name user starter-kit-dir)))
8+
(cond
9+
((file-exists-p org) org)
10+
((file-exists-p el) el)
11+
(t dir)))))
12+
(?s (file . ,(concat starter-kit-dir "starter-kit.org")))
13+
(?r (file . ,(concat starter-kit-dir "starter-kit-registers.org")))))
14+
(set-register (car r) (cadr r)))

starter-kit.el

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
2+
(let ((elisp-dir (expand-file-name "src" starter-kit-dir)))
3+
;; add the src directory to the load path
4+
(add-to-list 'load-path elisp-dir)
5+
;; load specific files
6+
(when (file-exists-p elisp-dir)
7+
(let ((default-directory elisp-dir))
8+
(normal-top-level-add-subdirs-to-load-path))))
9+
(setq autoload-file (concat starter-kit-dir "loaddefs.el"))
10+
(setq package-user-dir (concat starter-kit-dir "elpa"))
11+
(setq custom-file (concat starter-kit-dir "custom.el"))
12+
13+
(require 'cl)
14+
(require 'cl-lib)
15+
(require 'saveplace)
16+
(require 'ffap)
17+
(require 'uniquify)
18+
(require 'ansi-color)
19+
(require 'recentf)
20+
21+
(defun starter-kit-loadable-p (package)
22+
"Check if PACKAGE is loadable from a directory in `load-path'."
23+
(let ((load-file (concat (symbol-name package) ".el")))
24+
(catch 'file-found
25+
(dolist (dir load-path)
26+
(let ((path (expand-file-name load-file dir)))
27+
(when (file-exists-p path)
28+
(throw 'file-found path)))))))
29+
30+
(setq package-archives
31+
'(("gnu" . "http://elpa.gnu.org/packages/")
32+
("org" . "http://orgmode.org/elpa/")
33+
("melpa" . "http://melpa.org/packages/")
34+
("marmalade" . "http://marmalade-repo.org/packages/")))
35+
(package-initialize)
36+
37+
(defvar starter-kit-packages nil
38+
"Libraries that should be installed by default (currently none).")
39+
40+
(defun starter-kit-install-if-needed (&rest packages)
41+
"Install PACKAGES using ELPA if they are not loadable or installed locally."
42+
(when packages
43+
(unless package-archive-contents
44+
(package-refresh-contents))
45+
(dolist (package packages)
46+
(unless (or (starter-kit-loadable-p package)
47+
(package-installed-p package))
48+
(package-install package)))))
49+
50+
(defun starter-kit-load (file &optional header-or-tag)
51+
"Load configuration from other starter-kit-*.org files.
52+
If the optional argument is the id of a subtree then only
53+
configuration from within that subtree will be loaded. If it is
54+
not an id then it will be interpreted as a tag, and only subtrees
55+
marked with the given tag will be loaded.
56+
57+
For example, to load all of starter-kit-lisp.org simply
58+
add (starter-kit-load \"lisp\") to your configuration.
59+
60+
To load only the 'window-system' config from
61+
starter-kit-misc-recommended.org add
62+
(starter-kit-load \"misc-recommended\" \"window-system\")
63+
to your configuration."
64+
(let ((file (expand-file-name (if (string-match "starter-kit-.+\.org" file)
65+
file
66+
(format "starter-kit-%s.org" file))
67+
starter-kit-dir)))
68+
(org-babel-load-file
69+
(if header-or-tag
70+
(let* ((base (file-name-nondirectory file))
71+
(dir (file-name-directory file))
72+
(partial-file (expand-file-name
73+
(concat "." (file-name-sans-extension base)
74+
".part." header-or-tag ".org")
75+
dir)))
76+
(unless (file-exists-p partial-file)
77+
(with-temp-file partial-file
78+
(insert
79+
(with-temp-buffer
80+
(insert-file-contents file)
81+
(save-excursion
82+
(condition-case nil ;; collect as a header
83+
(progn
84+
(org-link-search (concat"#"header-or-tag))
85+
(org-narrow-to-subtree)
86+
(buffer-string))
87+
(error ;; collect all entries with as tags
88+
(let (body)
89+
(org-map-entries
90+
(lambda ()
91+
(save-restriction
92+
(org-narrow-to-subtree)
93+
(setq body (concat body "\n" (buffer-string)))))
94+
header-or-tag)
95+
body))))))))
96+
partial-file)
97+
file))))
98+
99+
(if (or
100+
(eq system-type 'darwin)
101+
(eq system-type 'berkeley-unix))
102+
(setq system-name (car (split-string system-name "\\."))))
103+
104+
(starter-kit-load "starter-kit-defuns.org")
105+
106+
(starter-kit-load "starter-kit-bindings.org")
107+
108+
(starter-kit-load "starter-kit-misc.org")
109+
110+
(starter-kit-load "starter-kit-registers.org")
111+
112+
(cl-flet ((sk-load (base)
113+
(let* ((path (expand-file-name base starter-kit-dir))
114+
(literate (concat path ".org"))
115+
(encrypted-org (concat path ".org.gpg"))
116+
(plain (concat path ".el"))
117+
(encrypted-el (concat path ".el.gpg")))
118+
(cond
119+
((file-exists-p encrypted-org) (org-babel-load-file encrypted-org))
120+
((file-exists-p encrypted-el) (load encrypted-el))
121+
((file-exists-p literate) (org-babel-load-file literate))
122+
((file-exists-p plain) (load plain)))))
123+
(remove-extension (name)
124+
(string-match "\\(.*?\\)\.\\(org\\(\\.el\\)?\\|el\\)\\(\\.gpg\\)?$" name)
125+
(match-string 1 name)))
126+
(let ((user-dir (expand-file-name user-login-name starter-kit-dir)))
127+
;; load system-specific config
128+
(sk-load system-name)
129+
;; load user-specific config
130+
(sk-load user-login-name)
131+
;; load any files in the user's directory
132+
(when (file-exists-p user-dir)
133+
(add-to-list 'load-path user-dir)
134+
(mapc #'sk-load
135+
(remove-duplicates
136+
(mapcar #'remove-extension
137+
(directory-files user-dir t ".*\.\\(org\\|el\\)\\(\\.gpg\\)?$"))
138+
:test #'string=)))))
139+
140+
(load custom-file 'noerror)

0 commit comments

Comments
 (0)