Skip to content

Instantly share code, notes, and snippets.

@peccu
Created April 1, 2010 12:43
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/351754 to your computer and use it in GitHub Desktop.
Save peccu/351754 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)
;;; Visible Bookmarks(global)
;; (install-elisp "http://cvs.savannah.gnu.org/viewvc/*checkout*/bm/bm/bm.el")
(defvar anything-c-source-bm-global
'((name . "Global Bookmarks")
(init . anything-c-bm-global-init)
(candidates-in-buffer)
;; (type . file-line))
"Needs bm.el.
http://www.nongnu.org/bm/")
(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つ取り出す
;; (message (format "file:%s" file))(sit-for 2)
;; (message (format "file:%s" (car file)))(sit-for 2)
;; (message (format "cdr:%s" (cdr file)))(sit-for 2)
;; (message (format "bookmarks:%s" (assoc 'bookmarks (cdr file))))(sit-for 2)
;; (message (format "bookmark list:%s" (cdr (assoc 'bookmarks (cdr file)))))(sit-for 2)
(dolist (bookmark (cdr (assoc 'bookmarks (cdr file)))) ;1つのファイルに対して複数のブックマークがあるので
;; (message (format "bookmark:%s" bookmark))(sit-for 5)
;; (message (format "position:%s" (assoc 'position bookmark)))(sit-for 2)
;; (message (format "annotation:%s" (assoc 'annotation bookmark)))(sit-for 2)
(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)
(when (string= "" annotation)
(setq line ""))
(if (string= "" line)
(setq line "<EMPTY LINE>")
(setq line (car (split-string (thing-at-point 'line) "[\n\r]"))))
(format "%s: %7d: [%s]: %s\n" file (line-number-at-pos) annotation line)))
;; (message (format "string:%s" str))(sit-for 2)
(with-current-buffer buf (insert str))
(pop-to-buffer buf) ;テスト中
)))))))
(anything-c-bm-global-init)
;; (anything 'anything-c-source-bm-global)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment