Skip to content

Instantly share code, notes, and snippets.

@peccu
Created April 1, 2010 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peccu/352058 to your computer and use it in GitHub Desktop.
Save peccu/352058 to your computer and use it in GitHub Desktop.
;; cf.http://d.hatena.ne.jp/grandVin/20080912/1221245359
;; どうもこれでできてるらしいけど,自分のためにも自作してみた
;; だいたい下のような設定になっていれば
;; `bm-repository'にbookmarkのリストが入っている
;; これをanythingで選択して,jumpできるようにする
;; (setq-default bm-buffer-persistence t)
;; (add-hook' after-init-hook 'bm-repository-load)
;; (add-hook 'find-file-hooks 'bm-buffer-restore)
;; (add-hook 'kill-buffer-hook 'bm-buffer-save)
;; (add-hook 'auto-save-hook 'bm-buffer-save)
;; (add-hook 'after-save-hook 'bm-buffer-save)
;; candidates-in-bufferと,普通のcandidateの両方ができちゃったので,両方置いときます
;; デフォルトはcandidates-in-bufferを使う方になってます
;; (defvaralias 'anything-c-source-bm-global 'anything-c-source-bm-global-use-candidates-in-buffer)
;; (defvaralias 'anything-c-source-bm-global 'anything-c-source-bm-global-normal)
;; (anything 'anything-c-source-bm-global)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; candidates-in-buffer ver. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Visible Bookmarks(global)
;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
(defvar anything-c-source-bm-global-use-candidates-in-buffer
'((name . "Global Bookmarks")
(init . anything-c-bm-global-init)
(candidates-in-buffer)
(type . file-line))
"show global bookmarks list.
Global means All bookmarks exist in `bm-repository'.
Needs bm.el.
http://www.nongnu.org/bm/")
;; (anything 'anything-c-source-bm-global-use-candidates-in-buffer)
(defvaralias 'anything-c-source-bm-global 'anything-c-source-bm-global-use-candidates-in-buffer)
;; (anything 'anything-c-source-bm-global)
(defun anything-c-bm-global-init ()
"Init function for `anything-c-source-bm-global'."
(when (require 'bm nil t)
(with-no-warnings
(let ((files bm-repository)
(buf (anything-candidate-buffer 'global)))
(dolist (file files) ;ブックマークされてるファイルリストから,1つ取り出す
(dolist (bookmark (cdr (assoc 'bookmarks (cdr file)))) ;1つのファイルに対して複数のブックマークがあるので
(let ((position (cdr (assoc 'position bookmark))) ;position
(annotation (cdr (assoc 'annotation bookmark))) ;annotation
(file (car file)) ;file名を取り出す
line
str)
(setq str (with-current-buffer (find-file-noselect file) ;anything用の文字列にformat
(goto-char position)
(beginning-of-line)
(unless annotation
(setq annotation ""))
(if (string= "" line)
(setq line "<EMPTY LINE>")
(setq line (car (split-string (thing-at-point 'line) "[\n\r]"))))
(format "%s:%d: [%s]: %s\n" file (line-number-at-pos) annotation line)))
(with-current-buffer buf (insert str)))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; normal candidate ver. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar anything-c-source-bm-global-normal
'((name . "Global Bookmarks")
(candidates . anything-bm-global-candidate)
(type . file-line)))
;; (anything 'anything-c-source-bm-global)
(defun anything-bm-global-candidate ()
"Return bookmark list for `anything-c-source-bm-global'."
(when (require 'bm nil t)
(with-no-warnings
(let (candidates
(files bm-repository))
(dolist (file files) ;ブックマークされてるファイルリストから,1つ取り出す
(dolist (bookmark (cdr (assoc 'bookmarks (cdr file)))) ;1つのファイルに対して複数のブックマークがあるので
(let ((position (cdr (assoc 'position bookmark))) ;position
(annotation (cdr (assoc 'annotation bookmark))) ;annotation
(file (car file)) ;file名を取り出す
line
str)
(setq str (format "%s" (with-current-buffer (find-file-noselect file) ;anything用の文字列にformat
(goto-char position)
(beginning-of-line)
(unless annotation
(setq annotation ""))
(if (string= "" line)
(setq line "<EMPTY LINE>")
(setq line (car (split-string (thing-at-point 'line) "[\n\r]"))))
(format "%s:%d: [%s]: %s" file (line-number-at-pos) annotation line))))
(add-to-list 'candidates str))))
candidates))))
;; (anything-bm-global-candidate)
(provide 'anything-bm-global)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment