Created
March 9, 2011 12:11
-
-
Save tlync/862092 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; anything | |
(add-to-load-path-recompile "~/.emacs.d/elisp/anything") | |
(require 'anything-startup) | |
;; | |
;; (anything sources) | |
;; | |
;; imenu | |
;; http://www.emacswiki.org/emacs/RubikitchAnythingConfiguration | |
;; -------------------------------------------------- | |
(defvar anything-c-imenu-delimiter " / ") | |
(defvar anything-c-imenu-index-filter nil) | |
(defvar anything-c-cached-imenu-alist nil) | |
(defvar anything-c-cached-imenu-candidates nil) | |
(defvar anything-c-cached-imenu-tick nil) | |
(make-variable-buffer-local 'anything-c-imenu-index-filter) | |
(make-variable-buffer-local 'anything-c-cached-imenu-alist) | |
(make-variable-buffer-local 'anything-c-cached-imenu-candidates) | |
(make-variable-buffer-local 'anything-c-cached-imenu-tick) | |
(defun anything-imenu-create-candidates (entry) | |
(if (listp (cdr entry)) | |
(mapcan (lambda (sub) | |
(if (consp (cdr sub)) | |
(mapcar | |
(lambda (subentry) | |
(concat (car entry) anything-c-imenu-delimiter subentry)) | |
(anything-imenu-create-candidates sub)) | |
(list (concat (car entry) anything-c-imenu-delimiter (car sub))))) | |
(cdr entry)) | |
(list entry))) | |
(setq anything-c-source-imenu | |
'((name . "Imenu") | |
(init . (lambda () | |
(setq anything-c-imenu-current-buffer | |
(current-buffer)))) | |
(candidates | |
. (lambda () | |
(with-current-buffer anything-c-imenu-current-buffer | |
(let ((tick (buffer-modified-tick))) | |
(if (eq anything-c-cached-imenu-tick tick) | |
anything-c-cached-imenu-candidates | |
(setq anything-c-cached-imenu-tick tick | |
anything-c-cached-imenu-candidates | |
(condition-case nil | |
(mapcan | |
'anything-imenu-create-candidates | |
(setq anything-c-cached-imenu-alist | |
(let ((index (imenu--make-index-alist))) | |
(if anything-c-imenu-index-filter | |
(funcall anything-c-imenu-index-filter index) | |
index)))) | |
(error nil)))))))) | |
(volatile) | |
(action | |
. (lambda (entry) | |
(let ((path (split-string entry anything-c-imenu-delimiter)) | |
(alist anything-c-cached-imenu-alist)) | |
(imenu | |
(progn | |
(while path | |
(setq alist (assoc (car path) alist) | |
path (cdr path))) | |
alist))))))) | |
;; moccur | |
;; http://d.hatena.ne.jp/IMAKADO/20080724/1216882563 | |
;; -------------------------------------------------- | |
(require 'anything-c-moccur) | |
(add-hook 'dired-mode-hook | |
'(lambda () | |
(local-set-key (kbd "O") 'anything-c-moccur-dired-do-moccur-by-moccur))) | |
;; (global-set-key (kbd "C-M-s") 'anything-c-moccur-isearch-forward) | |
;; (global-set-key (kbd "C-M-r") 'anything-c-moccur-isearch-backward) | |
(setq anything-c-moccur-anything-idle-delay 0.2 ;`anything-idle-delay' | |
anything-c-moccur-higligt-info-line-flag t ; `anything-c-moccur-dmoccur'などのコマンドでバッファの情報をハイライトする | |
anything-c-moccur-enable-auto-look-flag t ; 現在選択中の候補の位置を他のwindowに表示する | |
anything-c-moccur-enable-initial-pattern t) ; `anything-c-moccur-occur-by-moccur'の起動時にポイントの位置の単語を初期パターンにする | |
;; yasnippet | |
;; http://d.hatena.ne.jp/IMAKADO/20080401/1206715770 | |
;; -------------------------------------------------- | |
(require 'anything-c-yasnippet) | |
(setq anything-c-yas-space-match-any-greedy t) ;スペース区切りで絞り込めるようにする デフォルトは nil | |
;; files | |
;; http://d.hatena.ne.jp/rubikitch/20090211/1234349678 | |
;; -------------------------------------------------- | |
(defun anything-compile-source--candidates-file (source) | |
(if (assoc-default 'candidates-file source) | |
`((init acf-init | |
,@(let ((orig-init (assoc-default 'init source))) | |
(cond ((null orig-init) nil) | |
((functionp orig-init) (list orig-init)) | |
(t orig-init)))) | |
(candidates-in-buffer) | |
,@source) | |
source)) | |
(add-to-list 'anything-compile-source-functions 'anything-compile-source--candidates-file) | |
(defun acf-init () | |
(destructuring-bind (file &optional updating) | |
(anything-mklist (anything-attr 'candidates-file)) | |
(with-current-buffer (anything-candidate-buffer (find-file-noselect file)) | |
(when updating | |
(buffer-disable-undo) | |
(font-lock-mode -1) | |
(auto-revert-mode 1))))) | |
(defvar anything-c-source-home-directory | |
'((name . "Home Directories") | |
;;find ~ -type d \( -name .Trash -o -name .svn -o -name .git -o -name Cache \) \ | |
;; -prune -o -print > /tmp/tmp; mv /tmp/tmp ~/.emacs.d/log/home.filelist | |
(candidates-file "~/.emacs.d/log/home.filelist" updating) | |
(requires-pattern . 4) | |
(candidate-number-limit . 20) | |
(type . file))) | |
(setq large-file-warning-threshold 50000000) | |
(defvar anything-c-source-hatena-diary | |
'((name . "Hatena Diaries") | |
;;(candidates . (lambda () (directory-files "~/.hatena/tlync/diary"))) | |
;; find ~/.hatena/ -regex ".*[0-9]\.txt" > /tmp/tmp; mv /tmp/tmp ~/.emacs.d/log/hatena.filelist | |
(candidates-file "~/.emacs.d/log/hatena.filelist" updating) | |
(requires-pattern . 4) | |
(candidate-number-limit . 20) | |
(type . file))) | |
;; grep fallback | |
;; -------------------------------------------------- | |
(defvar anything-c-source-anything-grep-fallback | |
'((name . "Grep") | |
(dummy) | |
(action . (lambda (query) (anything-grep-by-name nil query))))) | |
;; google fallback | |
;; -------------------------------------------------- | |
(defvar anything-c-source-anything-google-fallback | |
'((name . "Google") | |
(dummy) | |
(action . (lambda (query) (anything-c-google-suggest-action query))))) | |
;; gist | |
;; -------------------------------------------------- | |
(require 'anything-gist) | |
;; | |
;; (anything command) | |
;; | |
(defvar anything-function 'anything-at-point) | |
(defun anything-sort-sources-by-major-mode (sources) | |
(loop for src in sources | |
for modes = (anything-attr 'major-mode (symbol-value src)) | |
if (memq major-mode modes) | |
collect src into prior | |
else | |
collect src into rest | |
finally (return (append prior rest)))) | |
;; default | |
;; -------------------------------------------------- | |
(defun anything-default () | |
(interactive) | |
(let ((anything-input-idle-delay 0.2) | |
(anything-idle-delay 0.7) | |
(anything-quick-update t) | |
(anything-sources | |
(append | |
'( ;;prior | |
anything-c-source-emacs-variable-at-point | |
anything-c-source-emacs-function-at-point | |
anything-c-source-buffers | |
anything-c-source-recentf | |
anything-c-source-home-directory | |
anything-c-source-hatena-diary | |
anything-c-source-file-name-history | |
) | |
(anything-sort-sources-by-major-mode | |
'(;; major-mode oriented sources | |
anything-c-source-imenu | |
anything-c-source-apropos-emacs-commands | |
anything-c-source-apropos-emacs-functions | |
anything-c-source-apropos-emacs-variables | |
;;anything-c-source-mysql-manual | |
)) | |
'(;; lower priority | |
anything-c-source-info-pages | |
anything-c-source-anything-grep-fallback | |
anything-c-source-anything-google-fallback | |
;;anything-c-source-auto-install-from-emacswiki | |
)))) | |
(call-interactively anything-function))) | |
;; | |
;; (misc) | |
;; | |
;; reset anything | |
;; http://www.emacswiki.org/emacs/RubikitchAnythingConfiguration | |
;; -------------------------------------------------- | |
(defun anything-reset () | |
"Clear internal state of `anything'." | |
(interactive) | |
(loop for v in '(anything-candidate-buffer-alist anything-candidate-cache | |
anything-saved-selection anything-current-buffer | |
anything-saved-selection anything-saved-action | |
anything-buffer-file-name anything-current-position | |
anything-last-sources anything-saved-current-source | |
anything-compiled-sources) | |
do (set v nil)) | |
(loop for b in (buffer-list) | |
for name = (buffer-name b) | |
when (string-match "^ ?\\*anything" name) | |
do (kill-buffer b))) | |
;; faces | |
;; -------------------------------------------------- | |
(custom-set-faces | |
'(anything-dir-priv ((t nil))) | |
'(anything-file-name ((t nil))) | |
'(widget-field ((t nil)))) | |
;; keys | |
;; -------------------------------------------------- | |
(global-set-key [?\C-'] 'anything-default) | |
(global-set-key (kbd "C-x a i") 'anything-imenu) | |
(global-set-key (kbd "C-x a k") 'anything-show-kill-ring) | |
(global-set-key (kbd "C-x a y") 'anything-c-yas-complete) | |
(global-set-key (kbd "C-x a h") 'anything-minibuffer-history) | |
(global-set-key (kbd "C-x a o") 'anything-c-moccur-occur-by-moccur) ;; buffers | |
(global-set-key (kbd "C-x a d") 'anything-c-moccur-dmoccur) ;; directory | |
(global-set-key (kbd "C-x a g") 'anything-for-gist) | |
(define-key anything-map (kbd "C-v") 'anything-next-source) | |
(define-key anything-map (kbd "M-v") 'anything-previous-source) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment