PC Memo‎ > ‎

.emacs

試行錯誤しているうちにNTEmacsの使い方が固まってきたので、.emacsを公開。

gnupack 版 emacs 23.2 で動作してますが、余計なことをいろいろやってるかもしれません。

あと、日本語設定については、Emacs23 日本語向け設定例 あたりを参考にいろいろやっといた方がいいかも。

(cd "~")

(setq load-path (append (list
(expand-file-name "~/elisp/")
(expand-file-name "~/elisp/howm-1.3.8")
) load-path))

(set-language-environment "Japanese")
(prefer-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(auto-compression-mode t)

(when (fboundp 'w32-ime-initialize)
(setq default-input-method "W32-IME")
(w32-ime-initialize)

(set-face-font 'default "MSゴシック-10")

(wrap-function-to-control-ime 'y-or-n-p nil nil)
(wrap-function-to-control-ime 'yes-or-no-p nil nil)
(wrap-function-to-control-ime 'universal-argument t nil)
(wrap-function-to-control-ime 'read-string nil nil)
(wrap-function-to-control-ime 'read-from-minibuffer nil nil)
(wrap-function-to-control-ime 'read-key-sequence nil nil)
(wrap-function-to-control-ime 'map-y-or-n-p nil nil)
(wrap-function-to-control-ime 'read-passwd t t) ; don't work as we expect.

(add-hook 'w32-ime-on-hook
(function (lambda () (set-cursor-color "blue"))))
(add-hook 'mw32-ime-off-hook
(function (lambda () (set-cursor-color "black"))))
(add-hook 'minibuffer-setup-hook
(function (lambda ()
(if (fep-get-mode)
(set-cursor-color "blue")
(set-cursor-color "black"))))))

(setq initial-frame-alist
(append (list
'(width . 100) ;; Width of frame
'(height . 50) ;; Height of frame
'(top . 60) ;; Position
'(left . 140) ;; Position
initial-frame-alist))

(add-hook 'c-mode-common-hook
(lambda()
(c-set-style "gnu")
(setq compile-command "make ")))

(which-function-mode t)

(require 'imenu)
(defcustom imenu-modes
'(emacs-lisp-mode c-mode c++-mode makefile-mode)
"List of major modes for which Imenu mode should be used."
:group 'imenu
:type '(choice (const :tag "All modes" t)
(repeat (symbol :tag "Major mode"))))
(defun my-imenu-ff-hook ()
"File find hook for Imenu mode."
(if (member major-mode imenu-modes)
(imenu-add-to-menubar "imenu")))
(add-hook 'find-file-hooks 'my-imenu-ff-hook t)

(global-set-key "\C-cg" 'imenu)

(if window-system (progn
(set-face-foreground 'font-lock-comment-face "SeaGreen")
(set-face-foreground 'font-lock-string-face "Brown")
(set-face-foreground 'font-lock-keyword-face "blue")
(set-face-foreground 'font-lock-function-name-face "blue")
(set-face-foreground 'font-lock-variable-name-face "red")
(set-face-foreground 'font-lock-type-face "LightSeaGreen")
(set-face-foreground 'font-lock-builtin-face "purple")
(set-face-foreground 'font-lock-constant-face "black")
(set-face-foreground 'font-lock-warning-face "blue")
))

(global-set-key [delete] 'delete-char)
(global-set-key "\C-h" 'backward-delete-char-untabify)
(global-set-key "\C-z" 'undo)
(global-set-key [M-kanji] 'ignore)
(global-set-key [insert] 'ignore)

;; Misc setup
(font-lock-mode t)
(setq inhibit-startup-message t) ; don't show the startup message
(setq kill-whole-line t) ; C-k deletes the end of line
(setq ring-bell-function '(lambda ())) ; no more beep
(setq visible-bell t)
(setq auto-save-default nil) ; disable auto-saving
(setq make-backup-files nil) ; don't make *~
(setq auto-save-list-file-prefix nil) ; don't make ~/.saves-PID-hostname
(line-number-mode t) ; line number in the mode line
(column-number-mode t)
;(menu-bar-mode t)
(tool-bar-mode nil)

(setq calendar-week-start-day 1)

(setq view-read-only t)

(load "pdf-preview")
(setq pdf-preview-ps2pdf-command "ps2pdf")
(setq pdf-preview-ps2pdf-paper-size-option "-sPAPERSIZE#")

(put 'upcase-region 'disabled nil) ; enable C-x C-u (upcase-region)
(put 'downcase-region 'disabled nil) ; enable C-x C-l (downcase-region)
(transient-mark-mode t)
(windmove-default-keybindings)

(setq recentf-exclude '("^/[^/:]+:"))
(recentf-mode t)

(show-paren-mode t)
(setq show-paren-style 'mixed)

(setq display-time-string-forms
'((format "%s %2s %s %2s:%2s" monthname day dayname 24-hours minutes)))
(display-time)

(setq frame-title-format
`(" %b " (buffer-file-name "( %f )") " on ",(system-name)
)); show directory name

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

; can use emacs-client
(server-start)

;; 1 = Shift_JIS, 2 = ISO-2022-JP, 3 = EUC-JP
(setq YaTeX-kanji-code 1) ; Shift_JIS
(setq YaTeX-default-documentclass "jsarticle")

(require 'jaspace)
(setq jaspace-alternate-eol-string "\xab\n")

(setq howm-menu-lang 'ja)
(global-set-key "\C-c,," 'howm-menu)
(mapc
(lambda (f)
(autoload f
"howm" "Hitori Otegaru Wiki Modoki" t))
'(howm-menu howm-list-all howm-list-recent
howm-list-grep howm-create
howm-keyword-to-kill-ring))

;; follow link with [tab]
(eval-after-load "howm-mode"
'(progn
(define-key howm-mode-map [tab] 'action-lock-goto-next-link)
(define-key howm-mode-map [backtab] 'action-lock-goto-previous-link)))

;; Show titles in "recent memo"
(setq howm-list-recent-title t)
;; Show titles in "all memo"
(setq howm-list-all-title t)
;; Cache menu for 2 hours
(setq howm-menu-expiry-hours 2)

;; auto-fill in howm-mode
(add-hook 'howm-mode-on-hook 'auto-fill-mode)

;; delete list buffer
(setq howm-view-summary-persistent nil)

(setq howm-menu-schedule-days-before 10)
(setq howm-menu-schedule-days 30)

(setq howm-file-name-format "%Y/%m/%Y-%m-%d-%H%M%S.howm")
;(setq howm-file-name-format "%Y/%m/%Y-%m-%d.howm")

(setq howm-view-grep-parse-line
"^\\(\\([a-zA-Z]:/\\)?[^:]*\\.howm\\):\\([0-9]*\\):\\(.*\\)")

(setq
howm-excluded-file-regexp
"/\\.#\\|[~#]$\\|\\.bak$\\|/CVS/\\|\\.doc$\\|\\.pdf$\\|\\.ppt$\\|\\.xls")

(if (not (memq 'delete-file-if-no-contents after-save-hook))
(setq after-save-hook
(cons 'delete-file-if-no-contents after-save-hook)))
(defun delete-file-if-no-contents ()
(when (and
(buffer-file-name (current-buffer))
(string-match "\\.howm" (buffer-file-name (current-buffer)))
(= (point-min) (point-max)))
(delete-file
(buffer-file-name (current-buffer)))))

(defun my-save-and-kill-buffer ()
(interactive)
(when (and
(buffer-file-name)
(string-match "\\.howm"
(buffer-file-name)))
(save-buffer)
(kill-buffer nil)))
(eval-after-load "howm"
'(progn
(define-key howm-mode-map
"\C-c\C-c" 'my-save-and-kill-buffer)))

;;; *scratch* buffer
(defun my-make-scratch (&optional arg)
(interactive)
(progn
;; make "*scratch*" buffer at buffer-list
(set-buffer (get-buffer-create "*scratch*"))
(funcall initial-major-mode)
(erase-buffer)
(when (and initial-scratch-message (not inhibit-startup-message))
(insert initial-scratch-message))
(or arg (progn (setq arg 0)
(switch-to-buffer "*scratch*")))
(cond ((= arg 0) (message "*scratch* is cleared up."))
((= arg 1) (message "another *scratch* is created")))))

(add-hook 'kill-buffer-query-functions
;; delete contents when *scratch* buffer is killed
(lambda ()
(if (string= "*scratch*" (buffer-name))
(progn (my-make-scratch 0) nil)
t)))

(add-hook 'after-save-hook
;; new *scratch* buffer after saving *scratch*
(lambda ()
(unless (member (get-buffer "*scratch*") (buffer-list))
(my-make-scratch 1))))