Skip to content

Latest commit

 

History

History
2868 lines (2292 loc) · 84.3 KB

tnoda.org

File metadata and controls

2868 lines (2292 loc) · 84.3 KB

Emacs 初期化ファイルの本体

ユーティリティ

ディレクトリ構成

prefix

elisp\_dir

(eval (defconst tnoda/elisp-dir (expand-file-name "elisp" tnoda/dotfiles-dir)))

info\_dir

(eval (defconst tnoda/info-dir (expand-file-name "share/info" tnoda/dotfiles-dir)))

src\_dir

(eval (defconst tnoda/src-dir (expand-file-name "src" tnoda/dotfiles-dir)))

bin\_dir

(defconst tnoda/bin-dir (expand-file-name "bin" tnoda/dotfiles-dir))

emacs

~/.emacs.d/bin/emacs

行間を広くする関数 tnoda/increase-line-spacing.

(defun tnoda/increase-line-spacing ()
  (setq line-spacing 4))

tnoda/require-or-package-install-from-url

(defun tnoda/require-or-package-install-from-url (feature url)
  "If feature FEATURE is not loaded, load it. If FEATURE is not
a member of the list `features', then the feature is not loaded;
so install the corresponding package from URL."
  (unless (require feature nil t)
    (-if-let (buf (url-retrieve-synchronously url))
        (progn
          (switch-to-buffer buf)
          (package-install-from-buffer)
          (require feature)))))

Emacs

Emacs 起動したらすぐ eshell を使えるようにする.

(add-hook 'emacs-startup-hook 'eshell)

Expand kill-ring-max to 300

(setq kill-ring-max 300)

Coding system in Windows settings

(when (eq system-type 'windows-nt)
  (setq default-file-name-coding-system 'cp932)
  (setq default-buffer-file-coding-system 'utf-8-unix)
  (setq default-process-coding-system '(cp932-dos . cp932-dos)))

表示

Full Screen; M-F toggles fullscreen.

Originally retrieved from http://www.emacswiki.org/emacs/FullScreen#toc23, on 2013-07-07

(when (or (eq window-system 'mac)
          (eq window-system 'ns)
          (eq window-system 'x))
  (setq ns-use-native-fullscreen nil)
  
  (defun tnoda/toggle-fullscreen ()
    "Toggle full screen"
    (interactive)
    (if (frame-parameter nil 'fullscreen)
        (progn
          (set-frame-parameter nil 'fullscreen nil)
          (set-frame-position (selected-frame) 1 1)
          (set-frame-size (selected-frame) 80 42))
      (set-frame-parameter nil 'fullscreen 'fullboth)))

  (global-set-key (kbd "M-F") 'tnoda/toggle-fullscreen))

s-f でフォント切り替え.

  • デフォルトは Inconsolata + ヒラギノ丸ゴ
  • s-f で拡大・縮小
(defun tnoda/fontset-setup-mac
  ()

  (defvar tnoda/current-fontset 'default)

  (defun tnoda/fontset-mac-default ()
    (set-face-attribute 'default nil
                        :family "Inconsolata"
                        :height 160)
    (set-fontset-font (frame-parameter nil 'font)
                      'japanese-jisx0208
                      (font-spec :family "Hiragino Maru Gothic ProN" :size 16))
    (set-fontset-font (frame-parameter nil 'font)
                      'mule-unicode-0100-24ff
                      (font-spec :family "Ricty" :size 16))
    (set-fontset-font nil
                      '(#x0370 . #x03FF)
                      (font-spec :family "Helvetica" :size 16))
    (setq tnoda/current-fontset 'default))

  (defun tnoda/fontset-mac-retina ()
    (set-face-attribute 'default nil
                        :family "Inconsolata"
                        :height 240)
    (set-fontset-font (frame-parameter nil 'font)
                      'japanese-jisx0208
                      (font-spec :family "Hiragino Maru Gothic ProN" :size 24))
    (set-fontset-font (frame-parameter nil 'font)
                      'mule-unicode-0100-24ff
                      (font-spec :family "Ricty" :size 24))
    (set-fontset-font nil
                      '(#x0370 . #x03FF)
                      (font-spec :family "Helvetica" :size 24))
    (setq tnoda/current-fontset 'retina))

  (defun tnoda/fontset-toggle ()
    (interactive)
    (case tnoda/current-fontset
      ('default
        (tnoda/fontset-mac-retina))
      ('retina
       (tnoda/fontset-mac-default))
      (t
       (error "invalid fontset"))))

  (tnoda/fontset-mac-default)
  (global-set-key (kbd "s-f") 'tnoda/fontset-toggle))

(defun tnoda/fontset-setup-windows
  ()
  (set-face-attribute 'default nil
                      :family "Inconsolata"
                      :height 144)
  (set-fontset-font t 'japanese-jisx0208 (font-spec :family "Meiryo"))
  (set-fontset-font t 'katakana-jisx0201 (font-spec :family "Meiryo"))
  (set-fontset-font t 'japanese-jisx0212 (font-spec :family "Meiryo"))
  (setq face-font-rescale-alist '(("メイリオ" . 0.96))))

(defun tnoda/fontset-setup-ubuntu ()
  (set-face-attribute 'default nil
                      :family "Ricty"
                      :height 120))

(cond ((or (eq window-system 'mac)
           (eq window-system 'ns))
       (tnoda/fontset-setup-mac))
      ((eq window-system 'w32)
       (tnoda/fontset-setup-windows))
      ((eq window-system 'x)
       (tnoda/fontset-setup-ubuntu)))

Solarized-dark theme

(use-package solarized-theme
  :ensure t
  :config
  (setq solarized-use-variable-pitch nil)
  (setq solarized-scale-org-headlines nil)
  (load-theme 'solarized-dark t))

Do manually as follows:

M-x load-theme solarized-dark RET

ツールバーなどを表示しない.

(tooltip-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(menu-bar-mode -1)

起動画面を表示しない.

(setq inhibit-startup-message t)

font-lock を有効にする.

(global-font-lock-mode t)

対応する括弧を表示させる.

(show-paren-mode 1)
(set-face-background 'show-paren-match-face "darkgreen")

モードラインに時刻を表示させる.

(display-time)

モードラインに行番号・列番号を表示させる.

(line-number-mode 1)
(column-number-mode 1)

Highlight a region

(transient-mark-mode 1)
(set-face-foreground 'region "blue")

カーソルを点滅させない.

(blink-cursor-mode -1)

Ediff 関連のバッファを一つにまとめる.

きっと auto-install.el で便利.

(setq ediff-window-setup-function 'ediff-setup-windows-plain)

Define a command to notify trailing whitespaces.

(defun tnoda/enable-show-trailing-whitespaces ()
  (interactive)
  (setq show-trailing-whitespace t))

バッテリー残量を表示する.

(when (eq system-type 'darwin)
  (display-battery-mode 1))

browse-url で Firefox を開く.

(when (eq system-type 'darwin)
  (setq browse-url-browser-function 'browse-url-generic
        browse-url-generic-program "open"
        browse-url-generic-args '("-a" "Firefox")))

C-c w invokes Dictionary.app.

Thanks to http://d.hatena.ne.jp/tunefs/20130212/p1.

(defun tnoda/dictionary ()
  "dictionary.app"
  (interactive)
  (let ((url (concat "dict://" (read-from-minibuffer "" (current-word)))))
    (browse-url url)))
(global-set-key (kbd "C-c w") 'tnoda/dictionary)

キーバインド

Mac OS X’s modifier settings

(when (eq system-type 'darwin)
  (setq mac-option-modifier 'super)
  (setq mac-command-modifier 'meta))

Windows key settings

(when (eq system-type 'windows-nt)
  (setq w32-pass-lwindow-to-system nil)
  (setq w32-lwindow-modifier 'meta))

s-q を無効に.誤爆したときのダメージが大きすぎる (save-buffers-kill-emacs)

(global-unset-key (kbd "s-q"))

C-hdelete-backward-char.

(global-set-key "\C-h" 'delete-backward-char)

C-x o を無効に.

(global-unset-key (kbd "C-x o"))

C-x C-bibuffer.

(global-set-key "\C-x\C-b" 'ibuffer)

M-/hippie-expand.

(global-set-key (kbd "M-/") 'hippie-expand)

C-zeshell.

(global-set-key (kbd "C-z") 'eshell)

C-x C-cserver-edit. 代わりに M-x ZZ で Emacs を終了.

(global-set-key (kbd "C-x C-c") 'server-edit)
(defalias 'ZZ 'save-buffers-kill-emacs)

dired-modeW を押すと wdired-mode になる.

(require 'dired)
(define-key dired-mode-map "W" 'wdired-change-to-wdired-mode)

C-; でウィンドウ切替か水平分割. C-: で垂直分割.

(defun tnoda/other-window-or-split-window-horizontally ()
  (interactive)
  (when (one-window-p) (split-window-horizontally))
  (other-window 1))
(global-set-key (kbd "C-;") 'tnoda/other-window-or-split-window-horizontally)
(global-set-key (kbd "C-:") 'split-window-vertically)

C-M-;follow-mode

(global-set-key (kbd "C-M-;") 'follow-delete-other-windows-and-split)

<f5>compileexecutable-interpret

(defun tnoda/script-p ()
    (and (>= (buffer-size) 2)
         (save-restriction
           (widen)
           (string= "#!" (buffer-substring (point-min) (+ 2 (point-min)))))))
(defun tnoda/compile-or-executable-interpret ()
  (interactive)
  (cond ((tnoda/script-p)
         (call-interactively 'executable-interpret))
        (t
         (call-interactively 'compile))))
(global-set-key (kbd "<f5>") 'tnoda/compile-or-executable-interpret)

C-m で改行してインデント.

(global-set-key (kbd "C-m") 'newline-and-indent)

C-x 4 qtnoda/View-quit-other-window.

(defun tnoda/View-quit-other-window ()
  (interactive)
  (save-selected-window
    (other-window 1)
    (call-interactively 'View-quit)))
(define-key ctl-x-4-map (kbd "q") 'tnoda/View-quit-other-window)

s-atnoda/kill-ring-save-whole-buffer.

(defun tnoda/kill-ring-save-whole-buffer ()
  (interactive)
  (save-excursion
    (copy-region-as-kill (point-min) (point-max))))
(global-set-key (kbd "s-a") 'tnoda/kill-ring-save-whole-buffer)

zap-up-to-char M-z

(require 'misc)
(global-set-key (kbd "M-z") 'zap-up-to-char)

ログと履歴

ログの記録行数を増やす.

(setq message-log-max 10000)

ミニバッファを再帰的に呼び出せるようにする.

(setq enable-recursive-minibuffers t)

履歴を沢山保存する.

(setq history-length 1000)

ミニバッファで入力を取り消しても履歴に残す.

誤取消で入力が失われるのを防ぐため.

(defadvice abort-recursive-edit (before minibuffer-save activate)
  (when (eq (selected-window) (active-minibuffer-window))
    (add-to-history minibuffer-history-variable (minibuffer-contents))))

ファイル内のカーソル位置を記憶する.

(setq-default save-place t)
(require 'saveplace)

カレンダー

現在位置を設定する.

  • calendar-latitude
  • calendar-longitude
  • calendar-location-name
(load "~/.calendar-location.el" t)

スクリプトファイルを保存するときには,モードを実行可能に設定する.

(add-hook 'after-save-hook
          'executable-make-buffer-file-executable-if-script-p)

exec-path

Add /Developer/usr/bin to exec-path.

(add-to-list 'exec-path "/Developer/usr/bin")

exec-path~/.emacs.d/bin を追加する.

(add-to-list 'exec-path tnoda/bin-dir)

exec-path に Homebrew を追加する.

(add-to-list 'exec-path "/opt/homebrew/bin")

exec-path/usr/texbin を追加する.

(add-to-list 'exec-path "/usr/texbin")

GC を減らして軽くする.

(setq gc-cons-threshold (* 16 gc-cons-threshold))

yes/no の代わりに y/n.

(fset 'yes-or-no-p 'y-or-n-p)  

新規ファイルを確認無しに作成する.

(setq confirm-nonexistent-file-or-buffer nil)

ダイアログボックスを使わないようにする.

(setq use-dialog-box nil)
(defalias 'message-box 'message)

キーストロークをエコーエリアに素早く表示する.

(setq echo-keystrokes 0.1)

大きいファイルを開くときの警告を 32 MB 以上にする.

(setq large-file-warning-threshold (* 25 1025 1024))

emacsclient

(server-start)
(setq server-window 'pop-to-buffer)

midnight: 深夜に不急と思われるバッファを消す.

(require 'midnight)

shell-mode のバッファを消すときに確認しない.

(setq kill-buffer-query-functions
      (remq 'process-kill-buffer-query-function
            kill-buffer-query-functions))

インデントにタブを使わない.

(setq-default indent-tabs-mode nil)

圧縮ファイルを読み書きできるようにする.

(auto-compression-mode t)

Narrowing: (C-x n n), (C-x n p) を有効にする.

(put 'narrow-to-region 'disabled nil)

環境変数 MANPATH を設定する.

(setenv "MANPATH" (mapconcat 'identity
                             (list (expand-file-name "shrea/man" tnoda/dotfiles-dir)
                                   "/opt/homebrew/share/man"
                                   "/Developer/usr/share/man"
                                   "/usr/share/man"
                                   "/usr/X11R6/man")
                             ":"))

Search /opt/emacs/share/info and /opt/mew/share/info for Info files

(setq Info-directory-list
      '("/opt/emacs/share/info" "/opt/mew/share/info"))

Unified diff を表示する.

(setq diff-switches "-u")

C-x F, C-x K, C-x V

(find-function-setup-keys)

Conflict したマージファイルを開くときには smerg-mode を有効にする.

(require 'smerge-mode)
(defun tnoda/try-smerge ()
  (save-excursion
    (goto-char (point-min))
    (when (re-search-forward smerge-begin-re nil t)
      (smerge-mode 1))))
(add-hook 'find-file-hook 'tnoda/try-smerge)

Printing

  • Printing by ps-print-buffer-with-faces.
(setq ps-multibyte-buffer 'non-latin-printer)
(setq ps-lpr-command "c:/Program Files/Ghostgum/gsview/gsview32.exe")
(setq ps-lpr-switches nil)
(setq ps-printer-name nil)
(setq ps-printer-name-option nil)
(setq ps-paper-type 'a4)
(setq ps-line-number t)
(setq ps-print-header t)
(setq ps-print-color-p t)

auto-insert

(require 'autoinsert)
(add-hook 'find-file-hook 'auto-insert)

dired

Mac OS X’s ls does not support the --dired option.

(setq dired-use-ls-dired nil)

wdired

(require 'dired)
(define-key dired-mode-map "e" 'wdired-change-to-wdired-mode)

EWW

Block all images by default

(require 'eww)

(defun tnoda/shr-block-all-images ()
    (interactive)
  (setq-local shr-blocked-images ".*"))

(defun tnoda/shr-display-all-images ()
    (interactive)
  (setq-local shr-blocked-images nil))

(add-hook 'eww-mode-hook 'tnoda/shr-block-all-images)

flyspell-mode

Configure aspell

  • aspell を使う.
  • 英語日本語混じりの文章でエラーが出ないようなおまじない (ispell-skip-region-alist).
(setq-default ispell-program-name "aspell")
(eval-after-load "ispell"
  '(add-to-list 'ispell-skip-region-alist '("[^\000-\377]+")))
  • Configure .aspell.conf
lang en_US

C-M-$ispell-buffer.

(global-set-key (kbd "C-M-$") 'ispell-buffer)

Bind flyspell-auto-correct-binding to s-;

(setq flyspell-auto-correct-binding (kbd "s-;"))

Enable flyspell-mode in text buffers

(--map (add-hook it 'flyspell-mode)
       '(markdown-mode-hook
         gfm-mode-hook
         org-mode-hook
         text-mode-hook
         latex-mode-hook))

Disable VIPER

(setq viper-mode nil)

Global

generic-x.el

(require 'generic-x)

imenu.el

(require 'imenu)
(setq imenu-max-item-length 80)

subword-mode

(defun tnoda/subword-mode-enable ()
  (subword-mode 1))

sequential-commmand.el

(tnoda/require-or-package-install-from-url
 'sequential-command
 "https://gist.githubusercontent.com/tnoda/49797ef440b7a2166986/raw/sequential-command.el")
(use-package sequential-command
  :ensure t
  :pin manual)

(define-sequential-command sequential-command:home
  beginning-of-line beginning-of-buffer sequential-command:return)
(define-sequential-command sequential-command:end
  end-of-line end-of-buffer sequential-command:return)

(defun tnoda/sequential-command:upcase-backward-word ()
  (interactive)
  (upcase-word (- (1+ (sequential-command:count)))))
(defun tnoda/sequential-command:capitalize-backward-word ()
  (interactive)
  (capitalize-word (- (1+ (sequential-command:count)))))
(defun tnoda/sequential-command:downcase-backward-word ()
  (interactive)
  (downcase-word (- (1+ (sequential-command:count)))))

(when (require 'org nil t)
  (define-sequential-command org-sequential-command:home
    org-beginning-of-line beginning-of-buffer sequential-command:return)
  (define-sequential-command org-sequential-command:end
    org-end-of-line end-of-buffer sequential-command:return))

(defun tnoda/sequential-command-setup-keys ()
  "Rebind C-a, C-e, M-u, M-c, and M-l to sequential-command:* commands.
  If you use `org-mode', rebind C-a and C-e."
  (interactive)
  (global-set-key "\C-a" 'sequential-command:home)
  (global-set-key "\C-e" 'sequential-command:end)
  (global-set-key "\M-u" 'tnoda/sequential-command:upcase-backward-word)
  (global-set-key "\M-c" 'tnoda/sequential-command:capitalize-backward-word)
  (global-set-key "\M-l" 'tnoda/sequential-command:downcase-backward-word)
  (when (require 'org nil t)
    (define-key org-mode-map "\C-a" 'org-sequential-command:home)
    (define-key org-mode-map "\C-e" 'org-sequential-command:end)))

(tnoda/sequential-command-setup-keys)

uniquify.el

ファイル名が同じファイルを複数開いたときに, バッファ名にディレクトリ名を含めて区別しやすくする.

(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
(setq uniquify-ignore-buffers-re "*[^*]+*")

direx.el

(use-package direx
  :ensure t
  :config
  (define-key dired-mode-map (kbd "b") 'direx:jump-to-directory)
  (define-key direx:direx-mode-map (kbd "b") 'dired-jump))

dired-x

(when (eq system-type 'windows-nt)
  (require 'dired-open)
  (setq dired-open-functions '(dired-open-guess-shell-alist))
  (let ((re (->> '("xlsx?" "pptx?" "docx?" "pdf" "jpg" "png" "bmp")
              (--map (concat "\\." it "\\'"))
              (-interpose "\\|")
              (apply 'concat))))
    (add-to-list 'dired-guess-shell-alist-user `(,re . ("explorer.exe")))))

ido.el

(ido-mode 1)
(ido-everywhere 1)
(setq ido-slow-ftp-hosts '("ssh"))
(setq ido-create-new-buffer 'always)
(setq ido-file-extensions-order '(".org" ".rb"))
(setq ido-enable-flex-matching t)

C-x C-f で URL を開く (ido-use-url-at-pint).

(setq ido-use-url-at-point t)

recentf-ext.el

(use-package recentf-ext
  :ensure t
  :bind
  ("C-@" . recentf-open-files)
  :config
  (setq recentf-max-saved-items 3000)
  (setq recentf-exclude '("/TAGS$" "/tmp/$" "\.html$" "/work/$" "/\.emacs\.bmk$" "~$"))
  (setq tnoda/recentf-exclude-org 
        (list
         "org_archive$"
         "/mobileorg.org$"
         "/COMMIT_EDITMSG$"
         (expand-file-name "~/diary")
         (expand-file-name "~/org/main\.org")
         (expand-file-name "~/org/notes\.org")))
  (setq recentf-exclude (append recentf-exclude tnoda/recentf-exclude-org))
  (remove-hook 'dired-mode-hook 'recentf-add-dired-directory))

bookmark.el

ファイル内の特定位置をマークする.

  • ブックマークに変更があれば即保存 (bookmark-save-flag).
  • 最近使ったブックマークを燁に持ってくる (tnoda/bookmark-arrange).
(setq bookmark-save-flag 1)
(setq bookmark-sort-flag nil)
(defun tnoda/bookmark-arrange ()
  (let ((latest (bookmark-get-bookmark bookmark)))
    (setq bookmark-alist (cons latest (delq latest bookmark-alist))))
  (bookmark-save))
(add-hook 'bookmark-after-jump-hook 'tnoda/bookmark-arrange)

auto-save-buffers-enhanced.el

(use-package auto-save-buffers-enhanced
  :ensure t
  :config
  (auto-save-buffers-enhanced t)
  (setq auto-save-buffers-enhanced-interval 3)
  (setq auto-save-buffers-enhanced-quiet-save-p t))

sense-region.el

C-SPC 連打で選択範囲が広がっていく.マークとポイントが対角線の矩形を選択できる.

(tnoda/require-or-package-install-from-url
 'sense-region
 "https://gist.githubusercontent.com/tnoda/1776988/raw/f1421879e6f9c96a1a0b9708bc8da0378f30e22b/sense-region.el")
(sense-region-on)

C-SPC 連打で mark-word できるので,=M-@= を無効にする.あまり使わないし.

  • Note taken on [2012-01-18 Wed 10:21]
    M-@ は特等席すぎるので,他で使うことにする.anything にしようかな...
(global-unset-key (kbd "M-@"))

goto-chg.el

(use-package goto-chg
  :ensure t)

Require

(require 'goto-chg)

C-< でカーソルを最後の編集場所に戻す (goto-last-change).

(global-set-key (kbd "C-<") 'goto-last-change)

C-> でカーソルを次の編集場所に進める (goto-last-change-reverse).

(global-set-key (kbd "C->") 'goto-last-change-reverse)

company-mode

(use-package company
  :ensure t
  :config

  ;; Retrieved from https://github.com/nsf/gocode/tree/master/emacs-company
  (setq company-tooltip-limit 20)
  (setq company-idle-delay .7)
  (setq company-echo-delay 0)
  (setq company-begin-commands '(self-insert-command))

  ;; Also retrieved from https://github.com/nsf/gocode/tree/master/emacs-company
  (custom-set-faces
   '(company-preview
     ((t (:foreground "darkgray" :underline t))))
   '(company-preview-common
     ((t (:inherit company-preview))))
   '(company-tooltip
     ((t (:background "lightgray" :foreground "black"))))
   '(company-tooltip-selection
     ((t (:background "steelblue" :foreground "white"))))
   '(company-tooltip-common
     ((((type x)) (:inherit company-tooltip :weight bold))
      (t (:inherit company-tooltip))))
   '(company-tooltip-common-selection
     ((((type x)) (:inherit company-tooltip-selection :weight bold))
      (t (:inherit company-tooltip-selection))))))

paredit.el

(use-package paredit
  :ensure t
  :config
  (progn
    (setq parens-require-spaces nil)
    (add-hook 'emacs-lisp-mode-hook 'enable-paredit-mode)
    (add-hook 'lisp-interaction-mode-hook 'enable-paredit-mode)
    (add-hook 'lisp-mode-hook 'enable-paredit-mode)
    (add-hook 'ielm-mode-hook 'enable-paredit-mode)))

open-junk-file.el

(use-package open-junk-file
  :ensure t)

Junk files will go to ~/.junk/.

(setq open-junk-file-format "~/.junk/%Y%m%d-%H%M%S.")

C-x f opens a new junk file.

(global-set-key (kbd "C-x f") 'open-junk-file)

text-adjust.el

(tnoda/require-or-package-install-from-url
 'mell
 "https://gist.githubusercontent.com/tnoda/dedb18a47780e9a50983/raw/eb99fe55f813f14b75009923301033cb17d601c2/mell.el")
(tnoda/require-or-package-install-from-url
 'text-adjust
 "https://gist.githubusercontent.com/tnoda/dedb18a47780e9a50983/raw/eb99fe55f813f14b75009923301033cb17d601c2/text-adjust.el")

kinsoku-ascii がいつのまにか kinsoku.el から無くなっているので定義.

(require 'text-adjust)
(defvar kinsoku-ascii t "Do kinsoku-shori for ASCII.")

M-qtext-adjust-* する.=C-u M-q= で *-buffer. C-u C-u M-qfill だけ.

(defun tnoda/text-adjust (arg)
  (interactive "p")
  (case arg
    (16
     (call-interactively 'text-adjust-fill))
    (4
     (call-interactively 'text-adjust-codecheck-buffer)
     (call-interactively 'text-adjust-hankaku-buffer)
     (call-interactively 'text-adjust-space-buffer)
     (call-interactively 'text-adjust-fill-buffer))
    (t
     (call-interactively 'text-adjust-codecheck)
     (call-interactively 'text-adjust-hankaku)
     (call-interactively 'text-adjust-space)
     (call-interactively 'text-adjust-fill))))
(global-set-key (kbd "M-q") 'tnoda/text-adjust)

左マージンを考慮する.

(setq adaptive-fill-regexp "[ \t]*")
(setq adaptive-fill-mode t)

?と!とを半角へ変換しないようにする.

(setq text-adjust-hankaku-except "?!@ー〜、,。.")

smartparens

(use-package smartparens
  :ensure t
  :config
  (require 'smartparens-config)
  (sp-use-paredit-bindings))

YASnippet

Use YASnippet as a non-global minor mode.

(use-package yasnippet
  :ensure t
  :config
  (yas-reload-all))

visual-regexp

(use-package visual-regexp
  :ensure t
  :config
  (global-set-key (kbd "C-M-%") 'vr/query-replace))

ace-isearch

(use-package ace-isearch
  :ensure t
  :config
  (global-ace-isearch-mode 1))

avy

(use-package avy
  :ensure t
  :config
  (global-set-key (kbd "C-c j") 'avy-goto-word-or-subword-1))

ace-link

(use-package ace-link
  :ensure t
  :config
  (ace-link-setup-default)
  (require 'org)
  (define-key org-mode-map (kbd "C-c M-o") 'ace-link-org))

flycheck

(use-package flycheck
  :ensure t)

hydra

(use-package hydra
  :ensure t)

EasyPG

(require 'epa)
(setq epa-file-encrypt-to user-mail-address)

Eshell

Plan 9 Smart Shell

(require 'eshell)
(require 'em-smart)
(setq eshell-where-to-jump 'begin)
(setq eshell-review-quick-commands nil)
(setq eshell-smart-space-goes-to-end t)

Bind cycle-buffer to C-z in eshell-mode.

Pressing C-z toggles between an eshell buffer and another.

(defun tnoda/eshell-toggle-key ()
  (define-key eshell-mode-map (kbd "C-z") 'bs-cycle-previous))
(add-hook 'eshell-mode-hook 'tnoda/eshell-toggle-key)

プロンプトの色を変える.

(require 'em-prompt)
(set-face-foreground 'eshell-prompt "cyan")

eshell-z

(use-package eshell-z
  :ensure t)

eshell-git-prompt

(use-package eshell-git-prompt
  :ensure t
  :config
  (eshell-git-prompt-use-theme 'git-radar))

Shell-mode

Suppress echo-backs

(add-hook 'shell-mode-hook
          (lambda ()
            (setq comint-process-echoes t)))

Pcomplete

Git ブランチのリストを返す関数 tnoda/git-branches.

(defun tnoda/git-branches ()
    (split-string (shell-command-to-string "git branch | sed -e 's/[ *]*//'")))

Git でステータス変更があったファイルのリストを返す関数 tnoda/git-modified-files.

(defun tnoda/git-modified-files ()
    (split-string (shell-command-to-string "git status -s | sed -e 's/^.. *//'")))

m (git merge へのエイリアス) を補完する.

(defun pcomplete/m ()
  "Completion for `m' (`git merge')"
  (pcomplete-here* (tnoda/git-branches)))

co (git checkout へのエイリアス) を補完する.

(defun pcomplete/co ()
  "Completion for `co' (`git checkout')"
  (pcomplete-here* (tnoda/git-branches)))

bd (git branch -d へのエイリアス) を補完する.

(defun pcomplete/bd ()
  "Completion for `bd' (`git branch -d')"
  (pcomplete-here* (tnoda/git-branches)))

a (git add -p へのエイリアス) を補完する.

(defun pcomplete/a ()
  "Completion for `a' (`git add -p')"
  (while (pcomplete-here (tnoda/git-modified-files))))

git addgit rm とをを補完する.

git add は新規ファイルの追加にのみ使用する.既存ファイルのステージングは a.

(defun tnoda/git-untracked-files ()
  (split-string (shell-command-to-string "git status -s -u | sed -e 's/^...//'")))

(defconst pcmpl-git-commands
  '("add" "bisect" "branch" "checkout" "clone"
    "commit" "diff" "fetch" "grep"
    "init" "log" "merge" "mv" "pull" "push" "rebase"
    "reset" "rm" "show" "status" "tag" )
  "List of `git' commands")

(defun pcomplete/git ()
  "Completion for `git'"
  ;; Completion for the command argument.
  (pcomplete-here* pcmpl-git-commands)  
  ;; complete files/dirs forever if the command is `add' or `rm'
  (cond
   ((pcomplete-match (regexp-opt '("add") ))
    (while (pcomplete-here (tnoda/git-untracked-files))))
   ((pcomplete-match (regexp-opt '("rm" "reset" "mv")) 1)
    (while (pcomplete-here (pcomplete-entries))))))

d (git diff へのエイリアス) を補完する.

(defun tnoda/git-unstaged-files ()
  "Return a list of files which are modified but unstaged."
  (split-string (shell-command-to-string "git status -s | egrep '^.M' | sed -e 's/^.M //'")))

(defun pcomplete/d ()
  "Completion for `d' (`git diff')."
  (while (pcomplete-here (tnoda/git-unstaged-files))))

dc (git diff --cached へのエイリアス) を補完する.

(defun tnoda/git-staged-files ()
  "Return a list of staged files."
  (split-string (shell-command-to-string "git status -s | egrep '^M' | sed -e 's/^M.//'")))

(defun pcomplete/dc ()
  "Completion for `dc' (`git diff')."
  (while (pcomplete-here (tnoda/git-staged-files))))

SKK

C-x C-jskk-mode.

(use-package skk
  :ensure ddskk
  :config
  (define-key ctl-x-map (kbd "C-j") 'skk-mode))

C-\ でも skk-mode.

(global-set-key (kbd "C-\\") 'skk-mode)

~/.skk.el の設定

  • skk-large-jisyo
  • skk-server-host
  • skk-server-portnum
  • skk-dcomp-activate
  • skk-today / skk-clock で西暦表示 (skk-data-ad).
  • 読点句点の代わりに,「,」「.」を使う (skk-rom-kana-rule-list).
  • アノテーションを表示する (skk-show-annotation).
  • 見出し語と送り仮名が一致した候補を優先表示 (skk-henkan-strict-okuri-precedence).
  • 半角カナの入力規則を有効に (skk-use-jisx0201-input-method).

Migemo

C/Migemo を使う.

(use-package migemo
  :ensure t
  :config
  (setq migemo-command "cmigemo")
  (setq migemo-options '("-q" "--emacs"))
  (setq migemo-dictionary "/opt/homebrew/Cellar/cmigemo/20110227/share/migemo/utf-8/migemo-dict")
  (setq migemo-user-dictionary nil)
  (setq migemo-regex-dictionary nil)
  (setq migemo-coding-system 'utf-8-unix)
  (load-library "migemo")
  (migemo-init)
  (setq search-whitespace-regexp nil))

Mail/News/WWW

Mew

Install script

cd src
curl http://mew.org/Release/mew-6.7.tar.gz | tar zxf -
cd mew-6.7
./configure --prefix=/opt/mew --with-emacs=/opt/emacs/bin/emacs
make
make install
make install-info
make install-jinfo

Windows

(when (eq system-type 'windows-nt)
  (defconst tnoda/mew-windows-dir
    (expand-file-name "mew-6.6" tnoda/src-dir))
  (add-to-list 'load-path tnoda/mew-windows-dir))

Mac OS X/Ubuntu

(when (or (eq system-type 'darwin)
          (eq system-type 'gnu/linux))
  (defconst tnoda/mew-prefix "/opt/mew")
  (add-to-list 'load-path
               (expand-file-name "share/emacs/site-lisp/mew"
                                 tnoda/mew-prefix))
  (add-to-list 'exec-path
               (expand-file-name "bin"
                                 tnoda/mew-prefix)))

最小限の設定

mail-user-agentsimple.el で,=define-mail-user-agent= は subr.el で,それぞれ定義されている.

(require 'mew)
(require 'simple)
(setq mail-user-agent 'mew-user-agent)
(define-mail-user-agent
  'mew-user-agent
  'mew-user-agent-compose
  'mew-draft-send-message
  'mew-draft-kill
  'mew-send-hook)

Cache passwords

(setq mew-use-cached-passwd t)

起動時にくるくる回らない.

(setq mew-demo nil)

起動時にメールを取得しない.

(setq mew-auto-get nil)

引用ラベルを簡潔にする.

(setq mew-cite-fields '("From:"))
(setq mew-cite-format "%s writes:\n")

Summary モードでは本文は不要なので,その分 subject を広くとる.

(setq mew-summary-form '(type (5 date) " " (18 from) " " t (0 subj)))

転送時に Received:Return-Path: をヘッダから削る.

(setq mew-field-delete-for-forwarding '("Received:" "Return-Path:"))

GnuPG を使う.

(setq mew-prog-pgp "gpg")

証明書の検証に失敗したり,証明書が無かったりする場合には SSL/TLS 接続しない.

(setq mew-ssl-verify-level 2)

添付ファイルのデフォルトの保存先は ~/tmp.

(setq mew-save-dir "~/tmp/")

用事が済んだらすぐに SSH 接続を切る.

(setq mew-ssh-keep-connection nil)

Hyper Estraier で検索する.

(setq mew-search-method 'est)

Use stunnel4 on Ubunte 14.04

(when (eq system-type 'gnu/linux)
  (setq mew-prog-ssl "stunnel4"))

Set mew-ssl-cert-directory on Mac OS X

(when (eq system-type 'darwin)
  (setq mew-ssl-cert-directory (expand-file-name ".certs" (getenv "HOME"))))

draftmessage とでは行間を広く表示する.

(add-hook 'mew-draft-mode-hook 'tnoda/increase-line-spacing)
(add-hook 'mew-message-mode-hook 'tnoda/increase-line-spacing)

draft-mode で Org のテーブル記法と箇条書きを有効にする.

(add-hook 'mew-draft-mode-hook 'turn-on-orgstruct++)
(add-hook 'mew-draft-mode-hook 'turn-on-orgtbl)

.mew.el の設定.

  • mew-refile-guess-alist
  • mew-config-alist

Lang

Clojure

Leiningen has been installed in ~/lein.

(add-to-list 'exec-path (expand-file-name ".lein" "~/"))

clojure-mode

(use-package clojure-mode
  :ensure t
  :config
  (define-key clojure-mode-map (kbd "C-:") nil)
  (defun tnoda/clojure-mode-hook ()
    (put-clojure-indent 'for-all 1)     ; for clojure.test.check
    (enable-paredit-mode)
    (subword-mode 1)
    (yas-minor-mode)
    (flyspell-prog-mode)
    (setq show-trailing-whitespace t)
    (setq buffer-save-without-query t))
  (add-hook 'clojure-mode-hook 'tnoda/clojure-mode-hook))

Yasnippet helper functions.

(defun tnoda/lein-root (&optional dir)
  (interactive)
  (setq dir (or dir default-directory))
  (if (file-exists-p (expand-file-name "project.clj" dir))
      (expand-file-name dir)
    (let ((new-dir (expand-file-name (file-name-as-directory "..") dir)))
      (unless (string-match "\\(^[[:alpha:]]:/$\\|^/[^\/]+:/?$\\|^/$\\)" dir)
        (tnoda/lein-root new-dir)))))

(defun tnoda/lein-guess-namespace ()
  "Return the clojure namespace associated with the current buffer."
  (interactive)
  (replace-regexp-in-string "_" "-" (replace-regexp-in-string "/" "." (substring (file-name-sans-extension buffer-file-name)
                                                                                 (+ 4 (length (tnoda/lein-root)))))))

CIDER

(use-package cider
  :ensure t
  :pin melpa-stable
  :config
  (setq cider-repl-history "~/.emacs.d/cider-repl-history")
  (setq cider-repl-use-pretty-printing t)
  (setq cider-repl-use-clojure-font-lock nil)
  (setq cider-repl-wrap-history t)
  (setq cider-repl-history-size 3000)
  (add-hook 'cider-mode-hook 'cider-turn-on-eldoc-mode)
  (add-hook 'cider-repl-mode-hook 'tnoda/clojure-mode-hook))

company-mode

(add-hook 'cider-mode-hook 'company-mode)
(add-hook 'cider-repl-mode-hook 'company-mode)

Inferior Lisp Mode

Enable paredit-mode in inferior-lisp-mode.

(add-hook 'inferior-lisp-mode-hook 'enable-paredit-mode)

M-x run-lisp で Clojure の REPL.

(setq inferior-lisp-program (expand-file-name "~/.lein/lein repl"))

inferior-lisp-mode で paredit に []{} も括弧扱いさせる.

via http://stackoverflow.com/questions/8598116/paredit-curly-brace-matching-in-swank-clojure-repl

(defun tnoda/curly-brace-matching-fix ()
  (modify-syntax-entry ?\{ "(}")
  (modify-syntax-entry ?\} "){")
  (modify-syntax-entry ?\[ "(]")
  (define-key inferior-lisp-mode-map
    (kbd "DEL") 'paredit-backward-delete)
  (define-key inferior-lisp-mode-map
    (kbd "{") 'paredit-open-curly)
  (define-key inferior-lisp-mode-map
    (kbd "}") 'paredit-close-curly)
  (modify-syntax-entry ?\] ")[")
  (modify-syntax-entry ?~ "'   ")
  (modify-syntax-entry ?, "    ")
  (modify-syntax-entry ?^ "'")
  (modify-syntax-entry ?= "'"))

(add-hook 'inferior-lisp-mode-hook 'tnoda/curly-brace-matching-fix)

Ruby

ruby-mode

(require 'ruby-mode)

smartparens-ruby

(require 'smartparens-ruby)
(add-hook 'ruby-mode-hook 'smartparens-strict-mode)

~/.rbenv/shimsexec-path に追加する.

(add-to-list 'exec-path (expand-file-name "~/.rbenv/shims"))

ruby-mode

(defun tnoda/ruby-mode-hook ()
  (electric-pair-mode -1)
  (electric-indent-mode 1)
  (electric-layout-mode 1)
  (subword-mode 1)
  (setq show-trailing-whitespace t)
  (outline-minor-mode 1)
  (setq outline-regexp " *\\(def \\|class\\|module\\|describe \\|it \\)"))

(add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.rake$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.gemspec$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.ru$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Rakefile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Gemfile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Capfile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Vagrantfile$" . ruby-mode))
(add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode))
(setq ruby-use-encoding-map nil)
(setq ruby-deep-indent-paren-style nil)
(setq ruby-insert-encoding-magic-comment nil)
(add-hook 'ruby-mode-hook 'tnoda/ruby-mode-hook)

Bind ruby-interpolate to #.

(defun ruby-interpolate ()
  "In a double quoted string, interpolate."
  (interactive)
  (insert "#")
  (when (and
         (looking-back "\".*")
         (looking-at ".*\""))
    (insert "{}")
    (backward-char 1)))

(define-key ruby-mode-map (kbd "#") 'ruby-interpolate)

inf-ruby

(use-package inf-ruby
  :ensure t
  :config
  (progn
    (add-to-list 'inf-ruby-implementations '("pry" . "pry -Ilib"))
    (setq inf-ruby-default-implementation
          (cond ((eq system-type 'darwin)
                 (progn
                   (setq inf-ruby-first-prompt-pattern
                         "^\\[[0-9]+\\] pry\\((.*)\\)> *")
                   (setq inf-ruby-prompt-pattern
                         "^\\[[0-9]+\\] pry\\((.*)\\)[>*\"'] *")
                   "pry"))
                (t "ruby")))))

C-mreindent-then-newline-and-indent に設定.

(define-key ruby-mode-map (kbd "RET") 'reindent-then-newline-and-indent)

ruby-modeC-M-atnoda/ruby-beginning-of-defun.

(defun tnoda/ruby-beginning-of-defun ()
  "Move backward to the beginning of the current defun"
  (interactive)
  (and (re-search-backward "\\bdef\\b" nil t)
       (beginning-of-line)))

(define-key ruby-mode-map (kbd "C-M-a") 'tnoda/ruby-beginning-of-defun)

ruby-modeC-M-etnoda/ruby-end-of-defun.

(defun tnoda/ruby-beginning-of-defun-indent-level ()
  (save-excursion
    (end-of-line)
    (when (re-search-backward "^\\( *\\)def\\b" nil t)
      (length (match-string 1)))))

(defun tnoda/ruby-end-of-defun ()
  "Move forward to the end of the current defun"
  (interactive)
  (let ((current-indent-level (tnoda/ruby-beginning-of-defun-indent-level)))
    (and current-indent-level
         (re-search-forward (concat "^"
                                    (make-string current-indent-level 32)
                                    "end\\b")
                            nil t)
         (forward-line 1))))

(define-key ruby-mode-map (kbd "C-M-e") 'tnoda/ruby-end-of-defun)

ruby-modeC-M-htnoda/ruby-mark-defun.

(defun tnoda/ruby-mark-defun ()
  "Put mark at the end of the current defun, point at the beginning"
  (interactive)
  (flet ((ruby-beginning-of-defun (&optional arg) (tnoda/ruby-beginning-of-defun))
         (ruby-end-of-defun (&optional arg) (tnoda/ruby-end-of-defun)))
    (call-interactively 'mark-defun)))

(define-key ruby-mode-map (kbd "C-M-h") 'tnoda/ruby-mark-defun)

align-rules-list. M-x align でコンマ区切りとハッシュを整列.

(require 'align)
(add-to-list 'align-rules-list
             '(ruby-comma-delimiter
               (regexp . ",\\(\\s-*\\)[^# \t\n]")
               (repeat . t)
               (modes  . '(ruby-mode))))
(add-to-list 'align-rules-list
             '(ruby-hash-literal
               (regexp . "\\(\\s-*\\)=>\\s-*[^# \t\n]")
               (repeat . t)
               (modes  . '(ruby-mode))))

Markdown

(use-package markdown-mode
  :ensure t)

Use the markdown command located in /opt/homebew/bin

(defun tnoda/markdown-custom ()
  "markdown-mode-hook"
  (setq markdown-command (expand-file-name "markdown" "/opt/homebrew/bin")))
(add-hook 'markdown-mode-hook 'tnoda/markdown-custom)

.text なファイルは markdown-mode で開く.

(add-to-list 'auto-mode-alist '("\\.text" . markdown-mode))

.md なファイルは gfm-mode で開く.

gfm-mode なファイルには,特製の bin/gfm を使う.

(add-to-list 'auto-mode-alist '("\\.md" . gfm-mode))

<S-tab>markdown-shifttab.

デフォルトでは markdown-shifttab<S-iso-lefttab> に割り当てられ ているため.

(defun tnoda/markdown-shifttab-fix ()
  "Bind `markdown-shifttab' to <S-tab>"
  (local-set-key (kbd "<S-tab>") 'markdown-shifttab))

(add-hook 'markdown-mode-hook 'tnoda/markdown-shifttab-fix)
(add-hook 'gfm-mode-hook 'tnoda/markdown-shifttab-fix)

Graphviz

(use-package graphviz-dot-mode
  :ensure t
  :config
  (setq graphviz-dot-indent-width 2))

Python

Yasnippet

(add-hook 'python-mode-hook 'yas-minor-mode)

pdb

(setq gud-pdb-command-name
      (expand-file-name ".pyenv/versions/anaconda-2.3.0/lib/python2.7/pdb.py"
                        (getenv "HOME")))

Jedi.el

(use-package jedi
  :ensure t
  :config
  (add-hook 'python-mode-hook 'jedi:setup)
  (setq jedi:complete-on-dot t)
  (require 'python)
  (define-key python-mode-map (kbd "M-.") 'jedi:goto-definition)
  (define-key python-mode-map (kbd "M-,") 'jedi:goto-definition-pop-marker)
  (setq python-shell-completion-native nil))

(use-package company-jedi
  :ensure t
  :config
  (defun tnoda/turn-on-company-jedi ()
    (add-to-list 'company-backends 'company-jedi))
  (add-hook 'python-mode-hook 'tnoda/turn-on-company-jedi))

EIP: Emacs IPython Notebook

(use-package ein
  :ensure t
  :config
  (add-hook 'ein:connect-mode-hook 'ein:jedi-setup))

Flycheck

(require 'python)

(defun tnoda/turn-on-flycheck-mode ()
  (flycheck-mode 1))
(add-hook 'python-mode-hook 'tnoda/turn-on-flycheck-mode)

Smartparens

(require 'python)
(add-hook 'python-mode-hook 'turn-on-smartparens-strict-mode)

Golang

go-mode/gocode

(defvar tnoda/gopath (expand-file-name "go" (getenv "HOME")))
(defvar tnoda/gopath-bin (expand-file-name "bin" tnoda/gopath))

(setenv "GOPATH" tnoda/gopath)
(setenv "PATH" (concat (getenv "PATH") ":" tnoda/gopath-bin))
(add-to-list 'exec-path tnoda/gopath-bin)

(use-package go-mode
  :ensure t
  :mode "\\.go\\'"
  :config
  (defun tnoda/gofmt-before-save ()
    "The original version of go-fmt may break the kill-region function,
if it has an advised version."
    (interactive)
    (when (eq major-mode 'go-mode)
      (sense-region-off)
      (gofmt)
      (sense-region-on)))

  (add-hook 'before-save-hook 'tnoda/gofmt-before-save)
  (add-hook 'go-mode-hook 'turn-on-smartparens-strict-mode)
  (add-hook 'go-mode-hook 'tnoda/increase-line-spacing)
  (add-hook 'go-mode-hook 'subword-mode)
  (add-hook 'go-mode-hook 'yas-minor-mode)

  (define-key go-mode-map (kbd "M-.") 'godef-jump)
  (define-key go-mode-map (kbd "M-,") 'pop-tag-mark)
  (define-key go-mode-map (kbd "C-c C-j") 'go-goto-imports)
  (define-key go-mode-map (kbd "C-c C-d") 'godoc)

  (defun tnoda/go-mode-tab-width ()
    (setq tab-width 4))

  (defun tnoda/go-mode-turn-off-auto-save-buffers ()
    (setq-local auto-save-buffers-enhanced-activity-flag nil))

  (add-hook 'go-mode-hook 'tnoda/go-mode-tab-width)
  (add-hook 'go-mode-hook 'tnoda/go-mode-turn-off-auto-save-buffers))

go-eldoc

(use-package go-eldoc
  :ensure t
  :config
  (add-hook 'go-mode-hook 'go-eldoc-setup))

flycheck

(add-hook 'go-mode-hook 'tnoda/turn-on-flycheck-mode)

goimports

https://godoc.org/golang.org/x/tools/cmd/goimports

(setq gofmt-command "goimports")

company-go

https://github.com/nsf/gocode/tree/master/emacs-company

(use-package company-go
  :ensure t
  :init
  (use-package company
    :ensure t)
  :config
  (defun tnoda/enable-company-go ()
    (set (make-local-variable 'company-backends) '(company-go))
    (setq company-go-insert-arguments nil)
    (company-mode))

  (add-hook 'go-mode-hook 'tnoda/enable-company-go))

Go Oracle

https://godoc.org/golang.org/x/tools/oracle

Before you can run the oracle, you must tell Emacs the analysis scope, which is done using the command:

M-x go-oracle-set-scope

This command prompts you for the analysis scope, described above, with words separated by spaces. The effect of go-oracle-set-scope persists across all oracle invocations until it is called again with a different value.

(load (expand-file-name "src/golang.org/x/tools/cmd/oracle/oracle.el"
                        (getenv "GOPATH")))
;; (add-hook 'go-mode-hook 'go-oracle-mode)

Rename

(load (expand-file-name "src/golang.org/x/tools/refactor/rename/go-rename.el"
                        (getenv "GOPATH")))
(define-key go-mode-map (kbd "C-c C-r") 'go-rename)

CSS

indent-offset

(defun tnoda/css-mode-indent-offset ()
  (setq-local css-indent-offset 2))

(add-hook 'css-mode-hook 'tnoda/css-mode-indent-offset)

emmet-mode

(use-package emmet-mode
  :ensure t
  :config
  (setq emmet-indentation 2)

  (defun tnoda/turn-on-emmet-mode ()
    (emmet-mode 1))

  (add-hook 'css-mode-hook 'tnoda/turn-on-emmet-mode)
  (add-hook 'css-mode-hook 'turn-on-smartparens-strict-mode))

ESS (R)

(use-package ess-site
  :ensure ess
  :config
  (add-hook 'inferior-ess-mode-hook 'turn-on-smartparens-mode))

Haskell

(add-to-list 'exec-path (expand-file-name "~/Library/Haskell/bin"))

haskell-mode

(use-package haskell-mode
  :ensure t
  :config
  (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  (add-hook 'haskell-mode-hook 'turn-on-haskell-doc)
  (add-hook 'haskell-mode-hook 'turn-on-smartparens-mode)
  (add-hook 'haskell-mode-hook 'turn-off-pretty-mode)
  (add-hook 'haskell-mode-hook 'turn-on-haskell-decl-scan)
  (define-key haskell-mode-map (kbd "C-,") 'haskell-move-nested-left)
  (define-key haskell-mode-map (kbd "C-.") 'haskell-move-nested-right)
  (define-key haskell-mode-map (kbd "C-c C-c") 'haskell-compile)
  (define-key haskell-mode-map (kbd "C-x C-d") nil)
  (define-key haskell-mode-map (kbd "C-c C-z") 'haskell-interactive-switch)
  (define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-file)
  (define-key haskell-mode-map (kbd "C-c C-b") 'haskell-interactive-switch)
  (define-key haskell-mode-map (kbd "C-c C-t") 'haskell-process-do-type)
  (define-key haskell-mode-map (kbd "C-c C-i") 'haskell-process-do-info)
  (define-key haskell-mode-map (kbd "C-c M-.") nil)
  (define-key haskell-mode-map (kbd "C-c C-d") nil)
  (eval-after-load "which-func"
    '(add-to-list 'which-func-modes 'haskell-mode))
  (eval-after-load "haskell-cabal"
    '(define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-compile)))

ghc

(use-package ghc
  :ensure t
  :pin melpa-stable
  :config
  (autoload 'ghc-init "ghc" nil t)
  (autoload 'ghc-debug "ghc" nil t)
  (add-hook 'haskell-mode-hook 'ghc-init)
  (use-package company-ghc
    :ensure t
    :pin melpa-stable
    :config
    (require 'company)
    (add-to-list 'haskell-mode-hook 'company-mode)
    (add-to-list 'company-backends 'company-ghc)))

C++

Keywords for competitive-programming macros

(font-lock-add-keywords
 'c++-mode
 '(("FOR" . font-lock-keyword-face)
   ("RFOR" . font-lock-keyword-face)
   ("REP" . font-lock-keyword-face)
   ("RREP" . font-lock-keyword-face)
   ("ALL" . font-lock-keyword-face)
   ("1000000007" . font-lock-constant-face)))

company-mode

(add-hook 'c++-mode-hook 'company-mode)

(use-package company-c-headers
  :ensure t
  :config
  (progn
    (when (eq system-type 'darwin)
      (add-to-list 'company-c-headers-path-system
                   "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1"))
    (add-to-list 'company-backends 'company-c-headers)))

google-c-style.el

(use-package google-c-style
  :ensure t
  :config
  (progn
    (add-hook 'c-mode-common-hook 'google-set-c-style)
    (add-hook 'c-mode-common-hook 'google-make-newline-indent)))

Semantic

(require 'cc-mode)
(require 'semantic)

(global-semanticdb-minor-mode 1)
(global-semantic-idle-scheduler-mode 1)

(semantic-mode 1)

(semantic-add-system-include "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1" 'c++-mode)

flycheck

(use-package flycheck
  :ensure t
  :config
  (defun tnoda/c++-mode-hook-flycheck ()
    (flycheck-mode 1)
    (setq flycheck-clang-language-standard "c++11"))
  (add-hook 'c++-mode-hook 'tnoda/c++-mode-hook-flycheck))

flycheck-google-cpplint

(use-package flycheck-google-cpplint
  :ensure t
  :config
  (custom-set-variables
   '(flycheck-c/c++-googlelint-executable
     (expand-file-name "bin/cpplint.py" default-directory))))

smartparens-mode

(add-hook 'c++-mode-hook 'turn-on-smartparens-strict-mode)

Yasnippet

(add-hook 'c++-mode-hook 'yas-minor-mode-on)

auto-insert

(define-auto-insert
  '("\\.\\(CC?\\|cc\\|cxx\\|cpp\\|c++\\)\\'" . "C++ skeleton")
  '("Simple C++ skelton"
    "#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <iomanip>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
typedef long long ll;" \n \n
    _ \n \n
    "int main(int argc, char *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
    
  return 0;
}
" \n))

LaTeX

AUCTeX

(use-package tex-jp
  :ensure auctex
  :config
  (setq TeX-engine-alist '((pdfuptex "pdfupTeX"
                                     "ptex2pdf -u -e -ot '%S %(mode)'"
                                     "ptex2pdf -u -l -ot '%S %(mode)'"
                                     "euptex")))
  (setq japanese-TeX-engine-default 'pdfuptex)
  (setq japanese-LaTeX-default-style "jsarticle")
  (dolist (command '("pTeX" "pLaTeX" "pBibTeX" "jTeX" "jLaTeX" "jBibTeX" "Mendex"))
    (delq (assoc command TeX-command-list) TeX-command-list))
  (setq preview-image-type 'dvipng)
  (setq TeX-source-correlate-method 'synctex)
  (setq TeX-source-correlate-start-server t)
  (add-hook 'LaTeX-mode-hook 'TeX-source-correlate-mode)
  (add-hook 'LaTeX-mode-hook 'TeX-PDF-mode)
  (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)

  (defun tnoda/TeX-command-list-config ()
    (add-to-list 'TeX-command-list
                 '("Latexmk"
                   "latexmk %t"
                   TeX-run-TeX nil (latex-mode) :help "Run Latexmk"))
    (add-to-list 'TeX-command-list
                 '("Latexmk-upLaTeX-pdfdvi"
                   "latexmk -e '$latex=q/uplatex %%O %S %(mode) %%S/' -e '$bibtex=q/upbibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/upmendex %%O -o %%D %%S/' -e '$dvipdf=q/dvipdfmx %%O -o %%D %%S/' -norc -gg -pdfdvi %t"
                   TeX-run-TeX nil (latex-mode) :help "Run Latexmk-upLaTeX-pdfdvi"))
    (add-to-list 'TeX-command-list
                 '("Latexmk-LuaLaTeX"
                   "latexmk -e '$pdflatex=q/lualatex %%O %S %(mode) %%S/' -e '$bibtex=q/upbibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/upmendex %%O -o %%D %%S/' -norc -gg -pdf %t"
                   TeX-run-TeX nil (latex-mode) :help "Run Latexmk-LuaLaTeX"))
    (add-to-list 'TeX-command-list
                 '("Latexmk-XeLaTeX"
                   "latexmk -e '$pdflatex=q/xelatex %%O %S %(mode) %%S/' -e '$bibtex=q/upbibtex %%O %%B/' -e '$biber=q/biber %%O --bblencoding=utf8 -u -U --output_safechars %%B/' -e '$makeindex=q/upmendex %%O -o %%D %%S/' -norc -gg -pdf %t"
                   TeX-run-TeX nil (latex-mode) :help "Run Latexmk-XeLaTeX"))
    (add-to-list 'TeX-command-list
                 '("Skim" "open -a Skim.app '%s.pdf'" TeX-run-command t nil))
    (add-to-list 'TeX-command-list
                 '("Evince"
                   "evince %s.pdf"
                   TeX-run-discard-or-function t t :help "Run Evince")))

  (add-hook 'LaTeX-mode-hook 'tnoda/TeX-command-list-config)


  ;; Skim
  (setq TeX-view-program-list
        '(("Skim"
           "/Applications/Skim.app/Contents/SharedSupport/displayline -b -g %n %o %b")))

  (cond ((eq system-type 'gnu/linux)
         (setq TeX-view-program-selection '((output-pdf "Evince"))))
        ((eq system-type 'darwin)
         (setq TeX-view-program-selection '((output-pdf "Skim")))))
  
  ;; RefTeX
  (add-hook 'LaTeX-mode-hook 'turn-on-reftex)
  (setq reftex-plug-into-AUCTeX t)

  ;; kinsoku.el
  (setq kinsoku-limit 10))

Octave

(require 'octave)
(add-to-list 'auto-mode-alist '("\\.m$" . octave-mode))
(add-hook 'octave-mode-hook
          (lambda ()
            (abbrev-mode 1)
            (auto-fill-mode 1)
            (smartparens-strict-mode 1)
            (if (eq window-system 'x)
                (font-lock-mode 1))))
(add-hook 'inferior-octave-mode-hook
          (lambda ()
            (turn-on-font-lock)
            (define-key inferior-octave-mode-map [up]
              'comint-previous-input)
            (define-key inferior-octave-mode-map [down]
              'comint-next-input)))

Stan

(use-package stan-mode
  :config
  (add-hook 'stan-mode-hook 'smartparens-strict-mode)
  (use-package stan-snippets
    :ensure t
    :config
    (add-hook 'stan-mode-hook '(lambda () (yas-minor-mode t)))))

Helm

(use-package helm
  :ensure t
  :init
  (setq helm-command-prefix-key "C-c h")
  :bind
  ("M-y" . helm-show-kill-ring)
  :config
  (require 'helm-config)
  (require 'helm-mode)
  (require 'helm-eshell)
  (require 'helm-files)
  (require 'helm-grep)
  (require 'helm-info)
  (define-key ctl-x-map (kbd "C-j") 'skk-mode)
  (define-key ctl-x-map (kbd "b") 'helm-mini)
  (define-key helm-command-map (kbd "a") 'helm-apropos)
  (define-key helm-command-map (kbd "i") 'helm-info-emacs)
  (define-key helm-command-map (kbd "l") 'helm-locate)
  (define-key helm-command-map (kbd "m") 'helm-man-woman)
  (define-key helm-command-map (kbd "o") 'helm-occur)
  (define-key helm-command-map (kbd "r") 'helm-resume)
  (define-key helm-command-map (kbd "s") 'helm-semantic-or-imenu)
  (add-to-list 'helm-completing-read-handlers-alist '(find-file . nil))
  (add-to-list 'helm-completing-read-handlers-alist '(execute-extended-command . nil))
  (setq
   helm-google-suggest-use-curl-p t
   helm-scroll-amount 4 ; scroll 4 lines other window using M-<next>/M-<prior>
   helm-quick-update t  ; do not display invisible candidates
   helm-idle-delay 0.01 ; be idle for this many seconds, before updating in delayed sources.
   helm-input-idle-delay 0.01 ; be idle for this many seconds, before updating candidate buffer
   helm-ff-search-library-in-sexp t ; search for library in `require' and `declare-function' sexp.
   helm-split-window-default-side 'other ;; open helm buffer in another window
   )
  (set-face-attribute 'helm-selection
                      'nil
                      :background "DarkGreen"
                      :foreground "Gray94")
  (helm-mode 1)
  )

helm-ls-git

(use-package helm-ls-git
  :ensure t
  :config
  (use-package helm
    :ensure t)
  (define-key helm-command-map (kbd "g") 'helm-ls-git-ls))

helm-gtags

http://tuhdo.github.io/c-ide.html

(use-package helm-gtags
  :ensure t
  :init
  (setq helm-gtags-prefix-key (kbd "C-c ;")
        helm-gtags-suggested-key-mapping t)
  :config
  (use-package helm
    :ensure t)
  (add-hook 'c-mode-hook 'helm-gtags-mode)
  (add-hook 'c++-mode-hook 'helm-gtags-mode)
  (define-key helm-gtags-mode-map (kbd "M-.") 'helm-gtags-dwim)
  (define-key helm-gtags-mode-map (kbd "M-,") 'helm-gtags-pop-stack)
  (define-key helm-gtags-mode-map (kbd "C-c <") 'helm-gtags-previous-history)
  (define-key helm-gtags-mode-map (kbd "C-c >") 'helm-gtags-next-history))

Org Mode

org-mew.el

(require 'org-mew)

Common

Require

(require 'org-habit)

Store per host org files in ~/org/ directory.

(setq org-directory "~/org")

Share org files using Dropbox

(setq tnoda/org-dropbox-directory "~/Dropbox/org")

org-extend-today-until

My day really ends at two o’clock in the morning.

(setq org-extend-today-until 2)

C-,=C-'= に割り当てられる org-cycle-agenda-files を無効にする.

(rassq-delete-all 'org-cycle-agenda-files org-mode-map)

org-edit-special 中は auto-save-buffers を停止する.

(lexical-let ((previous-active-p))
  (defadvice org-edit-src-code (before tnoda/auto-save-buffers-toggle activate)
    "Disable auto-save-buffers."
    (setq previous-active-p  auto-save-buffers-enhanced-activity-flag)
    (setq auto-save-buffers-enhanced-activity-flag nil))
  (defadvice org-edit-src-exit (after tndoa/auto-save-buffers-toggle activate)
    "Recover auto-save-buffers."
    (setq auto-save-buffers-enhanced-activity-flag previous-active-p)))

停止しないと,src ブロックを編集している最中に,

foo.org has changed since visited or saved. Save anyway? (y or n) ! foo.org changed on disk; really edit the buffer? (y, n, r or C-h) File on disk now will become a backup file if you save these changes.

と怒られる.

=code= の face を org-code から font-lock-constant-face に変更する.

(setq org-emphasis-alist
      (cons '("=" font-lock-constant-face "<code>" "</code>" verbatim)
            (remove-if (lambda (x)
                         (equal "=" (car x)))
                       org-emphasis-alist)))

Suppress automatic sub/superscript conversion

(setq org-use-sub-superscripts nil)

見出し入力の改善.

C-M-RETorg-insert-substring

(define-key org-mode-map (kbd "<C-M-return>") 'org-insert-subheading)

C-u C-RET で一レベル下の見出し, C-u C-u C-RET で一レベル上の見出し.

(defun tnoda/org-insert-heading-respect-content (arg)
  (interactive "p")
  (org-insert-heading-respect-content arg)
  (case arg
    (4 (org-do-demote))
    (16 (org-do-promote))))

(define-key org-mode-map (kbd "<C-return>") 'tnoda/org-insert-heading-respect-content)

Link

C-c l で org-store-link.

(global-set-key (kbd "C-c l") 'org-store-link)

Using links outside Org

(global-set-key (kbd "C-c L") 'org-insert-link-global)
(global-set-key (kbd "C-c o") 'org-open-at-point-global)

Refile

main.org のトップレベルに refile できるようにする.

(setq org-refile-targets
      '(("main.org.gpg" . (:level . 1))))

Archive

(setq org-archive-location "%s_archive.gpg::")

TODO

TODO keywords

(setq org-todo-keywords
      '((sequence "TODO(t)" "STARTED(s)" "|" "DONE(d)")
        (sequence "WAITING(w@/!)" "|")
        (sequence "APPT(a)" "|")
        (sequence "|" "CANCELED(c@)")
        (sequence "|" "DEFERRED(f@)")
        (sequence "|" "DELEGATED(g@)")))

Customize Org TODO faces

(defface tnoda/org-todo
  '((t (:foreground "gray" :background "dark red" :bold t)))
  "Font for TODO keywords.")

(defface tnoda/org-started
  '((t (:foreground "gold1" :background "gray10" :bold t)))
  "Font for STARTED keywords.")

(defface tnoda/org-waiting
  '((t (:foreground "gray" :background "green4" :bold t)))
  "Font for WAITING keywords.")

(defface tnoda/org-appt
  '((t (:foreground "gray" :background "DodgerBlue4" :bold t)))
  "Font for APPT keywords")

(setq org-todo-keyword-faces
      '(("TODO" . tnoda/org-todo)
        ("STARTED" . tnoda/org-started)
        ("WAITING" . tnoda/org-waiting)
        ("APPT" . tnoda/org-appt)))

Automatically change to DONE when all children are done.

(defun org-summary-todo (n-done n-not-done)
  "Switch entry to DONE when all subentries are done, to TODO otherwise."
  (let (org-log-done org-log-states)   ; turn off logging
    (org-todo (if (= n-not-done 0) "DONE" "TODO"))))

(add-hook 'org-after-todo-statistics-hook 'org-summary-todo)

Retrieved from info:org#Breaking down tasks

TODO ステータスが STARTED に変化したらクロックを開始する.

(defun sacha/org-clock-in-if-starting ()
  "Clock in when the task is marked STARTED."
  (when (and (string= org-state "STARTED")
             (not (string= org-last-state org-state)))
    (org-clock-in)))
(add-hook 'org-after-todo-state-change-hook
          'sacha/org-clock-in-if-starting)
;; (defadvice org-clock-in (after sacha activate)
;;   "Set this task's status to 'STARTED'."
;;   (org-todo "STARTED"))
(defun sacha/org-clock-out-if-waiting ()
  "Clock in when the task is marked STARTED."
  (when (and (string= org-state "WAITING")
             (not (string= org-last-state org-state)))
    (org-clock-out)))
(add-hook 'org-after-todo-state-change-hook
          'sacha/org-clock-out-if-waiting)

Tags

Globally defined tags

(setq org-tag-persistent-alist '((:startgroup . nil)
                                 ("home" . ?h)
                                 ("office" . ?o)
                                 (:endgroup . nil)
                                 ("computer" . ?c)
                                 ("errands" . ?e)
                                 ("library" . ?l)
                                 ("reading" . ?r)))

Capture

(setq org-default-notes-file (expand-file-name "journal.org.gpg"
                                               tnoda/org-dropbox-directory))
(define-key global-map "\C-cc" 'org-capture)

Templates

(setq org-capture-templates
      '(("j" "Journal" entry (file+datetree "") "* %?   %T\n"
         :prepend t
         :clock-keep t
         :empty-lines 1
         :kill-buffer t)
        ("z" "Break" entry (file+datetree "") "* %?   :break:\n"
         :pretend t
         :clock-in t
         :clock-resume t)
        ("t" "Todo" entry (file+headline (expand-file-name "main.org.gpg"
                                                           tnoda/org-dropbox-directory) "Tasks")
         "* TODO %? \n\n%i\n%a\nAdded: %U\n\n"
         :prepend t
         :clock-keep t
         :empty-lines 1
         :kill-buffer t)
        ("m" "Morning Routine" entry (file+datetree "")
         "* Morning Routine %U\n\n%[~/Dropbox/org/morning_routine.org]"
         :prepend t
         :clock-in t
         :empty-lines 1
         :kill-buffer t)
        ("r" "Daily Review" entry (file "")
         "* Daily Review %U\n\n%[~/Dropbox/org/daily_review.org]"
         :prepend t
         :clock-in t
         :empty-lines 1
         :kill-buffer t)))

GTD

M-x flaggedflagged.org を開く.

(defun flagged ()
  (interactive)
  (find-file (expand-file-name "flagged.org" org-directory)))

C-c gorg-clock-goto.

(global-set-key (kbd "C-c g") 'org-clock-goto)

Trello

(use-package org-trello
  :ensure t
  :config
  (setq org-trello-files
        (list (expand-file-name "trello.org.gpg" tnoda/org-dropbox-directory))))

Agenda

Agenda files

(setq org-agenda-files (--map (expand-file-name (format "%s.org.gpg" it)
                                                tnoda/org-dropbox-directory)
                              '("main"
                                "journal"
                                "projects"
                                "habits"
                                "trello")))

<S-f7><f7> に Org Agenda を開くコマンドを割り当てる.

  • 一日の始まり→ <S-f7> … Home Lists
  • タスクの確認→ <f7> … Daily Action List
(setq org-agenda-custom-commands
      '(("H" "Home Lists"
         ((agenda "")
          (tags-todo "family")
          (tags-todo "home")
          (tags-todo "office")
          (tags-todo "errands")
          (tags-todo "computer")
          (tags "library")
          (tags "reading")))
        ("D" "Daily Action List"
         ((agenda "" ((org-agenda-ndays 1)
                      (org-agenda-sorting-strategy
                       (quote ((agenda time-up priority-down tag-up) )))
                      (org-deadline-warning-days 0)))))))

(defun tnoda/org-agenda-home-lists ()
  (interactive)
  (org-agenda nil "H"))
(global-set-key (kbd "<S-f7>") 'tnoda/org-agenda-home-lists)
(defun tnoda/org-agenda-daily-action-list ()
  (interactive)
  (org-agenda nil "D"))
(global-set-key (kbd "<f7>") 'tnoda/org-agenda-daily-action-list)

そのほかの設定

(setq org-agenda-include-diary t)
(setq org-agenda-skip-deadline-if-done t)
(setq org-agenda-skip-scheduled-if-done t)
(setq org-agenda-start-on-weekday nil)

Faces

(set-face-attribute 'org-column nil
                    :background "gray16"
                    :strike-through nil
                    :underline nil
                    :height 160
                    :family "Ricty")
(set-face-attribute 'org-column-title nil
                    :background "grey30"
                    :underline t
                    :family "Ricty")

Mobile

(when (load "~/.org-mobile-encryption-password.el" t)
  (setq org-mobile-use-encryption t)
  (setq org-mobile-inbox-for-pull "~/org/flagged.org")
  (setq org-mobile-directory "~/Dropbox/Apps/MobileOrg"))

Exporting

(add-to-list 'org-export-backends 'beamer)

Latex

(require 'ox-latex)
(setq org-latex-pdf-process
      (cond ((executable-find "/Library/TeX/texbin/lualatex")
             '("/Library/TeX/texbin/lualatex %b"))
            ((executable-find "/usr/texbin/lualatex")
             '("/usr/texbin/lualatex %b"))
            ((executable-find "/usr/local/bin/lualatex")
             '("/usr/local/bin/lualatex %b"))))
(add-to-list 'org-latex-classes
             '("ltjsarticle"
               "\\documentclass{ltjsarticle}"
               ("\\section{%s}" . "\\section*{%s}")
               ("\\subsection{%s}" . "\\subsection*{%s}")
               ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
               ("\\paragraph{%s}" . "\\paragraph*{%s}")
               ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
(setq org-latex-default-class "ltjsarticle")
(setq org-latex-listings 'listings)
(add-to-list 'org-latex-listings-langs '(scala "Scala"))
(add-to-list 'org-latex-default-packages-alist '("" "luatexja" nil))
(setq org-latex-packages-alist
      '(("" "luatexja-fontspec" nil)
        ("" "lmodern" nil)
        ("" "listings" nil)
        ("" "color" nil)))

Inhibit HTML validation link

(setq org-html-validation-link nil)

Markdown

(require 'ox-md)

Babel

Emacs Lisp 以外の言語も有効にする.

(org-babel-do-load-languages
 'org-babel-load-languages
 '((sh . t)
   (emacs-lisp . t)
   (clojure . t)
   (scala . t)
   (ditaa . t)
   (dot . t)
   (haskell . t)
   (java . t)
   (js . t)
   (latex . t)
   (org . t)
   (python . t)
   (ruby . t)))

Ditaa

(setq org-ditaa-jar-path
      (shell-command-to-string "brew ls ditaa | grep jar | tr -d '\n'"))
(setq org-ditaa-eps-jar-path
      (expand-file-name "share/ditaa/DitaaEps.jar" tnoda/dotfiles-dir))
(add-to-list 'org-babel-default-header-args:ditaa '(:eps . t))
(add-to-list 'org-babel-default-header-args:ditaa '(:cmdline . "-S -E"))

Graphviz

(add-to-list 'org-babel-default-header-args:dot '(:cmdline . "-Teps"))

(require 'graphviz-dot-mode)
(add-to-list 'org-src-lang-modes '("dot" . graphviz-dot))

コードブロックのフォント修飾は,Emacs が重くなるのでやめる.

(setq org-src-fontify-natively nil)

コードブロックを確認無しに実行する.

(setq org-confirm-babel-evaluate nil)

Display/update images in org buffers after evaluation

(add-hook 'org-babel-after-execute-hook 'org-display-inline-images 'append)

ipython.el

(use-package ob-ipython
  :ensure t)

Easy Templates

  • <s で =#+STARTUP: =
  • <S で =#+SETUPFILE: =
  • <p で =#+PROPERTY: =
  • <b で beamer
(setq org-structure-template-alist
      (remove-if #'(lambda (x) (member (car x) '("s" "S" "p")))
                 org-structure-template-alist))
(push '("s" "#+STARTUP: ") org-structure-template-alist)
(push '("S" "#+SETUPFILE: %file ?") org-structure-template-alist)
(push '("p" "#+PROPERTY: ") org-structure-template-alist)
(push '("b" "# -*- org-src-fontify-natively: t -*-
#+STARTUP: beamer
#+COLUMNS: %40ITEM %10BEAMER_env(Env) %9BEAMER_envargs(Env Args) %4BEAMER_col(Col) %10BEAMER_extra(Extra)
#+TITLE: title
#+AUTHOR: Takahrio Noda (@tnoda)
#+DATE: [2001-01-01 Mon]
#+BEAMER_THEME: Pittsburgh
#+BEAMER_COLOR_THEME: solarized [accent=cyan]
#+BEAMER_FONT_THEME: structurebold
#+BEAMER_HEADER: \\beamertemplatenavigationsymbolsempty
#+BEAMER_HEADER: \\usepackage{inconsolata}
#+OPTIONS: toc:nil H:2
"
) org-structure-template-alist)

Ubuntu

Toggle touchpad

(when (string= system-name "bluetail")
  (defvar tnoda/touchpad-enabled 1)

  (defun tnoda/toggle-touchpad-enabled ()
    (interactive)
    (setq tnoda/touchpad-enabled (logxor tnoda/touchpad-enabled 1))
    (shell-command-to-string (format "xinput set-prop 10 \"Device Enabled\" %d"
                                     tnoda/touchpad-enabled))
    (message (if (eq 1 tnoda/touchpad-enabled)
                 "touchpad enabled"
               "touchpad disabled")))

  (global-set-key (kbd "<f12>") 'tnoda/toggle-touchpad-enabled))