README
Introduction
This Emacs configuration file is written with literate programming method.[fn:1]
The elisp file is extracted from this file, and then compiled to binary elc
file for fast loading in the future.
To use of this configuration, you can follow below shell commands to prepare the emacs configuration files and folders:
- back up
.emacsfile and.emacs.dfolder - clone
kimim-emacsto home folder - copy new
.emacsfile fromkimim-emacs
cd ~ && mv .emacs .emacs-backup && mv .emacs.d .emacs.d-backup && \
git clone https://github.com/kimim/kimim-emacs && \
cp kimim-emacs/.emacs ~Then execute emacs to bootstrap itself.
Preparation
Windows
Starter Script
Because I want Emacs to be executed in a specific home directory, so I
create a .bat file named emacs.bat to set the environment and run Emacs:
:: set home path for Emacs
set HOME=C:\Users\kimim\home
:: execute emacs with debug enable
%HOME%\kimikit\emacs\bin\runemacs.exe --debug-initAnother important path in Windows is kimikit, which is used to put some
portable applications. I plan to write some installation scripts to update and
install these applications automatically. These scripts are now hosted in
github: https://github.com/kimim/kimikit, welcome to fork and have a try.
Cygwin
Cygwin project[fn:2] is required for this configuration in Windows, which is a large collection of GNU and Open Source tools provide functionality similar to a Linux distribution on Windows.
MSYS2 [fn:3] is better than Cygwin in one aspect that the packages can be
installed in command line with pacman -S.
The explanation from Cygwin is that because Windows do not allow overwriting of in-use executable, so installing a new version of Cygwin DLL while a packager is using the DLL is problematic.[fn:4] But I guess MSYS2 should have the same issue.
However Cygwin standalone package management tool setup-x86.exe or
setup-x86_64.exe accept command-line arguments [fn:5], so I will try to use
the command line option to install packages as many as possible.
With kimikit, it is quite easy to upgrade cygwin setup tool:
$cd ~/kimikit/install $ make cyg wget https://cygwin.com/setup-x86_64.exe –2017-01-04 16:50:29– https://cygwin.com/setup-x86_64.exe Length: 916499 (895K) [application/octet-stream] Saving to: ‘setup-x86_64.exe’ … mv setup-x86_64.exe ../bin/cygup.exe
Mac OS
For Apple macOS, most UNIX tools are installed already. Homebrew [fn:6] is used to install additional application if it is missing in macOS.
Install Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"Linux
Most of the external tools I used in this Emacs configuration should be easily installed or already available in main Linux distributions.
Environment
Synchronization Folders
I’m using this Emacs configuration for both working usage and personal usage, and I want to synchronize some files in synchronization service, so I need to seperate the working file and personal file in different synchronization services. For example, working files are synchronized in Microsoft OneDrive Business or Box Business, while personal files are synchronized in Dropbox or SugarSync.
The variable for synchronization location is named as: kimim/path-sync
If the sync path is not set, then use HOME path ~ as the default folder, that
means, no synchronization. So please set these variables in your .emacs file.
;; Synchronization Folders
(if (not (boundp 'kimim/path-sync))
(defvar kimim/path-sync "~/"))kimim-emacs path
Another important folder is the folder for this configuration files, which is cloned from my github repository.
Anyway, you can change the path as you want, and set kimim/path-kimim-emacs
accordingly.
git clone https://github.com/kimim/kimim-emacs.git(if (not (boundp 'kimim/path-kimim-emacs))
(defvar kimim/path-kimim-emacs "~/kimim-emacs/"))PATH, exec-path and Info
Environment variable PATH is the the searching path of executables by the
shell running in Emacs while exec-path is the search path of Emacs itself. So
we should set both of them to almost the same paths.
As I have a Windows box in the office, and a Apple macOS at home, so I need to specify these variables in different way.
(cond ((eq window-system 'w32)
(setq kimim/path-root "C:/msys64/")
(add-to-list 'exec-path
(concat kimim/path-kimikit "emacs/bin/"))
(setenv "PATH"
(concat kimim/path-kimikit "emacs/bin" path-separator
(getenv "PATH"))))
((eq window-system 'ns)
(setq kimim/path-root "/")
(add-to-list 'exec-path "/Library/Frameworks/Python.framework/Versions/3.5/bin")
(setenv "PATH"
(concat
"/Library/Frameworks/Python.framework/Versions/3.5/bin" path-separator
(getenv "PATH")))))
(add-to-list 'exec-path (concat kimim/path-root "bin"))
(add-to-list 'exec-path (concat kimim/path-root "usr/bin"))
(add-to-list 'exec-path (concat kimim/path-root "usr/local/bin"))
(add-to-list 'exec-path "~/cross-tools/bin")
(setenv "PATH"
(concat
kimim/path-root "bin" path-separator
kimim/path-root "usr/bin" path-separator
kimim/path-root "usr/local/bin" path-separator
"~/cross-tools/bin" path-separator
(getenv "PATH")))Custom File
(if (not (boundp 'kimim/file-custom))
(defvar kimim/file-custom "~/.emacs.d/custom.el"))
(setq custom-file kimim/file-custom)
(load-file custom-file)Language
(setenv "LANG" "en_US.UTF-8")
(setenv "LC_ALL" "en_US.UTF-8")
;; remove svn log LC_TYPE not defined warning.
(setenv "LC_CTYPE" "en_US")
(set-locale-environment "English")
(set-language-environment 'English)
(prefer-coding-system 'utf-8)
(set-buffer-file-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(set-clipboard-coding-system 'utf-16le)
(set-file-name-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)global key map
Define new command prefix for keys such as “C-x m f”, “C-x m v”.
(define-prefix-command 'ctl-x-m-map)
(global-set-key "\C-xm" 'ctl-x-m-map)Emacs in Terminal
cmd.exe
emacs -nw works perfect in Windows cmd.exe as terminal mode!
mintty
nt-emacs running in mintty will report error such as:
$ /cygdrive/c/kimikit/emacs/bin/emacs -nw
emacs: standard input is not a ttyBecause the native win32 emacs wants to talk to a Windows console window, not to an actual tty – the error message is misleading here.[fn:7]
In order to use emacs also in mintty, please install emacs-nox with cygwin-setup.
Package
package [fn:8] is the modern elisp package management system, which let you
easily download and install packages that implement additional features. Each
package is a separate Emacs Lisp program, sometimes including other components
such as an Info manual.
All the extensions used in this file are installed and managed by package.
Here I use use-package to defer the package loading and even installation,
When you use the :commands keyword, it creates autoloads for those commands
and defers loading of the module until they are used.
(setq package-user-dir "~/.emacs.d/elpa")
(setq package-archives
'(("gnu" . "http://elpa.gnu.org/packages/")
("ELPA" . "http://tromey.com/elpa/")
("marmalade" . "https://marmalade-repo.org/packages/")
("melpa" . "http://melpa.org/packages/")))
(mapc
(lambda (package)
(unless (package-installed-p package)
(progn (message "installing %s" package)
(package-refresh-contents)
(package-install package))))
'(use-package diminish bind-key))
(require 'use-package)
(require 'diminish)
(require 'bind-key)
;; install package if missing
(setq use-package-always-ensure t)
(setq use-package-verbose t)Emacs Frame
Menu Bar and Tool Bar
(cond ((eq window-system 'w32)
;; Enable copy and paste in Win32
(setq select-enable-clipboard t)
(menu-bar-mode 0)
(tool-bar-mode -1)
(scroll-bar-mode -1))
((eq window-system 'ns)
(menu-bar-mode 1)
(tool-bar-mode -1)
(scroll-bar-mode -1))
((eq window-system 'x)
(menu-bar-mode 0)
(tool-bar-mode -1)
(scroll-bar-mode -1))
((eq window-system nil)
(menu-bar-mode 0)))Font and Frame Size
Set default font and frame size for both Windows and macOS.
;;set default font
(cond
((eq window-system 'w32)
;; cleaner font setting
(cond
((< (display-pixel-width) 1400)
(set-fontset-font
"fontset-default"
'han (font-spec :family "Microsoft Yahei" :size 16))
;; 16 for small screen; 28 for big screen
(setq default-frame-alist
'((top . 30) (left . 140)
(width . 135) (height . 42)
;; if you like anti-alias, use this to have a try
(font . "Inconsolata-12")
)))
((> (display-pixel-width) 1400)
(set-fontset-font
"fontset-default"
'han (font-spec :family "Microsoft Yahei" :size 28))
;; 16 for small screen; 28 for big screen
(setq default-frame-alist
'((top . 200) (left . 1000)
(width . 128) (height . 60)
;; if you like anti-alias, use this to have a try
(font . "Inconsolata-12")
)))))
((eq window-system 'ns)
(set-fontset-font
"fontset-default"
'han (font-spec :family "PingFang SC" :size 16))
;; OS X 下,只有雅黑字體的標點符號顯示的不是那麼難看
(set-fontset-font
"fontset-default"
'cjk-misc (font-spec :family "PingFang SC" :size 16))
(setq default-frame-alist
'((top . 100) (left . 600)
(width . 166) (height . 70)
(font . "Courier-14")
))))Title and Header
(setq frame-title-format
'("" invocation-name ": "
(:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
"%b"))))
(use-package path-headerline-mode
:defer 5
:config
;; only display headerline for real files
(defun kimim/ph--display-header (orig-fun &rest args)
(if (buffer-file-name)
(apply orig-fun args)
(setq header-line-format nil)))
(advice-add 'ph--display-header :around #'kimim/ph--display-header)
;; display file path in headerline
;; useful when in fullscreen mode
;;(path-headerline-mode t)
)Mode Line
Display time and (line, column) numbers in mode line.
(use-package time
:defer 1
:init
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(setq display-time-interval 10)
:config
(display-time-mode t))
(line-number-mode 1)
(column-number-mode 1)Color Theme
Use self defined color theme 1 seconds after init.
(setq font-lock-maximum-decoration t)
(setq font-lock-global-modes '(not shell-mode text-mode))
(setq font-lock-verbose t)
(global-font-lock-mode 1)
(use-package color-theme
:defer 1
)
(use-package color-theme-kimim
:defer 1
:commands (color-theme-kimim color-theme-jekyll)
:ensure nil
:load-path "~/kimim-emacs/site-lisp/"
:config
(if (eq window-system nil)
(color-theme-jekyll)
(color-theme-kimim))
(add-hook 'before-make-frame-hook
'(lambda ()
(tool-bar-mode -1)
(scroll-bar-mode -1)))
(add-hook 'after-make-frame-functions
(lambda (frame)
(select-frame frame)
(when (display-graphic-p frame)
(color-theme-kimim)))))Highlight
;; highlight current line
(use-package hl-line
:defer 5
:config
(global-hl-line-mode 1))
;; highlight current symbol
(use-package auto-highlight-symbol
:diminish auto-highlight-symbol-mode
:bind ("C-x m e" . ahs-edit-mode)
:config
(global-auto-highlight-symbol-mode t))Other Visual Element
(setq inhibit-startup-message t) ; 不顯示開始畫面
(setq initial-scratch-message nil) ; scratch 默認為空
(setq visible-bell t)
(setq ring-bell-function #'ignore)
(fset 'yes-or-no-p 'y-or-n-p)
(show-paren-mode 1) ; 高亮显示匹配的括号
(blink-cursor-mode 1) ; 光标不闪烁
(tooltip-mode nil)Help
Info
(use-package info
:defer t
:config
(add-to-list 'Info-additional-directory-list
(concat kimim/path-root "usr/share/info"))
(add-to-list 'Info-additional-directory-list
(concat kimim/path-root "usr/local/share/info"))
;; additional info, collected from internet
(add-to-list 'Info-additional-directory-list
"~/info"))tldr
TL;DR stands for “Too Long; Didn’t Read”[fn:9]. tldr.el [fn:10] is the Emacs
client.
(use-package tldr
:defer t
)Controlling
Window and Frame
(use-package winner
;; restore windows configuration, built-in package
:defer 5
:commands winner-mode
:config
(winner-mode t))
(use-package window-numbering
:ensure t
:defer 5
:commands window-numbering-mode
:config
(window-numbering-mode 1))
(bind-key "C-x m w" 'make-frame)
;; donno why, w/o following, new frame still has scroll-bar
(scroll-bar-mode -1)Command
;; https://github.com/justbur/emacs-which-key
(use-package which-key
:defer 5
:ensure t
:diminish which-key-mode
:config
;; use minibuffer as the popup type, otherwise conflict in ecb mode
(setq which-key-popup-type 'minibuffer)
(which-key-mode 1))
;; smex will list the recent function on top of the cmd list
(use-package smex
:defer t
:ensure t
:config
(smex-initialize))
(use-package counsel
:defer t
:bind
(("M-x" . counsel-M-x)
("C-x C-f" . counsel-find-file)
("C-x m f" . counsel-describe-function)
("C-x m v" . counsel-describe-variable)
("C-x m l" . counsel-load-library)
("C-x m i" . counsel-info-lookup-symbol)
("C-x m j" . counsel-bookmark)
("C-x m u" . counsel-unicode-char)
("C-c j" . counsel-git-grep)
("C-c g" . counsel-grep)
("C-c k" . counsel-ag)
("C-c p" . counsel-pt)
("C-x l" . counsel-locate)
("C-c m" . counsel-bbdb-complete-mail)
:map read-expression-map
("C-r" . counsel-expression-history))
:config
(use-package ivy)
(use-package smex)
(add-hook 'counsel-grep-post-action-hook 'recenter)
(ivy-mode 1))Key Frequency
(use-package keyfreq
:defer 5
:config
(keyfreq-mode)
(keyfreq-autosave-mode)
(setq keyfreq-file "~/.emacs.d/emacs.keyfreq"))Editing
General
;;========================================
;; Editor setting
;;========================================
(setq inhibit-eol-conversion nil) ; 不要轉換 end-of-line style
;; fill-column is a buffer-local variable, use setq-default to change it globally
(setq-default fill-column 80)
(toggle-word-wrap -1)
(use-package drag-stuff
:defer 3
:diminish drag-stuff-mode
:config
(drag-stuff-global-mode 1)) ; use Alt-up/down to drag line or region
;;(diminish 'drag-stuff-mode)
(delete-selection-mode 1) ; 輸入的文字覆蓋選中的文字
(setq kill-ring-max 200) ; kill-ring 最多的记录个数
(setq kill-whole-line t) ; 在行首 C-k 时,同时删除该行。
(setq require-final-newline t) ; 存盘的时候,要求最后一个字符时换行符
(setq-default tab-width 4) ; 用 space 替换 tab,tab 长度为 4
(setq tab-stop-list
(number-sequence 4 120 4)) ; 每次 tab 空格數
(setq track-eol t) ; 当光标在行尾上下移动的时候保持在行尾
;; 对于每个备份文件,保留最原始的两个版本和最新的五个版本。并且备份的时
;; 候,备份文件是复本,而不是原件。
(setq backup-directory-alist '(("." . "~/Temp")))
(setq version-control t)
(setq kept-old-versions 10)
(setq kept-new-versions 20)
(setq delete-old-versions t)
(setq backup-by-copying t)
(setq auto-save-interval 50)
(setq auto-save-timeout 60)
(setq auto-save-default nil) ; auto-save of every file-visiting buffer
(setq auto-save-list-file-prefix "~/Temp/auto-saves-")
(setq auto-save-file-name-transforms `((".*" , "~/Temp/")))
(setq create-lockfiles nil)
(setq time-stamp-active t)
(setq time-stamp-warn-inactive t)
(setq time-stamp-format "%:y-%02m-%02d %3a %02H:%02M:%02S kimi")
(add-hook 'write-file-hooks 'time-stamp); 自动更新 time-stamp
(add-hook 'before-save-hook 'kimim/delete-trailing-whitespace)
(defun kimim/save-buffer-advice (orig-fun &rest arg)
(delete-trailing-whitespace)
(apply orig-fun arg))
(advice-add 'save-buffer :around #'kimim/save-buffer-advice)
(setq ispell-program-name "aspell")
(diminish 'visual-line-mode)
(add-hook 'text-mode-hook
(lambda ()
(when (derived-mode-p 'org-mode 'markdown-mode 'text-mode)
(visual-line-mode))))
(setq-default indent-tabs-mode nil)
;; 当有两个文件名相同的缓冲时,使用前缀的目录名做 buffer 名字
(setq uniquify-buffer-name-style 'forward)
;; 当使用 M-x COMMAND 后,显示该 COMMAND 绑定的键 5 秒鐘時間
(setq suggest-key-bindings 5)
;;========================================
;; Global Mode Settings
;;========================================
(setq auto-mode-alist
(append '(("\\.css\\'" . css-mode)
("\\.S\\'" . asm-mode)
("\\.C\\w*\\'" . c-mode)
("\\.md\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode)
("\\.svg\\'" . html-mode)
("\\.pas\\'" . delphi-mode)
("\\.txt\\'" . org-mode)
)
auto-mode-alist))
;;========================================
;; Load other configuration files
;;========================================
(require 'saveplace)
(setq-default save-place t)
(setq save-place-file (expand-file-name "saveplace" "~"))
;; (use-package volatile-highlights
;; :config
;; (volatile-highlights-mode t)
;; :diminish volatile-highlights-mode)visual-fille-mode
(use-package visual-fill-column
:defer t
:ensure t
)
(setq visual-fill-column-width 80)
(setq visual-fill-column-center-text t)pangu-spacing
(use-package pangu-spacing
:defer t
:ensure t
:diminish pangu-spacing-mode
:config
(global-pangu-spacing-mode 1)
(add-hook 'org-mode-hook
'(lambda ()
(set (make-local-variable 'pangu-spacing-real-insert-separtor) t))))undo-tree
(use-package undo-tree
:defer 6
:diminish undo-tree-mode
:config
(global-undo-tree-mode)
(setq undo-tree-visualizer-timestamps t))Dired and Buffer
(use-package dired
:defer t
:ensure nil
:bind
("C-x C-j" . dired-jump)
:config
(require 'dired-x)
(add-hook 'dired-mode-hook
(lambda ()
;; Set dired-x buffer-local variables here. For example:
(dired-omit-mode 1)
(setq dired-omit-localp t)
(setq dired-omit-files
(concat "|NTUSER\\|ntuser\\"
"|Cookies\\|AppData\\"
"|Contacts\\|Links\\"
"|Intel\\|NetHood\\"
"|PrintHood\\|Recent\\"
"|Start\\|SendTo\\"
"|^\\.DS_Store\\"
"|qms-bmh"))))
;; Dired buffer 中列出文件时传递给 ls 的参数。加个 "l" 可以使大写的文
;; 件名在顶部,临时的改变可以用 C-u s。
(setq dired-listing-switches "-avhl")
;; 复制(删除)目录的时,第归的复制(删除)其中的子目录。
(setq dired-recursive-copies t)
(setq dired-recursive-deletes t)
(define-key dired-mode-map (kbd "<left>") 'dired-up-directory)
(define-key dired-mode-map (kbd "<right>") 'dired-find-file)
(defadvice dired-next-line (after dired-next-line-advice (arg) activate)
"Move down lines then position at filename, advice"
(interactive "p")
(if (eobp)
(progn
(goto-char (point-min))
(forward-line 2)
(dired-move-to-filename))))
(defadvice dired-previous-line (before dired-previous-line-advice (arg) activate)
"Move up lines then position at filename, advice"
(interactive "p")
(if (= 3 (line-number-at-pos))
(goto-char (point-max)))))
(use-package ibuffer
:defer t
:bind ("C-x C-b" . ibuffer-other-window)
:config
(defun ibuffer-visit-buffer-other-window (&optional noselect)
"Visit the buffer on this line in another window."
(interactive)
(let ((buf (ibuffer-current-buffer t)))
(bury-buffer (current-buffer))
(if noselect
(let ((curwin (selected-window)))
(pop-to-buffer buf)
(select-window curwin))
(switch-to-buffer-other-window buf)
(kill-buffer-and-its-windows "*Ibuffer*")
)))
;; Use human readable Size column instead of original one
(define-ibuffer-column size-h
(:name "Size" :inline t)
(cond
((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
((> (buffer-size) 100000) (format "%7.0fk" (/ (buffer-size) 1000.0)))
((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
(t (format "%8d" (buffer-size)))))
;; Modify the default ibuffer-formats
(setq ibuffer-formats
'((mark modified read-only " "
(name 18 18 :left :elide)
" "
(size-h 9 -1 :right)
" "
(mode 16 16 :left :elide)
" "
filename-and-process))))Navigation
;; bookmark setting
(setq bookmark-default-file "~/.emacs.d/emacs.bmk")
;; 每当设置书签的时候都保存书签文件,否则只在你退出 Emacs 时保存
(setq bookmark-save-flag 1)
(use-package bm
:bind (("C-x m t" . bm-toggle)
("C-x m s" . bm-show-all)))
(use-package ace-jump-mode
:bind
("C-x j" . ace-jump-mode)
("M-g j" . ace-jump-mode)
("C-`" . ace-jump-mode)
("<apps>" . ace-jump-mode))
(use-package ace-window
:bind
("C-\"" . ace-window)
:config
(setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)))Search and Finding
swiper replaces isearch
(use-package swiper
:init (setq swiper-action-recenter t)
:bind
("C-s" . swiper))ag: the silver searcher
ag [fn:11] is really a very fast grep tool, and ag.el [fn:12] provide the
Emacs interface to ag:
(use-package ag
:ensure t
:bind
("C-x g" . ag-project)
:config
(setq ag-highlight-search t))pt: the platium searcher
Because counsel-ag is not working in my Win64 machine, so I switch to pt
now.
Download pt from
https://github.com/monochromegane/the_platinum_searcher/releases, and it works
out of the box.
imenu & imenu-anywhere
imenu is used to navigate the function definitions in current buffer.
(use-package imenu
:defer t
:bind ("C-c C-i" . imenu)
:config
(advice-add 'imenu-default-goto-function
:around
#'kimim/imenu-default-goto-function-advice))
(use-package imenu-anywhere
:defer t
:bind ("C-c i" . imenu-anywhere))helm
(use-package helm
:defer 1)auto-complete
abbrev
(diminish 'abbrev-mode)ivy-mode
(use-package ivy
:defer 1
:diminish ivy-mode
:bind ("<f6>" . ivy-resume)
:config
(setq ivy-use-virtual-buffers t)
(setq ivy-count-format "(%d/%d) ")
(setq ivy-wrap nil)
(ivy-mode 1))auto parenthesis
;; add pair parenthis and quote automatically
(use-package autopair
:defer t
:diminish autopair-mode
:config
(autopair-global-mode 1))yasnippet
(use-package yasnippet
:defer 3
:config
(add-to-list
'yas-snippet-dirs (concat kimim/path-sync "kimikit/emacs.d/snippets"))
(yas-global-mode 1)
(use-package company)
(add-to-list 'company-backends 'company-yasnippet)
(use-package warnings)
(setq warning-suppress-types '((yasnippet backquote-change))))In order to remove following warning:
Warning (yasnippet): ‘xxx’ modified buffer in a backquote expression. To hide this warning, add (yasnippet backquote-change) to ‘warning-suppress-types’.
company dict
(use-package company-dict
:defer t
:config
;; Where to look for dictionary files
(setq company-dict-dir (concat kimim/path-sync "kimikit/emacs.d/dict"))
;; Optional: if you want it available everywhere
(add-to-list 'company-backends 'company-dict))company mode
English word list fetch from https://github.com/dwyl/english-words
(use-package company-try-hard
:defer t
:bind ("C-\\" . company-try-hard))
(use-package company
:diminish company-mode
:defer 5
:config
(use-package company-try-hard)
(use-package company-dict)
(global-company-mode t)
;; macOS will use system dict file directly
(cond ((eq window-system 'w32)
(setq ispell-alternate-dictionary "~/.emacs.d/dict/words3.txt")))
(add-to-list 'company-backends 'company-ispell))company statistics
(use-package company-statistics
:defer 10
:config
(company-statistics-mode 1))Programming General
Compiling
(setq next-error-recenter 20)
(bind-key "C-<f11>" 'compile)
;; error during init
;; (use-package compile-bookmarks
;; :defer t
;; :config
;; (compile-bookmarks-mode))Tagging
(use-package ggtags
:defer t
:bind (("C-c f" . ggtags-find-file)
("M-." . ggtags-find-tag-dwim))
:config
;; ggtags settings
;; Activate cygwin mount for gtags CDPATH issue on W32
;; (cond ((eq window-system 'w32)
;; (require 'cygwin-mount)
;; (cygwin-mount-activate))
;; ((eq window-system nil)
;; (require 'cygwin-mount)
;; (cygwin-mount-activate)))
(setq ggtags-global-ignore-case t)
(setq ggtags-sort-by-nearness t))
;; let ggtags use split-window with is redefined by ecb mode
;;(setq ggtags-split-window-function 'split-window-below)
;; close grep window and done ggtags navigation when type C-g
;; but some times it will close all the ecb windows, so remove this advice.
;; (advice-add 'keyboard-quit :before #'kimim/kill-grep-and-ggtags-done)
Version Control
;; ;; magit-status for git
(use-package magit
:defer t
:bind ("C-x m g" . magit-status))Following error will reported when using magit to commit changes:
server-ensure-safe-dir: The directory ‘~/.emacs.d/server’ is unsafe
The solution is to change the owner of ~/.emacs.d/server [fn:15]
Click R-mouse on ~/.emacs.d/server and select “Properties” (last item in menu). From Properties select the Tab “Security” and then select the button “Advanced”. Then select the Tab “Owner” and change the owner from “Administrators (\Administrators)” into “ (\”. Now the server code will accept this directory as secure because you are the owner.
Programming Language
C
;; Define the modes/packages you need
(use-package company-irony
:defer t
:ensure t
)
(use-package irony
:defer t
:diminish irony-mode
:config
(setq w32-pipe-read-delay 0)
(use-package company-irony)
(add-hook 'irony-mode-hook 'company-irony-setup-begin-commands)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
;; replace the `completion-at-point' and `complete-symbol' bindings in
;; irony-mode's buffers by irony-mode's function
(defun my-irony-mode-hook ()
(define-key irony-mode-map [remap completion-at-point]
'irony-completion-at-point-async)
(define-key irony-mode-map [remap complete-symbol]
'irony-completion-at-point-async))
(add-hook 'irony-mode-hook 'my-irony-mode-hook))
(use-package company-c-headers
:defer t
:ensure t
)
(use-package flycheck
:defer t
:ensure t
:config
;; set up flycheck
(add-hook 'flycheck-mode-hook #'flycheck-irony-setup))
(use-package cc-mode
:defer t
:ensure nil
:config
(use-package company)
(use-package company-irony)
(add-to-list 'company-backends 'company-irony)
(use-package company-c-headers)
(add-to-list 'company-c-headers-path-system "/usr/include")
(require 'irony)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)
(require 'flycheck)
(add-hook 'c-mode-hook 'flycheck-mode)
(add-hook 'c++-mode-hook 'flycheck-mode)
(require 'ggtags)
(add-hook 'c-mode-hook 'ggtags-mode)
(add-hook 'c++-mode-hook 'ggtags-mode)
(add-hook 'c-mode-common-hook
(lambda ()
;; show column width indicator
;;(fci-mode 0)
;;(syntax-subword-mode 1)
;;(hs-minor-mode 0)
;;(c-set-style "gnu")
(c-toggle-auto-newline 0)
(c-toggle-auto-hungry-state 0)
(c-toggle-syntactic-indentation 1)
;;(highlight-indentation-mode 1)
(which-function-mode 1)
(local-set-key "\C-co" 'ff-find-other-file)
;;(my-c-mode-common-hook-if0)
(setq c-basic-offset 4))))irony installation
irony-mode is developed by Sarcasm [fn:16]. It is an Emacs minor-mode that
aims at improving the editing experience for the C, C++ and Objective-C
languages. It works by using a combination of an Emacs package and a C++ program
(irony-server) that uses libclang. When correctly configured, it can provide
wonderful auto completion for functions and variables. The function prototypes
with parameters can be triggered as a yasnippet automatically.
It is quite easy to install irony-server under macOS, just invoke the command
“M-x irony-install-server”, and Emacs will compile and install it to
~/.emacs.d/irony/bin/irony-server, by invoking the make commands:
cmake -DCMAKE_INSTALL_PREFIX\=/Users/kimim/.emacs.d/irony/
/Users/kimim/.emacs.d/elpa/irony-20160925.1030/server && cmake --build
. --use-stderr --config Release --target installFor Cygwin/Windows, first we should install libclang 3.8.1-1 and
libclang-devel 3.8.1-1 and cmake with setup.exe.
Then compile irony-server with cmake and make:
~/.emacs.d/elpa/irony-20160925.1030/server/build
$ cmake -DCMAKE_INSTALL_PREFIX=~/.emacs.d/irony/ -G "Unix Makefiles" ..
~/.emacs.d/elpa/irony-20160925.1030/server/build
$ make install
Scanning dependencies of target irony-server
[ 14%] Building CXX object src/CMakeFiles/irony-server.dir/support/CommandLineParser.cpp.o
[ 28%] Building CXX object src/CMakeFiles/irony-server.dir/support/TemporaryFile.cpp.o
[ 42%] Building CXX object src/CMakeFiles/irony-server.dir/Command.cpp.o
[ 57%] Building CXX object src/CMakeFiles/irony-server.dir/Irony.cpp.o
[ 71%] Building CXX object src/CMakeFiles/irony-server.dir/TUManager.cpp.o
[ 85%] Building CXX object src/CMakeFiles/irony-server.dir/main.cpp.o
[100%] Linking CXX executable ../bin/irony-server.exe
[100%] Built target irony-server
Install the project...
-- Install configuration: "Release"
-- Up-to-date: /home/kimim/.emacs.d/irony/bin/irony-server.exePython
Python development configuration is quite easy. elpy [fn:17] is used here:
(use-package elpy
:defer t
:config
(elpy-enable))
(use-package python
:ensure nil
:mode ("\\.py\\'" . python-mode)
:defer t
:config
(add-hook 'python-mode-hook
(lambda ()
(setq yas-indent-line nil)))
(add-to-list 'python-shell-completion-native-disabled-interpreters "python"))
(use-package company-jedi
:defer t
:config
(setq elpy-rpc-backend "jedi")
(add-to-list 'company-backends 'company-jedi))Following python package is required according to elpy mannual:
pip install rope
pip install jedi
# flake8 for code checks
pip install flake8
# importmagic for automatic imports
pip install importmagic
# and autopep8 for automatic PEP8 formatting
pip install autopep8
# and yapf for code formatting
pip install yapf
# install virtualenv for jedi
pip install virtualenvGo lang
Open .go file with go-mode.
(use-package go-mode
:defer t
:mode ("\\.go\\'" . go-mode))Docker file
Some dockerfile is not end with .dockerfile, so lets guess:
(use-package dockerfile-mode
:defer t
:mode ("\\dockerfile\\'" . dockerfile-mode))Emacs lisp
(define-derived-mode lisp-interaction-mode emacs-lisp-mode "λ")
(eval-after-load 'company
'(add-to-list 'company-backends 'company-elisp))AutoHotKey
ahk-mode developed by Rich Alesi[fn:18]
(use-package ahk-mode
:defer t
:mode ("\\.ahk\\'" . ahk-mode))Calendar
(setq diary-file "~/.emacs.d/diary")
(setq calendar-latitude +30.16)
(setq calendar-longitude +120.12)
(setq calendar-location-name "Hangzhou")
(setq calendar-remove-frame-by-deleting t)
(setq calendar-week-start-day 1)
(setq holiday-christian-holidays nil)
(setq holiday-hebrew-holidays nil)
(setq holiday-islamic-holidays nil)
(setq holiday-solar-holidays nil)
(setq holiday-bahai-holidays nil)
(setq holiday-general-holidays '((holiday-fixed 1 1 "元旦")
(holiday-fixed 4 1 "愚人節")
(holiday-float 5 0 2 "父親節")
(holiday-float 6 0 3 "母親節")))
(setq calendar-mark-diary-entries-flag t)
(setq calendar-mark-holidays-flag nil)
(setq calendar-view-holidays-initially-flag nil)
(setq chinese-calendar-celestial-stem
["甲" "乙" "丙" "丁" "戊" "己" "庚" "辛" "壬" "癸"])
(setq chinese-calendar-terrestrial-branch
["子" "丑" "寅" "卯" "辰" "巳" "午" "未" "申" "酉" "戌" "亥"])Orgmode
org general setting
;; path and system environment setting for orgmode
(if (not (boundp 'kimim/path-org))
(defvar kimim/path-org (concat kimim/path-sync "org/")))
(use-package org
:defer t
:bind
("C-c a" . org-agenda)
("C-c b" . org-iswitchb)
("C-c c" . org-capture)
("C-c l" . org-store-link)
("C-c !" . org-time-stamp-inactive)
("C-c 。" . org-time-stamp)
:config
(setq org-export-allow-BIND t)
(setq org-support-shift-select t)
;; no empty line after collapsed
(setq org-cycle-separator-lines 0)
(setq org-src-fontify-natively t)
(setq org-startup-indented t))org for writing
(use-package org-download
:init (setq org-download-timestamp "")
:defer t
:config
(setq org-image-actual-width (/ (display-pixel-width) 3)))
(use-package org
:defer t
:config
(use-package org-download)
(use-package pangu-spacing)
(setq org-hide-leading-stars t)
(setq org-footnote-auto-adjust t)
(setq org-export-with-sub-superscripts '{})
(define-key org-mode-map (kbd "C-c C-x h") (lambda()
(interactive)
(insert "^{()}")
(backward-char 2)))
(define-key org-mode-map (kbd "C-c C-x l") (lambda()
(interactive)
(insert "_{}")
(backward-char 1)))
)org with source code
(use-package org
:defer t
:config
;; src block setting
(setq org-src-window-setup 'current-window)
(setq org-src-fontify-natively t)
(setq org-confirm-babel-evaluate nil)
(add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
(org-babel-do-load-languages
'org-babel-load-languages
'((C . t)
(python . t)
(emacs-lisp . t)
(shell . t)
(dot . t)
(ditaa . t)
(js . t)
(latex . t)
(plantuml . t)
(clojure . t)
(org . t)
))
)org exporting
(use-package org
:defer t
:config
(setq org-export-allow-BIND t)
(setq org-export-creator-string "")
(setq org-export-html-validation-link nil)
(setq org-html-validation-link nil))
(use-package org
:defer t
:config
(require 'ox-latex)
;;(setq org-latex-pdf-process
;; '("xelatex -interaction nonstopmode %f"
;; "xelatex -interaction nonstopmode %f"))
(setq org-latex-pdf-process
'("xelatex %f"
"xelatex %f"))
(add-to-list 'org-latex-classes
'("cn-article"
"\\documentclass[a4paper,UTF8]{ctexbook}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))
;; (use-package ox-reveal
;; :defer t
;; :config
;; (setq org-reveal-root "reveal.js")
;; ;;(setq org-reveal-root "~/../Tools/reveal.js")
;; ;;(setq org-reveal-root "http://cdn.jsdelivr.net/reveal.js/2.5.0/")
;; (setq org-reveal-theme "simple")
;; (setq org-reveal-width 1200)
;; (setq org-reveal-height 750)
;; (setq org-reveal-transition "fade")
;; (setq org-reveal-hlevel 2))
(use-package ox-html
:defer t
:ensure nil
:config
(defadvice org-html-paragraph (before fsh-org-html-paragraph-advice
(paragraph contents info) activate)
"Join consecutive Chinese lines into a single long line without
unwanted space when exporting org-mode to html."
(let ((fixed-contents)
(orig-contents (ad-get-arg 1))
(reg-han "[[:multibyte:]]"))
(setq fixed-contents (replace-regexp-in-string
(concat "\\(" reg-han "\\) *\n *\\(" reg-han "\\)")
"\\1\\2" orig-contents))
(ad-set-arg 1 fixed-contents)
))
(defun org-babel-result-to-file (result &optional description)
"Convert RESULT into an `org-mode' link with optional DESCRIPTION.
If the `default-directory' is different from the containing
file's directory then expand relative links."
(when (stringp result)
(if (string= "svg" (file-name-extension result))
(progn
(with-temp-buffer
(if (file-exists-p (concat result ".html"))
(delete-file (concat result ".html")))
(rename-file result (concat result ".html"))
(insert-file-contents (concat result ".html"))
(message (concat result ".html"))
(format "#+BEGIN_HTML
<div style=\"text-align: center;\">
%s
</div>
#+END_HTML"
(buffer-string)
)))
(progn
(format "[[file:%s]%s]"
(if (and default-directory
buffer-file-name
(not (string= (expand-file-name default-directory)
(expand-file-name
(file-name-directory buffer-file-name)))))
(expand-file-name result default-directory)
result)
(if description (concat "[" description "]") "")))))))org with diagram
;; plant uml setting
(use-package org
:defer t
:config
(require 'ob-plantuml)
(setenv "GRAPHVIZ_DOT" (concat kimim/path-root "bin/dot"))
(setq org-plantuml-jar-path (concat kimim/path-kimikit "plantuml/plantuml.jar")))org as GTD system
(use-package org
:defer t
:commands (org-toggle-office org-toggle-home)
:bind (:map org-mode-map
;;:map org-agenda-mode-map
;;("<S-right>" . (lambda ()
;; (interactive)
;; (org-agenda-todo 'right)))
)
:config
(require 'org-agenda)
(org-defkey org-agenda-mode-map
[(shift right)] (lambda ()
(interactive)
(org-agenda-todo 'right)))
(org-defkey org-agenda-mode-map
[(shift left)] (lambda ()
(interactive)
(org-agenda-todo 'left)))
(org-defkey org-agenda-mode-map
[(control right)] 'org-agenda-do-date-later)
(org-defkey org-agenda-mode-map
[(control left)] 'org-agenda-do-date-earlier)
(add-hook 'kill-emacs-hook
(lambda ()
(org-clock-out nil t nil)
(org-save-all-org-buffers)))
(setq org-todo-keywords
'(
;; for tasks
(sequence "TODO(t!)" "SCHED(s)" "|" "DONE(d@/!)")
;; for risks, actions, problems
(sequence "OPEN(o!)" "WAIT(w@/!)" "|" "CLOSE(c@/!)")
;; special states
(type "REPEAT(r)" "SOMEDAY(m)" "|" "ABORT(a@/!)")))
(setq org-tag-alist
'(("@office" . ?o) ("@home" . ?h)
("team" . ?t) ("leader" . ?l) ("boss" . ?b)
("risk" . ?k) ("sync" . ?s) ("followup" . ?f)
("reading" . ?r) ("writing" . ?w)
("project" . ?p) ("category" . ?c)
("habit" . ?H)
("next" . ?n)))
(setq org-tags-exclude-from-inheritance '("project" "category"))
(diminish 'auto-fill-function)
(add-hook 'org-mode-hook
(lambda ()
;;(auto-fill-mode)
(org-display-inline-images)
(drag-stuff-mode -1)
;; seems "g" can refresh stuck tasks now, 2017-07-14
;; (if (boundp 'org-agenda-mode-map)
;; (org-defkey org-agenda-mode-map "x"
;; 'org-agenda-list-stuck-projects))))
))
;; (setq org-stuck-projects
;; '("+LEVEL>=2-category-project-habit/-TODO-SCHED-DONE-OPEN-WAIT-CLOSE-SOMEDAY-REPEAT-ABORT"
;; ("TODO" "SCEHD" "OPEN" "WAIT") nil nil))
(setq org-stuck-projects
'("+LEVEL>=2-category-habit"
("TODO" "SCHED" "DONE"
"OPEN" "WAIT" "CLOSE"
"ABORT" "SOMEDAY" "REPEAT")
nil nil))
(setq org-refile-targets
'(;; refile to maxlevel 2 of current file
(nil . (:maxlevel . 1))
;; refile to maxlevel 1 of org-refile-files
(org-refile-files :maxlevel . 1)
;; refile to item with 'project' tag in org-refile-files
(org-refile-files :tag . "project")
(org-refile-files :tag . "category")))
(defadvice org-schedule (after add-todo activate)
(if (or (string= "OPEN" (org-get-todo-state))
(string= "WAIT" (org-get-todo-state))
(string= "CLOSE" (org-get-todo-state)))
(org-todo "WAIT")
(org-todo "SCHED")))
(defadvice org-deadline (after add-todo activate)
(if (or (string= "OPEN" (org-get-todo-state))
(string= "WAIT" (org-get-todo-state))
(string= "CLOSE" (org-get-todo-state)))
(org-todo "WAIT")
(org-todo "SCHED")))
(setq org-log-done t)
(setq org-todo-repeat-to-state "REPEAT")
;; settings for org-agenda-view
(setq org-agenda-span 2)
(setq org-agenda-skip-scheduled-if-done t)
(setq org-agenda-skip-deadline-if-done t)
(setq org-deadline-warning-days 2)
(setq org-agenda-custom-commands
'(("t" todo "TODO|SCHED"
((org-agenda-sorting-strategy '(priority-down))))
("o" todo "OPEN|WAIT"
((org-agenda-sorting-strategy '(priority-down))))
;; all task should be done or doing
("d" todo "TODO|SCHED|OPEN|WAIT"
((org-agenda-sorting-strategy '(priority-down))))
("h" tags "habit/-ABORT-CLOSE"
((org-agenda-sorting-strategy '(todo-state-down))))
("c" tags "clock"
((org-agenda-sorting-strategy '(priority-down))))))
(setq org-directory kimim/path-org)
(setq org-capture-templates
'(("c" "Capture" entry (file+headline "capture.org" "Inbox")
"* %?\n:PROPERTIES:\n:CAPTURED: %U\n:END:\n")
("t" "TODO Task" entry (file+headline "capture.org" "Inbox")
"* TODO %?\n:PROPERTIES:\n:CAPTURED: %U\n:END:\n")
("o" "OPEN Issue" entry (file+headline "capture.org" "Inbox")
"* OPEN %?\n:PROPERTIES:\n:CAPTURED: %U\n:END:\n")
("h" "Habit" entry (file+headline "global.org" "Habit")
"* %? :habit:\n:PROPERTIES:\n:CAPTURED: %U\n:END:\n")))
(defcustom org-location-home-or-office "office" "office")
(defun org-toggle-office ()
(interactive)
(setq org-location-home-or-office "office")
(setq org-agenda-files
(list kimim/path-org
(concat kimim/path-org "work/")))
(setq org-refile-files
(append
(file-expand-wildcards (concat kimim/path-org "*.org"))))
;;(file-expand-wildcards (concat kimim/path-org "work/*.org"))
;;(file-expand-wildcards (concat kimim/path-org "home/*.org"))))
(message "Agenda is from office..."))
(defun org-toggle-home ()
(interactive)
(setq org-location-home-or-office "home")
(setq org-agenda-files
(list kimim/path-org
(concat kimim/path-org "home/")))
(setq org-refile-files
(append
(file-expand-wildcards (concat kimim/path-org "*.org"))))
;;(file-expand-wildcards (concat kimim/path-org "home/*.org"))
;;(file-expand-wildcards (concat kimim/path-org "work/*.org"))))
(message "Agenda is from home..."))
(use-package ivy) ; use ivy to complete refile files
(defun org-toggle-home-or-office()
(interactive)
(if (string= org-location-home-or-office "home")
(org-toggle-office)
(org-toggle-home))))org link: match
New link to use everything to locate a file with unique ID:
(use-package org
:defer t
:config
(org-add-link-type "match" 'org-match-open)
(defun org-match-open (path)
"Visit the match search on PATH.
PATH should be a topic that can be thrown at everything/?."
(w32-shell-execute
"open" "Everything" (concat "-search " path))))
org link: onenote
New link to use everything to locate a file with unique ID:
(use-package org
:defer t
:config
(org-add-link-type "onenote" 'org-onenote-open)
(defun org-onenote-open (path)
"Visit the match search on PATH.
PATH should be a topic that can be thrown at everything/?."
(w32-shell-execute
"open" (concat "onenote:" path))))org publish to jekyll
(use-package org
:defer 3
:config
;; file in jekyll base will also be uploaded to github
(setq path-jekyll-base "~/kimi.im/_notes/_posts")
;; in order to sync draft with cloud sync driver
(setq path-jekyll-draft (concat kimim/path-sync "kimim/_draft/"))
;; file in jekyll base will also be uploaded to github
(setq org-publish-project-alist
'(
("org-blog-content"
;; Path to your org files.
:base-directory "~/kimi.im/_notes"
:base-extension "org"
;; Path to your jekyll project.
:publishing-directory "~/kimi.im/"
:recursive t
:publishing-function org-html-publish-to-html
:headline-levels 4
:section-numbers t
:html-extension "html"
:body-only t ;; Only export section between <body></body>
:with-toc nil
)
("org-blog-static"
:base-directory "~/kimi.im/_notes/"
:base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf\\|php\\|svg"
:publishing-directory "~/kimi.im/"
:recursive t
:publishing-function org-publish-attachment)
("blog" :components ("org-blog-content" "org-blog-static"))
))
(use-package ivy)
(defun jekyll-post ()
"Post current buffer to kimi.im"
(interactive)
;; get categories
;; get buffer file name
(let ((category (jekyll-get-category))
(filename (file-name-nondirectory buffer-file-name))
newfilename)
;; append date to the beginning of the file name
(setq newfilename (concat path-jekyll-base "/" category "/" (format-time-string "%Y-%m-%d-") filename))
;; mv the file to the categories folder
(rename-file buffer-file-name newfilename)
(switch-to-buffer (find-file-noselect newfilename))
;; (color-theme-initialize)
;; (color-theme-jekyll)
;; execute org-publish-current-file
(org-publish-current-file)
;; (color-theme-eclipse)
;; go to kimi.im folder and execute cyg command
(with-temp-buffer(dired "~/kimi.im/")
(kimim/cyg)
(kill-buffer))
))
(defun jekyll-tag ()
"add new tags"
(interactive)
;; find "tags: [" and replace with "tags: [new-tag, "
(let (tag)
(goto-char (point-min))
;; (search-forward "tags: [")
(re-search-forward "tags: \\[" nil t)
(setq tag (ivy-read "tags: " '(
"Deutsch" "Français" "English"
"emacs" "org-mode"
"Windows" "RTOS" "industry"
"travel" "street-shots" "photography"
"leadership"
"x"
)))
(if (string= "x" tag)
(insert "")
(insert tag ", "))
tag))
(defun jekyll-header()
"Insert jekyll post headers,
catergories and tags are generated from exisiting posts"
(interactive)
(insert "#+BEGIN_EXPORT html\n---\nlayout: post\ntitle: ")
(insert (read-string "Title: "))
(insert "\ncategories: [")
(insert (ivy-read "categories: " '(
"technology"
"productivity" "leadership"
"psychology" "language"
"education" "photography"
)))
(insert "]")
(insert "\ntags: [")
(while (progn
(setq tag (jekyll-tag))
(not (string= "x" tag))))
(move-end-of-line 1)
(backward-delete-char 2)
(insert "]\n---\n#+END_EXPORT\n\n")
)
(defun jekyll ()
(interactive)
(find-file (concat path-jekyll-draft "/" (read-string "Filename: ") ".org"))
(jekyll-header)
(save-buffer)
)
(defun jekyll-get-category ()
(interactive)
(goto-char (point-min))
(re-search-forward "^categories: \\[\\([a-z-]*\\)\\]$" nil t)
(match-string 1)
)
(defun jekyll-test ()
(interactive)
(color-theme-initialize)
(color-theme-jekyll)
(org-open-file (org-html-export-to-html nil))))
Note Taking Tools
Deft
(use-package deft
:defer t
:ensure t
:bind
(("C-x d" . deft-find-file)
("C-x C-d" . deft))
:config
(use-package ivy)
(setq deft-extensions '("txt" "tex" "org" "md"))
(if (not (boundp 'kimim/path-notes))
(defvar kimim/path-notes (concat kimim/path-sync "notes/")))
(setq deft-directory kimim/path-notes)
(setq deft-recursive t)
;; disable auto save
(setq deft-auto-save-interval 0)
(setq deft-file-naming-rules '((noslash . "_")))
(setq deft-text-mode 'org-mode)
(setq deft-use-filter-string-for-filename t)
(setq deft-org-mode-title-prefix t)
(setq deft-use-filename-as-title nil)
(setq deft-strip-summary-regexp
(concat "\\("
"[\n\t]" ;; blank
"\\|^#\\+[[:upper:]_]+:.*$" ;; org-mode metadata
"\\|^#\\+[[:alnum:]_]+:.*$" ;; org-mode metadata
"\\)"))
;;advise deft-open-file to replace spaces in file names with _
(require 'kimim)
(defun kimim/deft-open-file-advice (orig-fun &rest args)
(setq name (pop args))
(if (file-exists-p name)
(progn
(push name args)
(apply orig-fun args))
(progn
(setq title (file-name-sans-extension
(file-name-nondirectory name)))
(setq name (concat
(file-name-directory name)
(kimim/genfile-timestamp)
(downcase
(replace-regexp-in-string
" " "_" (file-name-nondirectory name)))
(if (not (file-name-extension name))
".txt")))
(push name args)
(apply orig-fun args)
(insert (concat "#+TITLE: " title "\n\n")))))
(advice-add 'deft-open-file
:around #'kimim/deft-open-file-advice)
(defun kimim/deft-new-file-named-advice (orig-fun &rest args)
(setq name (pop args))
(setq title name)
(setq name (concat
(kimim/genfile-timestamp)
(downcase
(replace-regexp-in-string
" " "_" name))))
(push name args)
(apply orig-fun args)
(insert (concat "#+TITLE: " title "\n\n")))
(advice-add 'deft-new-file-named
:around #'kimim/deft-new-file-named-advice))Reference management
(setq org-ref-bibliography-notes (concat kimim/path-ref "notes.org")
org-ref-default-bibliography (concat kimim/path-ref "docs.bib")
org-ref-pdf-directory (concat kimim/path-ref "pdfs/"))erc and gnus
;; erc settings
(use-package erc
:defer t
:config
(require 'erc-join)
(erc-autojoin-mode 1)
(erc-autojoin-enable)
(setq erc-default-server "irc.freenode.net")
(setq erc-autojoin-channels-alist
'(("irc.freenode.net" "#emacs")))
(setq erc-hide-list '("JOIN" "PART" "QUIT")))
;; gnus settings
(use-package gnus
:defer t
:bind
(("C-x m m" . compose-mail-kimim))
:config
(setq message-directory "~/Gnus/Mail/")
(setq gnus-directory "~/Gnus/News/")
(setq nnfolder-directory "~/Gnus/Mail/Archive")
(setq gnus-permanently-visible-groups "INBOX")
(setq gnus-alias-override-user-mail-address t)
(setq gnus-asynchronous t)
(setq gnus-use-article-prefetch 1000)
(setq gnus-fetch-old-headers 'some)
;; fetch only 50 latest articles to speed up downloading
(setq gnus-large-newsgroup 50)
(setq message-forward-as-mime t)
(setq message-forward-before-signature nil)
(setq message-forward-included-headers "^Date\\|^From\\|^To\\|^Subject:")
(setq message-make-forward-subject-function 'message-forward-subject-fwd)
(setq gnus-user-date-format-alist
'(((gnus-seconds-today) . "Today %H:%M")
((+ 86400 (gnus-seconds-today)) . "Yest. %H:%M")
(604800 . "%a %H:%M") ; That's one week
((gnus-seconds-month) . "%a %H:%M")
((gnus-seconds-year) . "%b %d")
(t . "%b %d %Y")))
(setq gnus-summary-line-format
":%U%R | %d%13&user-date; %-13,13f (%5k) | %B %s %-120= \n")
(setq gnus-article-sort-functions '(not gnus-article-sort-by-date))
(setq gnus-agent t)
(setq gnus-agent-expire-days 90)
; prompt for how many articles only for larger than 1000 articles
(setq gnus-large-newsgroup 1000)
(setq gnus-use-cache t)
(setq gnus-fetch-old-headers 1) ; show previous messages in a thread
(setq gnus-thread-indent-level 1)
(setq gnus-show-threads t)
(add-hook 'gnus-summary-prepare-hook 'gnus-summary-hide-all-threads)
(add-hook 'message-mode-hook 'orgstruct-mode)
)kimim utils
(use-package kimim
:defer 5
:ensure nil
:bind
("<f9>" . kimim/cyg)
("S-<f9>" . kimim/cmd)
("<f10>" . kimim/dc)
("C-c r" . kimim/rename-file-and-buffer)
("C-x m o" . kimim/open-in-external-app)
("C-c d" . kimim/lookinsight)
:load-path "~/kimim-emacs/site-lisp/"
)Key Binding
(bind-key "<f1>" 'delete-other-windows)
(bind-key "C-<f1>" 'nuke-other-buffers)
(bind-key "<f2>" 'other-window)
(bind-key "<f5>" (lambda()
(interactive)
(switch-to-buffer "*scratch*") (delete-other-windows)))
;;(bind-key "<f7>" 'kimim/toggle-highlight-tap)
;;(bind-key "<f8>" (lambda()
;; (interactive) (list-charset-chars 'ascii)))
(bind-key "<f7>" 'bury-buffer)
(bind-key "<f8>" 'unbury-buffer)
(bind-key "<f12>" 'org-toggle-home-or-office)
;; (bind-key "M-<SPC>" (lambda () (interactive)
;; (insert ?_)))
(bind-key "C-h" 'delete-backward-char)
(bind-key "M-h" 'backward-kill-word)
(bind-key "M-?" 'mark-paragraph)
(bind-key "C-x k" 'kill-this-buffer)
(bind-key "C-x C-v" 'view-file-other-window)
(bind-key "C-c C-o" 'occur)
(bind-key "C-z" 'set-mark-command)
(bind-key "M-o" 'other-window)
(bind-key "M-n" 'next-error)
(bind-key "M-p" 'previous-error)
;;(define-key hs-minor-mode-map "\C-c/" 'hs-toggle-hiding)
(bind-key "M-*" 'pop-tag-mark)
(bind-key "C-c C-/" 'comment-or-uncomment-region)
(bind-key "RET" 'newline-and-indent)
;;(define-key global-map (kbd "<M-S-mouse-1>") 'pop-tag-mark)
;; key bindings
(when (eq system-type 'darwin) ;; mac specific settings
(setq mac-option-modifier 'alt)
(setq mac-command-modifier 'meta)
;; sets fn-delete to be right-delete
(global-set-key [kp-delete] 'delete-char))
(bind-key "C-x m h" 'help)
(bind-key "C-x m c" 'calculator)
(bind-key "C-x m ." 'unbury-buffer)
(bind-key "C-x m ," 'bury-buffer)
(bind-key "C-x m 。" 'unbury-buffer)
(bind-key "C-x m ," 'bury-buffer)
(bind-key "C-x ," 'bury-buffer)
(bind-key "C-x ." 'unbury-buffer)
(bind-key "C-x C-," 'bury-buffer)
(bind-key "C-x C-." 'unbury-buffer)
(bind-key "C-x ," 'bury-buffer)
(bind-key "C-x 。" 'unbury-buffer)
(bind-key "C-x ‘" 'hippie-expand)
(bind-key "C-x ’" 'hippie-expand)Footnotes
[fn:1] http://www.literateprogramming.com/
[fn:2] http://cygwin.com/
[fn:3] http://msys2.github.io/
[fn:4] https://cygwin.com/install.html
[fn:5] https://cygwin.com/faq/faq.html#faq.setup.cli
[fn:6] http://brew.sh/
[fn:7] http://stackoverflow.com/questions/14465330/how-to-run-emacs-in-cli-mode-under-mintty-in-windows
[fn:8] https://www.gnu.org/software/emacs/manual/html_node/emacs/Packages.html
[fn:9] https://github.com/tldr-pages/tldr
[fn:10] https://github.com/kuanyui/tldr.el
[fn:11] https://github.com/ggreer/the_silver_searcher#installation
[fn:12] https://github.com/Wilfred/ag.el
[fn:13] http://www.voidtools.com
[fn:14] http://www.voidtools.com/es.zip
[fn:15] https://github.com/syl20bnr/spacemacs/issues/381
[fn:16] https://github.com/Sarcasm/irony-mode