2008年8月26日火曜日

今日の.emacs(カスタマイズ重視風)



(ffap-bindings) ;find file at point
(global-set-key "\M-/" 'hippie-expand) ;補完を強力に

(require 'dired-x) ;dired を拡張
(autoload 'wdired-change-to-wdired-mode "wdired") ;dired で簡単リネーム
(define-key dired-mode-map "r" 'wdired-change-to-wdired-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 検索強化
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; F3 でカーソル下の単語を検索(vim のまね、F4 で逆向き検索)
(defvar my-search-key-forward [f3])
(defvar my-search-key-backward [f4])
(defvar my-isearch-repeated nil)

(defun my-isearch-symbol (&optional repeat backward)
(interactive "p")
(and (eq repeat 1)
(let ((wd (thing-at-point 'symbol)))
(when wd
(let ((rq_wd (regexp-quote wd)))
(isearch-update-ring
(concat (if (string= (substring rq_wd 0 1) "_")
"\\W" "\\<")
rq_wd
(if (string= (substring rq_wd -1) "_")
"\\W" "\\>"))
t)))))
(cond (backward
(setq my-isearch-repeated 'backward)
(isearch-backward t))
(t
(setq my-isearch-repeated 'forward)
(isearch-forward t)))
(setq my-isearch-repeated nil))

(defun my-force-repeat ()
(cond ((eq my-isearch-repeated 'forward)
(isearch-repeat-forward))
((eq my-isearch-repeated 'backward)
(isearch-repeat-backward))))

(add-hook 'isearch-mode-hook 'my-force-repeat)

(global-set-key my-search-key-forward 'my-isearch-symbol)
(global-set-key my-search-key-backward (lambda (&optional repeat)
(interactive "p") (my-isearch-symbol repeat t)))
(define-key isearch-mode-map my-search-key-forward
(lambda ()
(interactive)
(and (not isearch-forward) (isearch-repeat-forward))
(isearch-repeat-forward)))
(define-key isearch-mode-map my-search-key-backward
(lambda ()
(interactive)
(and isearch-forward (isearch-repeat-backward))
(isearch-repeat-backward)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; フォント設定
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun my-set-assoc-data (list key value)
;; リストに既に同じキーがあれば上書き、無ければ新規追加
(let ((item (assoc key (symbol-value list))))
(if item
(setcdr item value)
(add-to-list list (cons key value)))))

(defun my-set-font (ascii-font jis-font size mul)
;; フォント設定
;; ascii フォント、和文フォント、サイズ、倍率の順に指定する。
(create-fontset-from-ascii-font
(concat "-*-" ascii-font "-normal-r-normal-normal-"
(int-to-string size) "-*-*-*-*-*-iso8859-1")
nil
(concat ascii-font (int-to-string size)))

(let* ((encoded (encode-coding-string jis-font 'emacs-mule))
(family (concat encoded "*"))
(fontset (concat "fontset-" ascii-font (int-to-string size))))

(set-fontset-font fontset 'japanese-jisx0208
(cons family "jisx0208-sjis"))
(set-fontset-font fontset 'katakana-jisx0201
(cons family "jisx0201-katakana"))

(my-set-assoc-data 'face-font-rescale-alist (concat ".*" encoded ".*") mul)
(my-set-assoc-data 'default-frame-alist 'font fontset)
(set-frame-font fontset)))

;; 倍率は全角と半角の比率を調整する。サイズによって最適値は異なる。
(my-set-font "Consolas" "メイリオ" 15 1.1)
;(my-set-font "Consolas" "メイリオ" 14 1.2)
;(my-set-font "Courier New" "MS ゴシック" 14 1.2)
;(my-set-font "MS ゴシック" "MS ゴシック" 14 1.0)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(c-default-style (quote ((c-mode . "linux") (java-mode . "java") (awk-mode . "awk") (other . "gnu"))))
'(column-number-mode t)
'(cua-mode t nil (cua-base))
'(cua-paste-pop-rotate-temporarily t)
'(current-language-environment "Japanese")
'(dired-recursive-copies (quote always))
'(dired-recursive-deletes (quote always))
'(grep-find-template "find . <X> -type f <F> -print0 | xargs -0 -s32000 grep -nH -e <R> ")
'(iswitchb-mode t)
'(mouse-wheel-scroll-amount (quote (1 ((shift) . 1) ((control)))))
'(partial-completion-mode t)
'(read-file-name-completion-ignore-case t)
'(recentf-mode t)
'(save-place t nil (saveplace))
'(show-paren-mode t)
'(tool-bar-mode nil)
'(view-read-only t)
'(viper-auto-indent t)
'(viper-buffer-search-char 103)
'(viper-case-fold-search t)
'(viper-ex-style-editing nil)
'(viper-keep-point-on-undo t)
'(viper-syntax-preference (quote extended))
'(viper-vi-style-in-minibuffer nil)
'(visible-bell t)
'(wdired-allow-to-change-permissions t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)

(put 'dired-find-alternate-file 'disabled nil)
(put 'narrow-to-region 'disabled nil)

2008年8月24日日曜日

NTEmacs22 フォント設定(Consolas + メイリオ)

フォント関連が難しいので簡易設定関数を自作した。
以下を .emacs にでも追記する。


(defun my-set-assoc-data (list key value)
;; リストに既に同じキーがあれば上書き、無ければ新規追加
(let ((item (assoc key (symbol-value list))))
(if item
(setcdr item value)
(add-to-list list (cons key value)))))

(defun my-set-font (ascii-font jis-font size mul)
;; フォント設定
;; ascii フォント、和文フォント、サイズ、倍率の順に指定する。
(create-fontset-from-ascii-font
(concat "-*-" ascii-font "-normal-r-normal-normal-"
(int-to-string size) "-*-*-*-*-*-iso8859-1")
nil
(concat ascii-font (int-to-string size)))

(let* ((encoded (encode-coding-string jis-font 'emacs-mule))
(family (concat encoded "*"))
(fontset (concat "fontset-" ascii-font (int-to-string size))))

(set-fontset-font fontset 'japanese-jisx0208
(cons family "jisx0208-sjis"))
(set-fontset-font fontset 'katakana-jisx0201
(cons family "jisx0201-katakana"))

(my-set-assoc-data 'face-font-rescale-alist (concat ".*" encoded ".*") mul)
(my-set-assoc-data 'default-frame-alist 'font fontset)
(set-frame-font fontset)))

;; 倍率は全角と半角の比率を調整する。サイズによって最適値は異なる。
(my-set-font "Consolas" "メイリオ" 15 1.1)
;(my-set-font "Consolas" "メイリオ" 14 1.2)
;(my-set-font "Courier New" "MS ゴシック" 14 1.2)
;(my-set-font "MS ゴシック" "MS ゴシック" 14 1.0)

2008年7月22日火曜日

gvimrc - 最低限の設定


" 2008/09/29: フォントを Osaka に変更

set iminsert=0 " 初期挿入は IM-OFF
set imsearch=0 " 初期検索は IM-OFF
set linespace=0 " 行間 (point、Osaka 以外のフォントは 2 ぐらいを設定)
set visualbell " beep 音を止める(代わりに画面フラッシュ)
set guioptions-=m " メニューを消す
set guioptions-=T " ツールバーを消す
set guioptions+=a " マウス選択や、visual 選択でクリップボードにコピー
set columns=80 " 横幅文字数
set lines=50 " 行数
set guifont=Osaka-等幅:h12
" set guifont=MS_Mincho:h12:cSHIFTJIS
" set guifont=M+2VM+IPAG_circle:h12:cSHIFTJIS
" set guifont=BDF_UM+:h9

" colorscheme default " 配色設定
" set background=light

" 日本語入力のカーソル色
hi CursorIM guifg=black guibg=red

" gp でクリップボードを貼り付け
nnoremap gp "*gp

2008年4月13日日曜日

現在編集しているファイル名をクリップボードに

人に説明する際に、ファイル名や抜粋がクリップボードにコピーしたくなることがある。
以下を vimrc にでも追記すれば :FN や :FL で簡単にコピーできる。
# visual 選択中の :FL は抜粋になる


" 'ファイル名' をヤンク/クリップボードのバッファにコピー
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
command! FN let @"=expand("%:p") | if has("gui_running") | let @*=@" | endif

" 'ファイル名 :L行番号' をヤンク/クリップボードのバッファにコピー
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:get_filename_with_line_number(s, e)
let result = expand("%:p")." :L".line(".")
if a:s == a:e
let @" = result
else
let result .= "\n===\n"
let result .= join(getline(a:s, a:e), "\n")
let @" = result."\n==="
endif

if has("gui_running")
let @* = @"
endif
endfunction
command! -range FL call s:get_filename_with_line_number(<line1>, <line2>)

2008年4月12日土曜日

SICP てきとー要約:1.1 The Elements of Programming

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html

強力なプログラム言語は、単なるコンピュータへの命令手段ではなく自分のアイデアをまとめるフレームワークでもある。そのため、プログラミングでは言語に用意されている単純なアイデアを複雑なアイデアに組み上げる仕組みについて意識すべきだ。強力といわれるあらゆる言語には 3 つの機構がある。
  • 最も単純な式
  • それを組み合わせる手段
  • また、それを抽象化する手段
プログラミングでは手続きとデータという 2 つの要素を扱い、強力なプログラム言語ではそれらを抽象化したり組み合わせたりできる。

この章では単純な数値データのルールについて説明する。

2008年4月7日月曜日

Redmineの工数詳細を100件に制限

工数登録が多くなると表示がかなり遅くなるので、
100 件で制限しておく。
全部表示したい場合は csv を指定すれば OK。

=====================================
app/controllers/timelog_controller.rb
=====================================

def details
sort_init 'spent_on', 'desc'
sort_update

####### 変更開始
#@entries = (@issue ? @issue : @project).time_entries.find(:all, :include => [:activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], :order => sort_clause)
find_param = [:all, {:include => [:activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], :order => sort_clause}]
if 'csv' != params[:export]
find_param[1][:limit] = 100
end
@entries = (@issue ? @issue : @project).time_entries.find(*find_param)
####### ここまで

@total_hours = @entries.inject(0) { |sum,entry| sum + entry.hours }
@owner_id = User.current.id

send_csv and return if 'csv' == params[:export]
render :action => 'details', :layout => false if request.xhr?
end

Redmineに工数確認機能を追加2

工数入力は同じ課題がしばらく続くことが多いので、
入力補助として履歴に最近入力した課題への工数入力のリンクを増やしてみた。

----------------------------------------
app/views/my/blocks/_hourhistories.rhtml
----------------------------------------
<h3>入力工数履歴</h3>

<ul>
<% sql =
"select user_id, spent_on, sum(hours) as day_hour" +
" from time_entries" +
" where user_id = #{user.id}" +
" group by spent_on" +
" order by spent_on desc" +
" limit 5"-%>
<% for entry in TimeEntry.find_by_sql(sql) %>
<li><%= "#{entry.spent_on}: #{entry.day_hour} h" %>
<% end %>
</ul>

<%= link_to "詳細", :controller => "man_hour" %>
<p>
<% sql =
"select distinct issue_id " +
" from time_entries" +
" where user_id = #{user.id}" +
" order by spent_on desc" +
" limit 10"-%>
<h3>最近工数入力した課題</h3>
<ul>
<% i = 0 %>
<% for entry in TimeEntry.find_by_sql(sql) %>
<% if entry.issue %>
<li>[<%= link_to '工数入力', :controller => 'timelog', :action => 'edit', :issue_id => entry.issue_id %>]
<%= link_to_issue entry.issue %> <%= entry.issue.subject %>
<% end %>
<% end %>
</ul>